Пример #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 void AssertApplicationRequirements(InPlaceHostingManager host)
 {
     host.AssertApplicationRequirements(true);
 }
Пример #3
-1
        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();
        }