Пример #1
0
        private SolutionApplyResult VerifyUpgrade(
            string solutionName,
            AsyncOperation asyncOperation,
            Exception syncApplyException)
        {
            SolutionApplyResult result = new SolutionApplyResult();

            if (asyncOperation != null)
            {
                if ((AsyncOperation_StatusCode)asyncOperation.StatusCode.Value
                    != AsyncOperation_StatusCode.Succeeded)
                {
                    result.Success      = false;
                    result.ErrorMessage = asyncOperation.Message;
                    //return result;
                }
            }
            if (syncApplyException != null)
            {
                result.Success      = false;
                result.ErrorMessage = syncApplyException.Message;
                //return result;
            }

            string upgradeName = solutionName + "_Upgrade";

            Solution solution = GetSolution(upgradeName, new ColumnSet());

            Logger.LogVerbose("Retrieving Solution: {0}", upgradeName);

            if (solution != null)
            {
                result.Success = false;
                if (!string.IsNullOrEmpty(result.ErrorMessage))
                {
                    result.ErrorMessage = string.Format("Solution still exists after upgrade: {0}", upgradeName);
                }
            }
            else
            {
                result.Success      = true;
                result.ErrorMessage = string.Empty;
                Logger.LogVerbose("Apply Upgrade completed: {0}", upgradeName);
            }

            return(result);
        }
        public SolutionImportResult ImportSolution(
            string importFolder,
            string logsFolder,
            SolutionImportOptions options)
        {
            SolutionImportResult importResult = ImportSolution(
                $"{importFolder}\\{options.SolutionFilePath}",
                options.PublishWorkflows,
                options.ConvertToManaged,
                options.OverwriteUnmanagedCustomizations,
                options.SkipProductUpdateDependencies,
                options.HoldingSolution,
                options.OverrideSameVersion,
                options.ImportAsync,
                options.SleepInterval,
                options.AsyncWaitTimeout,
                Guid.NewGuid(),
                true,
                logsFolder,
                string.Empty);

            if (importResult.Success &&
                options.ApplySolution)
            {
                SolutionApplyResult applyResult = ApplySolution(
                    importResult.SolutionName,
                    options.ApplyAsync,
                    options.SleepInterval,
                    options.AsyncWaitTimeout);

                importResult.Success      = applyResult.Success;
                importResult.ErrorMessage = applyResult.ErrorMessage;
            }

            return(importResult);
        }
        public SolutionApplyResult ApplySolution(
            string solutionName,
            bool importAsync,
            int sleepInterval,
            int asyncWaitTimeout
            )
        {
            Logger.LogVerbose("Upgrading Solution: {0}", solutionName);

            if (SkipUpgrade(solutionName))
            {
                return(new SolutionApplyResult()
                {
                    Success = true,
                    ApplySkipped = true
                });
            }

            Exception      syncApplyException = null;
            AsyncOperation asyncOperation     = null;

            var upgradeSolutionRequest = new DeleteAndPromoteRequest
            {
                UniqueName = solutionName
            };

            if (importAsync)
            {
                var asyncRequest = new ExecuteAsyncRequest
                {
                    Request = upgradeSolutionRequest
                };

                Logger.LogVerbose("Applying using Async Mode");

                var asyncResponse = OrganizationService.Execute(asyncRequest) as ExecuteAsyncResponse;

                Guid asyncJobId = asyncResponse.AsyncJobId;

                Logger.LogInformation(string.Format("Async JobId: {0}", asyncJobId));

                Logger.LogVerbose("Awaiting for Async Operation Completion");

                AsyncOperationManager asyncOperationManager = new AsyncOperationManager(
                    Logger, PollingOrganizationService);

                asyncOperation = asyncOperationManager.AwaitCompletion(
                    asyncJobId, asyncWaitTimeout, sleepInterval, null);

                Logger.LogInformation("Async Operation completed with status: {0}",
                                      ((AsyncOperation_StatusCode)asyncOperation.StatusCode.Value).ToString());

                Logger.LogInformation("Async Operation completed with message: {0}",
                                      asyncOperation.Message);
            }
            else
            {
                try
                {
                    OrganizationService.Execute(upgradeSolutionRequest);
                }
                catch (Exception ex)
                {
                    syncApplyException = ex;
                }
            }

            SolutionApplyResult result = VerifyUpgrade(
                solutionName,
                asyncOperation,
                syncApplyException);

            if (result.Success)
            {
                Logger.LogInformation("Solution Apply Completed Successfully");
            }
            else
            {
                Logger.LogInformation("Solution Apply Failed");
            }

            return(result);
        }