Esempio n. 1
0
        protected void VerifyFunctionality()
        {
            object serviceConfig = new CServiceConfig();
            IServiceSysTxnConfig sysTxnconfing = serviceConfig as IServiceSysTxnConfig;

            if (sysTxnconfing == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.QFENotPresent());
            }
        }
        object SetupServiceConfig(InstanceContext instanceContext, Message message)
        {
            object serviceConfig = new CServiceConfig();

            // Threading
            //
            IServiceThreadPoolConfig threadPoolConfig;

            threadPoolConfig = (IServiceThreadPoolConfig)(serviceConfig);
            switch (this.info.ThreadingModel)
            {
            case ThreadingModel.MTA:
                threadPoolConfig.SelectThreadPool(ThreadPoolOption.MTA);
                break;

            case ThreadingModel.STA:
                threadPoolConfig.SelectThreadPool(ThreadPoolOption.STA);
                break;

            default:
                Fx.Assert("Unexpected threading model");

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.UnexpectedThreadingModel());
            }
            threadPoolConfig.SetBindingInfo(BindingOption.BindingToPoolThread);

            // SxS activation context properties
            //


            // Manifest for VARIANT UDT types
            //

            // this only gets executed if we actually have UDTs
            if (this.info.HasUdts())
            {
                IServiceSxsConfig sxsConfig = serviceConfig as IServiceSxsConfig;
                if (sxsConfig == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.QFENotPresent());
                }

                lock (manifestLock)
                {
                    string tempPath = String.Empty;

                    try
                    {
                        tempPath = Path.GetTempPath();
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.CannotAccessDirectory(tempPath));
                    }

                    string manifestDirectory = tempPath + this.info.AppID.ToString() + @"\";


                    if (!Directory.Exists(manifestDirectory))
                    {
                        try
                        {
                            Directory.CreateDirectory(manifestDirectory);
                        }
                        catch (Exception e)
                        {
                            if (Fx.IsFatal(e))
                            {
                                throw;
                            }

                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.CannotAccessDirectory(manifestDirectory));
                        }

                        Guid[] assemblyGuids = this.info.Assemblies;
                        ComIntegrationManifestGenerator.GenerateManifestCollectionFile(assemblyGuids, manifestDirectory + manifestFileName + @".manifest", manifestFileName);

                        foreach (Guid g in assemblyGuids)
                        {
                            Type[] types = this.info.GetTypes(g);
                            if (types.Length > 0)
                            {
                                String guidStr = g.ToString();
                                ComIntegrationManifestGenerator.GenerateWin32ManifestFile(types, manifestDirectory + guidStr + @".manifest", guidStr);
                            }
                        }
                    }


                    sxsConfig.SxsConfig(CSC_SxsConfig.CSC_NewSxs);
                    sxsConfig.SxsName(manifestFileName + @".manifest");
                    sxsConfig.SxsDirectory(manifestDirectory);
                }
            }


            // Partitions
            //
            if (this.info.PartitionId != DefaultPartitionId)
            {
                IServicePartitionConfig partitionConfig;
                partitionConfig = (IServicePartitionConfig)(serviceConfig);
                partitionConfig.PartitionConfig(PartitionOption.New);
                partitionConfig.PartitionID(this.info.PartitionId);
            }

            // Transactions
            //
            IServiceTransactionConfig transactionConfig;

            transactionConfig = (IServiceTransactionConfig)(serviceConfig);
            transactionConfig.ConfigureTransaction(
                TransactionConfig.NoTransaction);

            if ((this.info.TransactionOption == TransactionOption.Required) ||
                (this.info.TransactionOption == TransactionOption.Supported))
            {
                Transaction messageTransaction = null;
                messageTransaction = MessageUtil.GetMessageTransaction(message);
                if (messageTransaction != null)
                {
                    TransactionProxy proxy = new TransactionProxy(info.AppID, info.Clsid);
                    proxy.SetTransaction(messageTransaction);

                    instanceContext.Extensions.Add(proxy);
                    IServiceSysTxnConfig sysTxnconfing = (IServiceSysTxnConfig)transactionConfig;
                    IntPtr pUnk = TransactionProxyBuilder.CreateTransactionProxyTearOff(proxy);
                    sysTxnconfing.ConfigureBYOTSysTxn(pUnk);
                    Marshal.Release(pUnk);
                }
            }
            return(serviceConfig);
        }
        private object SetupServiceConfig(InstanceContext instanceContext, Message message)
        {
            object obj2 = new CServiceConfig();
            IServiceThreadPoolConfig config = (IServiceThreadPoolConfig)obj2;

            switch (this.info.ThreadingModel)
            {
            case ThreadingModel.MTA:
                config.SelectThreadPool(System.ServiceModel.ComIntegration.ThreadPoolOption.MTA);
                break;

            case ThreadingModel.STA:
                config.SelectThreadPool(System.ServiceModel.ComIntegration.ThreadPoolOption.STA);
                break;

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.UnexpectedThreadingModel());
            }
            config.SetBindingInfo(System.ServiceModel.ComIntegration.BindingOption.BindingToPoolThread);
            if (this.info.HasUdts())
            {
                IServiceSxsConfig config2 = obj2 as IServiceSxsConfig;
                if (config2 == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.QFENotPresent());
                }
                lock (manifestLock)
                {
                    string directory = string.Empty;
                    try
                    {
                        directory = Path.GetTempPath();
                    }
                    catch (Exception exception)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.CannotAccessDirectory(directory));
                    }
                    string path = directory + this.info.AppID.ToString() + @"\";
                    if (!Directory.Exists(path))
                    {
                        try
                        {
                            Directory.CreateDirectory(path);
                        }
                        catch (Exception exception2)
                        {
                            if (Fx.IsFatal(exception2))
                            {
                                throw;
                            }
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.CannotAccessDirectory(path));
                        }
                        Guid[] assemblies = this.info.Assemblies;
                        ComIntegrationManifestGenerator.GenerateManifestCollectionFile(assemblies, path + manifestFileName + ".manifest", manifestFileName);
                        foreach (Guid guid in assemblies)
                        {
                            System.Type[] types = this.info.GetTypes(guid);
                            if (types.Length > 0)
                            {
                                string assemblyName = guid.ToString();
                                ComIntegrationManifestGenerator.GenerateWin32ManifestFile(types, path + assemblyName + ".manifest", assemblyName);
                            }
                        }
                    }
                    config2.SxsConfig(CSC_SxsConfig.CSC_NewSxs);
                    config2.SxsName(manifestFileName + ".manifest");
                    config2.SxsDirectory(path);
                }
            }
            if (this.info.PartitionId != DefaultPartitionId)
            {
                IServicePartitionConfig config3 = (IServicePartitionConfig)obj2;
                config3.PartitionConfig(System.ServiceModel.ComIntegration.PartitionOption.New);
                config3.PartitionID(this.info.PartitionId);
            }
            IServiceTransactionConfig config4 = (IServiceTransactionConfig)obj2;

            config4.ConfigureTransaction(TransactionConfig.NoTransaction);
            if ((this.info.TransactionOption == TransactionOption.Required) || (this.info.TransactionOption == TransactionOption.Supported))
            {
                Transaction messageTransaction = null;
                messageTransaction = MessageUtil.GetMessageTransaction(message);
                if (messageTransaction != null)
                {
                    System.ServiceModel.ComIntegration.TransactionProxy item = new System.ServiceModel.ComIntegration.TransactionProxy(this.info.AppID, this.info.Clsid);
                    item.SetTransaction(messageTransaction);
                    instanceContext.Extensions.Add(item);
                    IServiceSysTxnConfig config5 = (IServiceSysTxnConfig)config4;
                    IntPtr pITxByot = TransactionProxyBuilder.CreateTransactionProxyTearOff(item);
                    config5.ConfigureBYOTSysTxn(pITxByot);
                    Marshal.Release(pITxByot);
                }
            }
            return(obj2);
        }