Ejemplo n.º 1
0
        public ComCatalogCollection GetCollection(string collectionName)
        {
            ICatalogCollection collection = (ICatalogCollection)this.catalogCollection.GetCollection(collectionName, this.catalogObject.Key());

            collection.Populate();
            return(new ComCatalogCollection(collection));
        }
        private void EnsureRole(Hashtable cache)
        {
            ICatalogCollection appColl  = null;
            ICatalogObject     app      = null;
            ICatalogCollection roleColl = null;

            // Check to see if we've cached the existence of the role:
            Hashtable appRoleCache = (Hashtable)(cache[RoleCacheString]);

            if (appRoleCache == null)
            {
                appRoleCache           = new Hashtable();
                cache[RoleCacheString] = appRoleCache;
            }

            if (appRoleCache[_role] != null)
            {
                return;
            }

            appColl = (ICatalogCollection)(cache["ApplicationCollection"]);
            app     = (ICatalogObject)(cache["Application"]);
            DBG.Info(DBG.Registration, "Getting roles for app: " + app.Key());
            roleColl = (ICatalogCollection)(appColl.GetCollection(CollectionName.Roles, app.Key()));
            roleColl.Populate();

            ICatalogObject newRole = Search(roleColl, "Name", _role);

            if (newRole == null)
            {
                // We didn't find it, we need to try to add a new role:
                newRole = (ICatalogObject)(roleColl.Add());
                newRole.SetValue("Name", _role);

                if (_description != null)
                {
                    newRole.SetValue("Description", _description);
                }

                roleColl.SaveChanges();

                if (_setEveryoneAccess)
                {
                    DBG.Info(DBG.Registration, "\tAdding everyone to the role!");
                    ICatalogCollection userColl = (ICatalogCollection)(roleColl.GetCollection(CollectionName.UsersInRole, newRole.Key()));
                    userColl.Populate();

                    // Add the Everyone user to this guy, so that activation will
                    // subsequently succeed:
                    ICatalogObject newUser = (ICatalogObject)(userColl.Add());

                    newUser.SetValue("User", EveryoneAccount);

                    userColl.SaveChanges();
                }
            }

            // Mark this guy in the cache.
            appRoleCache[_role] = (Object)true;
        }
        public object FindObject(ICatalogCollection coll, object key)
        {
            ICatalogObject obj2      = (ICatalogObject)key;
            int            slot      = (int)obj2.GetValue("Index");
            ComMemberType  method    = ComMemberType.Method;
            MemberInfo     setMethod = Marshal.GetMethodInfoForComSlot(this._type, slot, ref method);

            if (setMethod is PropertyInfo)
            {
                switch (method)
                {
                case ComMemberType.PropSet:
                    setMethod = ((PropertyInfo)setMethod).GetSetMethod();
                    break;

                case ComMemberType.PropGet:
                    setMethod = ((PropertyInfo)setMethod).GetGetMethod();
                    break;
                }
            }
            if (this._map.InterfaceMethods != null)
            {
                for (int i = 0; i < this._map.InterfaceMethods.Length; i++)
                {
                    MethodInfo info2 = setMethod as MethodInfo;
                    if (this._map.InterfaceMethods[i] == info2)
                    {
                        return(this._map.TargetMethods[i]);
                    }
                }
            }
            return(setMethod);
        }
        static bool FindListener(Guid appid, out Guid clsid, out string progid)
        {
            clsid  = Guid.Empty;
            progid = null;

            ICatalogObject     appObj  = null;
            ICatalogCollection appColl = null;

            if (!FindApplication(appid.ToString("B"), out appObj, out appColl))
            {
                throw Tool.CreateException(SR.GetString(SR.ApplicationNotFound, appid.ToString("B")), null);
            }

            ICatalogCollection comps = (ICatalogCollection)appColl.GetCollection(CollectionName.Components, appObj.Key());

            comps.Populate();
            for (int i = 0; i < comps.Count(); i++)
            {
                ICatalogObject compObj = (ICatalogObject)comps.Item(i);
                if (IsListenerComponent(compObj))
                {
                    clsid  = new Guid((string)compObj.Key());
                    progid = (string)compObj.Name();
                    return(true);
                }
            }

            return(false);
        }
        public static bool GetApplicationBitness(ICatalog2 catalog, string partitionID, string applicationID)
        {
            ICatalogCollection partitions   = (ICatalogCollection)(catalog.GetCollection(CollectionName.Partitions));
            ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partitionID));

            applications.Populate();
            ICatalogCollection components = (ICatalogCollection)applications.GetCollection(CollectionName.Components, applicationID);

            try
            {
                components.Populate();
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                throw Tool.CreateException(SR.GetString(SR.FailedToDetermineTheBitnessOfApplication, applicationID), ex);
            }
            ICatalogObject component = (ICatalogObject)(components.Item(0));

            return(IsBitness64bit(component));
        }
        static bool SetComponentProperty(string appIdOrName, string compIdOrName, string property, object value)
        {
            ICatalogObject     appObj  = null;
            ICatalogCollection appColl = null;

            if (!FindApplication(appIdOrName, out appObj, out appColl))
            {
                throw Tool.CreateException(SR.GetString(SR.ApplicationNotFound, appIdOrName), null);
            }

            ICatalogCollection comps = (ICatalogCollection)appColl.GetCollection(CollectionName.Components, appObj.Key());

            comps.Populate();

            compIdOrName = compIdOrName.ToLowerInvariant(); //make compName lowercase

            for (int i = 0; i < comps.Count(); i++)
            {
                ICatalogObject compObj = (ICatalogObject)comps.Item(i);
                string         name    = ((string)compObj.Name()).ToLowerInvariant(); //make name lowercase
                string         id      = ((string)compObj.Key()).ToLowerInvariant();  //make key lowercase

                if (name == compIdOrName || id == compIdOrName)
                {
                    compObj.SetValue(property, value);
                    comps.SaveChanges();
                    return(true);
                }
            }

            return(false);
        }
        static void MarkComponentAsPrivate(ICatalog2 catalog, string partitionID, string applicationID, string progid)
        {
            ICatalogCollection partitions   = (ICatalogCollection)(catalog.GetCollection(CollectionName.Partitions));
            ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partitionID));

            applications.Populate();
            ICatalogCollection components = (ICatalogCollection)applications.GetCollection(CollectionName.Components, applicationID);

            try
            {
                components.Populate();
                for (int j = 0; j < components.Count(); j++)
                {
                    ICatalogObject component = (ICatalogObject)(components.Item(j));
                    if ((string)component.Name() == progid)
                    {
                        component.SetValue(PropertyName.IsPrivateComponent, true);
                        components.SaveChanges();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                ToolConsole.WriteWarning(SR.GetString(SR.FailedToMarkListenerComponentAsPrivateForApplication, progid, applicationID));
            }
        }
Ejemplo n.º 8
0
        public InterfaceConfigCallback(ICatalogCollection coll, Type t, Hashtable cache, RegistrationDriver driver)
        {
            _type   = t;
            _coll   = coll;
            _cache  = cache;
            _driver = driver;

            // TODO:  Populate w/ QueryByKey
            // TODO:  Build cache for FindObject()
            _ifcs = GetInteropInterfaces(_type);

            // Check to see if one of the interfaces is IProcessInitializer
            foreach (Type ifc in _ifcs)
            {
                if (Marshal.GenerateGuidForType(ifc) == IID_IProcessInitializer)
                {
                    DBG.Info(DBG.Registration, "Setting component " + cache["ComponentType"] + " up as process initializer");
                    try
                    {
                        ICatalogObject     comp     = cache["Component"] as ICatalogObject;
                        ICatalogCollection compColl = cache["ComponentCollection"] as ICatalogCollection;

                        comp.SetValue("InitializesServerApplication", 1);
                        compColl.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        throw new RegistrationException(Resource.FormatString("Reg_FailPIT", _type), e);
                    }
                }
            }

            RegistrationDriver.Populate(_coll);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            string             packageName = "TRICOLOR";
            ICOMAdminCatalog   catalog     = (ICOMAdminCatalog)Interaction.CreateObject("COMAdmin.COMAdminCatalog", string.Empty);
            ICatalogCollection packages    = (ICatalogCollection)catalog.GetCollection("Applications");

            packages.Populate();
            foreach (ICatalogObject package in packages)
            {
                if (package.Name.ToString().Equals(packageName))
                {
                    ICatalogCollection roles = (ICatalogCollection)packages.GetCollection("Roles", package.Key);
                    roles.Populate();
                    ICatalogObject role = (ICatalogObject)roles.Add();
                    role.set_Value("Name", "MyRoleName");
                    roles.SaveChanges();
                    ICatalogCollection users = (ICatalogCollection)roles.GetCollection("UsersInRole", role.Key);
                    users.Populate();
                    ICatalogObject user = (ICatalogObject)users.Add();
                    user.set_Value("User", "MV0266\\IUSR_MV0266");
                    users.SaveChanges();
                    break;
                }
            }
        }
        private void ConfigureComponents(ApplicationSpec spec)
        {
            ICatalogCollection coll = null;

            try
            {
                ICatalogObject obj2 = this.FindApplication(this._appColl, spec);
                if (obj2 == null)
                {
                    throw new RegistrationException(Resource.FormatString("Reg_AppNotFoundErr", spec));
                }
                this._cache["Application"]           = obj2;
                this._cache["ApplicationType"]       = spec.Assembly;
                this._cache["ApplicationCollection"] = this._appColl;
                coll = (ICatalogCollection)this._appColl.GetCollection(CollectionName.Components, obj2.Key());
                this.ConfigureCollection(coll, new ComponentConfigCallback(coll, spec, this._cache, this, this._installFlags));
            }
            catch (RegistrationException)
            {
                throw;
            }
            catch (COMException exception)
            {
                throw this.WrapCOMException(coll, exception, Resource.FormatString("Reg_ConfigErr"));
            }
            catch (Exception exception2)
            {
                if ((exception2 is NullReferenceException) || (exception2 is SEHException))
                {
                    throw;
                }
                throw new RegistrationException(Resource.FormatString("Reg_ConfigUnkErr"), exception2);
            }
        }
Ejemplo n.º 11
0
        public void ConfigureSubCollections(ICatalogCollection coll)
        {
            if ((_installFlags & InstallationFlags.ConfigureComponentsOnly) == 0)
            {
                foreach (Type t in _spec.ConfigurableTypes)
                {
                    ICatalogObject     obj     = (ICatalogObject)FindObject(coll, t);
                    ICatalogCollection ifcColl = (ICatalogCollection)(coll.GetCollection(CollectionName.Interfaces, obj.Key()));

                    // Poke the cache so it's up to date...
                    _cache["Component"]     = obj;
                    _cache["ComponentType"] = t;

                    InterfaceConfigCallback cb = new InterfaceConfigCallback(ifcColl, t, _cache, _driver);
                    _driver.ConfigureCollection(ifcColl, cb);

                    if (_cache["SecurityOnMethods"] != null || ServicedComponentInfo.AreMethodsSecure(t))
                    {
                        DBG.Info(DBG.Registration, "Found security on methods for: " + t);
                        FixupMethodSecurity(ifcColl);
                        _cache["SecurityOnMethods"] = null;
                    }
                }
            }
        }
 public InterfaceConfigCallback(ICatalogCollection coll, Type t, Hashtable cache, RegistrationDriver driver)
 {
     this._type = t;
     this._coll = coll;
     this._cache = cache;
     this._driver = driver;
     this._ifcs = this.GetInteropInterfaces(this._type);
     foreach (Type type in this._ifcs)
     {
         if (Marshal.GenerateGuidForType(type) == IID_IProcessInitializer)
         {
             try
             {
                 ICatalogObject obj2 = cache["Component"] as ICatalogObject;
                 ICatalogCollection catalogs = cache["ComponentCollection"] as ICatalogCollection;
                 obj2.SetValue("InitializesServerApplication", 1);
                 catalogs.SaveChanges();
             }
             catch (Exception exception)
             {
                 if ((exception is NullReferenceException) || (exception is SEHException))
                 {
                     throw;
                 }
                 throw new RegistrationException(Resource.FormatString("Reg_FailPIT", this._type), exception);
             }
         }
     }
     RegistrationDriver.Populate(this._coll);
 }
 private static void ConfigureComponent(ICatalogCollection coll, ICatalogObject obj)
 {
     obj.SetValue("Transaction", TransactionOption.RequiresNew);
     obj.SetValue("ComponentTransactionTimeoutEnabled", true);
     obj.SetValue("ComponentTransactionTimeout", 0);
     coll.SaveChanges();
 }
        public object FindObject(ICatalogCollection coll, object key)
        {
            ICatalogObject obj2 = (ICatalogObject) key;
            int slot = (int) obj2.GetValue("Index");
            ComMemberType method = ComMemberType.Method;
            MemberInfo setMethod = Marshal.GetMethodInfoForComSlot(this._type, slot, ref method);
            if (setMethod is PropertyInfo)
            {
                switch (method)
                {
                    case ComMemberType.PropSet:
                        setMethod = ((PropertyInfo) setMethod).GetSetMethod();
                        break;

                    case ComMemberType.PropGet:
                        setMethod = ((PropertyInfo) setMethod).GetGetMethod();
                        break;
                }
            }
            if (this._map.InterfaceMethods != null)
            {
                for (int i = 0; i < this._map.InterfaceMethods.Length; i++)
                {
                    MethodInfo info2 = setMethod as MethodInfo;
                    if (this._map.InterfaceMethods[i] == info2)
                    {
                        return this._map.TargetMethods[i];
                    }
                }
            }
            return setMethod;
        }
Ejemplo n.º 15
0
        public static void DeleteCOMApplication(string applicationName)
        {
            ICatalogCollection catalogColl = GetApplicationCollection();
            ICatalogObject     catalogObj;

            catalogColl.Populate();

            if (catalogColl.Count == 0)
            {
                Console.WriteLine("No application found...");
                return;
            }

            for (int i = 0; i < catalogColl.Count; i++)
            {
                catalogObj = (ICatalogObject)catalogColl.get_Item(i);
                if (applicationName == ((string)catalogObj.Name))
                {
                    catalogColl.Remove(i);
                    catalogColl.SaveChanges();
                    Thread.Sleep(100);
                    //Console.WriteLine(applicationName + " application has been deleted...")
                    return;
                }
            }
        }
        internal bool ConfigureObject(ICustomAttributeProvider t, ICatalogObject obj, ICatalogCollection coll, string prefix, Hashtable cache)
        {
            bool flag = false;

            object[] customAttributes = t.GetCustomAttributes(true);
            cache[prefix]                = obj;
            cache[prefix + "Type"]       = t;
            cache[prefix + "Collection"] = coll;
            cache["CurrentTarget"]       = prefix;
            foreach (object obj2 in customAttributes)
            {
                if (obj2 is IConfigurationAttribute)
                {
                    try
                    {
                        IConfigurationAttribute attribute = (IConfigurationAttribute)obj2;
                        if (attribute.IsValidTarget(prefix) && attribute.Apply(cache))
                        {
                            flag = true;
                        }
                    }
                    catch (Exception exception)
                    {
                        if ((exception is NullReferenceException) || (exception is SEHException))
                        {
                            throw;
                        }
                        throw new RegistrationException(Resource.FormatString("Reg_ComponentAttrErr", obj.Name(), obj2), exception);
                    }
                }
            }
            return(flag);
        }
 public InterfaceConfigCallback(ICatalogCollection coll, Type t, Hashtable cache, RegistrationDriver driver)
 {
     this._type   = t;
     this._coll   = coll;
     this._cache  = cache;
     this._driver = driver;
     this._ifcs   = this.GetInteropInterfaces(this._type);
     foreach (Type type in this._ifcs)
     {
         if (Marshal.GenerateGuidForType(type) == IID_IProcessInitializer)
         {
             try
             {
                 ICatalogObject     obj2     = cache["Component"] as ICatalogObject;
                 ICatalogCollection catalogs = cache["ComponentCollection"] as ICatalogCollection;
                 obj2.SetValue("InitializesServerApplication", 1);
                 catalogs.SaveChanges();
             }
             catch (Exception exception)
             {
                 if ((exception is NullReferenceException) || (exception is SEHException))
                 {
                     throw;
                 }
                 throw new RegistrationException(Resource.FormatString("Reg_FailPIT", this._type), exception);
             }
         }
     }
     RegistrationDriver.Populate(this._coll);
 }
Ejemplo n.º 18
0
        public void UnregisterComTransactionEventsListener()
        {
            ICOMAdminCatalog   pICat  = new COMAdminCatalog();
            ICatalogCollection pISubs = (ICatalogCollection)pICat.GetCollection("TransientSubscriptions");

            long           lCount = 0;
            int            i      = 0;
            ICatalogObject pISub;

            pISubs.Populate();
            lCount = pISubs.Count;
            if (lCount == 0)
            {
                return;
            }
            for (i = 0; i < lCount; i++)
            {
                pISub = (ICatalogObject)pISubs.get_Item(i);

                if (subID == (string)pISub.get_Value("ID"))
                {
                    pISubs.Remove(i);
                    pISubs.SaveChanges();
                    return;
                }
            }
        }
 private static void ConfigureComponent(ICatalogCollection coll, ICatalogObject obj)
 {
     obj.SetValue("Transaction", TransactionOption.RequiresNew);
     obj.SetValue("ComponentTransactionTimeoutEnabled", true);
     obj.SetValue("ComponentTransactionTimeout", 0);
     coll.SaveChanges();
 }
 public ComAdminClassInfo(ICatalogObject compObj, ICatalogCollection compColl)
 {
     this.clsid             = new Guid((string)compObj.Key());
     this.progid            = (string)compObj.Name();
     this.isPrivate         = (bool)compObj.GetValue(PropertyName.IsPrivateComponent);
     this.transactionOption = (TransactionOption)compObj.GetValue(PropertyName.TransactionOption);
     this.BuildInterfaces(compObj, compColl);
 }
 public ComponentConfigCallback(ICatalogCollection coll, ApplicationSpec spec, Hashtable cache, RegistrationDriver driver, InstallationFlags installFlags)
 {
     this._spec = spec;
     this._coll = coll;
     this._cache = cache;
     this._driver = driver;
     this._installFlags = installFlags;
     RegistrationDriver.Populate(coll);
 }
Ejemplo n.º 22
0
        internal static ComCatalogObject FindApplication(Guid applicationId)
        {
            ICatalog2 catalog = (ICatalog2)(new xCatalog());

            ICatalogObject     appObject           = null;
            ICatalogCollection partitionCollection = null;

            try
            {
                partitionCollection = (ICatalogCollection)catalog.GetCollection(
                    "Partitions");
                partitionCollection.Populate();
            }
            catch (COMException comException)
            {
                if (comException.ErrorCode != HR.COMADMIN_E_PARTITIONS_DISABLED)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(comException);
                }
            }

            if (partitionCollection != null)
            {
                for (int i = 0; i < partitionCollection.Count(); i++)
                {
                    ICatalogObject partition;
                    partition = (ICatalogObject)partitionCollection.Item(i);

                    ICatalogCollection appCollection;
                    appCollection = (ICatalogCollection)partitionCollection.GetCollection(
                        "Applications",
                        partition.Key());
                    appCollection.Populate();

                    appObject = FindApplication(appCollection, applicationId);
                    if (appObject != null)
                    {
                        return(new ComCatalogObject(appObject, appCollection));
                    }
                }
            }
            else
            {
                ICatalogCollection appCollection;
                appCollection = (ICatalogCollection)catalog.GetCollection(
                    "Applications");
                appCollection.Populate();

                appObject = FindApplication(appCollection, applicationId);
                if (appObject != null)
                {
                    return(new ComCatalogObject(appObject, appCollection));
                }
            }

            return(null);
        }
 public ComponentConfigCallback(ICatalogCollection coll, ApplicationSpec spec, Hashtable cache, RegistrationDriver driver, InstallationFlags installFlags)
 {
     this._spec         = spec;
     this._coll         = coll;
     this._cache        = cache;
     this._driver       = driver;
     this._installFlags = installFlags;
     RegistrationDriver.Populate(coll);
 }
