예제 #1
0
        private void EndUpdateAsync(DeploymentManager dm, Exception error, bool cancelled)
        {
            Interlocked.Exchange(ref this._guard, 0);
            AsyncCompletedEventArgs    e = new AsyncCompletedEventArgs(error, cancelled, (object)null);
            AsyncCompletedEventHandler completedEventHandler = (AsyncCompletedEventHandler)this.Events[ApplicationDeployment.updateCompletedKey];

            if (completedEventHandler != null)
            {
                completedEventHandler((object)this, e);
            }
            if (dm == null)
            {
                return;
            }
            dm.ProgressChanged      -= new DeploymentProgressChangedEventHandler(this.UpdateProgressChangedEventHandler);
            dm.BindCompleted        -= new BindCompletedEventHandler(this.UpdateBindCompletedEventHandler);
            dm.SynchronizeCompleted -= new SynchronizeCompletedEventHandler(this.SynchronizeNullCompletedEventHandler);
            new NamedPermissionSet("FullTrust").Assert();
            try
            {
                dm.Dispose();
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
        }
예제 #2
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);
 }
예제 #3
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);
        }
예제 #4
0
        private void CheckForUpdateBindCompletedEventHandler(object sender, BindCompletedEventArgs e)
        {
            Exception         error             = (Exception)null;
            DeploymentManager deploymentManager = (DeploymentManager)null;
            bool    updateAvailable             = false;
            Version availableVersion            = (Version)null;
            bool    isUpdateRequired            = false;
            Version minimumRequiredVersion      = (Version)null;
            long    updateSize = 0;

            new NamedPermissionSet("FullTrust").Assert();
            try
            {
                deploymentManager = (DeploymentManager)sender;
                if (e.Error == null && !e.Cancelled)
                {
                    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;
                    }
                    updateAvailable        = true;
                    availableVersion       = updateCheckResult.AvailableVersion;
                    isUpdateRequired       = updateCheckResult.IsUpdateRequired;
                    minimumRequiredVersion = updateCheckResult.MinimumRequiredVersion;
                    updateSize             = updateCheckResult.UpdateSizeBytes;
                }
                else
                {
                    error = e.Error;
                }
            }
            catch (Exception ex)
            {
                if (ExceptionUtility.IsHardException(ex))
                {
                    throw;
                }
                else
                {
                    error = ex;
                }
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
                Interlocked.Exchange(ref this._guard, 0);
                CheckForUpdateCompletedEventArgs    e1 = new CheckForUpdateCompletedEventArgs(error, e.Cancelled, (object)null, updateAvailable, availableVersion, isUpdateRequired, minimumRequiredVersion, updateSize);
                CheckForUpdateCompletedEventHandler completedEventHandler = (CheckForUpdateCompletedEventHandler)this.Events[ApplicationDeployment.checkForUpdateCompletedKey];
                if (completedEventHandler != null)
                {
                    completedEventHandler((object)this, e1);
                }
                if (deploymentManager != null)
                {
                    deploymentManager.ProgressChanged -= new DeploymentProgressChangedEventHandler(this.CheckForUpdateProgressChangedEventHandler);
                    deploymentManager.BindCompleted   -= new BindCompletedEventHandler(this.CheckForUpdateBindCompletedEventHandler);
                    new NamedPermissionSet("FullTrust").Assert();
                    try
                    {
                        deploymentManager.Dispose();
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
        }
 private void EndUpdateAsync(DeploymentManager dm, Exception error, bool cancelled)
 {
     Interlocked.Exchange(ref this._guard, 0);
     AsyncCompletedEventArgs e = new AsyncCompletedEventArgs(error, cancelled, null);
     AsyncCompletedEventHandler handler = (AsyncCompletedEventHandler) this.Events[updateCompletedKey];
     if (handler != null)
     {
         handler(this, e);
     }
     if (dm != null)
     {
         dm.ProgressChanged -= new DeploymentProgressChangedEventHandler(this.UpdateProgressChangedEventHandler);
         dm.BindCompleted -= new BindCompletedEventHandler(this.UpdateBindCompletedEventHandler);
         dm.SynchronizeCompleted -= new SynchronizeCompletedEventHandler(this.SynchronizeNullCompletedEventHandler);
         new NamedPermissionSet("FullTrust").Assert();
         try
         {
             dm.Dispose();
         }
         finally
         {
             CodeAccessPermission.RevertAssert();
         }
     }
 }
예제 #6
0
        private void CheckForUpdateBindCompletedEventHandler(object sender, BindCompletedEventArgs e)
        {
            Exception         error        = null;
            DeploymentManager manager      = null;
            bool    updateAvailable        = false;
            Version availableVersion       = null;
            bool    isUpdateRequired       = false;
            Version minimumRequiredVersion = null;
            long    updateSize             = 0L;

            new NamedPermissionSet("FullTrust").Assert();
            try
            {
                manager = (DeploymentManager)sender;
                if ((e.Error == null) && !e.Cancelled)
                {
                    UpdateCheckInfo info = this.DetermineUpdateCheckResult(manager.ActivationDescription);
                    if (info.UpdateAvailable)
                    {
                        manager.DeterminePlatformRequirements();
                        try
                        {
                            TrustParams trustParams = new TrustParams {
                                NoPrompt = true
                            };
                            manager.DetermineTrust(trustParams);
                        }
                        catch (TrustNotGrantedException)
                        {
                            if (!manager.ActivationDescription.IsUpdateInPKTGroup)
                            {
                                throw;
                            }
                        }
                    }
                    this.ProcessUpdateCheckResult(info, manager.ActivationDescription);
                    if (info.UpdateAvailable)
                    {
                        updateAvailable        = true;
                        availableVersion       = info.AvailableVersion;
                        isUpdateRequired       = info.IsUpdateRequired;
                        minimumRequiredVersion = info.MinimumRequiredVersion;
                        updateSize             = info.UpdateSizeBytes;
                    }
                }
                else
                {
                    error = e.Error;
                }
            }
            catch (Exception exception2)
            {
                if (ExceptionUtility.IsHardException(exception2))
                {
                    throw;
                }
                error = exception2;
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
                Interlocked.Exchange(ref this._guard, 0);
                CheckForUpdateCompletedEventArgs    args    = new CheckForUpdateCompletedEventArgs(error, e.Cancelled, null, updateAvailable, availableVersion, isUpdateRequired, minimumRequiredVersion, updateSize);
                CheckForUpdateCompletedEventHandler handler = (CheckForUpdateCompletedEventHandler)this.Events[checkForUpdateCompletedKey];
                if (handler != null)
                {
                    handler(this, args);
                }
                if (manager != null)
                {
                    manager.ProgressChanged -= new DeploymentProgressChangedEventHandler(this.CheckForUpdateProgressChangedEventHandler);
                    manager.BindCompleted   -= new BindCompletedEventHandler(this.CheckForUpdateBindCompletedEventHandler);
                    new NamedPermissionSet("FullTrust").Assert();
                    try
                    {
                        manager.Dispose();
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
        }