示例#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();
            }
        }
示例#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);
        }
        public void UninstallAssembly(RegistrationConfig regConfig, object obSync)
        {
            CatalogSync        sync       = null;
            SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

            permission.Demand();
            permission.Assert();
            if (obSync != null)
            {
                if (!(obSync is CatalogSync))
                {
                    throw new ArgumentException(Resource.FormatString("Err_obSync"));
                }
                sync = (CatalogSync)obSync;
            }
            Assembly        asm  = this.NewLoadAssembly(regConfig.AssemblyFile);
            ApplicationSpec spec = new ApplicationSpec(asm, regConfig);

            if (spec.ConfigurableTypes != null)
            {
                this.PrepDriver(ref spec);
                if (spec.ConfigurableTypes != null)
                {
                    ICatalogObject obj2 = this.FindApplication(this._appColl, spec);
                    if (obj2 == null)
                    {
                        throw new RegistrationException(Resource.FormatString("Reg_AppNotFoundErr", spec));
                    }
                    ICatalogCollection collection = (ICatalogCollection)this._appColl.GetCollection(CollectionName.Components, obj2.Key());
                    string[]           arr        = new string[spec.ConfigurableTypes.Length];
                    int index = 0;
                    foreach (Type type in spec.ConfigurableTypes)
                    {
                        arr[index] = Marshal.GenerateGuidForType(type).ToString();
                        index++;
                    }
                    Populate(collection);
                    bool flag   = true;
                    int  lIndex = 0;
                    while (lIndex < collection.Count())
                    {
                        ICatalogObject obj3 = (ICatalogObject)collection.Item(lIndex);
                        string         g    = (string)obj3.Key();
                        g = new Guid(g).ToString();
                        if (this.FindIndexOf(arr, g) != -1)
                        {
                            collection.Remove(lIndex);
                            if (sync != null)
                            {
                                sync.Set();
                            }
                        }
                        else
                        {
                            lIndex++;
                            flag = false;
                        }
                    }
                    SaveChanges(collection);
                    if (flag)
                    {
                        for (int i = 0; i < this._appColl.Count(); i++)
                        {
                            ICatalogObject obj4 = (ICatalogObject)this._appColl.Item(i);
                            if (obj4.Key().Equals(obj2.Key()))
                            {
                                this._appColl.Remove(i);
                                if (sync != null)
                                {
                                    sync.Set();
                                }
                                break;
                            }
                        }
                        SaveChanges(this._appColl);
                    }
                }
                this.UnregisterAssembly(asm, spec);
                this.CleanupDriver();
            }
        }
        public void InstallAssembly(RegistrationConfig regConfig, object obSync)
        {
            Assembly           asm        = null;
            ApplicationSpec    spec       = null;
            CatalogSync        sync       = null;
            bool               flag       = false;
            bool               flag2      = false;
            SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

            try
            {
                permission.Demand();
                permission.Assert();
                ICatalogObject app = null;
                this.PrepArguments(regConfig);
                asm  = this.NewLoadAssembly(regConfig.AssemblyFile);
                spec = new ApplicationSpec(asm, regConfig);
                if (spec.ConfigurableTypes == null)
                {
                    regConfig.Application = null;
                    regConfig.TypeLibrary = null;
                }
                else
                {
                    if (obSync != null)
                    {
                        if (!(obSync is CatalogSync))
                        {
                            throw new ArgumentException(Resource.FormatString("Err_obSync"));
                        }
                        sync = (CatalogSync)obSync;
                    }
                    this.PrepDriver(ref spec);
                    string message = string.Empty;
                    if (!this.ValidateBitness(spec, out message))
                    {
                        throw new RegistrationException(message);
                    }
                    if ((regConfig.InstallationFlags & InstallationFlags.Register) != InstallationFlags.Default)
                    {
                        flag = !this.IsAssemblyRegistered(spec);
                        this.ClassicRegistration(spec.Assembly);
                        if ((regConfig.InstallationFlags & InstallationFlags.ExpectExistingTypeLib) != InstallationFlags.Default)
                        {
                            RegisterTypeLibrary(spec.TypeLib);
                        }
                        else
                        {
                            flag2 = true;
                            GenerateTypeLibrary(spec.Assembly, spec.TypeLib, new Report(this.ReportWarning));
                        }
                    }
                    if (((regConfig.InstallationFlags & InstallationFlags.Install) != InstallationFlags.Default) && (spec.ConfigurableTypes != null))
                    {
                        if ((regConfig.InstallationFlags & InstallationFlags.CreateTargetApplication) != InstallationFlags.Default)
                        {
                            app = this.CreateApplication(spec, true);
                        }
                        else if ((regConfig.InstallationFlags & InstallationFlags.FindOrCreateTargetApplication) != InstallationFlags.Default)
                        {
                            app = this.FindOrCreateApplication(spec, (regConfig.InstallationFlags & InstallationFlags.ReconfigureExistingApplication) != InstallationFlags.Default);
                        }
                        this.InstallTypeLibrary(spec);
                        if (sync != null)
                        {
                            sync.Set();
                        }
                    }
                    if (((regConfig.InstallationFlags & InstallationFlags.Configure) != InstallationFlags.Default) && (spec.ConfigurableTypes != null))
                    {
                        this.ConfigureComponents(spec);
                        if (sync != null)
                        {
                            sync.Set();
                        }
                    }
                    if (app != null)
                    {
                        this.PostProcessApplication(app, spec);
                    }
                    this.CleanupDriver();
                }
            }
            catch (Exception exception)
            {
                if ((exception is NullReferenceException) || (exception is SEHException))
                {
                    throw;
                }
                if (((exception is SecurityException) || (exception is UnauthorizedAccessException)) || ((exception.InnerException != null) && ((exception.InnerException is SecurityException) || (exception.InnerException is UnauthorizedAccessException))))
                {
                    exception = new RegistrationException(Resource.FormatString("Reg_Unauthorized"), exception);
                }
                if (flag && (null != asm))
                {
                    try
                    {
                        this.ClassicUnregistration(asm);
                    }
                    catch (Exception exception2)
                    {
                        if ((exception2 is NullReferenceException) || (exception2 is SEHException))
                        {
                            throw;
                        }
                    }
                }
                if (flag2 && (null != asm))
                {
                    try
                    {
                        this.UnregisterTypeLib(asm);
                    }
                    catch (Exception exception3)
                    {
                        if ((exception3 is NullReferenceException) || (exception3 is SEHException))
                        {
                            throw;
                        }
                    }
                }
                throw exception;
            }
        }