Ejemplo n.º 24
0
        public SensAdvisor()
        {
            COMAdminCatalogClass comAdmin      = new COMAdminCatalogClass();
            ICatalogCollection   subCollection = (ICatalogCollection)comAdmin.GetCollection("TransientSubscriptions");

            SubscribeToEvent(subCollection, "PostShell", ISensLogon2_ID);
            SubscribeToEvent(subCollection, "Logon", ISensLogon2_ID);
            SubscribeToEvent(subCollection, "Logoff", ISensLogon2_ID);
            SubscribeToEvent(subCollection, "SessionReconnect", ISensLogon2_ID);
            SubscribeToEvent(subCollection, "SessionDisconnect", ISensLogon2_ID);
        }
 private ICatalogObject FindApplication(ICatalogCollection apps, ApplicationSpec spec)
 {
     for (int i = 0; i < apps.Count(); i++)
     {
         ICatalogObject obj2 = (ICatalogObject)apps.Item(i);
         if (spec.Matches(obj2))
         {
             return(obj2);
         }
     }
     return(null);
 }
 public void ConfigureSubCollections(ICatalogCollection coll)
 {
     foreach (ICatalogObject obj2 in this)
     {
         Type t = (Type) this.FindObject(coll, obj2);
         if (t != null)
         {
             ICatalogCollection collection = (ICatalogCollection) coll.GetCollection(CollectionName.Methods, obj2.Key());
             this._driver.ConfigureCollection(collection, new MethodConfigCallback(collection, t, this._type, this._cache, this._driver));
         }
     }
 }
 public void ConfigureSubCollections(ICatalogCollection coll)
 {
     foreach (ICatalogObject obj2 in this)
     {
         Type t = (Type)this.FindObject(coll, obj2);
         if (t != null)
         {
             ICatalogCollection collection = (ICatalogCollection)coll.GetCollection(CollectionName.Methods, obj2.Key());
             this._driver.ConfigureCollection(collection, new MethodConfigCallback(collection, t, this._type, this._cache, this._driver));
         }
     }
 }
        public object FindObject(ICatalogCollection coll, object key)
        {
            ICatalogObject ifcObj = (ICatalogObject)key;
            Type           type   = null;

            type = this.FindInterfaceByID(ifcObj, this._type, this._ifcs);
            if (type == null)
            {
                type = this.FindInterfaceByName(ifcObj, this._type, this._ifcs);
            }
            return(type);
        }
