コード例 #1
0
        public void SearchAsync()
        {
            var client  = new WindowsUpdateClient(UpdateServer.Default);
            var results = client.SearchAsync("IsInstalled=1", CancellationToken.None).Result;

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.Updates);
            Assert.IsTrue(ToArray(results.Updates).Any());
        }
コード例 #2
0
        public void Search()
        {
            var client  = new WindowsUpdateClient(UpdateServer.Default);
            var results = client.Search("IsInstalled=1");

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.Updates);
            Assert.IsTrue(ToArray(results.Updates).Any());
        }
コード例 #3
0
        public void GetAllUpdates()
        {
            const string Criteria = "IsHidden=0 AND DeploymentAction=*";

            var client  = new WindowsUpdateClient(UpdateServer.WindowsUpdate);
            var results = client.Search(Criteria);

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.Updates);
            Assert.IsTrue(ToArray(results.Updates).Any());
        }
コード例 #4
0
        public void DownloadAsync()
        {
            var client  = new WindowsUpdateClient(UpdateServer.WindowsUpdate);
            var results = client.SearchAsync(CancellationToken.None).Result;

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.Updates);
            Assert.IsTrue(ToArray(results.Updates).Any());

            var downloadResult = client.DownloadAsync(results.Updates, CancellationToken.None).Result;

            Assert.AreEqual((int)Client.OperationResultCode.Succeeded, (int)downloadResult.ResultCode);
        }
コード例 #5
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();
                }
            }
        }