public static ActionResult CheckApplicationExists(Session session) { var deploymentManifest = new Uri(session["DeploymentManifest"]); var downloadTask = (Task<GetManifestCompletedEventArgs>)null; 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; } var manifest = downloadTask.Result; var result = manifest.ApplicationManifest.CheckApplicationExists(); if(result == ActionResult.SkipRemainingActions) { session.Log("{0} is already installed.", manifest.ProductName); } return result; } }
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; }