Example #1
0
        internal static string[] GetRoleMembers(ComCatalogObject application, ComCatalogCollection rolesCollection)
        {
            ComCatalogCollection collection = application.GetCollection("Roles");
            List <string>        list       = new List <string>();

            ComCatalogCollection.Enumerator enumerator = rolesCollection.GetEnumerator();
            while (enumerator.MoveNext())
            {
                ComCatalogObject current = enumerator.Current;
                string           str     = (string)current.GetValue("Name");
                ComCatalogCollection.Enumerator enumerator2 = collection.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    ComCatalogObject obj3 = enumerator2.Current;
                    string           str2 = (string)obj3.GetValue("Name");
                    if (str == str2)
                    {
                        ComCatalogCollection.Enumerator enumerator3 = obj3.GetCollection("UsersInRole").GetEnumerator();
                        while (enumerator3.MoveNext())
                        {
                            ComCatalogObject obj4 = enumerator3.Current;
                            string           item = (string)obj4.GetValue("User");
                            list.Add(item);
                        }
                        continue;
                    }
                }
            }
            return(list.ToArray());
        }
 internal static string[] GetRoleMembers(ComCatalogObject application, ComCatalogCollection rolesCollection)
 {
     ComCatalogCollection collection = application.GetCollection("Roles");
     List<string> list = new List<string>();
     ComCatalogCollection.Enumerator enumerator = rolesCollection.GetEnumerator();
     while (enumerator.MoveNext())
     {
         ComCatalogObject current = enumerator.Current;
         string str = (string) current.GetValue("Name");
         ComCatalogCollection.Enumerator enumerator2 = collection.GetEnumerator();
         while (enumerator2.MoveNext())
         {
             ComCatalogObject obj3 = enumerator2.Current;
             string str2 = (string) obj3.GetValue("Name");
             if (str == str2)
             {
                 ComCatalogCollection.Enumerator enumerator3 = obj3.GetCollection("UsersInRole").GetEnumerator();
                 while (enumerator3.MoveNext())
                 {
                     ComCatalogObject obj4 = enumerator3.Current;
                     string item = (string) obj4.GetValue("User");
                     list.Add(item);
                 }
                 continue;
             }
         }
     }
     return list.ToArray();
 }
Example #3
0
        public ContractInfo(Guid iid,
                            ServiceEndpointElement endpoint,
                            ComCatalogObject interfaceObject,
                            ComCatalogObject application)
        {
            this.name = endpoint.Contract;
            this.iid  = iid;

            // Interface Roles
            //
            ComCatalogCollection roles;

            roles = interfaceObject.GetCollection("RolesForInterface");
            this.interfaceRoleMembers = CatalogUtil.GetRoleMembers(application,
                                                                   roles);

            // Operations
            //
            this.operations = new List <OperationInfo>();

            ComCatalogCollection methods;

            methods = interfaceObject.GetCollection("MethodsForInterface");
            foreach (ComCatalogObject method in methods)
            {
                this.operations.Add(new OperationInfo(method,
                                                      application));
            }
        }
Example #4
0
        public OperationInfo(ComCatalogObject methodObject, ComCatalogObject application)
        {
            this.name = (string)methodObject.GetValue("Name");
            ComCatalogCollection collection = methodObject.GetCollection("RolesForMethod");

            this.methodRoleMembers = CatalogUtil.GetRoleMembers(application, collection);
        }
 public bool MoveNext()
 {
     this.count++;
     if (this.count >= this.collection.Count)
     {
         return false;
     }
     this.current = this.collection.Item(this.count);
     return true;
 }
Example #6
0
 public bool MoveNext()
 {
     this.count++;
     if (this.count >= this.collection.Count)
     {
         return(false);
     }
     this.current = this.collection.Item(this.count);
     return(true);
 }
 public DllHostedComPlusServiceHost(Guid clsid,
                                    ServiceElement service,
                                    ComCatalogObject applicationObject,
                                    ComCatalogObject classObject)
 {
     Initialize(clsid,
                service,
                applicationObject,
                classObject,
                HostingMode.ComPlus);
 }
 public DllHostedComPlusServiceHost (Guid clsid,
                                     ServiceElement service,
                                     ComCatalogObject applicationObject,
                                     ComCatalogObject classObject)
 {
     Initialize (clsid,
                 service,
                 applicationObject,
                 classObject,
                 HostingMode.ComPlus);
 }
        protected void Initialize (Guid clsid,
                                   ServiceElement service,
                                   ComCatalogObject applicationObject,
                                   ComCatalogObject classObject,
                                   HostingMode hostingMode)
        {
            VerifyFunctionality();         
 
            this.info = new ServiceInfo(clsid,
                                        service,
                                        applicationObject,
                                        classObject,
                                        hostingMode);
            base.InitializeDescription(new UriSchemeKeyedCollection());
        }
