Esempio n. 1
0
 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
     {
         using (DeploymentManager manager = this.CreateDeploymentManager())
         {
             manager.Bind();
             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)
             {
                 return(false);
             }
             manager.Synchronize();
             if (manager.ActivationDescription.IsUpdateInPKTGroup)
             {
                 this._subState = this._subStore.GetSubscriptionState(manager.ActivationDescription.DeployManifest);
             }
         }
     }
     finally
     {
         Interlocked.Exchange(ref this._guard, 0);
     }
     return(true);
 }
Esempio n. 2
0
 private bool DetermineTrustCore(bool blocking, TrustParams tp)
 {
     try
     {
         Logger.AddMethodCall(this._log, "DeploymentManager.DetermineTrustCore() called.");
         SubscriptionState   subscriptionState = this._subStore.GetSubscriptionState(this._actDesc.DeployManifest);
         TrustManagerContext tmc = new TrustManagerContext {
             IgnorePersistedDecision = false,
             NoPrompt = false,
             Persist  = true
         };
         if (tp != null)
         {
             tmc.NoPrompt = tp.NoPrompt;
         }
         if (!blocking && this._cancellationPending)
         {
             return(true);
         }
         if (subscriptionState.IsInstalled && !string.Equals(subscriptionState.EffectiveCertificatePublicKeyToken, this._actDesc.EffectiveCertificatePublicKeyToken, StringComparison.Ordinal))
         {
             Logger.AddInternalState(this._log, "Application family is installed but effective certificate public key token has changed between versions: subState.EffectiveCertificatePublicKeyToken=" + subscriptionState.EffectiveCertificatePublicKeyToken + ",_actDesc.EffectiveCertificatePublicKeyToken=" + this._actDesc.EffectiveCertificatePublicKeyToken);
             Logger.AddInternalState(this._log, "Removing cached trust for the CurrentBind.");
             System.Deployment.Application.ApplicationTrust.RemoveCachedTrust(subscriptionState.CurrentBind);
         }
         bool isUpdate = false;
         if (this._actDesc.IsUpdate)
         {
             isUpdate = true;
         }
         if (this._actDesc.IsUpdateInPKTGroup)
         {
             isUpdate = false;
             ApplicationSecurityInfo info = new ApplicationSecurityInfo(this._actCtx);
             this._actDesc.IsFullTrustRequested = info.DefaultRequestSet.IsUnrestricted();
         }
         this._actDesc.Trust = System.Deployment.Application.ApplicationTrust.RequestTrust(subscriptionState, this._actDesc.DeployManifest.Deployment.Install, isUpdate, this._actCtx, tmc);
     }
     catch (Exception exception)
     {
         this.LogError(Resources.GetString("Ex_DetermineTrustFailed"), exception);
         Logger.AddInternalState(this._log, "Exception thrown in  DetermineTrustCore(): " + exception.GetType().ToString() + " : " + exception.Message + "\r\n" + exception.StackTrace);
         throw;
     }
     return(false);
 }