Ejemplo n.º 29
0
 private ICatalogObject Search(ICatalogCollection coll, string key, string value)
 {
     for (int i = 0; i < coll.Count(); i++)
     {
         ICatalogObject obj2 = (ICatalogObject)coll.Item(i);
         string         str  = (string)obj2.GetValue(key);
         if (str == value)
         {
             return(obj2);
         }
     }
     return(null);
 }
Ejemplo n.º 30
0
        private void FixupMethodSecurity(ICatalogCollection coll)
        {
            // HACK:  We've gone through and configured all the methods
            // and interfaces.  If we noticed that we've got method
            // based security, we need to add a Marshaler role to
            // IManagedObject (in order to let remote activators marshal
            // this guy into their space), to IDisposable (to let the caller dispose
            // the object) and to IServiceComponentInfo (to query remote object).

            FixupMethodSecurityForInterface(coll, typeof(IManagedObject));
            FixupMethodSecurityForInterface(coll, typeof(IServicedComponentInfo));
            FixupMethodSecurityForInterface(coll, typeof(IDisposable));
        }
 private static ICatalogObject FindApplication(ICatalogCollection appCollection, Guid applicationId)
 {
     ICatalogObject obj2 = null;
     for (int i = 0; i < appCollection.Count(); i++)
     {
         obj2 = (ICatalogObject) appCollection.Item(i);
         if (Fx.CreateGuid((string) obj2.GetValue("ID")) == applicationId)
         {
             return obj2;
         }
     }
     return null;
 }
 private ICatalogObject Search(ICatalogCollection coll, string key, string value)
 {
     for (int i = 0; i < coll.Count(); i++)
     {
         ICatalogObject obj2 = (ICatalogObject) coll.Item(i);
         string str = (string) obj2.GetValue(key);
         if (str == value)
         {
             return obj2;
         }
     }
     return null;
 }
    public SensEvents()
    {
        _sink = new Sink(this);
        COMAdminCatalogClass catalog = new COMAdminCatalogClass();     // need a reference to COMAdmin
        // we just need a transient subscription, for the lifetime of our application
        ICatalogCollection subscriptions = (ICatalogCollection)catalog.GetCollection("TransientSubscriptions");
        ICatalogObject     subscription  = (ICatalogObject)subscriptions.Add();

        subscription.set_Value("EventCLSID", SENSGUID_EVENTCLASS_LOGON2.ToString("B"));
        subscription.set_Value("SubscriberInterface", _sink);
        // NOTE: we don't specify a method name, so all methods may be called
        subscriptions.SaveChanges();
    }
        public static void SetAppDir(string appidOrName, string path)
        {
            ICatalogObject     appObj  = null;
            ICatalogCollection appColl = null;

            if (!FindApplication(appidOrName, out appObj, out appColl))
            {
                throw Tool.CreateException(SR.GetString(SR.ApplicationNotFound, appidOrName), null);
            }

            appObj.SetValue(PropertyName.ApplicationDirectory, path);
            appColl.SaveChanges();
        }
        public static bool ResolveApplicationId(string appidOrName, out Guid appId)
        {
            ICatalogObject     appObj  = null;
            ICatalogCollection appColl = null;

            appId = Guid.Empty;
            if (!FindApplication(appidOrName, out appObj, out appColl))
            {
                return(false);
            }

            appId = new Guid((string)appObj.Key());
            return(true);
        }
