Example #1
0
        public static void SetConfiguredVersion(string roleName, Version configuredVersion)
        {
            string keyName = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\ExchangeServer\\v15\\" + RolesUtility.GetRoleKeyByName(roleName, false);
            string text    = (string)Registry.GetValue(keyName, "ConfiguredVersion", "<unset>");

            TaskLogger.Trace("Updating configured version from {0} to {1}", new object[]
            {
                text,
                configuredVersion
            });
            Registry.SetValue(keyName, "ConfiguredVersion", configuredVersion.ToString());
            if (RolesUtility.GetPostSetupVersion(roleName) == null)
            {
                RolesUtility.SetPostSetupVersion(roleName, new Version("0.0.0.0"));
            }
            using (RegistryKey registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\ExchangeServer\\v15\\" + RolesUtility.GetRoleKeyByName(roleName, false)))
            {
                registryKey.SetValue("ConfiguredVersion", configuredVersion.ToString());
            }
        }
Example #2
0
        internal bool GenerateAndExecuteTaskScript(InstallationCircumstances installationCircumstance)
        {
            this.completedSteps = 0;
            bool flag = false;
            ConfigurationStatus configurationStatus = new ConfigurationStatus(this.taskNoun, this.InstallationMode);
            string text = string.Format("{0}-{1}", this.taskVerb, this.taskNoun);

            TaskLogger.LogEnter();
            bool          flag2         = this.ShouldExecuteComponentTasks();
            StringBuilder stringBuilder = new StringBuilder();

            List <TaskInfo> .Enumerator enumerator = default(List <TaskInfo> .Enumerator);
            this.PopulateContextVariables();
            try
            {
                string path  = string.Format("{0}-{1}.ps1", text, base.Fields["InvocationID"]);
                string text2 = Path.Combine(ConfigurationContext.Setup.SetupLoggingPath, path);
                base.WriteVerbose(Strings.WritingInformationScript(text2));
                if (this.shouldWriteLogFile)
                {
                    this.logFileStream           = new StreamWriter(text2);
                    this.logFileStream.AutoFlush = true;
                }
                this.WriteLogFile(Strings.SetupLogHeader(this.taskNoun, this.taskVerb, (DateTime)ExDateTime.Now));
                this.WriteLogFile(Strings.VariablesSection);
                if (base.ServerSettings != null)
                {
                    this.monadConnection.RunspaceProxy.SetVariable(ExchangePropertyContainer.ADServerSettingsVarName, base.ServerSettings);
                }
                this.SetRunspaceVariables();
                SortedList <string, object> sortedList = new SortedList <string, object>();
                foreach (object obj in base.Fields)
                {
                    DictionaryEntry dictionaryEntry = (DictionaryEntry)obj;
                    sortedList.Add((string)dictionaryEntry.Key, dictionaryEntry.Value);
                }
                foreach (KeyValuePair <string, object> keyValuePair in sortedList)
                {
                    string text3 = this.GenerateScriptVarCommand(keyValuePair.Key, keyValuePair.Value);
                    this.WriteLogFile(text3);
                    if (flag2)
                    {
                        this.ExecuteScript(text3, false, 0, LocalizedString.Empty);
                    }
                }
                this.FilterComponents();
                if (this.InstallationMode == InstallationModes.Uninstall)
                {
                    base.WriteVerbose(Strings.ReversingTaskList);
                    this.ComponentInfoList.Reverse();
                    foreach (SetupComponentInfo setupComponentInfo in this.ComponentInfoList)
                    {
                        setupComponentInfo.Tasks.Reverse();
                    }
                }
                List <SetupComponentInfo> .Enumerator enumerator5 = this.ComponentInfoList.GetEnumerator();
                bool flag3 = false;
                this.FindStartingTask(ref enumerator5, ref enumerator, ref flag3, this.InstallationMode, installationCircumstance);
                using (enumerator5)
                {
                    bool flag4 = true;
                    bool flag5 = true;
                    this.WriteLogFile(Strings.ComponentTaskSection);
                    this.totalSteps = this.CountStepsToBeExecuted(this.ComponentInfoList, this.InstallationMode, installationCircumstance);
                    while (flag4)
                    {
                        SetupComponentInfo setupComponentInfo2 = enumerator5.Current;
                        string             name = setupComponentInfo2.Name;
                        LocalizedString    localizedString;
                        if (string.IsNullOrEmpty(setupComponentInfo2.DescriptionId))
                        {
                            localizedString = Strings.SetupProgressGenericComponent;
                        }
                        else
                        {
                            try
                            {
                                Strings.IDs key = (Strings.IDs)Enum.Parse(typeof(Strings.IDs), setupComponentInfo2.DescriptionId, false);
                                localizedString = Strings.GetLocalizedString(key);
                            }
                            catch (ArgumentException)
                            {
                                localizedString = Strings.SetupProgressGenericComponent;
                            }
                        }
                        base.WriteVerbose(Strings.ProcessingComponent(name, localizedString));
                        this.WriteLogFile(Strings.ComponentSection(name));
                        while (flag5)
                        {
                            TaskInfo taskInfo = enumerator.Current;
                            string   task     = taskInfo.GetTask(this.InstallationMode, installationCircumstance);
                            if (string.IsNullOrEmpty(task))
                            {
                                flag5 = enumerator.MoveNext();
                            }
                            else if (!this.IsTaskIncluded(taskInfo, enumerator5.Current))
                            {
                                flag5 = enumerator.MoveNext();
                            }
                            else
                            {
                                string text4  = task;
                                string id     = taskInfo.GetID();
                                int    weight = taskInfo.GetWeight(this.InstallationMode);
                                bool   flag6  = !flag3 && taskInfo.IsFatal(this.InstallationMode);
                                flag3 = false;
                                string          description = taskInfo.GetDescription(this.InstallationMode);
                                LocalizedString localizedString2;
                                if (string.IsNullOrEmpty(description))
                                {
                                    localizedString2 = localizedString;
                                }
                                else
                                {
                                    try
                                    {
                                        Strings.IDs key2 = (Strings.IDs)Enum.Parse(typeof(Strings.IDs), description, false);
                                        localizedString2 = Strings.GetLocalizedString(key2);
                                    }
                                    catch (ArgumentException)
                                    {
                                        localizedString2 = localizedString;
                                    }
                                }
                                this.WriteLogFile(string.Format("# [ID = {0:x}, Wt = {1}, isFatal = {2}] \"{3}\"", new object[]
                                {
                                    taskInfo.GetID(),
                                    weight,
                                    flag6,
                                    localizedString2
                                }));
                                this.WriteLogFile(ExDateTime.Now + ":" + text4);
                                if (flag2)
                                {
                                    configurationStatus.Watermark = id;
                                    if (this.ImplementsResume)
                                    {
                                        RolesUtility.SetConfiguringStatus(configurationStatus);
                                    }
                                    if (!text4.Contains("\n"))
                                    {
                                        text4 = "\n\t" + text4 + "\n\n";
                                    }
                                    ExDateTime now      = ExDateTime.Now;
                                    bool       flag7    = this.ExecuteScript(text4, !flag6, weight, localizedString2);
                                    TimeSpan   timeSpan = ExDateTime.Now - now;
                                    if (ComponentInfoBasedTask.monitoredCmdlets.Contains(text.ToLowerInvariant()) && timeSpan.CompareTo(this.executionTimeThreshold) > 0)
                                    {
                                        if (taskInfo is ServicePlanTaskInfo)
                                        {
                                            ServicePlanTaskInfo servicePlanTaskInfo = (ServicePlanTaskInfo)taskInfo;
                                            stringBuilder.AppendLine(string.Format("Task {0}__{1} had execution time: {2}.", servicePlanTaskInfo.FileId, servicePlanTaskInfo.FeatureName, timeSpan.ToString()));
                                        }
                                        else
                                        {
                                            stringBuilder.AppendLine(string.Format("Task {0} had execution time: {1}.", taskInfo.GetID(), timeSpan.ToString()));
                                        }
                                    }
                                    flag = (!flag7 && flag6);
                                    if (flag)
                                    {
                                        base.WriteVerbose(new LocalizedString(string.Format("[ERROR-REFERENCE] Id={0} Component={1}", taskInfo.GetID(), taskInfo.Component)));
                                        base.WriteVerbose(Strings.HaltingExecution);
                                        break;
                                    }
                                }
                                flag5 = enumerator.MoveNext();
                            }
                        }
                        if (flag)
                        {
                            break;
                        }
                        flag4 = enumerator5.MoveNext();
                        if (flag4)
                        {
                            enumerator.Dispose();
                            enumerator = enumerator5.Current.Tasks.GetEnumerator();
                            flag5      = enumerator.MoveNext();
                        }
                    }
                    base.WriteVerbose(Strings.FinishedComponentTasks);
                }
            }
            catch (Exception ex)
            {
                base.WriteVerbose(Strings.ExceptionOccured(ex.ToString()));
                flag = true;
                this.OnHalt(ex);
                throw;
            }
            finally
            {
                if (!string.IsNullOrEmpty(stringBuilder.ToString()) && ComponentInfoBasedTask.monitoredCmdlets.Contains(text.ToLowerInvariant()))
                {
                    if (base.Fields["TenantName"] != null)
                    {
                        ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_ExecuteTaskScriptOptic, new string[]
                        {
                            text,
                            base.Fields["TenantName"].ToString(),
                            stringBuilder.ToString()
                        });
                    }
                    else if (base.Fields["OrganizationHierarchicalPath"] != null)
                    {
                        ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_ExecuteTaskScriptOptic, new string[]
                        {
                            text,
                            base.Fields["OrganizationHierarchicalPath"].ToString(),
                            stringBuilder.ToString()
                        });
                    }
                    else
                    {
                        ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_ExecuteTaskScriptOptic, new string[]
                        {
                            text,
                            string.Empty,
                            stringBuilder.ToString()
                        });
                    }
                }
                if (flag)
                {
                    if (this.IsCmdletLogEntriesEnabled)
                    {
                        ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_ComponentTaskFailed, this.GetComponentEventParameters(this.GetVerboseInformation(this.GetCmdletLogEntries())));
                    }
                    base.WriteProgress(this.Description, Strings.ProgressStatusFailed, 100);
                }
                else
                {
                    if (this.IsCmdletLogEntriesEnabled)
                    {
                        ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_ComponentTaskExecutedSuccessfully, this.GetComponentEventParameters(this.GetVerboseInformation(this.GetCmdletLogEntries())));
                    }
                    base.WriteProgress(this.Description, Strings.ProgressStatusCompleted, 100);
                    if (flag2)
                    {
                        RolesUtility.ClearConfiguringStatus(configurationStatus);
                        if (text == "Start-PostSetup")
                        {
                            foreach (string roleName in base.Fields["Roles"].ToString().Split(new char[]
                            {
                                ','
                            }))
                            {
                                RolesUtility.SetPostSetupVersion(roleName, (Version)base.Fields["TargetVersion"]);
                            }
                            RolesUtility.SetPostSetupVersion("AdminTools", (Version)base.Fields["TargetVersion"]);
                        }
                    }
                }
                if (this.logFileStream != null)
                {
                    this.logFileStream.Close();
                    this.logFileStream = null;
                }
                enumerator.Dispose();
                TaskLogger.LogExit();
            }
            return(!flag);
        }