コード例 #1
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));
            }
        }
コード例 #2
0
        public ComponentInstallationResult InstallNextComponent(int componentId, Version installationVersion)
        {
            var thisVersion = discovery
                              .Discover()
                              .SingleOrDefault(iv => iv.Version.CompareTo(installationVersion) == 0);

            if (thisVersion == null)
            {
                return(ComponentInstallationResult.Fail(componentId, installationVersion, "Installation version not found"));
            }

            if (!thisVersion.InstallationComponents.ContainsKey(componentId))
            {
                return(ComponentInstallationResult.Fail(componentId, installationVersion,
                                                        string.Format("Component with id {0} not found in installation version {1}", componentId, installationVersion)));
            }

            return(this.InstallComponent(componentId, thisVersion));
        }