Esempio n. 1
0
        private void readCentralConfiguration()
        {
            mRetryCount++;

            string xmlData = null;

            Logger.Debug("Reading central configuration.");

            try
            {
                xmlData = WebHttpClient.GetResponse(LocalConfig.ConfigurationFileUrl);
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to read central configuration " + LocalConfig.ConfigurationFileUrl, ex);
                WindowsTaskHandler.WriteEventLog(Constants.CEventLogId, EventLogEntryType.Warning, Constants.CEventLogFailedToRetrieveCentralConfiguration);
            }

            if (!string.IsNullOrEmpty(xmlData))
            {
                mRetryCount = 0;
                var serializer = new Serialization <CustomerConfigurationsFile>();
                mCentralConfiguration = serializer.GetObjectFromXml(xmlData).FirstOrDefault(cc => cc.CustomerName.Equals(mCustomerName, StringComparison.InvariantCultureIgnoreCase));
            }
            else
            {
                if (mRetryCount == LocalConfig.ReadConfigFileRetryCount)
                {
                    mCentralConfiguration = null;
                    mRetryCount           = 0;
                }

                if (mCentralConfiguration == null)
                {
                    throw new Exception("Could not read central configuration file.");
                }
            }
        }
Esempio n. 2
0
        private void reportUpdateInstallationStatus(UpdateInstallationLog updateLog, bool isCurrent)
        {
            Logger.Debug("Update log:");

            var sortedUpdateLog = UpdateInstallationLog.Create(updateLog.OrderBy(log => log.UpdateInstallationStatus));

            foreach (var updateInstallationLogEntry in sortedUpdateLog)
            {
                log(updateInstallationLogEntry);
                Reporter.ReportStatus(updateInstallationLogEntry);
            }

            bool success = commitWithRetry();

            if (!success)
            {
                Logger.Debug("Writing event log: " + Constants.CEventLogFailedToWriteToDatabase);
                WindowsTaskHandler.WriteEventLog(Constants.CEventLogId, EventLogEntryType.Warning, Constants.CEventLogFailedToWriteToDatabase);
            }

            if (isCurrent)
            {
                if (!success)
                {
                    saveReport(sortedUpdateLog);
                }
            }
            else
            {
                if (success)
                {
                    deleteReport();
                }
            }

            Logger.Debug("Finished reporting installation status.");
        }
Esempio n. 3
0
        private void runUpdateProcedure()
        {
            lock (mSyncObject)
            {
                try
                {
                    Logger.Debug("START runUpdateProcedure");

                    mInactivated = false;

                    mStopServiceEvent.Reset();

                    logSystemInfo();

                    readLocalConfiguration();
                    readCentralConfiguration();
                    getExcludedUpdates();

                    if (mCentralConfiguration == null)
                    {
                        Logger.DebugFormat("Going idle - Customer name '{0}' was not found in the CustomerConfigurations section.", LocalConfig.CustomerName);
                        inactivate();
                        return;
                    }

                    if (isServerInExclusionList())
                    {
                        Logger.Debug("Going idle - Server is present in exclusion list.");
                        inactivate();
                        return;
                    }

                    if (!isWithinMaintenanceTimeFrame())
                    {
                        Logger.Debug("Going idle - Not within maintenance timeframe.");
                        inactivate();
                        return;
                    }

                    trySendSavedReports();

                    Logger.Debug("Fetching available updates.");
                    IUpdateCollection updates = WindowsUpdateClient.GetAvailableUpdates();

                    if (updates == null || updates.Count == 0)
                    {
                        Logger.Debug("Going idle - No updates retrieved from WUA.");
                        inactivate();
                        return;
                    }

                    var updatesToInstall = new UpdateCollectionClass();
                    var excludedUpdates  = new UpdateCollectionClass();

                    for (int i = 0; i < updates.Count; i++)
                    {
                        IUpdate update = updates[i];
                        if (!isUpdateExcluded(update))
                        {
                            updatesToInstall.Add(update);
                        }
                        else
                        {
                            excludedUpdates.Add(update);
                        }
                    }

                    if (updatesToInstall.Count == 0)
                    {
                        if (excludedUpdates.Count > 0)
                        {
                            var entries = UpdateInstallationLog.CreateExcludedLogEntries(excludedUpdates);
                            var log     = UpdateInstallationLog.Create(entries);
                            reportUpdateInstallationStatus(log, true);
                        }
                        Logger.Debug("Going idle - No new updates found.");
                        inactivate();
                        return;
                    }

                    Logger.Debug("Writing event log and monitoring API call.");
                    WindowsTaskHandler.WriteEventLog(Constants.CEventLogId, Constants.CEventLogDescription);
                    WindowsTaskHandler.CallMonitoringApi();

                    Logger.Debug("Installing updates.");
                    Result result = WindowsUpdateClient.InstallUpdates(updatesToInstall);

                    // add excluded updates to result
                    var excludedEntries = UpdateInstallationLog.CreateExcludedLogEntries(excludedUpdates);
                    result.UpdateInstallationLog.AddRange(excludedEntries);

                    reportStatus(result);

                    if (result.InstallationResult.RebootRequired)
                    {
                        Logger.Debug("Rebooting system.");
                        WindowsTaskHandler.RebootSystem();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                finally
                {
                    if (!mInactivated)
                    {
                        inactivate();
                    }

                    Logger.Debug("FINISH runUpdateProcedure");
                    mStopServiceEvent.Set();
                }
            }
        }