Example #1
0
        private static IEnumerable <ExportedSolution> LoadSolutions(IEnumerable <ImportSolutionConfig> solutionConfigs)
        {
            solutionConfigs.Require(nameof(solutionConfigs));

            var solutions = new List <ExportedSolution>();

            foreach (var config in solutionConfigs)
            {
                var folder = config.SolutionFolder;
                var file   = config.SolutionFile;

                if (file.IsEmpty())
                {
                    throw new ArgumentNullException("SolutionFile", "File name is empty in config.");
                }

                var parsedPath = config.IsRegex ? ParseSolutionPath(folder, file) : Path.Combine(folder ?? ".", file);

                if (parsedPath.IsEmpty())
                {
                    throw new NotFoundException($"Solution file '{file}' could not be found.");
                }

                var solution = new ExportedSolution {
                    Data = File.ReadAllBytes(parsedPath)
                };
                var xml = GetSolutionXml(parsedPath);

                var doc = new XmlDocument();
                doc.LoadXml(xml);
                solution.SolutionName = doc.SelectSingleNode("/ImportExportXml/SolutionManifest/UniqueName")?.InnerText;
                solution.Version      = doc.SelectSingleNode("/ImportExportXml/SolutionManifest/Version")?.InnerText;
                solution.IsManaged    = doc.SelectSingleNode("/ImportExportXml/SolutionManifest/Managed")?.InnerText == "1";

                solutions.Add(solution);
            }

            return(solutions);
        }
Example #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);
        }