public override void DialogCommand() { string folder = null; var visualStudioService = ApplicationController.ResolveType(typeof(IVisualStudioService)) as IVisualStudioService; if (visualStudioService == null) { throw new NullReferenceException("visualStudioService"); } var selectedItems = visualStudioService.GetSelectedItems(); foreach (var selectedItem in selectedItems) { var solutionFolder = selectedItem as ISolutionFolder; if (solutionFolder != null) { foreach (var item in solutionFolder.ProjectItems) { if (item.FileName?.EndsWith(".zip") ?? false) { folder = item.FileFolder; break; } } } } if (folder == null) { throw new Exception("Could not find the package directory. Could not find zip file in the selected solution folder"); } var request = DeployPackageRequest.CreateForDeployPackage(folder); var uri = new UriQuery(); uri.AddObject(nameof(DeployPackageDialog.Request), request); ApplicationController.RequestNavigate("Main", typeof(DeployPackageDialog), uri); }
public async Task <Deployment> DeployPackageAsync(DeployPackageRequest request) { var queryParamValues = QueryParamValues.From( new NamedValue(nameof(request.PackageId).Decapitalize(), request.PackageId), new NamedValue(nameof(request.PackageNumber).Decapitalize(), request.PackageNumber), new NamedValue(nameof(request.ReleaseId).Decapitalize(), request.ReleaseId), new NamedValue(nameof(request.ReleaseNumber).Decapitalize(), request.ReleaseNumber), new NamedValue(nameof(request.ApplicationId).Decapitalize(), request.ApplicationId), new NamedValue(nameof(request.ApplicationName).Decapitalize(), request.ApplicationName), new NamedValue(nameof(request.ToStage).Decapitalize(), request.ToStage), new NamedValue(nameof(request.Force).Decapitalize(), request.Force.ToTrueFalse()) ); foreach (var variable in request.Variables) { queryParamValues.Add(variable.Name, variable.Value); } return(await GetReleasesApiClient("packages/deploy", queryParamValues) .PutAsync(new StringContent("")) .ReceiveJson <Deployment>()); }
private void CreateDeploymentPackage(CreatePackageRequest request, ServiceRequestController controller, CreatePackageResponse response) { var folderPath = request.FolderPath.FolderPath; var tasksDone = 0; var totalTasks = 4; var xrmRecordService = XrmRecordService; var service = xrmRecordService.XrmService; var solution = service.Retrieve(Entities.solution, new Guid(request.Solution.Id)); tasksDone++; if (solution.GetStringField(Fields.solution_.version) != request.ThisReleaseVersion) { controller.UpdateProgress(tasksDone, totalTasks, "Setting Release Version " + request.ThisReleaseVersion); solution.SetField(Fields.solution_.version, request.ThisReleaseVersion); service.Update(solution, new[] { Fields.solution_.version }); } controller.UpdateProgress(tasksDone, totalTasks, "Exporting Solution " + request.Solution.Name); var uniqueName = (string)solution.GetStringField(Fields.solution_.uniquename); var req = new ExportSolutionRequest(); req.Managed = request.ExportAsManaged; req.SolutionName = uniqueName; var exportResponse = (ExportSolutionResponse)service.Execute(req); var version = solution.GetStringField(Fields.solution_.version); var versionText = version == null ? null : version.Replace(".", "_"); var fileName = string.Format("{0}_{1}{2}.zip", uniqueName, versionText, request.ExportAsManaged ? "_managed" : null); FileUtility.WriteToFile(folderPath, fileName, exportResponse.ExportSolutionFile); ++tasksDone; if (request.DataToInclude != null && request.DataToInclude.Any()) { controller.UpdateProgress(tasksDone, totalTasks, "Exporting Data " + request.Solution.Name); var dataExportService = new ExportXmlService(xrmRecordService); dataExportService.ExportXml(request.DataToInclude, new Folder(GetDataExportFolder(folderPath)), request.IncludeNotes, request.IncludeNNRelationshipsBetweenEntities, controller.Controller); } tasksDone++; if (solution.GetStringField(Fields.solution_.version) != request.SetVersionPostRelease) { controller.UpdateProgress(tasksDone, totalTasks, "Setting New Solution Version " + request.SetVersionPostRelease); solution.SetField(Fields.solution_.version, request.SetVersionPostRelease); service.Update(solution, new[] { Fields.solution_.version }); } if (request.DeployPackageInto != null) { if (response.HasError) { throw new Exception("Package Deployment Aborted Due To Errors During Creating"); } else { var deployRequest = new DeployPackageRequest { FolderContainingPackage = request.FolderPath, Connection = request.DeployPackageInto }; var deployService = new DeployPackageService(); var deployPackageResponse = new DeployPackageResponse(); deployService.ExecuteExtention(deployRequest, deployPackageResponse, controller); response.LoadDeployPackageResponse(deployPackageResponse); } } }
public void VsixCreateAndDeployPackageTest() { //clear some stuff DeleteAll(Entities.account); DeleteAll(Entities.contact); var tempFolder = Path.Combine(TestingFolder, "TEMP"); if (Directory.Exists(tempFolder)) { FileUtility.DeleteFiles(tempFolder); FileUtility.DeleteSubFolders(tempFolder); } //create and account for the deployment package var account = CreateAccount(); var packageSettings = GetTestPackageSettings(); //set solution v2 prior to package create XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); var app = CreateAndLoadTestApplication <VsixCreatePackageModule>(); //run the dialog - including a redirect to enter the package settings first var originalConnection = HijackForPackageEntryRedirect(app); var dialog = app.NavigateToDialog <VsixCreatePackageModule, VsixCreatePackageDialog>(); VerifyPackageEntryRedirect(originalConnection, dialog); //okay no should be at the entry the create package details var packageEntry = dialog.Controller.UiItems.First() as ObjectEntryViewModel; //create package request var request = new CreatePackageRequest(); request.HideTypeAndFolder = true; request.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; app.EnterObject(request, packageEntry); //lets set explicit versions packageEntry.GetStringFieldFieldViewModel(nameof(CreatePackageRequest.ThisReleaseVersion)).Value = "3.0.0.0"; packageEntry.GetStringFieldFieldViewModel(nameof(CreatePackageRequest.SetVersionPostRelease)).Value = "4.0.0.0"; if (!packageEntry.Validate()) { throw new Exception(packageEntry.GetValidationSummary()); } packageEntry.SaveButtonViewModel.Invoke(); var createResponse = dialog.CompletionItem as ServiceResponseBase <DataImportResponseItem>; Assert.IsFalse(createResponse.HasError); //verify the files created in the solution package folder var folder = Directory.GetDirectories(Path.Combine(VisualStudioService.SolutionDirectory, "Releases")).First(); Assert.IsTrue(FileUtility.GetFiles(folder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(folder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(folder).First())).Any()); //+ the solution version changed var solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for account for recreation during import XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.Connection = packageSettings.Connections.First(); //set the package folder selected in vidsual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioSolutionFolder(folder)); //run the deployment dialog var deployTestApplication = CreateAndLoadTestApplication <VsixDeployPackageModule>(); var deployResponse = deployTestApplication.NavigateAndProcessDialog <VsixDeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(deployResponse.HasError); //verify the solution dpeloyed with updated version solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //account should be recreated account = Refresh(account); //Okay now lets just do the solution import it //set the solutoon version something XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //set the solution zip selected in visual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioProjectItem(FileUtility.GetFiles(folder).First())); //run the dialog var importSolutionRequest = new ImportSolutionRequest(); importSolutionRequest.Connection = packageSettings.Connections.First(); var importSolutionApplication = CreateAndLoadTestApplication <ImportSolutionModule>(); var importSolutionResponse = importSolutionApplication.NavigateAndProcessDialog <ImportSolutionModule, ImportSolutionDialog, ImportSolutionResponse>(importSolutionRequest); Assert.IsFalse(importSolutionResponse.HasError); //verify the solution dpeloyed with updated version Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //Okay now lets just do the records import //delete for account for recreation during import XrmService.Delete(account); //set the xml files selected VisualStudioService.SetSelectedItems(FileUtility.GetFiles(FileUtility.GetFolders(folder).First()).Select(f => new FakeVisualStudioProjectItem(f))); //run the import records dialog var importRecordsRequest = new ImportRecordsRequest(); importRecordsRequest.Connection = packageSettings.Connections.First(); var importRecordsApplication = CreateAndLoadTestApplication <ImportRecordsModule>(); var importRecordsResponse = importRecordsApplication.NavigateAndProcessDialog <ImportRecordsModule, ImportRecordsDialog, ImportRecordsResponse>(importRecordsRequest); Assert.IsFalse(importRecordsResponse.HasError); //should be recreated account = Refresh(account); }
public void VsixCreateAndDeployPackageTest() { //clear some stuff DeleteAll(Entities.account); DeleteAll(Entities.contact); var tempFolder = Path.Combine(TestingFolder, "TEMP"); if (Directory.Exists(tempFolder)) { FileUtility.DeleteFiles(tempFolder); FileUtility.DeleteSubFolders(tempFolder); } //create and account for the deployment package var account = CreateAccount(); var packageSettings = GetTestPackageSettings(); //set solution v2 prior to package create XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //run create package dialog var request = CreatePackageRequest.CreateForCreatePackage(tempFolder, packageSettings.Solution); request.ThisReleaseVersion = "3.0.0.0"; request.SetVersionPostRelease = "4.0.0.0"; request.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; var createTestApplication = CreateAndLoadTestApplication <VsixCreatePackageModule>(); var createResponse = createTestApplication.NavigateAndProcessDialog <VsixCreatePackageModule, VsixCreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(request); Assert.IsFalse(createResponse.HasError); //verify the files created in the solution package folder var folder = Directory.GetDirectories(Path.Combine(VisualStudioService.SolutionDirectory, "Releases")).First(); Assert.IsTrue(FileUtility.GetFiles(folder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(folder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(folder).First())).Any()); //+ the solution version changed var solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for account for recreation during import XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.Connection = packageSettings.Connections.First(); //set the package folder selected in vidsual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioSolutionFolder(folder)); //run the deployment dialog var deployTestApplication = CreateAndLoadTestApplication <VsixDeployPackageModule>(); var deployResponse = deployTestApplication.NavigateAndProcessDialog <VsixDeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(deployResponse.HasError); //verify the solution dpeloyed with updated version solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //account should be recreated account = Refresh(account); //Okay now lets just do the solution import it //set the solutoon version something XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //set the solution zip selected in visual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioProjectItem(FileUtility.GetFiles(folder).First())); //run the dialog var importSolutionRequest = new ImportSolutionRequest(); importSolutionRequest.Connection = packageSettings.Connections.First(); var importSolutionApplication = CreateAndLoadTestApplication <ImportSolutionModule>(); var importSolutionResponse = importSolutionApplication.NavigateAndProcessDialog <ImportSolutionModule, ImportSolutionDialog, ImportSolutionResponse>(importSolutionRequest); Assert.IsFalse(importSolutionResponse.HasError); //verify the solution dpeloyed with updated version Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //Okay now lets just do the records import //delete for account for recreation during import XrmService.Delete(account); //set the xml files selected VisualStudioService.SetSelectedItems(FileUtility.GetFiles(FileUtility.GetFolders(folder).First()).Select(f => new FakeVisualStudioProjectItem(f))); //run the import records dialog var importRecordsRequest = new ImportRecordsRequest(); importRecordsRequest.Connection = packageSettings.Connections.First(); var importRecordsApplication = CreateAndLoadTestApplication <ImportRecordsModule>(); var importRecordsResponse = importRecordsApplication.NavigateAndProcessDialog <ImportRecordsModule, ImportRecordsDialog, ImportRecordsResponse>(importRecordsRequest); Assert.IsFalse(importRecordsResponse.HasError); //should be recreated account = Refresh(account); }
public override void DialogCommand() { string solutionFolderPath = null; var visualStudioService = ApplicationController.ResolveType(typeof(IVisualStudioService)) as IVisualStudioService; if (visualStudioService == null) { throw new NullReferenceException("visualStudioService"); } var selectedItems = visualStudioService.GetSelectedItems(); foreach (var selectedItem in selectedItems) { var solutionFolder = selectedItem as ISolutionFolder; if (solutionFolder != null) { var parentFolderName = solutionFolder.ParentProjectName; solutionFolderPath = Path.Combine(visualStudioService.SolutionDirectory, parentFolderName, solutionFolder.Name); foreach (var item in solutionFolder.ProjectItems) { if (item.FileName?.EndsWith(".zip") ?? false) { if (item.FileFolder?.Replace("\\\\", "\\") != solutionFolderPath?.Replace("\\\\", "\\")) { throw new Exception($"The Zip File In the Package Folder Is In An Unexpected Directory. You Will Need To Move It Into A Matching Folder Path For The Solution Folder. The Expected Path Was {solutionFolderPath}, The Actual path Is {item.FileFolder}"); } } } var isDataFolderInVs = false; var dataFolderOnDisk = Path.Combine(solutionFolderPath, "Data"); foreach (var item in solutionFolder.SubFolders) { if (item.Name == "Data") { isDataFolderInVs = true; var filesInSolutionFolder = item .ProjectItems .Select(pi => pi.FileName?.Replace("\\\\", "\\")) .OrderBy(s => s) .ToArray(); var filesOnDisk = Directory.Exists(dataFolderOnDisk) ? FileUtility.GetFiles(dataFolderOnDisk) .Select(s => s?.Replace("\\\\", "\\")) .OrderBy(s => s) .ToArray() : new string[0]; var itemsOnDiskNotInVs = filesOnDisk.Except(filesInSolutionFolder).ToArray(); if (itemsOnDiskNotInVs.Any()) { throw new Exception($"At Least One Data File On Disk Is Not In The Visual Studio Solution Folder. For The Deployment Process To Run All Files In The Matching Directory On Disk Must Be Added In The Visual Studio Solution Folder. The First Unexpected Item On Disk Is {itemsOnDiskNotInVs.First()}"); } var itemsInVsNotOnDisk = filesInSolutionFolder.Except(filesOnDisk).ToArray(); if (itemsInVsNotOnDisk.Any()) { throw new Exception($"At Least One Of The Data Files In The Visual Studio Folder Is Not In The Correct Folder On Disk. For The Deployment Process To Run All Items In The Deployment Must Be In A Matching Directory For The Visual Studio Folder. The First Unexpected Item Is Located At {itemsInVsNotOnDisk.First()}"); } } } if (!isDataFolderInVs && Directory.Exists(dataFolderOnDisk) && FileUtility.GetFiles(dataFolderOnDisk).Any()) { throw new Exception($"There Is A Data Folder On Disk With Items Within The Solution Package Directory, But Those Items Are Not Added In The Visual Studio Release Folder. For The Deployment Process To Run All Items On Disk Within The Folder Must Be In Added In The Visual Studio Folder. The First Unexpected Item Is Located At {FileUtility.GetFiles(dataFolderOnDisk).First()}"); } } } if (solutionFolderPath == null) { throw new Exception("Could not find the package directory"); } var request = DeployPackageRequest.CreateForDeployPackage(solutionFolderPath); var uri = new UriQuery(); uri.AddObject(nameof(DeployPackageDialog.Request), request); ApplicationController.NavigateTo(typeof(DeployPackageDialog), uri); }
public void DeploymentCreateAndDeployPackageModuleTest() { DeleteAll(Entities.account); DeleteAll(Entities.contact); var account = CreateAccount(); var solution = XrmRecordService.GetFirst("solution", XrmRecordService.GetPrimaryField("solution"), "Test Components"); Assert.IsNotNull(solution); FileUtility.DeleteFiles(TestingFolder); var createDeploymentPackageRequest = new CreatePackageRequest(); createDeploymentPackageRequest.FolderPath = new Folder(TestingFolder); createDeploymentPackageRequest.Solution = solution.ToLookup(); createDeploymentPackageRequest.ThisReleaseVersion = "3.0.0.0"; createDeploymentPackageRequest.SetVersionPostRelease = "4.0.0.0"; createDeploymentPackageRequest.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords, }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; var createApplication = CreateAndLoadTestApplication <CreatePackageModule>(); var response = createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.IsFalse(response.HasError); Assert.IsTrue(FileUtility.GetFiles(TestingFolder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(TestingFolder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(TestingFolder).First())).Any()); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for recreation XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.FolderContainingPackage = new Folder(TestingFolder); deployRequest.Connection = GetSavedXrmRecordConfiguration(); var deployApplication = CreateAndLoadTestApplication <DeployPackageModule>(); response = deployApplication.NavigateAndProcessDialog <DeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(response.HasError); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //should be recreated account = Refresh(account); createDeploymentPackageRequest = new CreatePackageRequest(); createDeploymentPackageRequest.FolderPath = new Folder(TestingFolder); createDeploymentPackageRequest.Solution = solution.ToLookup(); createDeploymentPackageRequest.ThisReleaseVersion = "3.0.0.0"; createDeploymentPackageRequest.SetVersionPostRelease = "4.0.0.0"; createDeploymentPackageRequest.DeployPackageInto = GetSavedXrmRecordConfiguration(); createDeploymentPackageRequest.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; //error if already .zips on the folder FileUtility.WriteToFile(TestingFolder, "Fake.zip", "FakeContent"); createApplication = CreateAndLoadTestApplication <CreatePackageModule>(); try { createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.Fail(); } catch (Exception ex) { Assert.IsFalse(ex is AssertFailedException); } FileUtility.DeleteFiles(TestingFolder); FileUtility.DeleteSubFolders(TestingFolder); response = createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.IsFalse(response.HasError); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); }