internal static string ToSerializedValue(this HostingMode value)
        {
            switch (value)
            {
            case HostingMode.Default:
                return("default");

            case HostingMode.HighDensity:
                return("highDensity");
            }
            return(null);
        }
Esempio n. 2
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());
        }
        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());
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
            }
        }