Example #10
0
        protected void Initialize(Guid clsid,
                                  ServiceElement service,
                                  ComCatalogObject applicationObject,
                                  ComCatalogObject classObject,
                                  HostingMode hostingMode)
        {
            VerifyFunctionality();

            this.info = new ServiceInfo(clsid,
                                        service,
                                        applicationObject,
                                        classObject,
                                        hostingMode);
            base.InitializeDescription(new UriSchemeKeyedCollection());
        }
        public ContractInfo(Guid iid, ServiceEndpointElement endpoint, ComCatalogObject interfaceObject, ComCatalogObject application)
        {
            this.name = endpoint.Contract;
            this.iid  = iid;
            ComCatalogCollection collection = interfaceObject.GetCollection("RolesForInterface");

            this.interfaceRoleMembers = CatalogUtil.GetRoleMembers(application, collection);
            this.operations           = new List <OperationInfo>();
            ComCatalogCollection.Enumerator enumerator = interfaceObject.GetCollection("MethodsForInterface").GetEnumerator();
            while (enumerator.MoveNext())
            {
                ComCatalogObject current = enumerator.Current;
                this.operations.Add(new OperationInfo(current, application));
            }
        }
Example #12
0
        internal static string[] GetRoleMembers(
            ComCatalogObject application,
            ComCatalogCollection rolesCollection)
        {
            ComCatalogCollection applicationRoles;

            applicationRoles = application.GetCollection("Roles");

            // This is inefficient. If it turns into a
            // performance problem, then we'll need to put a cache in
            // somewhere.
            //
            List <string> roleMembers = new List <string>();

            foreach (ComCatalogObject role in rolesCollection)
            {
                string roleName = (string)role.GetValue("Name");

                // Find the role in the app roles list.
                //
                foreach (ComCatalogObject appRole in applicationRoles)
                {
                    string appRoleName = (string)appRole.GetValue("Name");
                    if (roleName == appRoleName)
                    {
                        // Found it, put all of the user names into
                        // the role members list.
                        //
                        ComCatalogCollection users;
                        users = appRole.GetCollection("UsersInRole");
                        foreach (ComCatalogObject userObject in users)
                        {
                            string user = (string)userObject.GetValue("User");
                            roleMembers.Add(user);
                        }

                        break;
                    }
                }
            }

            return(roleMembers.ToArray());
        }
        // NOTE: Construction of this thing is quite inefficient-- it
        //       has several nested loops that could probably be
        //       improved. Such optimizations have been left for when
        //       it turns out to be a performance problem, for the
        //       sake of simplicity.
        //
        public ServiceInfo(Guid clsid,
                            ServiceElement service,
                            ComCatalogObject application,
                            ComCatalogObject classObject,
                            HostingMode hostingMode)
        {
            // Simple things...
            //
            this.service = service;
            this.clsid = clsid;
            this.appid = Fx.CreateGuid((string)application.GetValue("ID"));
            this.partitionId = Fx.CreateGuid((string)application.GetValue("AppPartitionID"));
            this.bitness = (Bitness)classObject.GetValue("Bitness");
            this.transactionOption = (TransactionOption)classObject.GetValue("Transaction");
            this.hostingMode = hostingMode;
            this.managedType = TypeCacheManager.ResolveClsidToType(clsid);
            this.serviceName = application.Name + "." + classObject.Name;
            this.udts = new Dictionary<Guid, List<Type>>();

            // Isolation Level
            COMAdminIsolationLevel adminIsolationLevel;
            adminIsolationLevel = (COMAdminIsolationLevel)classObject.GetValue("TxIsolationLevel");
            switch (adminIsolationLevel)
            {
                case COMAdminIsolationLevel.Any:
                    this.isolationLevel = IsolationLevel.Unspecified;
                    break;
                case COMAdminIsolationLevel.ReadUncommitted:
                    this.isolationLevel = IsolationLevel.ReadUncommitted;
                    break;
                case COMAdminIsolationLevel.ReadCommitted:
                    this.isolationLevel = IsolationLevel.ReadCommitted;
                    break;
                case COMAdminIsolationLevel.RepeatableRead:
                    this.isolationLevel = IsolationLevel.RepeatableRead;
                    break;
                case COMAdminIsolationLevel.Serializable:
                    this.isolationLevel = IsolationLevel.Serializable;
                    break;
                default:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                        SR.GetString(SR.InvalidIsolationLevelValue,
                                     this.clsid, adminIsolationLevel)));
            }

            // Threading Model
            //
            COMAdminThreadingModel adminThreadingModel;
            adminThreadingModel = (COMAdminThreadingModel)classObject.GetValue("ThreadingModel");
            switch (adminThreadingModel)
            {
                case COMAdminThreadingModel.Apartment:
                case COMAdminThreadingModel.Main:
                    this.threadingModel = ThreadingModel.STA;
                    objectPoolingEnabled = false;
                    break;

                default:
                    this.threadingModel = ThreadingModel.MTA;
                    objectPoolingEnabled = (bool)classObject.GetValue("ObjectPoolingEnabled");
                    break;
            }

            // Object Pool settings
            // 

            if (objectPoolingEnabled)
            {
                maxPoolSize = (int)classObject.GetValue("MaxPoolSize");
            }
            else
                maxPoolSize = 0;
            // Security Settings
            //
            bool appSecurityEnabled;
            appSecurityEnabled = (bool)application.GetValue(
                "ApplicationAccessChecksEnabled");
            if (appSecurityEnabled)
            {

                bool classSecurityEnabled;
                classSecurityEnabled = (bool)classObject.GetValue(
                    "ComponentAccessChecksEnabled");
                if (classSecurityEnabled)
                {
                    this.checkRoles = true;
                }
            }

            // Component Roles
            //
            ComCatalogCollection roles;
            roles = classObject.GetCollection("RolesForComponent");
            this.componentRoleMembers = CatalogUtil.GetRoleMembers(application, roles);
            // Contracts
            // One ContractInfo per unique IID exposed, so we need to
            // filter duplicates.
            //
            this.contracts = new List<ContractInfo>();
            ComCatalogCollection interfaces;
            interfaces = classObject.GetCollection("InterfacesForComponent");
            foreach (ServiceEndpointElement endpoint in service.Endpoints)
            {
                ContractInfo contract = null;
                if (endpoint.Contract == ServiceMetadataBehavior.MexContractName)
                    continue;

                Guid iid;
                if (DiagnosticUtility.Utility.TryCreateGuid(endpoint.Contract, out iid))
                {
                    // (Filter duplicates.)
                    bool duplicate = false;
                    foreach (ContractInfo otherContract in this.contracts)
                    {
                        if (iid == otherContract.IID)
                        {
                            duplicate = true;
                            break;
                        }
                    }
                    if (duplicate) continue;

                    foreach (ComCatalogObject interfaceObject in interfaces)
                    {
                        Guid otherInterfaceID;
                        if (DiagnosticUtility.Utility.TryCreateGuid((string)interfaceObject.GetValue("IID"), out otherInterfaceID))
                        {
                            if (otherInterfaceID == iid)
                            {
                                contract = new ContractInfo(iid,
                                                            endpoint,
                                                            interfaceObject,
                                                            application);
                                break;
                            }
                        }
                    }
                }

                if (contract == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                        SR.GetString(SR.EndpointNotAnIID,
                                     clsid.ToString("B").ToUpperInvariant(),
                                     endpoint.Contract)));
                }
                this.contracts.Add(contract);
            }
        }
        public OperationInfo(ComCatalogObject methodObject,
                             ComCatalogObject application)
        {
            this.name = (string)methodObject.GetValue("Name");

            // Method Roles
            //
            ComCatalogCollection roles;
            roles = methodObject.GetCollection("RolesForMethod");
            this.methodRoleMembers = CatalogUtil.GetRoleMembers(application,
                                                                roles);
        }
        public ContractInfo(Guid iid,
                            ServiceEndpointElement endpoint,
                            ComCatalogObject interfaceObject,
                            ComCatalogObject application)
        {
            this.name = endpoint.Contract;
            this.iid = iid;

            // Interface Roles
            //
            ComCatalogCollection roles;
            roles = interfaceObject.GetCollection("RolesForInterface");
            this.interfaceRoleMembers = CatalogUtil.GetRoleMembers(application,
                                                                   roles);

            // Operations
            //
            this.operations = new List<OperationInfo>();

            ComCatalogCollection methods;
            methods = interfaceObject.GetCollection("MethodsForInterface");
            foreach (ComCatalogObject method in methods)
            {
                this.operations.Add(new OperationInfo(method,
                                                      application));
            }
        }
