コード例 #1
0
        public ComponentInstallationResult StartInstallation()
        {
            var currentVersion = GetCurrentVersion();
            var thisVersion    = GetNextVersion(currentVersion);

            if (thisVersion == null)
            {
                return(ComponentInstallationResult.Success(Version.Parse(CrmConstants.InitialSolutionVersion)));
            }

            var thisComponent = thisVersion.InstallationComponents[0];

            return(ComponentInstallationResult.Success(null, thisVersion.Version, 0, thisVersion.Version, thisComponent.Description));
        }
コード例 #2
0
        private ComponentInstallationResult InstallComponent(int componentId, InstallationVersion version)
        {
            var thisComponent = version.InstallationComponents[componentId];
            var nextComponent = GetNextInstallationComponent(version, componentId);

            try
            {
                dataAccessDispatcher.Dispatch(thisComponent.InstallationAction);
                dataAccessDispatcher.Dispatch(thisComponent.DataChangeAction);

                if (!nextComponent.HasValue || (nextComponent.HasValue && nextComponent.Value.Value.Version.CompareTo(version.Version) > 0))
                {
                    /* The next component is part of a newer version,
                     * so at this point we update the solution to reflect that this
                     * installation version has installed. If the solution update fails,
                     * we should rollback and fail the current component too */
                    try
                    {
                        var solution = dataAccessDispatcher.Dispatch(SolutionActions.GetSolutionByName(CrmConstants.DefaultSolutionSettings.Name));
                        solution.Version = version.Version.ToString();
                        dataAccessDispatcher.Dispatch(SolutionActions.UpdateSolution(solution));
                    }
                    catch
                    {
                        dataAccessDispatcher.Dispatch(thisComponent.RollbackAction);
                        throw;
                    }
                }

                if (nextComponent.HasValue)
                {
                    var nextComponentDescription = nextComponent.Value.Value.InstallationComponents[nextComponent.Value.Key].Description;
                    var nextComponentKey         = nextComponent.Value.Key;
                    var nextComponentVersion     = nextComponent.Value.Value.Version;

                    return(ComponentInstallationResult.Success(componentId, version.Version, nextComponentKey, nextComponentVersion, nextComponentDescription));
                }
                else
                {
                    return(ComponentInstallationResult.Success(componentId, version.Version, true));
                }
            }
            catch (Exception ex)
            {
                return(ComponentInstallationResult.Fail(componentId, version.Version, ex.Message));
            }
        }