Ejemplo n.º 36
0
        private static ICatalogObject FindApplication(ICatalogCollection appCollection, Guid applicationId)
        {
            ICatalogObject obj2 = null;

            for (int i = 0; i < appCollection.Count(); i++)
            {
                obj2 = (ICatalogObject)appCollection.Item(i);
                if (Fx.CreateGuid((string)obj2.GetValue("ID")) == applicationId)
                {
                    return(obj2);
                }
            }
            return(null);
        }
 internal static void Populate(ICatalogCollection coll)
 {
     try
     {
         coll.Populate();
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode != -2146368511)
         {
             throw;
         }
     }
 }
 public object FindObject(ICatalogCollection coll, object key)
 {
     Guid guid = Marshal.GenerateGuidForType((Type) key);
     for (int i = 0; i < coll.Count(); i++)
     {
         ICatalogObject obj2 = (ICatalogObject) coll.Item(i);
         Guid guid2 = new Guid((string) obj2.Key());
         if (guid2 == guid)
         {
             return obj2;
         }
     }
     throw new RegistrationException(Resource.FormatString("Reg_ComponentMissing", ((Type) key).FullName));
 }
 private void ApplicationDefaults(ICatalogObject obj, ICatalogCollection coll)
 {
     obj.SetValue("Activation", ActivationOption.Library);
     obj.SetValue("AccessChecksLevel", AccessChecksLevelOption.Application);
     obj.SetValue("ApplicationAccessChecksEnabled", true);
     obj.SetValue("Authentication", AuthenticationOption.Packet);
     obj.SetValue("CRMEnabled", false);
     obj.SetValue("EventsEnabled", true);
     obj.SetValue("ImpersonationLevel", ImpersonationLevelOption.Impersonate);
     obj.SetValue("QueuingEnabled", false);
     obj.SetValue("QueueListenerEnabled", false);
     obj.SetValue("SoapActivated", false);
     obj.SetValue("QCListenerMaxThreads", 0);
 }
 private static ICatalogObject FindApplication(ICatalogCollection coll, Guid appid, ref int idx)
 {
     int num = coll.Count();
     for (int i = 0; i < num; i++)
     {
         ICatalogObject obj2 = (ICatalogObject) coll.Item(i);
         Guid guid = new Guid((string) obj2.GetValue("ID"));
         if (guid == appid)
         {
             idx = i;
             return obj2;
         }
     }
     return null;
 }
 private static ICatalogObject FindComponent(ICatalogCollection coll, Guid clsid, ref int idx)
 {
     RegistrationDriver.Populate(coll);
     int num = coll.Count();
     for (int i = 0; i < num; i++)
     {
         ICatalogObject obj2 = (ICatalogObject) coll.Item(i);
         Guid guid = new Guid((string) obj2.GetValue("CLSID"));
         if (guid == clsid)
         {
             idx = i;
             return obj2;
         }
     }
     return null;
 }
 private void FindInterfaceByKey(string key, ICatalogCollection coll, Type comp, out ICatalogObject ifcObj, out Type ifcType)
 {
     ifcType = FindInterfaceByName(key, comp);
     if (ifcType == null)
     {
         throw new RegistrationException(Resource.FormatString("Reg_TypeFindError", key, comp.ToString()));
     }
     Guid guid = Marshal.GenerateGuidForType(ifcType);
     object[] aKeys = new object[] { "{" + guid + "}" };
     coll.PopulateByKey(aKeys);
     if (coll.Count() != 1)
     {
         throw new RegistrationException(Resource.FormatString("Reg_TypeFindError", key, comp.ToString()));
     }
     ifcObj = (ICatalogObject) coll.Item(0);
 }