Example #16
0
        public ServiceInfo(Guid clsid, System.ServiceModel.Configuration.ServiceElement service, ComCatalogObject application, ComCatalogObject classObject, System.ServiceModel.ComIntegration.HostingMode hostingMode)
        {
            this.service = service;
            this.clsid = clsid;
            this.appid = Fx.CreateGuid((string) application.GetValue("ID"));
            this.partitionId = Fx.CreateGuid((string) application.GetValue("AppPartitionID"));
            this.bitness = (System.ServiceModel.ComIntegration.Bitness) classObject.GetValue("Bitness");
            this.transactionOption = (System.EnterpriseServices.TransactionOption) classObject.GetValue("Transaction");
            this.hostingMode = hostingMode;
            this.managedType = TypeCacheManager.ResolveClsidToType(clsid);
            this.serviceName = application.Name + "." + classObject.Name;
            this.udts = new Dictionary<Guid, List<Type>>();
            COMAdminIsolationLevel level = (COMAdminIsolationLevel) classObject.GetValue("TxIsolationLevel");
            switch (level)
            {
                case COMAdminIsolationLevel.Any:
                    this.isolationLevel = System.Transactions.IsolationLevel.Unspecified;
                    break;

                case COMAdminIsolationLevel.ReadUncommitted:
                    this.isolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                    break;

                case COMAdminIsolationLevel.ReadCommitted:
                    this.isolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                    break;

                case COMAdminIsolationLevel.RepeatableRead:
                    this.isolationLevel = System.Transactions.IsolationLevel.RepeatableRead;
                    break;

                case COMAdminIsolationLevel.Serializable:
                    this.isolationLevel = System.Transactions.IsolationLevel.Serializable;
                    break;

                default:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("InvalidIsolationLevelValue", new object[] { this.clsid, level })));
            }
            switch (((COMAdminThreadingModel) classObject.GetValue("ThreadingModel")))
            {
                case COMAdminThreadingModel.Apartment:
                case COMAdminThreadingModel.Main:
                    this.threadingModel = System.ServiceModel.ComIntegration.ThreadingModel.STA;
                    this.objectPoolingEnabled = false;
                    break;

                default:
                    this.threadingModel = System.ServiceModel.ComIntegration.ThreadingModel.MTA;
                    this.objectPoolingEnabled = (bool) classObject.GetValue("ObjectPoolingEnabled");
                    break;
            }
            if (this.objectPoolingEnabled)
            {
                this.maxPoolSize = (int) classObject.GetValue("MaxPoolSize");
            }
            else
            {
                this.maxPoolSize = 0;
            }
            if (((bool) application.GetValue("ApplicationAccessChecksEnabled")) && ((bool) classObject.GetValue("ComponentAccessChecksEnabled")))
            {
                this.checkRoles = true;
            }
            ComCatalogCollection collection = classObject.GetCollection("RolesForComponent");
            this.componentRoleMembers = CatalogUtil.GetRoleMembers(application, collection);
            this.contracts = new List<ContractInfo>();
            ComCatalogCollection catalogs2 = classObject.GetCollection("InterfacesForComponent");
            foreach (ServiceEndpointElement element in service.Endpoints)
            {
                ContractInfo item = null;
                if (element.Contract != "IMetadataExchange")
                {
                    Guid guid;
                    if (DiagnosticUtility.Utility.TryCreateGuid(element.Contract, out guid))
                    {
                        bool flag3 = false;
                        foreach (ContractInfo info2 in this.contracts)
                        {
                            if (guid == info2.IID)
                            {
                                flag3 = true;
                                break;
                            }
                        }
                        if (flag3)
                        {
                            continue;
                        }
                        ComCatalogCollection.Enumerator enumerator = catalogs2.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            Guid guid2;
                            ComCatalogObject current = enumerator.Current;
                            if (DiagnosticUtility.Utility.TryCreateGuid((string) current.GetValue("IID"), out guid2) && (guid2 == guid))
                            {
                                item = new ContractInfo(guid, element, current, application);
                                break;
                            }
                        }
                    }
                    if (item == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("EndpointNotAnIID", new object[] { clsid.ToString("B").ToUpperInvariant(), element.Contract })));
                    }
                    this.contracts.Add(item);
                }
            }
        }
        public WebHostedComPlusServiceHost(string webhostParams, Uri[] baseAddresses)
        {
            Guid        guid;
            Guid        guid2;
            HostingMode webHostInProcess;

            foreach (Uri uri in baseAddresses)
            {
                base.InternalBaseAddresses.Add(uri);
            }
            string[] strArray = webhostParams.Split(new char[] { ',' });
            if (strArray.Length != 2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ServiceStringFormatError", new object[] { webhostParams })));
            }
            if (!DiagnosticUtility.Utility.TryCreateGuid(strArray[0], out guid))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ServiceStringFormatError", new object[] { webhostParams })));
            }
            if (!DiagnosticUtility.Utility.TryCreateGuid(strArray[1], out guid2))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ServiceStringFormatError", new object[] { webhostParams })));
            }
            string           str = guid.ToString("B").ToUpperInvariant();
            ComCatalogObject applicationObject = CatalogUtil.FindApplication(guid2);

            if (applicationObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ApplicationNotFound", new object[] { guid2.ToString("B").ToUpperInvariant() })));
            }
            ComCatalogCollection collection  = applicationObject.GetCollection("Components");
            ComCatalogObject     classObject = null;

            ComCatalogCollection.Enumerator enumerator = collection.GetEnumerator();
            while (enumerator.MoveNext())
            {
                ComCatalogObject current = enumerator.Current;
                string           str2    = (string)current.GetValue("CLSID");
                if (str.Equals(str2, StringComparison.OrdinalIgnoreCase))
                {
                    classObject = current;
                    break;
                }
            }
            if (classObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ClsidNotInApplication", new object[] { str, guid2.ToString("B").ToUpperInvariant() })));
            }
            ServicesSection section = ServicesSection.GetSection();
            ServiceElement  service = null;

            foreach (ServiceElement element2 in section.Services)
            {
                Guid     empty     = Guid.Empty;
                Guid     result    = Guid.Empty;
                string[] strArray2 = element2.Name.Split(new char[] { ',' });
                if ((((strArray2.Length == 2) && DiagnosticUtility.Utility.TryCreateGuid(strArray2[0], out result)) && (DiagnosticUtility.Utility.TryCreateGuid(strArray2[1], out empty) && (empty == guid))) && (result == guid2))
                {
                    service = element2;
                    break;
                }
            }
            if (service == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ClsidNotInConfiguration", new object[] { str })));
            }
            if (((int)applicationObject.GetValue("Activation")) == 0)
            {
                webHostInProcess = HostingMode.WebHostInProcess;
            }
            else
            {
                webHostInProcess = HostingMode.WebHostOutOfProcess;
            }
            base.Initialize(guid, service, applicationObject, classObject, webHostInProcess);
        }
        internal static string[] GetRoleMembers(
            ComCatalogObject application,
            ComCatalogCollection rolesCollection)
        {
            ComCatalogCollection applicationRoles;
            applicationRoles = application.GetCollection("Roles");

            // This is inefficient. If it turns into a
            // performance problem, then we'll need to put a cache in
            // somewhere.
            //
            List<string> roleMembers = new List<string>();
            foreach (ComCatalogObject role in rolesCollection)
            {
                string roleName = (string)role.GetValue("Name");

                // Find the role in the app roles list.
                //
                foreach (ComCatalogObject appRole in applicationRoles)
                {
                    string appRoleName = (string)appRole.GetValue("Name");
                    if (roleName == appRoleName)
                    {
                        // Found it, put all of the user names into
                        // the role members list.
                        //
                        ComCatalogCollection users;
                        users = appRole.GetCollection("UsersInRole");
                        foreach (ComCatalogObject userObject in users)
                        {
                            string user = (string)userObject.GetValue("User");
                            roleMembers.Add(user);
                        }

                        break;
                    }
                }
            }

            return roleMembers.ToArray();
        }
