Example #1
0
        internal void OnDownloadProgressChanged(object sender, DownloadFileProgressChangedArgs args)
        {
            double percent = Math.Round((double)args.BytesReceived / args.TotalBytesToReceive * 100, 2);

            UpdateProgressWindow.ProgressBar.IsIndeterminate = false;
            UpdateProgressWindow.SetNewProgress(percent);
            UpdateProgressWindow.ProgressIndicatorText.Text = $@"{percent}% - {args.BytesReceived / 1024}KB / {args.TotalBytesToReceive / 1024}KB";
        }
Example #2
0
        public void DownloadAndInstallPackage()
        {
            UpdateProgressWindow = new UpdateProgressWindow();//弹出下载更新窗口
            UpdateProgressWindow.Show();

            IFileDownloader fileDownloader = new FileDownloader();

            fileDownloader.DownloadProgressChanged += OnDownloadProgressChanged;
            fileDownloader.DownloadFileCompleted   += OnDownloadFileCompleted;

            string destinationPath = AppDomain.CurrentDomain.BaseDirectory + @"\Package.zip";

            //DirectorySecurity directorySecurity = new DirectorySecurity();
            //directorySecurity.AddAccessRule(new FileSystemAccessRule(@"Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
            //Directory.CreateDirectory(destinationPath);
            fileDownloader.DownloadFileAsync(PackageUri, destinationPath);
        }
Example #3
0
        internal void OnDownloadFileCompleted(object sender, DownloadFileCompletedArgs eventArgs)
        {
            if (eventArgs.State == CompletedState.Succeeded)
            {
                //download completed
                UpdateProgressWindow.SetNewProgress(100);
                UpdateProgressWindow.ProgressIndicatorText.Text = "下载已完成,请稍候...";

                //await Task.Run(() => { Thread.Sleep(2000); });

                UpdateProgressWindow.Close();
                StartUpdateInstall();
            }
            else if (eventArgs.State == CompletedState.Failed)
            {
                NotificationManager.ShowNotification("Snap Desktop", "在下载更新包时遇到问题");
                //download failed
            }
        }