Esempio n. 3
0
 public void DetermineTrust(TrustParams trustParams)
 {
     try
     {
         if (this._actDesc == null)
         {
             throw new InvalidOperationException(Resources.GetString("Ex_BindFirst"));
         }
         this.DetermineTrustCore(true, trustParams);
     }
     catch (Exception)
     {
         this._trustNotGrantedEvent.Set();
         throw;
     }
     this._trustGrantedEvent.Set();
 }
 public void AssertApplicationRequirements(bool grantApplicationTrust)
 {
     lock (this._lock)
     {
         try
         {
             Logger.AddMethodCall(this._log, "InPlaceHostingManager.AssertApplicationRequirements(" + grantApplicationTrust.ToString() + ") called.");
             if (this._appType == AppType.CustomHostSpecified)
             {
                 throw new InvalidOperationException(Resources.GetString("Ex_CannotCallAssertApplicationRequirements"));
             }
             this.AssertState(State.GetManifestSucceeded, State.DownloadingApplication);
             this.ChangeState(State.VerifyingRequirements);
             this._deploymentManager.DeterminePlatformRequirements();
             if (grantApplicationTrust)
             {
                 Logger.AddMethodCall(this._log, "Persisting trust without evaluation.");
                 this._deploymentManager.PersistTrustWithoutEvaluation();
             }
             else
             {
                 TrustParams trustParams = new TrustParams {
                     NoPrompt = true
                 };
                 this._deploymentManager.DetermineTrust(trustParams);
             }
             this.ChangeState(State.VerifyRequirementsSucceeded);
         }
         catch (Exception exception)
         {
             Logger.AddInternalState(this._log, "Exception thrown in AssertApplicationRequirements(bool grantApplicationTrust): " + exception.GetType().ToString() + " : " + exception.Message + "\r\n" + exception.StackTrace);
             this.ChangeState(State.Done);
             throw;
         }
     }
 }
 public void AssertApplicationRequirements(bool grantApplicationTrust)
 {
     lock (this._lock)
     {
         try
         {
             Logger.AddMethodCall(this._log, "InPlaceHostingManager.AssertApplicationRequirements(" + grantApplicationTrust.ToString() + ") called.");
             if (this._appType == AppType.CustomHostSpecified)
             {
                 throw new InvalidOperationException(Resources.GetString("Ex_CannotCallAssertApplicationRequirements"));
             }
             this.AssertState(State.GetManifestSucceeded, State.DownloadingApplication);
             this.ChangeState(State.VerifyingRequirements);
             this._deploymentManager.DeterminePlatformRequirements();
             if (grantApplicationTrust)
             {
                 Logger.AddMethodCall(this._log, "Persisting trust without evaluation.");
                 this._deploymentManager.PersistTrustWithoutEvaluation();
             }
             else
             {
                 TrustParams trustParams = new TrustParams {
                     NoPrompt = true
                 };
                 this._deploymentManager.DetermineTrust(trustParams);
             }
             this.ChangeState(State.VerifyRequirementsSucceeded);
         }
         catch (Exception exception)
         {
             Logger.AddInternalState(this._log, "Exception thrown in AssertApplicationRequirements(bool grantApplicationTrust): " + exception.GetType().ToString() + " : " + exception.Message + "\r\n" + exception.StackTrace);
             this.ChangeState(State.Done);
             throw;
         }
     }
 }
 private void UpdateBindCompletedEventHandler(object sender, BindCompletedEventArgs e)
 {
     Exception error = null;
     DeploymentManager dm = null;
     bool flag = false;
     new NamedPermissionSet("FullTrust").Assert();
     try
     {
         dm = (DeploymentManager) sender;
         if ((e.Error == null) && !e.Cancelled)
         {
             UpdateCheckInfo info = this.DetermineUpdateCheckResult(dm.ActivationDescription);
             if (info.UpdateAvailable)
             {
                 dm.DeterminePlatformRequirements();
                 try
                 {
                     TrustParams trustParams = new TrustParams {
                         NoPrompt = true
                     };
                     dm.DetermineTrust(trustParams);
                 }
                 catch (TrustNotGrantedException)
                 {
                     if (!dm.ActivationDescription.IsUpdateInPKTGroup)
                     {
                         throw;
                     }
                 }
             }
             this.ProcessUpdateCheckResult(info, dm.ActivationDescription);
             if (info.UpdateAvailable)
             {
                 flag = true;
                 dm.SynchronizeAsync();
             }
             if (dm.ActivationDescription.IsUpdateInPKTGroup)
             {
                 this._subState = this._subStore.GetSubscriptionState(dm.ActivationDescription.DeployManifest);
             }
         }
         else
         {
             error = e.Error;
         }
     }
     catch (Exception exception2)
     {
         if (ExceptionUtility.IsHardException(exception2))
         {
             throw;
         }
         error = exception2;
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
         if (!flag)
         {
             this.EndUpdateAsync(dm, error, e.Cancelled);
         }
     }
 }
 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
     {
         using (DeploymentManager manager = this.CreateDeploymentManager())
         {
             manager.Bind();
             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)
             {
                 return false;
             }
             manager.Synchronize();
             if (manager.ActivationDescription.IsUpdateInPKTGroup)
             {
                 this._subState = this._subStore.GetSubscriptionState(manager.ActivationDescription.DeployManifest);
             }
         }
     }
     finally
     {
         Interlocked.Exchange(ref this._guard, 0);
     }
     return true;
 }
 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();
             }
         }
     }
 }
 private bool DetermineTrustCore(bool blocking, TrustParams tp)
 {
     try
     {
         Logger.AddMethodCall(this._log, "DeploymentManager.DetermineTrustCore() called.");
         SubscriptionState subscriptionState = this._subStore.GetSubscriptionState(this._actDesc.DeployManifest);
         TrustManagerContext tmc = new TrustManagerContext {
             IgnorePersistedDecision = false,
             NoPrompt = false,
             Persist = true
         };
         if (tp != null)
         {
             tmc.NoPrompt = tp.NoPrompt;
         }
         if (!blocking && this._cancellationPending)
         {
             return true;
         }
         if (subscriptionState.IsInstalled && !string.Equals(subscriptionState.EffectiveCertificatePublicKeyToken, this._actDesc.EffectiveCertificatePublicKeyToken, StringComparison.Ordinal))
         {
             Logger.AddInternalState(this._log, "Application family is installed but effective certificate public key token has changed between versions: subState.EffectiveCertificatePublicKeyToken=" + subscriptionState.EffectiveCertificatePublicKeyToken + ",_actDesc.EffectiveCertificatePublicKeyToken=" + this._actDesc.EffectiveCertificatePublicKeyToken);
             Logger.AddInternalState(this._log, "Removing cached trust for the CurrentBind.");
             System.Deployment.Application.ApplicationTrust.RemoveCachedTrust(subscriptionState.CurrentBind);
         }
         bool isUpdate = false;
         if (this._actDesc.IsUpdate)
         {
             isUpdate = true;
         }
         if (this._actDesc.IsUpdateInPKTGroup)
         {
             isUpdate = false;
             ApplicationSecurityInfo info = new ApplicationSecurityInfo(this._actCtx);
             this._actDesc.IsFullTrustRequested = info.DefaultRequestSet.IsUnrestricted();
         }
         this._actDesc.Trust = System.Deployment.Application.ApplicationTrust.RequestTrust(subscriptionState, this._actDesc.DeployManifest.Deployment.Install, isUpdate, this._actCtx, tmc);
     }
     catch (Exception exception)
     {
         this.LogError(Resources.GetString("Ex_DetermineTrustFailed"), exception);
         Logger.AddInternalState(this._log, "Exception thrown in  DetermineTrustCore(): " + exception.GetType().ToString() + " : " + exception.Message + "\r\n" + exception.StackTrace);
         throw;
     }
     return false;
 }
 public void DetermineTrust(TrustParams trustParams)
 {
     try
     {
         if (this._actDesc == null)
         {
             throw new InvalidOperationException(Resources.GetString("Ex_BindFirst"));
         }
         this.DetermineTrustCore(true, trustParams);
     }
     catch (Exception)
     {
         this._trustNotGrantedEvent.Set();
         throw;
     }
     this._trustGrantedEvent.Set();
 }
