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
        private bool TryTransactedUninstall(RegistrationConfig regConfig)
        {
            Perf.Tick("RegistrationHelper - Object creation (uninstall)");

            RegistrationHelperTx reg = null;

            try
            {
                reg = new RegistrationHelperTx();
                if (!reg.IsInTransaction())
                {
                    reg = null;
                }
                // reg is now bound into a transactional context?  do transactional work:
            }
            catch (Exception e)
            {
                DBG.Info(DBG.Registration, "Transacted uninstall failed w/ " + e);
                try
                {
                    EventLog appLog = new EventLog();
                    appLog.Source = "System.EnterpriseServices";
                    String errMsg = String.Format(Resource.FormatString("Reg_ErrTxUninst"), e);
                    appLog.WriteEntry(errMsg, EventLogEntryType.Error);
                }
                catch
                {}                      // We don't want to fail... fall back as we were before.
            }

            // Couldn't set up to do a transactional install
            if (reg == null)
            {
                return(false);
            }

            // HACK:  We have to pass in this CatalogSync object, which we use
            // so that we can watch until the CLB is updated on disc, because
            // there is a CRM bug in Win2K which keeps us from
            CatalogSync sync = new CatalogSync();

            reg.UninstallAssemblyFromConfig(ref regConfig, sync);
            sync.Wait();

            Perf.Tick("RegistrationHelper - Done");

            return(true);
        }