Example #19
0
        public void Startup(IProcessInitControl control)
        {
            this.applicationId = ContextUtil.ApplicationId;
            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Information, 0x50008, "TraceCodeComIntegrationDllHostInitializerStarting", this.applicationId);
            Thread thread = null;

            try
            {
                thread = new Thread(new ParameterizedThreadStart(DllHostInitializeWorker.PingProc));
                thread.Start(control);
                ComCatalogObject applicationObject = CatalogUtil.FindApplication(this.applicationId);
                if (applicationObject == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ApplicationNotFound", new object[] { this.applicationId.ToString("B").ToUpperInvariant() })));
                }
                if (((int)applicationObject.GetValue("ConcurrentApps")) > 1)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("PooledApplicationNotSupportedForComplusHostedScenarios", new object[] { this.applicationId.ToString("B").ToUpperInvariant() })));
                }
                if ((((((int)applicationObject.GetValue("RecycleLifetimeLimit")) > 0) || (((int)applicationObject.GetValue("RecycleCallLimit")) > 0)) || (((int)applicationObject.GetValue("RecycleActivationLimit")) > 0)) || (((int)applicationObject.GetValue("RecycleMemoryLimit")) > 0))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("RecycledApplicationNotSupportedForComplusHostedScenarios", new object[] { this.applicationId.ToString("B").ToUpperInvariant() })));
                }
                ComCatalogCollection collection = applicationObject.GetCollection("Components");
                ServicesSection      section    = ServicesSection.GetSection();
                bool flag3 = false;
                foreach (ServiceElement element in section.Services)
                {
                    Guid     empty    = Guid.Empty;
                    Guid     result   = Guid.Empty;
                    string[] strArray = element.Name.Split(new char[] { ',' });
                    if (strArray.Length != 2)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("OnlyClsidsAllowedForServiceType", new object[] { element.Name })));
                    }
                    if (!DiagnosticUtility.Utility.TryCreateGuid(strArray[0], out result))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("OnlyClsidsAllowedForServiceType", new object[] { element.Name })));
                    }
                    if (!DiagnosticUtility.Utility.TryCreateGuid(strArray[1], out empty))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("OnlyClsidsAllowedForServiceType", new object[] { element.Name })));
                    }
                    flag3 = false;
                    ComCatalogCollection.Enumerator enumerator = collection.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        ComCatalogObject current = enumerator.Current;
                        Guid             clsid   = Fx.CreateGuid((string)current.GetValue("CLSID"));
                        if ((clsid == empty) && (this.applicationId == result))
                        {
                            flag3 = true;
                            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Verbose, 0x50009, "TraceCodeComIntegrationDllHostInitializerAddingHost", this.applicationId, clsid, element);
                            this.hosts.Add(new DllHostedComPlusServiceHost(clsid, element, applicationObject, current));
                        }
                    }
                    if (!flag3)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CannotFindClsidInApplication", new object[] { empty.ToString("B").ToUpperInvariant(), this.applicationId.ToString("B").ToUpperInvariant() })));
                    }
                }
                if (!flag3)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.DllHostInitializerFoundNoServices());
                }
                foreach (ComPlusServiceHost host in this.hosts)
                {
                    host.Open();
                }
            }
            catch (Exception exception)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.ComPlus, (EventLogEventId)(-1073610729), new string[] { this.applicationId.ToString(), exception.ToString() });
                throw;
            }
            finally
            {
                if (thread != null)
                {
                    thread.Abort();
                }
            }
            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Information, 0x5000a, "TraceCodeComIntegrationDllHostInitializerStarted", this.applicationId);
        }
