예제 #1
0
        public static ActionResult DownloadApplication(Session session) {
            var deploymentManifest = new Uri(session["DeploymentManifest"]);
            var cancellationTokenSource = new CancellationTokenSource();
            var previousProgressPercentage = 0;
            var downloadTask = (Task)null;

            DisplayActionData(session, "Hello, World!");

            ResetProgress(session);

            using(var host = new InPlaceHostingManager(deploymentManifest, false)) {
                downloadTask = host.DownloadManifestAsync();

                downloadTask.Wait();

                if(downloadTask.IsCanceled) {
                    return ActionResult.UserExit;
                }
                else if(downloadTask.IsFaulted) {
                    session.Message(InstallMessage.Error, new Record { FormatString = downloadTask.Exception.ToString() });
                    return ActionResult.Failure;
                }
                // Requirements
                host.AssertApplicationRequirements(true);

                // Download
                downloadTask = host.DownloadApplicationAsync(progress => {
                    session.Log("Downloaded {0,10}", (((double)progress.ProgressPercentage) / 100d).ToString("P"));

                    IncrementProgress(session, progress.ProgressPercentage - previousProgressPercentage);

                    previousProgressPercentage = progress.ProgressPercentage;
                });

                downloadTask.Wait();

                if(downloadTask.IsCanceled) {
                    return ActionResult.UserExit;
                }
                else if(downloadTask.IsFaulted) {
                    session.Message(InstallMessage.Error, new Record { FormatString = downloadTask.Exception.ToString() });
                    return ActionResult.Failure;
                }
            }

            return ActionResult.Success;
        }
        private static Task DownloadApplication(InPlaceHostingManager host)
        {
            var completion = new TaskCompletionSource<int>();

            host.DownloadApplicationCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    completion.SetException(e.Error);
                }

                else
                {
                    completion.SetResult(0);
                }
            };

            host.DownloadApplicationAsync();

            return completion.Task;
        }
예제 #3
-1
파일: install.cs 프로젝트: mojjia/blog
        private void InstallApplication(Uri app)
        {
            var manager = new InPlaceHostingManager(app, false);
            manager.GetManifestCompleted +=
                new EventHandler<GetManifestCompletedEventArgs>(
                    OnGetManifestCompleted
                );

            // I would love to just "await manager.GetManifestAsync" here
            // but GetManifestAsync returns void
            _event = new AutoResetEvent(false);
            // Console.WriteLine("Getting manifest for {0}", app);
            manager.GetManifestAsync();
            _event.WaitOne();

            // this call is synchronous
            // Console.WriteLine("Asserting application requirements for {0}", app);
            manager.AssertApplicationRequirements(true);
            // Console.WriteLine("AssertApplicationRequirements passes");

            manager.DownloadApplicationCompleted +=
                new EventHandler<DownloadApplicationCompletedEventArgs>(
                    OnDownloadApplicationCompleted
                );
            // Console.WriteLine("Downloading and installing {0}", app);
            manager.DownloadApplicationAsync();
            _event.WaitOne();
        }