Beispiel #1
0
 /// <summary>Starts a synchronous download and installation of the latest version of this application. </summary>
 /// <returns>true if an application has been updated; otherwise, false.</returns>
 /// <exception cref="T:System.Deployment.Application.TrustNotGrantedException">The local computer did not grant the application the permission level it requested to execute.</exception>
 /// <exception cref="T:System.Deployment.Application.InvalidDeploymentException">Your ClickOnce deployment is corrupted. For tips on how to diagnose and correct the problem, see Troubleshooting ClickOnce Deployments.</exception>
 /// <exception cref="T:System.Deployment.Application.DeploymentDownloadException">The new deployment could not be downloaded from its location on the network.</exception>
 /// <exception cref="T:System.InvalidOperationException">The application is currently being updated.</exception>
 public bool Update()
 {
     new NamedPermissionSet("FullTrust").Demand();
     if (Interlocked.CompareExchange(ref this._guard, 2, 0) != 0)
     {
         throw new InvalidOperationException(Resources.GetString("Ex_SingleOperation"));
     }
     this._cancellationPending = false;
     try
     {
         DeploymentManager deploymentManager = this.CreateDeploymentManager();
         try
         {
             deploymentManager.Bind();
             UpdateCheckInfo updateCheckResult = this.DetermineUpdateCheckResult(deploymentManager.ActivationDescription);
             if (updateCheckResult.UpdateAvailable)
             {
                 deploymentManager.DeterminePlatformRequirements();
                 try
                 {
                     deploymentManager.DetermineTrust(new TrustParams()
                     {
                         NoPrompt = true
                     });
                 }
                 catch (TrustNotGrantedException ex)
                 {
                     if (!deploymentManager.ActivationDescription.IsUpdateInPKTGroup)
                     {
                         throw;
                     }
                 }
             }
             this.ProcessUpdateCheckResult(updateCheckResult, deploymentManager.ActivationDescription);
             if (!updateCheckResult.UpdateAvailable)
             {
                 return(false);
             }
             deploymentManager.Synchronize();
             if (deploymentManager.ActivationDescription.IsUpdateInPKTGroup)
             {
                 this._subState = this._subStore.GetSubscriptionState(deploymentManager.ActivationDescription.DeployManifest);
             }
         }
         finally
         {
             deploymentManager.Dispose();
         }
     }
     finally
     {
         Interlocked.Exchange(ref this._guard, 0);
     }
     return(true);
 }
Beispiel #2
0
        /// <summary>Performs the same operation as <see cref="M:System.Deployment.Application.ApplicationDeployment.CheckForUpdate" />, but returns extended information about the available update.</summary>
        /// <returns>An <see cref="T:System.Deployment.Application.UpdateCheckInfo" /> for the available update.</returns>
        /// <param name="persistUpdateCheckResult">If false, the update will be applied silently and no dialog box will be displayed.</param>
        public UpdateCheckInfo CheckForDetailedUpdate(bool persistUpdateCheckResult)
        {
            new NamedPermissionSet("FullTrust").Demand();
            if (Interlocked.CompareExchange(ref this._guard, 2, 0) != 0)
            {
                throw new InvalidOperationException(Resources.GetString("Ex_SingleOperation"));
            }
            this._cancellationPending = false;
            UpdateCheckInfo info = (UpdateCheckInfo)null;

            try
            {
                DeploymentManager deploymentManager = this.CreateDeploymentManager();
                try
                {
                    deploymentManager.Bind();
                    info = this.DetermineUpdateCheckResult(deploymentManager.ActivationDescription);
                    if (info.UpdateAvailable)
                    {
                        deploymentManager.DeterminePlatformRequirements();
                        try
                        {
                            deploymentManager.DetermineTrust(new TrustParams()
                            {
                                NoPrompt = true
                            });
                        }
                        catch (TrustNotGrantedException ex)
                        {
                            if (!deploymentManager.ActivationDescription.IsUpdateInPKTGroup)
                            {
                                throw;
                            }
                        }
                    }
                    if (persistUpdateCheckResult)
                    {
                        this.ProcessUpdateCheckResult(info, deploymentManager.ActivationDescription);
                    }
                }
                finally
                {
                    deploymentManager.Dispose();
                }
            }
            finally
            {
                Interlocked.Exchange(ref this._guard, 0);
            }
            return(info);
        }