Example #20
0
 public Enumerator(ComCatalogCollection collection)
 {
     this.collection = collection;
     this.current    = null;
     this.count      = -1;
 }
Example #21
0
        public WebHostedComPlusServiceHost(string webhostParams, Uri[] baseAddresses)
        {
            foreach (Uri address in baseAddresses)
            {
                this.InternalBaseAddresses.Add(address);
            }

            // Split up the parameter string into "clsid,appid".
            //
            string[] parameters = webhostParams.Split(',');
            if (parameters.Length != 2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ServiceStringFormatError,
                                                                                           webhostParams)));
            }

            Guid clsid;
            Guid appId;

            if (!DiagnosticUtility.Utility.TryCreateGuid(parameters[0], out clsid))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ServiceStringFormatError,
                                                                                           webhostParams)));
            }

            if (!DiagnosticUtility.Utility.TryCreateGuid(parameters[1], out appId))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ServiceStringFormatError,
                                                                                           webhostParams)));
            }

            // "B" == "With dashes and curly braces"
            // (The catalog gives us GUIDs in this format)
            //
            string clsidString = clsid.ToString("B").ToUpperInvariant();

            // Look up the COM+ AdminSDK information for this
            // AppID/CLSID pair.
            //
            ComCatalogObject application;

            application = CatalogUtil.FindApplication(appId);
            if (application == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ApplicationNotFound,
                                                                                           appId.ToString("B").ToUpperInvariant())));
            }

            ComCatalogCollection classes;

            classes = application.GetCollection("Components");

            ComCatalogObject classObject = null;

            foreach (ComCatalogObject tempClassObject in classes)
            {
                string otherClsid = (string)tempClassObject.GetValue("CLSID");
                if (clsidString.Equals(
                        otherClsid,
                        StringComparison.OrdinalIgnoreCase))
                {
                    classObject = tempClassObject;
                    break;
                }
            }

            if (classObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ClsidNotInApplication,
                                                                                           clsidString,
                                                                                           appId.ToString("B").ToUpperInvariant())));
            }

            // Load up Indigo configuration, get the configuration for
            // this service.
            //
            ServicesSection services = ServicesSection.GetSection();
            ServiceElement  service  = null;

            foreach (ServiceElement serviceInConfig in services.Services)
            {
                Guid clsidFromConfig = Guid.Empty;
                Guid appidFromConfig = Guid.Empty;

                string[] serviceParams = serviceInConfig.Name.Split(',');
                if (serviceParams.Length != 2)
                {
                    continue;
                }


                if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[0], out appidFromConfig))
                {
                    // We are tolerant of having non COM+ based services
                    // for webhost.
                    continue;
                }

                if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[1], out clsidFromConfig))
                {
                    // We are tolerant of having non COM+ based services
                    // for webhost.
                    continue;
                }

                if (clsidFromConfig == clsid && appidFromConfig == appId)
                {
                    service = serviceInConfig;
                    break;
                }
            }
            if (service == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ClsidNotInConfiguration,
                                                                                           clsidString)));
            }


            // Hosting mode evaluation
            //
            HostingMode hostingMode;
            int         activation = (int)application.GetValue("Activation");

            if (activation == 0)
            {
                hostingMode = HostingMode.WebHostInProcess;
            }
            else
            {
                hostingMode = HostingMode.WebHostOutOfProcess;
            }

            // Now we have everything we need, do common
            // initialization.
            //
            Initialize(clsid,
                       service,
                       application,
                       classObject,
                       hostingMode);
        }
