Ejemplo n.º 1
0
        public void UninstallAssemblyFromConfig([MarshalAs(UnmanagedType.IUnknown)] ref RegistrationConfig regConfig)
        {
            SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

            permission.Demand();
            permission.Assert();
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                RegistrationThreadWrapper wrapper = new RegistrationThreadWrapper(this, regConfig);
                Thread thread = new Thread(new ThreadStart(wrapper.UninstallThread));
                thread.Start();
                thread.Join();
                wrapper.PropUninstallResult();
            }
            else
            {
                TransactionOptions transactionOptions = new TransactionOptions {
                    Timeout        = TimeSpan.FromMinutes(0.0),
                    IsolationLevel = IsolationLevel.Serializable
                };
                CatalogSync obSync = new CatalogSync();
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions, EnterpriseServicesInteropOption.Full))
                {
                    new RegistrationDriver().UninstallAssembly(regConfig, obSync);
                    scope.Complete();
                }
                obSync.Wait();
            }
        }
Ejemplo n.º 2
0
        /// <include file='doc\RegistrationWrappers.uex' path='docs/doc[@for="RegistrationHelper.InstallAssemblyFromConfig"]/*' />
        public void InstallAssemblyFromConfig([MarshalAs(UnmanagedType.IUnknown)] ref RegistrationConfig regConfig)
        {
            // Create a permission object for unmanaged code
            SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

            // demand that the caller have this permission
            sp.Demand();

            // now that the caller is clean, assert it from now on.
            sp.Assert();

            Platform.Assert(Platform.W2K, "RegistrationHelper.InstallAssemblyFromConfig");

            if (Thread.CurrentThread.ApartmentState == ApartmentState.STA)
            {
                // HACK:  In order to reduce deadlock likelihood, we need to get off
                // the current STA (into an MTA) in order to do this work.
                // Whip off a new thread...
                RegistrationThreadWrapper wrap = new RegistrationThreadWrapper(this, regConfig);
                Thread t = new Thread(new ThreadStart(wrap.InstallThread));
                t.Start();
                t.Join();
                wrap.PropInstallResult();
            }
            else
            {
                // First, try to do this in a "transacted" manner.  This will
                // return false if we couldn't start up the transaction,
                // true if it succeeded.
                // We only do the transacted install if we're on win2k or higher,
                // cause MTS is all in the registry.
                if (Platform.IsLessThan(Platform.W2K) || !TryTransactedInstall(regConfig))
                {
                    // We need to try a non-transacted install:
                    DBG.Info(DBG.Registration, "Failed to do a transacted install.  Using non-tx install.");
                    RegistrationDriver helper = new RegistrationDriver();
                    helper.InstallAssembly(regConfig, null);
                }
            }
        }