/// Be sure to update UnsafeGetAssociatedSection if you modify this method
        internal static object GetAssociatedSection(ContextInformation evalContext, string sectionPath)
        {
            object retval = null;

            if (evalContext != null)
            {
                retval = evalContext.GetSection(sectionPath);
            }
            else
            {
                retval = AspNetEnvironment.Current.GetConfigurationSection(sectionPath);

                // Trace after call to underlying configuration system to
                // insure that configuration system is initialized
                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.GetConfigurationSection,
                                            SR.GetString(SR.TraceCodeGetConfigurationSection),
                                            new StringTraceRecord("ConfigurationSection", sectionPath), null, null);
                }
            }
            if (retval == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new ConfigurationErrorsException(SR.GetString(SR.ConfigSectionNotFound,
                                                                        sectionPath)));
            }
            return(retval);
        }
Example #2
0
        internal static object GetAssociatedSection(ContextInformation evalContext, string sectionPath)
        {
            object section = null;

            if (evalContext == null)
            {
                section = (!(bool)InvokeHelper.InvokeStaticGet(typeof(ServiceHostingEnvironment), "IsHosted") ? ConfigurationManager.GetSection(sectionPath) : Microsoft.ServiceBus.Configuration.ConfigurationHelpers.GetSectionFromWebConfigurationManager(sectionPath));
                if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceVerbose)
                {
                    TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.GetConfigurationSection, new StringTraceRecord("ConfigurationSection", sectionPath), null, null);
                }
            }
            else
            {
                section = evalContext.GetSection(sectionPath);
            }
            if (section == null)
            {
                ExceptionUtility exceptionUtility      = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           configSectionNotFound = Resources.ConfigSectionNotFound;
                object[]         objArray = new object[] { sectionPath };
                throw exceptionUtility.ThrowHelperError(new ConfigurationErrorsException(Microsoft.ServiceBus.SR.GetString(configSectionNotFound, objArray)));
            }
            return(section);
        }
Example #3
0
        internal static object GetAssociatedSection(ContextInformation evalContext, string sectionPath)
        {
            object section = null;

            if (evalContext != null)
            {
                section = evalContext.GetSection(sectionPath);
            }
            else
            {
                section = AspNetEnvironment.Current.GetConfigurationSection(sectionPath);
                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    TraceUtility.TraceEvent(TraceEventType.Verbose, 0x80024, System.ServiceModel.SR.GetString("TraceCodeGetConfigurationSection"), new StringTraceRecord("ConfigurationSection", sectionPath), null, null);
                }
            }
            if (section == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigSectionNotFound", new object[] { sectionPath })));
            }
            return(section);
        }
Example #4
0
        /// <summary>
        /// Registers WCF services type mappings from the given configuration excluding specified endpoints if needed.
        /// </summary>
        public static IServiceCollection AddWcfServices(this IServiceCollection container, ContextInformation ctx, Func <ServiceEndpointElement, bool> exclEndpoints)
        {
            string          servicesPath = "system.serviceModel/services";
            ServicesSection services     = (ServicesSection)(ctx != null ? ctx.GetSection(servicesPath) : ConfigurationManager.GetSection(servicesPath));

            foreach (ServiceElement service in services.Services)
            {
                Type serviceType = AppInitializer.GetType(service.Name);
                if (serviceType == null)
                {
                    continue;
                }
                foreach (ServiceEndpointElement endpoint in service.Endpoints)
                {
                    Type contractType = AppInitializer.GetType(endpoint.Contract);
                    if (contractType == null || endpoint.IsSystemEndpoint || exclEndpoints != null && exclEndpoints(endpoint))
                    {
                        continue;
                    }
                    container.AddScoped(contractType, serviceType);
                }
            }
            return(container);
        }
Example #5
0
        /// <summary>
        /// Registers WCF client type mappings from the given configuration excluding specified endpoints if needed.
        /// </summary>
        public static IServiceCollection AddWcfClientServices(this IServiceCollection container, Func <SecurityToken> tokenProvider,
                                                              ContextInformation ctx, Func <ChannelEndpointElement, bool> exclEndpoints)
        {
            string        clientPath = "system.serviceModel/client";
            ClientSection client     = (ClientSection)(ctx != null ? ctx.GetSection(clientPath) : ConfigurationManager.GetSection(clientPath));

            foreach (ChannelEndpointElement endpoint in client.Endpoints)
            {
                if (endpoint.Name == null || endpoint.Contract == null || exclEndpoints != null && exclEndpoints(endpoint))
                {
                    continue;
                }
                Type contractType = AppInitializer.GetType(endpoint.Contract);
                Type factoryType  = ctx != null ?
                                    typeof(ConfigurationChannelFactory <>).MakeGenericType(contractType) :
                                    typeof(ChannelFactory <>).MakeGenericType(contractType);
                container.AddSingleton(factoryType, sp => ctx == null ? Activator.CreateInstance(factoryType, endpoint.Name) :
                                       Activator.CreateInstance(factoryType, endpoint.Name, ctx, null));
                container.AddScoped(contractType, sp => tokenProvider != null ? factoryType.InvokeMember("CreateChannelWithIssuedToken",
                                                                                                         BindingFlags.InvokeMethod, null, sp.GetService(factoryType), new object[] { tokenProvider() }) :
                                    factoryType.InvokeMember("CreateChannel", BindingFlags.InvokeMethod, null, sp.GetService(factoryType), new object[] { }));
            }
            return(container);
        }
 internal static object UnsafeGetSectionFromContext(ContextInformation evalContext, string sectionPath)
 {
     return(evalContext.GetSection(sectionPath));
 }