public void Should_CallCompletedCallback_When_DownloadCompletes()
        {
            ManualResetEvent callbackSignal = new ManualResetEvent(false);
            IDownloadResult  result         = null;

            WuStateDownloading.DownloadCompletedCallback callback = (x, u) => { result = x; callbackSignal.Set(); };
            IUpdateCollection updates = new UpdateCollectionFake();

            Dictionary <OperationResultCode, UpdateDownloaderFake> downloaders = new Dictionary <OperationResultCode, UpdateDownloaderFake>();

            downloaders.Add(OperationResultCode.orcAborted, GetDownloaderWithResultCode(OperationResultCode.orcAborted));
            downloaders.Add(OperationResultCode.orcFailed, GetDownloaderWithResultCode(OperationResultCode.orcFailed));
            downloaders.Add(OperationResultCode.orcSucceeded, GetDownloaderWithResultCode(OperationResultCode.orcSucceeded));
            downloaders.Add(OperationResultCode.orcSucceededWithErrors, GetDownloaderWithResultCode(OperationResultCode.orcSucceededWithErrors));

            foreach (var downloader in downloaders)
            {
                callbackSignal.Reset();
                result = null;
                var downloading = new WuStateDownloading(downloader.Value, updates, callback, _defaultTimeout, null, 100);
                downloading.EnterState(new WuStateReady());

                if (!callbackSignal.WaitOne(1000))
                {
                    Assert.Fail($"callback was not called");
                }
                Assert.AreEqual(result.ResultCode, downloader.Key);
            }
        }
Ejemplo n.º 2
0
        protected void OnUpdatesDownloaded(IDownloadJob downloadJob, bool Install)
        {
            if (downloadJob != mDownloadJob)
            {
                return;
            }
            mDownloadJob = null;
            mCallback    = null;

            IDownloadResult DownloadResults = null;

            try
            {
                DownloadResults = mDownloader.EndDownload(downloadJob);
            }
            catch (Exception err)
            {
                AppLog.Line(Program.fmt("Downloading updates failed, Error: {0}", err.Message));
                OnFinished(false);
                return;
            }

            AppLog.Line(Program.fmt("Updates downloaded to %windir%\\SoftwareDistribution\\Download"));

            if (Install)
            {
                InstallUpdates(downloadJob.Updates);
            }
            else
            {
                OnFinished(true);
            }
        }