Ejemplo n.º 43
0
        static bool FindApplication(string appidOrName, out ICatalogObject targetAppObj, out ICatalogCollection appColl)
        {
            targetAppObj = null;
            appColl = null;

            bool found = false;
            ICatalog2 catalog = GetCatalog();
            string partitionId = null;

            partitionId = GetPartitionIdForApplication(catalog, appidOrName, true);
            if (!string.IsNullOrEmpty(partitionId))
            {
                SetCurrentPartition(catalog, partitionId);
            }

            appColl = (ICatalogCollection)(catalog.GetCollection(CollectionName.Applications));
            appColl.Populate();

            for (int i = 0; i < appColl.Count(); i++)
            {
                ICatalogObject appObj = (ICatalogObject)(appColl.Item(i));
                string id = ((string)appObj.Key()).ToLowerInvariant();
                string name = ((string)appObj.Name()).ToLowerInvariant();
                appidOrName = appidOrName.ToLowerInvariant();

                if (!found)
                {
                    if ((appidOrName == id) || (appidOrName == name))
                    {
                        found = true;
                        targetAppObj = appObj;
                    }
                }
                else
                {
                    if ((appidOrName == id) || (appidOrName == name))
                    {
                        throw Tool.CreateException(SR.GetString(SR.AmbiguousApplicationName, appidOrName), null);
                    }
                }
            }

            return found;
        }
 public void ConfigureSubCollections(ICatalogCollection coll)
 {
     if ((this._installFlags & InstallationFlags.ConfigureComponentsOnly) == InstallationFlags.Default)
     {
         foreach (Type type in this._spec.ConfigurableTypes)
         {
             ICatalogObject obj2 = (ICatalogObject) this.FindObject(coll, type);
             ICatalogCollection collection = (ICatalogCollection) coll.GetCollection(CollectionName.Interfaces, obj2.Key());
             this._cache["Component"] = obj2;
             this._cache["ComponentType"] = type;
             InterfaceConfigCallback cb = new InterfaceConfigCallback(collection, type, this._cache, this._driver);
             this._driver.ConfigureCollection(collection, cb);
             if ((this._cache["SecurityOnMethods"] != null) || ServicedComponentInfo.AreMethodsSecure(type))
             {
                 this.FixupMethodSecurity(collection);
                 this._cache["SecurityOnMethods"] = null;
             }
         }
     }
 }
 public MethodConfigCallback(ICatalogCollection coll, Type t, Type impl, Hashtable cache, RegistrationDriver driver)
 {
     this._type = t;
     this._impl = impl;
     this._coll = coll;
     this._cache = cache;
     this._driver = driver;
     if (this._type.IsInterface)
     {
         this._map = this._impl.GetInterfaceMap(this._type);
     }
     else
     {
         this._map.InterfaceMethods = null;
         this._map.InterfaceType = null;
         this._map.TargetMethods = null;
         this._map.TargetType = null;
     }
     RegistrationDriver.Populate(coll);
 }
 internal bool AfterSaveChanges(ICustomAttributeProvider t, ICatalogObject obj, ICatalogCollection coll, string prefix, Hashtable cache)
 {
     bool flag = false;
     object[] customAttributes = t.GetCustomAttributes(true);
     cache[prefix] = obj;
     cache[prefix + "Type"] = t;
     cache[prefix + "Collection"] = coll;
     cache["CurrentTarget"] = prefix;
     foreach (object obj2 in customAttributes)
     {
         if (obj2 is IConfigurationAttribute)
         {
             IConfigurationAttribute attribute = (IConfigurationAttribute) obj2;
             if (attribute.IsValidTarget(prefix) && attribute.AfterSaveChanges(cache))
             {
                 flag = true;
             }
         }
     }
     return flag;
 }
 private static RegistrationErrorInfo[] BuildErrorInfoChain(ICatalogCollection coll)
 {
     RegistrationErrorInfo[] infoArray2;
     try
     {
         Populate(coll);
         int num = coll.Count();
         RegistrationErrorInfo[] infoArray = null;
         if (num > 0)
         {
             infoArray = new RegistrationErrorInfo[num];
             for (int i = 0; i < num; i++)
             {
                 string majorRef = null;
                 string minorRef = null;
                 int errorCode = 0;
                 ICatalogObject obj2 = (ICatalogObject) coll.Item(i);
                 string name = (string) obj2.GetValue("Name");
                 errorCode = (int) obj2.GetValue("ErrorCode");
                 majorRef = (string) obj2.GetValue("MajorRef");
                 minorRef = (string) obj2.GetValue("MinorRef");
                 infoArray[i] = new RegistrationErrorInfo(majorRef, minorRef, name, errorCode);
             }
         }
         infoArray2 = infoArray;
     }
     catch (Exception exception)
     {
         if ((exception is NullReferenceException) || (exception is SEHException))
         {
             throw;
         }
         throw new RegistrationException(Resource.FormatString("Reg_ErrCollectionErr"), exception);
     }
     return infoArray2;
 }
