private OperationResultCode InstallUpdatesUtil()

in src/PatchOrchestrationApplication/NodeAgentNTService/src/Manager/WindowsUpdateManager.cs [546:601]


        private OperationResultCode InstallUpdatesUtil(CancellationToken cancellationToken)
        {
            try
            {
                TimeSpan operationTimeOut = TimeSpan.FromMinutes(this.GetRemainingInstallationTimeout());
                UpdateCollection updatesToInstall = new UpdateCollection();
                foreach (WUUpdateWrapper item in this._wuCollectionWrapper.Collection.Values)
                {
                    if (item.IsDownloaded && !item.IsInstalled)
                    {
                        updatesToInstall.Add(item.Update);
                    }
                }
                // if no updates to install
                if (updatesToInstall.Count == 0)
                {
                    _eventSource.InfoMessage("No updates to install.");
                    return OperationResultCode.orcSucceeded;
                }

                IUpdateInstaller uInstaller = this._uSession.CreateUpdateInstaller();
                uInstaller.Updates = updatesToInstall;

                InstallationCompletedCallback installationCompletedCallback = new InstallationCompletedCallback();
                IInstallationJob installationJob = uInstaller.BeginInstall(new InstallationProgressChangedCallback(),
                    installationCompletedCallback, null);
                
                if (
                    !this._helper.WaitOnTask(installationCompletedCallback.Task,
                        (int)operationTimeOut.TotalMilliseconds, cancellationToken))
                {
                    _eventSource.Message("installationJob : Requested Abort");
                    installationJob.RequestAbort();
                }

                IInstallationResult uResult = uInstaller.EndInstall(installationJob);
                for (int i = 0; i < updatesToInstall.Count; i++)
                {
                    var hResult = uResult.GetUpdateResult(i).HResult;
                    var updateID = updatesToInstall[i].Identity.UpdateID;
                    this._wuCollectionWrapper.Collection[updateID].IsInstalled = (hResult == 0);
                    this._wuCollectionWrapper.Collection[updateID].HResult = hResult;
                    if (hResult != 0)
                    {
                        _eventSource.WarningMessage(string.Format("Install for update ID {0} returned hResult {1}", updateID, hResult));
                    }
                }

                return uResult.ResultCode;
            }
            catch (Exception e)
            {
                _eventSource.InfoMessage("Exception while installing Windows-Updates: {0}", e);
                return OperationResultCode.orcFailed;
            }
        }