Ejemplo n.º 3
0
        protected void OnUpdatesDownloaded(IDownloadJob downloadJob, List <MsUpdate> Updates)
        {
            if (downloadJob != mDownloadJob)
            {
                return;
            }
            mDownloadJob = null;
            mCallback    = null;

            IDownloadResult DownloadResults = null;

            try
            {
                DownloadResults = mDownloader.EndDownload(downloadJob);
            }
            catch (Exception err)
            {
                AppLog.Line("Downloading updates failed");
                LogError(err);
                OnFinished(false);
                return;
            }

            OnUpdatesChanged();

            if (mCurOperation == AgentOperation.PreparingUpdates)
            {
                InstallUpdates(Updates);
            }
            else
            {
                AppLog.Line("Updates downloaded to %windir%\\SoftwareDistribution\\Download");
                OnFinished(DownloadResults.ResultCode == OperationResultCode.orcSucceeded);
            }
        }
        /// <summary>
        /// Callback for completed download operations.
        /// </summary>
        private void EndDownloadUpdates(IDownloadResult result, IUpdateCollection updates)
        {
            Log.Debug("Download result callback received: " + result.ResultCode.ToString("G"));
            using (ll.Lock(StateLock))
            {
                switch (result.ResultCode)
                {
                case OperationResultCode.orcSucceeded:
                    EnterStateWhenAllowed(new WuStateDownloadCompleted(updates, result.HResult));
                    break;

                case OperationResultCode.orcSucceededWithErrors:
                    EnterStateWhenAllowed(new WuStateDownloadPartiallyFailed(null, "Could not download all updates: HResult " + result.HResult));
                    break;

                default:
                    if (_currentState is WuStateDownloadFailed)
                    {
                        return;
                    }
                    EnterStateWhenAllowed(new WuStateDownloadFailed(null, "Could not download updates: HResult" + result.HResult));
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        protected void OnUpdatesDownloaded(IDownloadJob downloadJob, List <MsUpdate> Updates)
        {
            if (downloadJob != mDownloadJob)
            {
                return;
            }
            mDownloadJob = null;
            mCallback    = null;

            IDownloadResult DownloadResults = null;

            try
            {
                DownloadResults = mDownloader.EndDownload(downloadJob);
            }
            catch (Exception err)
            {
                AppLog.Line("Downloading updates failed");
                LogError(err);
                OnFinished(RetCodes.InternalError);
                return;
            }

            OnUpdatesChanged();

            if (mCurOperation == AgentOperation.PreparingUpdates)
            {
                RetCodes ret = InstallUpdates(Updates);
                if (ret <= 0)
                {
                    OnFinished(ret);
                }
            }
            else
            {
                AppLog.Line("Updates downloaded to %windir%\\SoftwareDistribution\\Download");

                RetCodes ret = RetCodes.Undefined;
                if (DownloadResults.ResultCode == OperationResultCode.orcSucceeded || DownloadResults.ResultCode == OperationResultCode.orcSucceededWithErrors)
                {
                    ret = RetCodes.Success;
                }
                else if (DownloadResults.ResultCode == OperationResultCode.orcAborted)
                {
                    ret = RetCodes.Abborted;
                }
                else if (DownloadResults.ResultCode == OperationResultCode.orcFailed)
                {
                    ret = RetCodes.InternalError;
                }
                OnFinished(ret);
            }
        }
        public static UpdateCollection DownloadUpdates()
        {
            UpdateSession    UpdateSession      = new UpdateSession();
            IUpdateSearcher  SearchUpdates      = UpdateSession.CreateUpdateSearcher();
            ISearchResult    UpdateSearchResult = SearchUpdates.Search("IsInstalled=0 and IsPresent=0");
            UpdateCollection UpdateCollection   = new UpdateCollection();

            //Accept Eula code for each update
            for (int i = 0; i < UpdateSearchResult.Updates.Count; i++)
            {
                IUpdate Updates = UpdateSearchResult.Updates[i];
                if (Updates.EulaAccepted == false)
                {
                    Updates.AcceptEula();
                }
                UpdateCollection.Add(Updates);
            }
            //Accept Eula ends here
            //if it is zero i am not sure if it will trow an exception -- I havent tested it.
            if (UpdateSearchResult.Updates.Count > 0)
            {
                UpdateCollection DownloadCollection = new UpdateCollection();
                UpdateDownloader Downloader         = UpdateSession.CreateUpdateDownloader();

                for (int i = 0; i < UpdateCollection.Count; i++)
                {
                    DownloadCollection.Add(UpdateCollection[i]);
                }

                Downloader.Updates = DownloadCollection;
                Console.WriteLine("Downloading Updates... This may take several minutes.");


                IDownloadResult  DownloadResult    = Downloader.Download();
                UpdateCollection InstallCollection = new UpdateCollection();
                for (int i = 0; i < UpdateCollection.Count; i++)
                {
                    if (DownloadCollection[i].IsDownloaded)
                    {
                        InstallCollection.Add(DownloadCollection[i]);
                    }
                }
                Console.WriteLine("Download Finished");
                return(InstallCollection);
            }
            else
            {
                return(UpdateCollection);
            }
        }
Ejemplo n.º 7
0
        private void DownloadPatches(UpdateSession session, List <IUpdate5> updates)
        {
            Log($"Downloading {updates.Count} patches...");

            foreach (IUpdate5 update in updates.OrderBy(u => u.Title))
            {
                if (update.IsDownloaded)
                {
                    Log($"Patch is already downloaded: {update.Title}");
                    continue;
                }


                UpdateCollection updateCollection = new UpdateCollection();
                updateCollection.Add(update);

                UpdateDownloader downloader = session.CreateUpdateDownloader();
                downloader.Updates = updateCollection;

                bool downloaded = false;

                for (int tries = 0; tries < 3 && !downloaded; tries++)
                {
                    try
                    {
                        string printtry = tries > 0 ? $" (try {(tries + 1)})" : string.Empty;

                        Log($"Downloading {printtry}: {update.Title}: {GetPrintSize(update.MaxDownloadSize)} MB.");

                        IDownloadResult downloadresult = downloader.Download();
                        if (downloadresult.ResultCode == OperationResultCode.orcSucceeded)
                        {
                            downloaded = true;
                        }
                        else
                        {
                            Log($"Couldn't download patch: {downloadresult.ResultCode}: 0x{downloadresult.HResult:X)}");
                        }
                    }
                    catch (COMException ex)
                    {
                        Log($"Couldn't download patch: 0x{ex.HResult:X)}");
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void DownloadPatches(UpdateSession session, List <IUpdate5> updates, Stream output)
        {
            Bender.WriteLine("Downloading " + updates.Count + " patches...", output);

            foreach (IUpdate5 update in updates.OrderBy(u => u.Title))
            {
                if (update.IsDownloaded)
                {
                    Bender.WriteLine("Patch is already downloaded: " + update.Title, output);
                    continue;
                }


                UpdateCollection updateCollection = new UpdateCollection();
                updateCollection.Add(update);

                UpdateDownloader downloader = session.CreateUpdateDownloader();
                downloader.Updates = updateCollection;

                bool downloaded = false;

                for (int tries = 0; tries < 3 && !downloaded; tries++)
                {
                    try
                    {
                        string printtry = tries > 0 ? " (try " + (tries + 1) + ")" : string.Empty;

                        Bender.WriteLine("Downloading" + printtry + ": " + update.Title + ": " + GetPrintSize(update.MaxDownloadSize) + " MB.", output);

                        IDownloadResult downloadresult = downloader.Download();
                        if (downloadresult.ResultCode == OperationResultCode.orcSucceeded)
                        {
                            downloaded = true;
                        }
                        else
                        {
                            Bender.WriteLine("Couldn't download patch: " + downloadresult.ResultCode + ": 0x" + downloadresult.HResult.ToString("X"), output);
                        }
                    }
                    catch (COMException ex)
                    {
                        Bender.WriteLine("Couldn't download patch: 0x" + ex.HResult.ToString("X"), output);
                    }
                }
            }
        }
 public void iDownloadComplete()
 {
     iDownloadResult = iUpdateDownloader.EndDownload(iDownloadJob);
     if (iDownloadResult.ResultCode == OperationResultCode.orcSucceeded)
     {
         this.toolStripStatusLabel1.Text = "Installing Updates...";
         iInstallation();
     }
     else
     {
         string            message = "The Download has failed: " + iDownloadResult.ResultCode + ". Please check your     internet connection then Re-Start the application.";
         string            caption = "Download Failed!";
         MessageBoxButtons buttons = MessageBoxButtons.OK;
         MessageBoxIcon    icon    = MessageBoxIcon.Error;
         MessageBox.Show(message, caption, buttons, icon);
         Application.Exit();
     }
 }
Ejemplo n.º 10
0
        void DownloadComplete()
        {
            _downloadResult = _updateDownloader.EndDownload(_downloadJob);

            _downloadJob = null;

            if (_downloadResult.ResultCode == OperationResultCode.orcSucceeded ||
                _downloadResult.ResultCode == OperationResultCode.orcSucceededWithErrors)
            {
                this.ShowProgressMessage("progress_download", "");

                if (_downloadResult.ResultCode == OperationResultCode.orcSucceeded)
                {
                    this.AppendString("下载完成。\r\n");
                }
                else
                {
                    this.AppendString("下载部分完成,部分出错。\r\n");
                }

#if NO
                DialogResult result = MessageBox.Show(this,
                                                      "要安装这些更新么?",
                                                      "WindowsUpdateDialog",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button2);
                if (result == System.Windows.Forms.DialogResult.No)
                {
                    OnAllComplete();
                    return;
                }
#endif

                BeginInstallation();
            }
            else
            {
                this.AppendString("下载更新失败。错误码: " + _downloadResult.ResultCode);
                // 全部结束
                OnAllComplete();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     The <see cref="Execute(CodeActivityContext)"/> method inherited from <see cref="CodeActivity{TResult}"/>.
        /// </summary>
        /// <param name="context">The current <see cref="CodeActivity"/> context.</param>
        /// <returns>A DateTime object.</returns>
        /// <inheritdoc cref="SwedishCodeActivity{T}"/>
        protected override object Execute(CodeActivityContext context)
        {
            UpdateSession   updateSession  = new UpdateSession();
            IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher();

            try
            {
                ISearchResult searchResult = updateSearcher.Search("IsInstalled=0 And IsHidden=0");
                foreach (IUpdate update in searchResult.Updates)
                {
                    if (update.EulaAccepted == false)
                    {
                        update.AcceptEula();
                    }
                }

                UpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader();
                updateDownloader.Priority = DownloadPriority.dpHigh;
                updateDownloader.Updates  = searchResult.Updates;
                IDownloadResult downloadResult = updateDownloader.Download();
                while (downloadResult.ResultCode == OperationResultCode.orcInProgress)
                {
                    Thread.Sleep(10);
                }

                // Check that the updates downloaded successfully.
                if (downloadResult.ResultCode == OperationResultCode.orcSucceeded || downloadResult.ResultCode == OperationResultCode.orcSucceededWithErrors)
                {
                    UpdateCollection updateCollection = new UpdateCollection();
                    foreach (IUpdate update in searchResult.Updates)
                    {
                        if (update.IsDownloaded)
                        {
                            updateCollection.Add(update);
                        }
                    }

                    IUpdateInstaller updateInstaller = updateSession.CreateUpdateInstaller();
                    updateInstaller.Updates = updateCollection;
                    IInstallationResult installationResult = updateInstaller.Install();
                    if (installationResult.ResultCode == OperationResultCode.orcSucceeded || installationResult.ResultCode == OperationResultCode.orcSucceededWithErrors)
                    {
                        if (installationResult.RebootRequired)
                        {
                            // Restart the system.
                            // For the reason these particular flags are used, see: https://docs.microsoft.com/en-us/windows/desktop/Shutdown/system-shutdown-reason-codes
                            InitiateSystemShutdownEx(null, null, 0, true, true, ShutdownReason.SHTDN_REASON_MAJOR_OPERATINGSYSTEM | ShutdownReason.SHTDN_REASON_MINOR_HOTFIX | ShutdownReason.SHTDN_REASON_FLAG_PLANNED);
                            return("Updates completed and machine is rebooting.");
                        }
                        else
                        {
                            return("Updates completed.");
                        }
                    }
                }
                else
                {
                    return("There was a problem downloading updates.");
                }
            }
            catch (COMException e)
            {
                if (e.HResult == -2145124316)
                {
                    return("No updates were found. Exiting...");
                }
                else
                {
                    return($"Exception {e.HResult}: {e.Message} was hit. Exiting...");
                }
            }

            return(string.Empty);
        }
Ejemplo n.º 12
0
        void DownloadComplete()
        {
            _downloadResult = _updateDownloader.EndDownload(_downloadJob);

            _downloadJob = null;

            if (_downloadResult.ResultCode == OperationResultCode.orcSucceeded
                || _downloadResult.ResultCode == OperationResultCode.orcSucceededWithErrors)
            {
                this.ShowProgressMessage("progress_download", "");

                if (_downloadResult.ResultCode == OperationResultCode.orcSucceeded)
                    this.AppendString("下载完成。\r\n");
                else
                    this.AppendString("下载部分完成,部分出错。\r\n");

#if NO
                DialogResult result = MessageBox.Show(this,
"要安装这些更新么?",
"WindowsUpdateDialog",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
                if (result == System.Windows.Forms.DialogResult.No)
                {
                    OnAllComplete();
                    return;
                }
#endif

                BeginInstallation();
            }
            else
            {
                this.AppendString("下载更新失败。错误码: " + _downloadResult.ResultCode);
                // 全部结束
                OnAllComplete();
            }
        }
 public static void SetDownloadResult(this IFileDownloader downloader, string url, IDownloadResult downloadResult)
 {
     downloader.DownloadDataAsync(url).Returns(Task.Run(() => downloadResult));
 }
Ejemplo n.º 14
0
 public static string IDownloadResultToString(IDownloadResult r)
 {
     return($"{nameof(r.HResult)}:{r.HResult}"
            + $", {nameof(r.ResultCode)}:{r.ResultCode}");
 }
Ejemplo n.º 15
0
        private static IResult ConvertToResult(IDownloadResult result)
        {
            if (result.ResultCode == OperationResultCode.orcAborted)
                return new UpdateOperationCancelled();

            if (result.ResultCode == OperationResultCode.orcSucceeded)
                return new NextResult();

            if (result.ResultCode == OperationResultCode.orcSucceededWithErrors)
                return new NextResult();

            return new UpdateDownloadFailed(result);
        }
Ejemplo n.º 16
0
        private static void LogDownloadResults(IEnumerable updates, IDownloadResult results)
        {
            try
            {
                var count = 0;
                var succeeded = 0;

                foreach (IUpdate update in updates)
                {
                    var result = results.GetUpdateResult(count);
                    if (result.ResultCode == OperationResultCode.orcSucceeded)
                    {
                        Log.DebugFormat("{0} downloaded successfully!", update.Title);
                        count++;
                        succeeded++;
                        continue;
                    }

                    var issue = new UpdateDownloadFailed(string.Format("Unable to download {0}", update.Title), result);
                    Log.Warn(issue.Issue);
                    count++;
                }

                if (count == succeeded)
                    Log.InfoFormat("{0} updates downloaded successfully", count);
                else
                    Log.WarnFormat("{0} of {1} updates downloaded successfully", succeeded, count);
            }
            catch (Exception e)
            {
                Log.WarnFormat("An exception occurred while logging download results: {0}", e.Message);
            }
        }
Ejemplo n.º 17
0
        private static InstallationResultViewModel CreateDownloadFailedResult(IViewModelService viewModelService, InstallerViewModel installerViewModel, IDownloadResult downloadResult)
        {
            if (downloadResult.Result != DownloadResultState.Failed)
            {
                throw new ArgumentException($"Result is {downloadResult.Result.ToString()}, expected {nameof(DownloadResultState.Failed)}.", nameof(downloadResult));
            }

            Exception exception;

            if (downloadResult is FailedDownloadResult failedDownloadResult)
            {
                exception = failedDownloadResult.Exception;
            }
            else
            {
                exception = new Exception(Strings.ErrorOccured);
                Log.Error($"DownloadResult with failed state is not of type {nameof(FailedDownloadResult)}.");
            }

            return(CreateDownloadFailedResult(viewModelService, installerViewModel, exception));
        }
Ejemplo n.º 18
0
 public UpdateDownloadFailed(IDownloadResult result)
 {
     var message = GetMessageForResult(result.HResult);
     Issue = string.Format("One or more updates failed to download ({0}): {1}", result.ResultCode,
                           message);
 }
        private OperationResultCode DownloadUpdatesUtil(CancellationToken cancellationToken)
        {
            try
            {
                UpdateDownloader uDownloader       = this._uSession.CreateUpdateDownloader();
                UpdateCollection updatesToDownload = new UpdateCollection();

                foreach (WUUpdateWrapper item in this._wuCollectionWrapper.Collection.Values)
                {
                    if (!item.IsDownloaded)
                    {
                        if (item.Update.EulaAccepted == false)
                        {
                            if (this._serviceSettings.AcceptWindowsUpdateEula)
                            {
                                try
                                {
                                    item.Update.AcceptEula();
                                }
                                catch (Exception e)
                                {
                                    _eventSource.WarningMessage(string.Format("Error occurred while accepting Eula for {0} . Exception : {1}",
                                                                              item, e));
                                }
                                updatesToDownload.Add(item.Update);
                            }
                        }
                        else
                        {
                            updatesToDownload.Add(item.Update);
                        }
                    }
                }

                uDownloader.Updates = updatesToDownload;

                DownloadCompletedCallback downloadCompletedCallback = new DownloadCompletedCallback();
                IDownloadJob downloadJob = uDownloader.BeginDownload(new DownloadProgressChangedCallback(),
                                                                     downloadCompletedCallback, null);

                TimeSpan operationTimeOut = TimeSpan.FromMinutes(this._serviceSettings.WUOperationTimeOutInMinutes);
                if (
                    !this._helper.WaitOnTask(downloadCompletedCallback.Task, (int)operationTimeOut.TotalMilliseconds,
                                             cancellationToken))
                {
                    _eventSource.Message("downloadJob : Requested Abort");
                    downloadJob.RequestAbort();
                }

                IDownloadResult uResult = uDownloader.EndDownload(downloadJob);
                for (int i = 0; i < updatesToDownload.Count; i++)
                {
                    var hResult  = uResult.GetUpdateResult(i).HResult;
                    var updateID = updatesToDownload[i].Identity.UpdateID;
                    this._wuCollectionWrapper.Collection[updateID].IsDownloaded = (hResult == 0);
                    if (hResult != 0)
                    {
                        _eventSource.WarningMessage(string.Format("Download for update ID {0} returned hResult {1}", updateID, hResult));
                    }
                }

                return(uResult.ResultCode);
            }
            catch (Exception e)
            {
                if ((uint)e.HResult == WUErrorCodes.WU_E_NO_UPDATE)
                {
                    return(OperationResultCode.orcSucceeded); // no updates found.
                }
                _eventSource.InfoMessage("Exception while downloading Windows-Updates: {0}", e);
                return(OperationResultCode.orcFailed);
            }
        }
Ejemplo n.º 20
0
 // Token: 0x06000003 RID: 3 RVA: 0x000020E8 File Offset: 0x000002E8
 public void DoUpdate()
 {
     if (this.ConsoleDiagnostics)
     {
         Console.WriteLine("Checking for Updates.");
     }
     try
     {
         UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StartScan, null, new string[0]);
         IUpdateSession updateSession = new UpdateSessionClass();
         updateSession.ClientApplicationID = "Exchange12";
         IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher();
         ISearchResult   searchResult   = updateSearcher.Search("IsInstalled=0 and CategoryIDs contains 'ab62c5bd-5539-49f6-8aea-5a114dd42314'");
         UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StopScan, null, new string[0]);
         if (searchResult.Updates.Count == 0)
         {
             if (this.ConsoleDiagnostics)
             {
                 Console.WriteLine("No Updates.");
             }
         }
         else
         {
             foreach (object obj in searchResult.Updates)
             {
                 IUpdate update = (IUpdate)obj;
                 UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_PatchAvailable, null, new string[]
                 {
                     update.Title
                 });
                 if (this.ConsoleDiagnostics)
                 {
                     Console.WriteLine("Title: {0}", update.Title);
                 }
             }
             UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StartDownload, null, new string[0]);
             UpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader();
             updateDownloader.Priority = 3;
             updateDownloader.Updates  = searchResult.Updates;
             IDownloadResult downloadResult = updateDownloader.Download();
             UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StopDownload, null, new string[0]);
             for (int i = 0; i < updateDownloader.Updates.Count; i++)
             {
                 if (downloadResult.GetUpdateResult(i).ResultCode == 4 || downloadResult.GetUpdateResult(i).ResultCode == 5)
                 {
                     UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_DownloadFailure, null, new string[]
                     {
                         updateDownloader.Updates[i].Title,
                         downloadResult.GetUpdateResult(i).HResult.ToString()
                     });
                     if (this.ConsoleDiagnostics)
                     {
                         Console.WriteLine("Errors: {0}: {1}", updateDownloader.Updates[i].Title, downloadResult.GetUpdateResult(i).HResult);
                     }
                 }
             }
             bool flag = false;
             foreach (object obj2 in updateDownloader.Updates)
             {
                 IUpdate update2 = (IUpdate)obj2;
                 if (update2.IsDownloaded)
                 {
                     flag = true;
                 }
             }
             if (!flag)
             {
                 if (this.ConsoleDiagnostics)
                 {
                     Console.WriteLine("Nothing to Install.");
                 }
             }
             else
             {
                 if (this.ConsoleDiagnostics)
                 {
                     Console.WriteLine("Starting Installation.");
                 }
                 UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StartInstall, null, new string[0]);
                 IUpdateInstaller updateInstaller = updateSession.CreateUpdateInstaller();
                 updateInstaller.Updates = updateDownloader.Updates;
                 IInstallationResult installationResult = updateInstaller.Install();
                 UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StopInstall, null, new string[0]);
                 for (int j = 0; j < updateInstaller.Updates.Count; j++)
                 {
                     IUpdate update3 = updateInstaller.Updates[j];
                     if (installationResult.GetUpdateResult(j).ResultCode == 4 || installationResult.GetUpdateResult(j).ResultCode == 3)
                     {
                         UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_InstallFailure, null, new string[]
                         {
                             updateInstaller.Updates[j].Title,
                             installationResult.GetUpdateResult(j).HResult.ToString()
                         });
                         if (this.ConsoleDiagnostics)
                         {
                             Console.WriteLine("Errors: {0}: {1}", updateInstaller.Updates[j].Title, installationResult.GetUpdateResult(j).HResult);
                         }
                     }
                 }
                 if (this.ConsoleDiagnostics)
                 {
                     Console.WriteLine("Finished.");
                 }
             }
         }
     }
     catch (COMException ex)
     {
         UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_WuaFail, null, new string[]
         {
             ex.Message
         });
         if (this.ConsoleDiagnostics)
         {
             Console.WriteLine("Failed: {0}", ex.Message);
         }
     }
 }
