示例#1
0
 void IDownloadProgressChangedCallback.Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs)
 {
     if (this.showProgress)
     {
         IDownloadProgress progress = callbackArgs.Progress;
         Console.WriteLine("WUA_DownloadingProgress:{0}|{1}|{2}",
             progress.CurrentUpdateIndex + 1,
             progress.CurrentUpdatePercentComplete,
             progress.PercentComplete);
     }
 }
 // Implementation of IDownloadCompletedCallback interface...
 public void Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs e)
 {
     form1.iDownloadComplete();
 }
            public void Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs callbackArgs)
            {
                var clearProgressFlag = false;
                try
                {
                    if (_updateInProgress) return;

                    _updateInProgress = true;
                    clearProgressFlag = true;
                    var wrapper = new UpdateWrapper(downloadJob) { TotalPercent = 100, UpdatePercent = 100, CurrentIndex = downloadJob.Updates.Count};
                    wrapper.AdjustValues(_lastWrapper);
                    _lastWrapper = wrapper;
                    SetTitle(wrapper);
                    SetText(wrapper);
                }
                catch (Exception e)
                {
                    Log.WarnFormat("An issue occurred while An issue occurred while handling a download updates progress completed event: {0}", e);
                }
                finally
                {
                    if (clearProgressFlag) _updateInProgress = false;
                }
            }
示例#4
0
 void IDownloadCompletedCallback.Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs callbackArgs)
 {
 }
 public void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs)
 {
     ServiceEventSource.Current.VerboseMessage("Callback: Downloading of Windows Updates is In-Progress. Percent completed : " + downloadJob.GetProgress().PercentComplete);
 }
 public extern virtual IDownloadResult EndDownload([In][MarshalAs(UnmanagedType.Interface)] IDownloadJob value);
示例#7
0
 // Implementation of IDownloadCompletedCallback interface...
 public void Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs e)
 {
     form1.DownloadComplete();
 }
示例#8
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();
            }
        }
示例#9
0
 void IDownloadCompletedCallback.Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs callbackArgs)
 {
 }
示例#10
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");
        }
示例#11
0
 public Job(ISong song, IDownloadJob downloadJob, IEnumerable <SongTarget> targets, JobFinishedCallback jobFinishedCallback, IProgress <JobProgress> progress)
     : this(song, downloadJob, targets, progress)
 {
     JobFinishedCallback = jobFinishedCallback;
 }
 public void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs) => _state.Invoke(downloadJob, callbackArgs);
 public void Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs callbackArgs) => _state.Invoke(downloadJob, callbackArgs);
 public void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs) => Action?.Invoke(callbackArgs.Progress);
 public void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs e)
 {
     WindowsUpdateFrame.progressWindow.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.progressWindow.progressBar1.Value = e.Progress.PercentComplete));
     WindowsUpdateFrame.progressWindow.Dispatcher.BeginInvoke(new Action(() => WindowsUpdateFrame.progressWindow.textBlock1.Text    = e.Progress.PercentComplete.ToString() + "%"));
 }
示例#16
0
 public void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs)
 {
     this.Progress = callbackArgs.Progress;
 }
示例#17
0
        void BeginDownloadUpdate()
        {
            this.AppendString("开始下载更新 ...\r\n");

            _updateSession = new UpdateSession();
            _updateDownloader = _updateSession.CreateUpdateDownloader();

            _updateDownloader.Updates = _updateCollection;
            _updateDownloader.Priority = DownloadPriority.dpHigh;
            _downloadJob = _updateDownloader.BeginDownload(new DownloadProgressChangedFunc(this),
                new DownloadCompleteFunc(this),
                null // new UpdateDownloader_state(this)
                );
        }
示例#18
0
 public IDownloadResult EndDownload(IDownloadJob value)
 {
     throw new NotImplementedException();
 }
示例#19
0
            // Implementation of IDownloadProgressChangedCallback interface...
            public void Invoke(IDownloadJob downloadJob,
                IDownloadProgressChangedCallbackArgs e)
            {
                decimal downloaded = ((e.Progress.TotalBytesDownloaded / 1024) / 1024);
                decimal toDownloaded = ((e.Progress.TotalBytesToDownload / 1024) / 1024);
                downloaded = decimal.Round(downloaded, 2);
                toDownloaded = decimal.Round(toDownloaded, 2);

                form1.ShowProgressMessage("progress_download",
                    "下载进度: "
                 + e.Progress.CurrentUpdateIndex
                 + "/"
                 + downloadJob.Updates.Count
                 + " - "
                 + downloaded + "Mb"
                 + " / "
                 + toDownloaded + "Mb");
            }
示例#20
0
 public UpdateWrapper(IDownloadJob job, IDownloadProgressChangedCallbackArgs args)
 {
     TotalUpdates = job.Updates.Count;
     TotalPercent = args.Progress.PercentComplete;
     CurrentIndex = args.Progress.CurrentUpdateIndex+1;
     Title = job.Updates[args.Progress.CurrentUpdateIndex].Title;
     UpdatePercent = args.Progress.CurrentUpdatePercentComplete;
 }
 public DownloadManagerSpec()
 {
     manager = new DownloadManager();
     job     = manager.CreateJob("name", "http://xvs.xamarin.com/Tests/Windows.Bits.Tests-DO-NOT-DELETE.bin", "blob.bin");
 }
示例#22
0
 public UpdateWrapper(IDownloadJob job)
 {
     TotalUpdates = job.Updates.Count;
 }
        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);
                    this._wuCollectionWrapper.Collection[updateID].HResult      = hResult;
                    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);
            }
        }
示例#24
0
            public void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs)
            {
                var clearProgressFlag = false;
                try
                {
                    if (_updateInProgress) return;

                    _updateInProgress = true;
                    clearProgressFlag = true;
                    var wrapper = new UpdateWrapper(downloadJob, callbackArgs);
                    wrapper.AdjustValues(_lastWrapper);
                    _lastWrapper = wrapper;
                    SetTitle(wrapper);
                    SetText(wrapper);
                }
                catch (Exception e)
                {
                    Log.WarnFormat("An issue occurred while handling a download updates progress changed event: {0}", e);
                }
                finally
                {
                    if (clearProgressFlag) _updateInProgress = false;
                }
            }
 public void Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs callbackArgs)
 {
     this.CompleteTask();
     ServiceEventSource.Current.VerboseMessage("Callback: Downloading of Windows Updates completed.");
 }
示例#26
0
        public void CancelOperations()
        {
            if (mWebClient != null)
            {
                mWebClient.CancelAsync();
                mWebClient = null;
            }

            if (mCallback == null)
            {
                return;
            }

            if (mSearchJob != null)
            {
                try
                {
                    mUpdateSearcher.EndSearch(mSearchJob);
                }
                catch (Exception err) { }
                mSearchJob = null;
            }

            if (mOfflineService != null)
            {
                try
                {
                    mUpdateServiceManager.RemoveService(mOfflineService.ServiceID);
                }
                catch (Exception err) { }
                mOfflineService = null;
            }

            if (mDownloadJob != null)
            {
                try
                {
                    mDownloader.EndDownload(mDownloadJob);
                }
                catch (Exception err) { }
                mDownloadJob = null;
            }

            if (mInstalationJob != null)
            {
                try
                {
                    if (mCallback.Install)
                    {
                        mInstaller.EndInstall(mInstalationJob);
                    }
                    else
                    {
                        mInstaller.EndUninstall(mInstalationJob);
                    }
                }
                catch (Exception err) { }
                mInstalationJob = null;
            }

            mCallback = null;
        }