Esempio n. 11
0
        private void UpdateBindCompletedEventHandler(object sender, BindCompletedEventArgs e)
        {
            Exception         error = null;
            DeploymentManager dm    = null;
            bool flag = false;

            new NamedPermissionSet("FullTrust").Assert();
            try
            {
                dm = (DeploymentManager)sender;
                if ((e.Error == null) && !e.Cancelled)
                {
                    UpdateCheckInfo info = this.DetermineUpdateCheckResult(dm.ActivationDescription);
                    if (info.UpdateAvailable)
                    {
                        dm.DeterminePlatformRequirements();
                        try
                        {
                            TrustParams trustParams = new TrustParams {
                                NoPrompt = true
                            };
                            dm.DetermineTrust(trustParams);
                        }
                        catch (TrustNotGrantedException)
                        {
                            if (!dm.ActivationDescription.IsUpdateInPKTGroup)
                            {
                                throw;
                            }
                        }
                    }
                    this.ProcessUpdateCheckResult(info, dm.ActivationDescription);
                    if (info.UpdateAvailable)
                    {
                        flag = true;
                        dm.SynchronizeAsync();
                    }
                    if (dm.ActivationDescription.IsUpdateInPKTGroup)
                    {
                        this._subState = this._subStore.GetSubscriptionState(dm.ActivationDescription.DeployManifest);
                    }
                }
                else
                {
                    error = e.Error;
                }
            }
            catch (Exception exception2)
            {
                if (ExceptionUtility.IsHardException(exception2))
                {
                    throw;
                }
                error = exception2;
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
                if (!flag)
                {
                    this.EndUpdateAsync(dm, error, e.Cancelled);
                }
            }
        }
Esempio n. 12
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();
                    }
                }
            }
        }