Ejemplo n.º 48
0
        public ComAdminAppInfo(ICatalogObject appObj, ICatalogCollection appColl)
        {
            this.appid = new Guid((string)appObj.Key());
            this.appname = (string)appObj.Name();
            this.appdir = (string)appObj.GetValue(PropertyName.ApplicationDirectory);
            // Note that casting to long would throw an InvalidCastException
            this.serverActivated = ((int)appObj.GetValue(PropertyName.Activation)) == 1;
            this.systemApplication = (bool)appObj.GetValue(PropertyName.IsSystem);
            this.processPooled = ((int)appObj.GetValue(PropertyName.ConcurrentApps)) > 1;
            this.automaticRecycling = (((int)appObj.GetValue(PropertyName.RecycleActivationLimit) > 0) ||
                ((int)appObj.GetValue(PropertyName.RecycleCallLimit) > 0) ||
                ((int)appObj.GetValue(PropertyName.RecycleLifetimeLimit) > 0) ||
                ((int)appObj.GetValue(PropertyName.RecycleMemoryLimit) > 0));

            this.BuildClasses(appObj, appColl);
        }
 public object FindObject(ICatalogCollection coll, object key)
 {
     ICatalogObject ifcObj = (ICatalogObject) key;
     Type type = null;
     type = this.FindInterfaceByID(ifcObj, this._type, this._ifcs);
     if (type == null)
     {
         type = this.FindInterfaceByName(ifcObj, this._type, this._ifcs);
     }
     return type;
 }
 private void FixupMethodSecurity(ICatalogCollection coll)
 {
     this.FixupMethodSecurityForInterface(coll, typeof(IManagedObject));
     this.FixupMethodSecurityForInterface(coll, typeof(IServicedComponentInfo));
     this.FixupMethodSecurityForInterface(coll, typeof(IDisposable));
 }
 private void FixupMethodSecurityForInterface(ICatalogCollection coll, Type InterfaceType)
 {
     ICatalogObject obj2 = null;
     Guid guid = Marshal.GenerateGuidForType(InterfaceType);
     int num = coll.Count();
     for (int i = 0; i < num; i++)
     {
         ICatalogObject obj3 = (ICatalogObject) coll.Item(i);
         if (new Guid((string) obj3.Key()) == guid)
         {
             obj2 = obj3;
             break;
         }
     }
     if (obj2 != null)
     {
         SecurityRoleAttribute attribute = new SecurityRoleAttribute("Marshaler", false) {
             Description = Resource.FormatString("Reg_MarshalerDesc")
         };
         IConfigurationAttribute attribute2 = attribute;
         this._cache["CurrentTarget"] = "Interface";
         this._cache["InterfaceCollection"] = coll;
         this._cache["Interface"] = obj2;
         this._cache["InterfaceType"] = InterfaceType;
         if (attribute2.Apply(this._cache))
         {
             coll.SaveChanges();
         }
         if (attribute2.AfterSaveChanges(this._cache))
         {
             coll.SaveChanges();
         }
     }
 }
 public void ConfigureSubCollections(ICatalogCollection coll)
 {
 }
 internal static void SaveChanges(ICatalogCollection coll)
 {
     coll.SaveChanges();
 }
 private void PrepDriver(ref ApplicationSpec spec)
 {
     try
     {
         this._cat = (ICatalog) new xCatalog();
     }
     catch (Exception exception)
     {
         if ((exception is NullReferenceException) || (exception is SEHException))
         {
             throw;
         }
         throw new RegistrationException(Resource.FormatString("Reg_CatalogErr"), exception);
     }
     if (((spec.Partition == null) || (spec.Partition.Length == 0)) && (spec.ID != null))
     {
         try
         {
             Type type = this._cat.GetType();
             try
             {
                 spec.Partition = (string) this.InvokeMemberHelper(type, "GetAppPartitionId", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.ID });
             }
             catch (COMException exception2)
             {
                 if (-2147352570 == exception2.ErrorCode)
                 {
                     spec.Partition = (string) this.InvokeMemberHelper(type, "GetPartitionID", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.ID });
                 }
             }
         }
         catch (Exception exception3)
         {
             if ((exception3 is NullReferenceException) || (exception3 is SEHException))
             {
                 throw;
             }
         }
     }
     if ((spec.Partition != null) && (spec.Partition.Length != 0))
     {
         try
         {
             Type type2 = this._cat.GetType();
             try
             {
                 this.InvokeMemberHelper(type2, "SetApplicationPartition", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.Partition });
             }
             catch (COMException exception4)
             {
                 if (-2147352570 != exception4.ErrorCode)
                 {
                     throw;
                 }
                 this.InvokeMemberHelper(type2, "CurrentPartition", BindingFlags.SetProperty, null, this._cat, new object[] { spec.Partition });
             }
         }
         catch (Exception exception5)
         {
             if ((exception5 is NullReferenceException) || (exception5 is SEHException))
             {
                 throw;
             }
             throw new RegistrationException(Resource.FormatString("Reg_PartitionErr", spec.Partition), exception5);
         }
     }
     try
     {
         this._appColl = (ICatalogCollection) this._cat.GetCollection(CollectionName.Applications);
         Populate(this._appColl);
     }
     catch (Exception exception6)
     {
         if ((exception6 is NullReferenceException) || (exception6 is SEHException))
         {
             throw;
         }
         throw new RegistrationException(Resource.FormatString("Reg_CatalogErr"), exception6);
     }
     this._cache = new Hashtable();
 }
