You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SolutionService.cs 4.7KB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using SIE.IVSDK.Services;
  2. using SIE.VSDK.Exceptions.DirectoryDestination;
  3. using SIE.VSDK.Exceptions.Solution;
  4. using SIE.VSDK.Extensions;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. namespace SIE.VSDK.Services
  8. {
  9. public class SolutionService : ISolutionService
  10. {
  11. private readonly IPathService _pathService;
  12. public SolutionService(IPathService pathService)
  13. {
  14. _pathService = pathService;
  15. }
  16. public void CreateProjectTemplatesFromSolution(string solutionPath, string directoryDestinationPath, string newSolutionName)
  17. {
  18. if(solutionPath==null)
  19. {
  20. throw new SolutionPathIsNullException($"Le chemin de la solution {Path.GetFileName(solutionPath)} ne doit pas être null !");
  21. }
  22. if(solutionPath.Trim() == string.Empty)
  23. {
  24. throw new SolutionPathIsEmptyException($"Le chemin de la solution {Path.GetFileName(solutionPath)} ne doit pas être vide !");
  25. }
  26. if (!_pathService.IsValidPath(solutionPath))
  27. {
  28. throw new InvalidSolutionPathException($"Le chemin de la solution {Path.GetFileName(solutionPath)} n'est pas valide !");
  29. }
  30. if (Path.GetExtension(solutionPath) != ".sln")
  31. {
  32. throw new ExtensionSolutionPathException($"Le chemin de la solution {Path.GetFileName(solutionPath)} doit être d'extension .sln !");
  33. }
  34. if (!File.Exists(solutionPath))
  35. {
  36. throw new SolutionPathIsNotAFileException($"Le chemin de la solution {Path.GetFileName(solutionPath)} doit être un fichier existant!");
  37. }
  38. if(directoryDestinationPath ==null)
  39. {
  40. throw new DirectoryDestinationIsNullException($"Le chemin de destination {directoryDestinationPath} ne doit pas être null !");
  41. }
  42. if(directoryDestinationPath.Trim()==string.Empty)
  43. {
  44. throw new DirectoryDestinationIsEmptyException($"Le chemin de destination {directoryDestinationPath} ne doit pas être vide !");
  45. }
  46. if(!_pathService.IsValidPath(directoryDestinationPath))
  47. {
  48. throw new InvalideDirectoryDestinationException($"Le chemin de destination {directoryDestinationPath} n'est pas valide !");
  49. }
  50. if(!Directory.Exists(directoryDestinationPath))
  51. {
  52. throw new DirectoryDestinationNotFoundException($"Le dossier de destination {directoryDestinationPath} n'existe pas!");
  53. }
  54. if (newSolutionName == null)
  55. {
  56. throw new NewSolutionIsNullException("Le nom de la nouvelle solution est null");
  57. }
  58. if (newSolutionName.Trim() == string.Empty)
  59. {
  60. throw new NewSolutionIsEmptyException("Le nom de la nouvelle solution est vide");
  61. }
  62. if (Path.GetExtension(newSolutionName) != ".sln")
  63. {
  64. throw new ExtensionNewSolutionException($"Le nom de la nouvelle solution {newSolutionName} doit être de type .sln !");
  65. }
  66. string VSDK_ECOLOCALE_directory = Path.Combine(directoryDestinationPath, "VSDK_ECOLOCALE");
  67. if (!Directory.Exists(VSDK_ECOLOCALE_directory))
  68. {
  69. Directory.CreateDirectory(VSDK_ECOLOCALE_directory);
  70. }
  71. string TMP_TEMPLATE_directory = Path.Combine(VSDK_ECOLOCALE_directory, "TMP_TEMPLATE");
  72. if (!Directory.Exists(TMP_TEMPLATE_directory))
  73. {
  74. Directory.CreateDirectory(TMP_TEMPLATE_directory);
  75. }
  76. string TMP_SLN_directory = Path.Combine(TMP_TEMPLATE_directory, Path.GetFileNameWithoutExtension(newSolutionName));
  77. if (!Directory.Exists(TMP_SLN_directory))
  78. {
  79. Directory.CreateDirectory(TMP_SLN_directory);
  80. }
  81. DirectoryInfo sourceDir = new DirectoryInfo(Path.GetDirectoryName(solutionPath));
  82. sourceDir.DeepCopy(TMP_SLN_directory);
  83. string oldName = Path.Combine(TMP_SLN_directory, Path.GetFileName(solutionPath));
  84. File.Delete(oldName);
  85. sourceDir = new DirectoryInfo(Path.GetDirectoryName(TMP_SLN_directory));
  86. List<string> csProjFiles = sourceDir.GetCsProjFiles();
  87. }
  88. }
  89. }