public void Startup(IProcessInitControl control)
        {
            // Find our application object, and associated components
            // (classes) collection from the COM+ catalog.
            //
            applicationId = ContextUtil.ApplicationId;

            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Information, TraceCode.ComIntegrationDllHostInitializerStarting,
                                                 SR.TraceCodeComIntegrationDllHostInitializerStarting, applicationId);

            Thread pingThread = null;

            try
            {
                pingThread = new Thread(PingProc);
                pingThread.Start(control);

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

                bool processPooled = ((int)application.GetValue("ConcurrentApps")) > 1;
                if (processPooled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                                  SR.GetString(SR.PooledApplicationNotSupportedForComplusHostedScenarios,
                                                                                               applicationId.ToString("B").ToUpperInvariant())));
                }

                bool processRecycled = ((int)application.GetValue("RecycleLifetimeLimit")) > 0 ||
                                       ((int)application.GetValue("RecycleCallLimit")) > 0 ||
                                       ((int)application.GetValue("RecycleActivationLimit")) > 0 ||
                                       ((int)application.GetValue("RecycleMemoryLimit")) > 0;

                if (processRecycled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                                  SR.GetString(SR.RecycledApplicationNotSupportedForComplusHostedScenarios,
                                                                                               applicationId.ToString("B").ToUpperInvariant())));
                }


                ComCatalogCollection classes;
                classes = application.GetCollection("Components");

                // Load up Indigo configuration.
                //
                ServicesSection services     = ServicesSection.GetSection();
                bool            foundService = false;


                foreach (ServiceElement service in services.Services)
                {
                    Guid clsidToCompare = Guid.Empty;
                    Guid appIdToCompare = Guid.Empty;

                    string[] serviceParams = service.Name.Split(',');
                    if (serviceParams.Length != 2)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.OnlyClsidsAllowedForServiceType, service.Name)));
                    }

                    if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[0], out appIdToCompare))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.OnlyClsidsAllowedForServiceType, service.Name)));
                    }

                    if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[1], out clsidToCompare))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.OnlyClsidsAllowedForServiceType, service.Name)));
                    }

                    foundService = false;

                    // CODEWORK: Consider farming this out across multiple threadpool threads.
                    // When it was discovered that startup time could be a problem it was too late
                    // to to do that since it can cause failure conditions that need to be considered
                    // (such as the threadpool running out) so we decided not to touch that part.
                    // But since this can potentially take a very long time on big COM apps
                    // it should be parallelized at some point.
                    foreach (ComCatalogObject classObject in classes)
                    {
                        Guid clsid = Fx.CreateGuid((string)classObject.GetValue("CLSID"));

                        if (clsid == clsidToCompare && applicationId == appIdToCompare)
                        {
                            foundService = true;
                            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationDllHostInitializerAddingHost,
                                                                 SR.TraceCodeComIntegrationDllHostInitializerAddingHost, applicationId, clsid, service);
                            this.hosts.Add(
                                new DllHostedComPlusServiceHost(clsid,
                                                                service,
                                                                application,
                                                                classObject));
                        }
                    }
                    if (!foundService)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString
                                                                                                                    (SR.CannotFindClsidInApplication, clsidToCompare.ToString("B").ToUpperInvariant(), applicationId.ToString("B").ToUpperInvariant())));
                    }
                }
                if (foundService == false)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.DllHostInitializerFoundNoServices());
                }

                foreach (ComPlusServiceHost host in this.hosts)
                {
                    host.Open();
                }
            }
            catch (Exception e)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.ComPlus,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.ComPlusDllHostInitializerStartingError,
                                                    applicationId.ToString(),
                                                    e.ToString());
                throw;
            }
            finally
            {
                if (null != pingThread)
                {
                    pingThread.Abort(); // We are done; stop pinging.
                }
            }
            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Information, TraceCode.ComIntegrationDllHostInitializerStarted,
                                                 SR.TraceCodeComIntegrationDllHostInitializerStarted, applicationId);
        }
예제 #2
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);
        }
        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);
        }
예제 #4
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);
        }