Ejemplo n.º 55
0
        void BuildInterfaces(ICatalogObject compObj, ICatalogCollection compColl)
        {
            this.interfaces = new List<ComAdminInterfaceInfo>();

            ICatalogCollection interfaceColl = (ICatalogCollection)compColl.GetCollection(CollectionName.InterfacesForComponent, compObj.Key());
            interfaceColl.Populate();
            for (int i = 0; i < interfaceColl.Count(); i++)
            {
                ICatalogObject itf = (ICatalogObject)interfaceColl.Item(i);
                Guid interfaceID = new Guid((string)itf.Key());
                ComAdminInterfaceInfo interfaceInfo = new ComAdminInterfaceInfo(interfaceID, (string)itf.Name());
                this.interfaces.Add(interfaceInfo);

            }

        }
Ejemplo n.º 56
0
        static ICatalogObject FindApplication(ICatalogCollection appCollection,
                                              Guid applicationId)
        {
            ICatalogObject appObject = null;

            for (int i = 0; i < appCollection.Count(); i++)
            {
                appObject = (ICatalogObject)appCollection.Item(i);
                Guid id = Fx.CreateGuid((string)appObject.GetValue("ID"));

                if (id == applicationId)
                    return appObject;
            }

            return null;
        }
Ejemplo n.º 57
0
        void BuildClasses(ICatalogObject appObj, ICatalogCollection appColl)
        {
            int versionStrSize = 256;
            StringBuilder version = new StringBuilder(256);

            bool isFrameworkVersionSet = false;
            bool isRuntimeVersionSet = false;
            bool isRuntimeVersionInstalled = true;

            int length = 0;
            Version appClrVersion = null;
            this.classes = new List<ComAdminClassInfo>();

            ICatalogCollection comps = (ICatalogCollection)appColl.GetCollection(CollectionName.Components, appObj.Key());
            comps.Populate();

            for (int i = 0; i < comps.Count(); i++)
            {
                ICatalogObject comp = (ICatalogObject)comps.Item(i);
                ComAdminClassInfo classInfo = new ComAdminClassInfo(comp, comps);
                isFrameworkVersionSet = false;

                if (!isRuntimeVersionSet)
                {
                    isFrameworkVersionSet = (SafeNativeMethods.ERROR_SUCCESS == SafeNativeMethods.GetRequestedRuntimeVersionForCLSID(classInfo.Clsid, version, versionStrSize, ref length, 0));
                    if (isFrameworkVersionSet && TryGetVersionFromString(version, out appClrVersion))
                    {
                        if (IsCLRVersionInstalled(appClrVersion))
                        {
                            isRuntimeVersionSet = true;
                        }
                        else if (ValidateCLRVersion(appClrVersion))
                        {
                            // We've found an valid CLR version in the app but that runtime version is not installed
                            isRuntimeVersionSet = true;
                            isRuntimeVersionInstalled = false;
                        }
                    }
                }

                if (ComAdminWrapper.IsListenerComponent(comp))
                {
                    this.listenerExists = true;
                }
                else
                {
                    this.classes.Add(classInfo);
                }
            }

            //Parse the version number we get
            // If the version is V4.0* we are going to register the 4.0 version of ServiceMonikerSupport.dll
            // Anything else we are going to register the 3.0 version of ServiceMonikerSupport.dll
            if (isRuntimeVersionSet && isRuntimeVersionInstalled)
            {
                if (appClrVersion.Major == 4 && appClrVersion.Minor == 0)
                {
                    this.runtimeVersion = RuntimeVersions.V40;
                }
                else if (appClrVersion.Major == 2 && appClrVersion.Minor == 0)
                {
                    this.runtimeVersion = RuntimeVersions.V20;
                }
                else
                {
                    // It is non of the CLR version this tool recognize
                    throw Tool.CreateException(SR.GetString(SR.FailedToGetRuntime, appClrVersion.ToString()), null);
                }
            }
            else if (!isRuntimeVersionInstalled)
            {
                // When we can't find the matching runtime for the user application, throw an application exception
                throw Tool.CreateException(SR.GetString(SR.FailedToGetRuntime, appClrVersion.ToString()), null);
            }
            else
            {
                this.runtimeVersion = RuntimeVersions.V40;
            }
        }
Ejemplo n.º 58
0
 public ComAdminClassInfo(ICatalogObject compObj, ICatalogCollection compColl)
 {
     this.clsid = new Guid((string)compObj.Key());
     this.progid = (string)compObj.Name();
     this.isPrivate = (bool)compObj.GetValue(PropertyName.IsPrivateComponent);
     this.transactionOption = (TransactionOption)compObj.GetValue(PropertyName.TransactionOption);
     this.BuildInterfaces(compObj, compColl);
 }
Ejemplo n.º 59
0
 public ComCatalogObject(ICatalogObject catalogObject,
                         ICatalogCollection catalogCollection)
 {
     this.catalogObject = catalogObject;
     this.catalogCollection = catalogCollection;
 }
Ejemplo n.º 60
0
 public ComCatalogCollection(ICatalogCollection catalogCollection)
 {
     this.catalogCollection = catalogCollection;
 }