예제 #1
0
        private static ExportedSolution RetrieveSolution(SolutionConfig solutionConfig,
                                                         IEnhancedOrgService service)
        {
            solutionConfig.Require(nameof(solutionConfig));
            service.Require(nameof(service));

            var version = RetrieveSolutionVersion(solutionConfig.SolutionName, service);

            if (string.IsNullOrWhiteSpace(version))
            {
                throw new NotFoundException($"Couldn't retrieve solution version of solution"
                                            + $" '{solutionConfig.SolutionName}'.");
            }

            var request =
                new ExportSolutionRequest
            {
                Managed      = solutionConfig.IsManaged,
                SolutionName = solutionConfig.SolutionName
            };

            log.Log($"Exporting solution '{solutionConfig.SolutionName}'...");
            var response = (ExportSolutionResponse)service.Execute(request);

            log.Log($"Exported!");

            var exportXml = response.ExportSolutionFile;

            return(new ExportedSolution
            {
                SolutionName = solutionConfig.SolutionName,
                Version = version,
                IsManaged = solutionConfig.IsManaged,
                Data = exportXml
            });
        }
예제 #2
0
        private static bool ImportSolution(ExportedSolution solution, IEnhancedOrgService service)
        {
            solution.Require(nameof(solution));
            service.Require(nameof(service));

            var importJobId = Guid.NewGuid();

            var request =
                new ExecuteAsyncRequest
            {
                Request =
                    new ImportSolutionRequest
                {
                    CustomizationFile = solution.Data,
                    ConvertToManaged  = solution.IsManaged,
                    OverwriteUnmanagedCustomizations = false,
                    PublishWorkflows = true,
                    SkipProductUpdateDependencies = true,
                    ImportJobId = importJobId
                }
            };

            log.Log($"Importing solution '{solution.SolutionName}' ...");

            service.Execute(request);

            MonitorJobProgress(service, importJobId);

            var job = service.Retrieve("importjob", importJobId,
                                       new ColumnSet(ImportJob.Fields.Progress, ImportJob.Fields.Data))
                      .ToEntity <ImportJob>();

            var importXmlLog = job.GetAttributeValue <string>("data");

            if (importXmlLog.IsNotEmpty())
            {
                var isFailed = ProcessErrorXml(importXmlLog);

                if (isFailed)
                {
                    return(false);
                }
            }

            log.Log($"Imported!");
            log.Log("Publishing customisations ...");

            for (var i = 0; i < 3; i++)
            {
                Thread.Sleep(5000);

                try
                {
                    service.Execute(new PublishAllXmlRequest());
                    log.Log("Finished publishing customisations.");
                    break;
                }
                catch (Exception e)
                {
                    log.Log(e);

                    if (i < 2)
                    {
                        log.LogWarning("Retrying publish ...");
                    }
                }
            }

            return(true);
        }