Ejemplo n.º 21
0
 public HelpUpdateDownloadedEventArgs( INamedVersionedUniqueId plugin, IDownloadResult downloadResult )
     : base(plugin)
 {
     DownloadResult = downloadResult;
 }
 public void Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs callbackArgs)
 {
     DownloadJob    = downloadJob;
     DownloadResult = Downloader?.EndDownload(DownloadJob);
 }
Ejemplo n.º 23
0
        public void Start(bool showProgress)
        {
            this.ShowProgress = showProgress;

            Console.WriteLine("WUA_Starting");

            IUpdateSession updateSession = new UpdateSessionClass();

            IUpdateSearcher   updateSearcher   = updateSession.CreateUpdateSearcher();
            IUpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader();
            IUpdateInstaller  updateInstaller  = updateSession.CreateUpdateInstaller();

            if (updateInstaller.IsBusy)
            {
                Console.WriteLine("WUA_IsBusy");
                return;
            }

            // SEARCHING

            Console.WriteLine("WUA_FindingUpdates");

            ISearchResult searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'");

            if (searchResult.Updates.Count.Equals(0))
            {
                Console.WriteLine("WUA_NoApplicableUpdates");
                return;
            }

            // LISTING

            UpdateCollection updateToDownload = new UpdateCollectionClass();

            for (int i = 0; i < searchResult.Updates.Count; i++)
            {
                IUpdate update = searchResult.Updates[i];

                Console.WriteLine("WUA_UpdateItem:{0}|{1}", i + 1, update.Title);

                if (!update.IsDownloaded)
                {
                    updateToDownload.Add(update);
                }
            }

            // DOWNLOADING

            if (!updateToDownload.Count.Equals(0))
            {
                Console.WriteLine("WUA_DownloadingStarted");

                updateDownloader.Updates  = updateToDownload;
                updateDownloader.IsForced = true;
                updateDownloader.Priority = DownloadPriority.dpHigh;

                IDownloadJob    job = updateDownloader.BeginDownload(this, this, updateDownloader);
                IDownloadResult downloaderResult = updateDownloader.EndDownload(job);

                Console.WriteLine("WUA_DownloadingCompleted:{0}", downloaderResult.ResultCode);
            }

            // INSTALLATION

            updateInstaller.Updates  = searchResult.Updates;
            updateInstaller.IsForced = true;

            Console.WriteLine("WUA_InstallationStarted");

            IInstallationJob    installationJob = updateInstaller.BeginInstall(this, this, updateInstaller);
            IInstallationResult result          = updateInstaller.EndInstall(installationJob);

            Console.WriteLine("WUA_InstallationCompleted:{0}|{1}", result.ResultCode, result.RebootRequired);

            // RESULT

            for (int i = 0; i < searchResult.Updates.Count; i++)
            {
                IUpdateInstallationResult resultItem = result.GetUpdateResult(i);
                Console.WriteLine("WUA_InstallationResult:{0}|{1}|{2}",
                                  i + 1, resultItem.ResultCode, resultItem.RebootRequired);
            }

            Console.WriteLine("WUA_Finish");
        }