Example #22
0
        // NOTE: Construction of this thing is quite inefficient-- it
        //       has several nested loops that could probably be
        //       improved. Such optimizations have been left for when
        //       it turns out to be a performance problem, for the
        //       sake of simplicity.
        //
        public ServiceInfo(Guid clsid,
                           ServiceElement service,
                           ComCatalogObject application,
                           ComCatalogObject classObject,
                           HostingMode hostingMode)
        {
            // Simple things...
            //
            this.service           = service;
            this.clsid             = clsid;
            this.appid             = Fx.CreateGuid((string)application.GetValue("ID"));
            this.partitionId       = Fx.CreateGuid((string)application.GetValue("AppPartitionID"));
            this.bitness           = (Bitness)classObject.GetValue("Bitness");
            this.transactionOption = (TransactionOption)classObject.GetValue("Transaction");
            this.hostingMode       = hostingMode;
            this.managedType       = TypeCacheManager.ResolveClsidToType(clsid);
            this.serviceName       = application.Name + "." + classObject.Name;
            this.udts = new Dictionary <Guid, List <Type> >();

            // Isolation Level
            COMAdminIsolationLevel adminIsolationLevel;

            adminIsolationLevel = (COMAdminIsolationLevel)classObject.GetValue("TxIsolationLevel");
            switch (adminIsolationLevel)
            {
            case COMAdminIsolationLevel.Any:
                this.isolationLevel = IsolationLevel.Unspecified;
                break;

            case COMAdminIsolationLevel.ReadUncommitted:
                this.isolationLevel = IsolationLevel.ReadUncommitted;
                break;

            case COMAdminIsolationLevel.ReadCommitted:
                this.isolationLevel = IsolationLevel.ReadCommitted;
                break;

            case COMAdminIsolationLevel.RepeatableRead:
                this.isolationLevel = IsolationLevel.RepeatableRead;
                break;

            case COMAdminIsolationLevel.Serializable:
                this.isolationLevel = IsolationLevel.Serializable;
                break;

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                              SR.GetString(SR.InvalidIsolationLevelValue,
                                                                                           this.clsid, adminIsolationLevel)));
            }

            // Threading Model
            //
            COMAdminThreadingModel adminThreadingModel;

            adminThreadingModel = (COMAdminThreadingModel)classObject.GetValue("ThreadingModel");
            switch (adminThreadingModel)
            {
            case COMAdminThreadingModel.Apartment:
            case COMAdminThreadingModel.Main:
                this.threadingModel  = ThreadingModel.STA;
                objectPoolingEnabled = false;
                break;

            default:
                this.threadingModel  = ThreadingModel.MTA;
                objectPoolingEnabled = (bool)classObject.GetValue("ObjectPoolingEnabled");
                break;
            }

            // Object Pool settings
            //

            if (objectPoolingEnabled)
            {
                maxPoolSize = (int)classObject.GetValue("MaxPoolSize");
            }
            else
            {
                maxPoolSize = 0;
            }
            // Security Settings
            //
            bool appSecurityEnabled;

            appSecurityEnabled = (bool)application.GetValue(
                "ApplicationAccessChecksEnabled");
            if (appSecurityEnabled)
            {
                bool classSecurityEnabled;
                classSecurityEnabled = (bool)classObject.GetValue(
                    "ComponentAccessChecksEnabled");
                if (classSecurityEnabled)
                {
                    this.checkRoles = true;
                }
            }

            // Component Roles
            //
            ComCatalogCollection roles;

            roles = classObject.GetCollection("RolesForComponent");
            this.componentRoleMembers = CatalogUtil.GetRoleMembers(application, roles);
            // Contracts
            // One ContractInfo per unique IID exposed, so we need to
            // filter duplicates.
            //
            this.contracts = new List <ContractInfo>();
            ComCatalogCollection interfaces;

            interfaces = classObject.GetCollection("InterfacesForComponent");
            foreach (ServiceEndpointElement endpoint in service.Endpoints)
            {
                ContractInfo contract = null;
                if (endpoint.Contract == ServiceMetadataBehavior.MexContractName)
                {
                    continue;
                }

                Guid iid;
                if (DiagnosticUtility.Utility.TryCreateGuid(endpoint.Contract, out iid))
                {
                    // (Filter duplicates.)
                    bool duplicate = false;
                    foreach (ContractInfo otherContract in this.contracts)
                    {
                        if (iid == otherContract.IID)
                        {
                            duplicate = true;
                            break;
                        }
                    }
                    if (duplicate)
                    {
                        continue;
                    }

                    foreach (ComCatalogObject interfaceObject in interfaces)
                    {
                        Guid otherInterfaceID;
                        if (DiagnosticUtility.Utility.TryCreateGuid((string)interfaceObject.GetValue("IID"), out otherInterfaceID))
                        {
                            if (otherInterfaceID == iid)
                            {
                                contract = new ContractInfo(iid,
                                                            endpoint,
                                                            interfaceObject,
                                                            application);
                                break;
                            }
                        }
                    }
                }

                if (contract == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                                  SR.GetString(SR.EndpointNotAnIID,
                                                                                               clsid.ToString("B").ToUpperInvariant(),
                                                                                               endpoint.Contract)));
                }
                this.contracts.Add(contract);
            }
        }
 public Enumerator(ComCatalogCollection collection)
 {
     this.collection = collection;
     this.current = null;
     this.count = -1;
 }