예제 #1
0
        public IDictionary <string, string> Parse(Stream input)
        {
            IDictionary <string, string> data = new SortedDictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            var visitor = new ContextAwareVisitor();

            var yamlStream = new YamlStream();

            using (var reader = new StreamReader(input))
            {
                yamlStream.Load(reader);
            }

            if (!yamlStream.Documents.Any())
            {
                return(data);
            }

            yamlStream.Accept(visitor);

            foreach (var item in visitor.Items)
            {
                var key = item.Key;

                if (!string.IsNullOrEmpty(this.root))
                {
                    key = ConfigurationPath.Combine(this.root, key);
                }

                if (data.ContainsKey(key))
                {
                    throw new FormatException(string.Format("The key '{0}' is duplicated.", key));
                }
                data[key] = item.Value;
            }

            return(data);
        }
        public void LoggerProviders_ConsoleEnabled_InConfiguration()
        {
            var hostBuilder = new HostBuilder()
                              .ConfigureAppConfiguration(c =>
            {
                c.AddInMemoryCollection(new Dictionary <string, string>
                {
                    { ConfigurationPath.Combine(_loggingPath, "Console", "IsEnabled"), "True" }
                });
            })
                              .ConfigureDefaultTestWebScriptHost();

            using (IHost host = hostBuilder.Build())
            {
                IEnumerable <ILoggerProvider> loggerProviders = host.Services.GetService <IEnumerable <ILoggerProvider> >();

                Assert.Equal(6, loggerProviders.Count());
                loggerProviders.OfType <SystemLoggerProvider>().Single();
                loggerProviders.OfType <HostFileLoggerProvider>().Single();
                loggerProviders.OfType <FunctionFileLoggerProvider>().Single();
                loggerProviders.OfType <ConsoleLoggerProvider>().Single();
                loggerProviders.OfType <AzureMonitorDiagnosticLoggerProvider>().Single();
            }
        }
예제 #3
0
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .ConfigureAppConfiguration((hostingContext, config) =>
 {
     // Assemblies aren't loaded yet so have to scan the files in the folder
     var wordpressExtensions = new Dictionary <string, string>();
     var index = 0;
     foreach (var wordpressConfigFile in
              Directory.GetFiles(
                  Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                  "*.dll",
                  SearchOption.TopDirectoryOnly)
              .Where(f => Path.GetFileName(f).StartsWith(WORDPRESS_EXTENSIONS_PREFIX))
              .Select(f => Path.GetFileNameWithoutExtension(f)))
     {
         Console.WriteLine($"Trying to load extension: {wordpressConfigFile} | {ConfigurationPath.Combine(WORDPRESS_EXTENSIONS_CONFIGURATION, index.ToString())}");
         wordpressExtensions.Add(
             ConfigurationPath.Combine(WORDPRESS_EXTENSIONS_CONFIGURATION, index.ToString()),
             wordpressConfigFile);
         index++;
     }
     config.AddInMemoryCollection(wordpressExtensions);
 })
 .UseStartup <Startup>();
예제 #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddApplicationInsightsTelemetry();
            services.AddSwaggerGen(swaggerGenOptions =>
            {
                swaggerGenOptions.SwaggerDoc("V1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Title          = "FirstWebapp on azure",
                    Version        = "V1",
                    Description    = "Sample Hello world application.",
                    TermsOfService = "None."
                });

                swaggerGenOptions.OperationFilter <AddResponseHeadersFilter>();
                swaggerGenOptions.DescribeAllEnumsAsStrings();
                var xmlfile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = ConfigurationPath.Combine(AppContext.BaseDirectory, xmlfile);
                if (File.Exists(xmlPath))
                {
                    swaggerGenOptions.IncludeXmlComments(xmlPath);
                }
            });
        }
        public void Configure_AppliesDefaults_IfDynamic()
        {
            var settings = new Dictionary <string, string>();

            var environment = new TestEnvironment();

            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteSku, "Dynamic");

            var options = GetConfiguredOptions(settings, environment);

            Assert.Equal(ScriptHostOptionsSetup.DefaultFunctionTimeoutDynamic, options.FunctionTimeout);

            // When functionTimeout is set as null
            settings.Add(ConfigurationPath.Combine(ConfigurationSectionNames.JobHost, "functionTimeout"), string.Empty);

            options = GetConfiguredOptions(settings, environment);
            Assert.Equal(ScriptHostOptionsSetup.DefaultFunctionTimeoutDynamic, options.FunctionTimeout);

            // TODO: DI Need to ensure JobHostOptions is correctly configured
            //var timeoutConfig = options.HostOptions.FunctionTimeout;
            //Assert.NotNull(timeoutConfig);
            //Assert.True(timeoutConfig.ThrowOnTimeout);
            //Assert.Equal(scriptConfig.FunctionTimeout.Value, timeoutConfig.Timeout);
        }
        /// <summary>
        /// Loads configuration properties using the Environment Variables Provider.
        /// </summary>
        /// <param name="variables">The Environment variables to filter.</param>
        public void Load(IDictionary variables)
        {
            var data       = new SortedDictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            var enumerator = new EnvironmentVariablesEnumerator(mustStartWith, separator);

            foreach (var item in enumerator.GetItems(variables))
            {
                var key = item.Key;

                if (!string.IsNullOrEmpty(root))
                {
                    key = ConfigurationPath.Combine(root, key);
                }

                if (data.ContainsKey(key))
                {
                    throw new FormatException($"The key '{key}' is duplicated.");
                }

                data[key] = item.Value;
            }

            Data = data;
        }
예제 #7
0
        /// <summary>
        /// Adds Configuration for UseStaticFiles middleware to use Azure Storage container.
        /// </summary>
        /// <typeparam name="TOptions"></typeparam>
        /// <param name="services">The collection of Dependency Injection services.</param>
        /// <param name="azureStorageSectionName">The Default value is 'Account'. This corresponds to 'Account' in 'AzureStorage' configuration.</param>
        /// <param name="configure">The delegate to configure the <see cref="StorageAccountOptions"/>.</param>
        /// <returns></returns>
        public static IServiceCollection AddAzureStorageForStaticFiles <TOptions>(
            this IServiceCollection services,
            string azureStorageSectionName = "",
            Action <TOptions> configure    = null)
            where TOptions : StorageFileProviderOptions
        {
            services.AddAzureStorage(azureStorageSectionName);

            services.ConfigureOptions <TOptions>(Constants.StorageFileProviders, (config, path, options) =>
            {
                options.AzureStorageConfiguration = azureStorageSectionName;

                if (path != typeof(TOptions).Name)
                {
                    path = ConfigurationPath.Combine(path, typeof(TOptions).Name);
                }
                var section = config.GetSection(path);
                section.Bind(options);

                configure?.Invoke(options);
            });

            return(services);
        }
예제 #8
0
파일: Startup.cs 프로젝트: Kirill-bab/HW11
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add options
            services
            .Configure <CacheOptions>(Configuration.GetSection("Cache"))
            .Configure <NbuClientOptions>(Configuration.GetSection("Client"))
            .Configure <RatesOptions>(Configuration.GetSection("Rates"));

            // Add application services
            services.AddScoped <IRatesService, RatesService>();

            // Add NbuClient as Transient
            services.AddHttpClient <IRatesProviderClient, NbuClient>()
            .ConfigureHttpClient(client => client.Timeout = TimeSpan.FromSeconds(10));

            // Add CacheHostedService as Singleton
            services.AddHostedService <CacheHostedService>();
            services.AddSingleton <RegistrationExceptions>();
            services.AddSingleton <RecyclableMemoryStreamManager>();
            // Add batch of Swashbuckle Swagger services
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "DI Demo App API", Version = "v1"
                });
                var filePath = ConfigurationPath.Combine(AppContext.BaseDirectory + "DepsWebApp.xml");
                if (File.Exists(filePath))
                {
                    c.IncludeXmlComments(filePath);
                }
            });

            // Add batch of framework services
            services.AddMemoryCache();
            services.AddControllers();
        }
 void PushContext(string context)
 {
     this.context.Push(context);
     currentPath = ConfigurationPath.Combine(this.context.Reverse());
 }
        public async Task InvocationsContainDifferentOperationIds()
        {
            // Verify that when a request specializes the host we don't capture the context
            // of that request. Application Insights uses this context to correlate telemetry
            // so it had a confusing effect. Previously all TimerTrigger traces would have the
            // operation id of this request and all host logs would as well.

            // Start a host in standby mode.
            StandbyManager.ResetChangeToken();

            string standbyPath           = Path.Combine(Path.GetTempPath(), "functions", "standby", "wwwroot");
            string specializedScriptRoot = @"TestScripts\CSharp";
            string scriptRootConfigPath  = ConfigurationPath.Combine(ConfigurationSectionNames.WebHost, nameof(ScriptApplicationHostOptions.ScriptPath));

            var settings = new Dictionary <string, string>()
            {
                { EnvironmentSettingNames.AzureWebsitePlaceholderMode, "1" },
                { EnvironmentSettingNames.AzureWebsiteContainerReady, null },
            };

            var environment    = new TestEnvironment(settings);
            var loggerProvider = new TestLoggerProvider();
            var channel        = new TestTelemetryChannel();

            var builder = Program.CreateWebHostBuilder()
                          .ConfigureLogging(b =>
            {
                b.AddProvider(loggerProvider);
            })
                          .ConfigureAppConfiguration(c =>
            {
                c.AddInMemoryCollection(new Dictionary <string, string>
                {
                    { scriptRootConfigPath, specializedScriptRoot }
                });
            })
                          .ConfigureServices((bc, s) =>
            {
                s.AddSingleton <IEnvironment>(environment);

                // Ensure that we don't have a race between the timer and the
                // request for triggering specialization.
                s.AddSingleton <IStandbyManager, InfiniteTimerStandbyManager>();
            })
                          .AddScriptHostBuilder(webJobsBuilder =>
            {
                webJobsBuilder.Services.AddSingleton <ITelemetryChannel>(_ => channel);

                webJobsBuilder.Services.Configure <FunctionResultAggregatorOptions>(o =>
                {
                    o.IsEnabled = false;
                });

                webJobsBuilder.Services.PostConfigure <ApplicationInsightsLoggerOptions>(o =>
                {
                    o.SamplingSettings = null;
                });

                webJobsBuilder.Services.PostConfigure <ScriptJobHostOptions>(o =>
                {
                    // Only load the function we care about, but not during standby
                    if (o.RootScriptPath != standbyPath)
                    {
                        o.Functions = new[]
                        {
                            "OneSecondTimer",
                            "FunctionExecutionContext"
                        };
                    }
                });
            })
                          .ConfigureScriptHostAppConfiguration(c =>
            {
                c.AddInMemoryCollection(new Dictionary <string, string>
                {
                    [EnvironmentSettingNames.AppInsightsInstrumentationKey] = "some_key"
                });
            });

            using (var testServer = new TestServer(builder))
            {
                var client = testServer.CreateClient();

                HttpResponseMessage response = await client.GetAsync("api/warmup");

                Assert.True(response.IsSuccessStatusCode, loggerProvider.GetLog());

                // Now that standby mode is warmed up, set the specialization properties...
                environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteContainerReady, "1");
                environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "0");

                // ...and issue a request which will force specialization.
                response = await client.GetAsync("api/functionexecutioncontext");

                Assert.True(response.IsSuccessStatusCode, loggerProvider.GetLog());

                // Wait until we have a few logs from the timer trigger.
                IEnumerable <TraceTelemetry> timerLogs = null;
                await TestHelpers.Await(() =>
                {
                    timerLogs = channel.Telemetries
                                .OfType <TraceTelemetry>()
                                .Where(p => p.Message == "OneSecondTimer fired!");

                    return(timerLogs.Count() >= 3);
                });

                var startupRequest = channel.Telemetries
                                     .OfType <RequestTelemetry>()
                                     .Where(p => p.Name == "FunctionExecutionContext")
                                     .Single();

                // Make sure that auto-Http tracking worked with this request.
                Assert.Equal("200", startupRequest.ResponseCode);

                // The host logs should not be associated with this request.
                var logsWithRequestId = channel.Telemetries
                                        .OfType <TraceTelemetry>()
                                        .Select(p => p.Context.Operation.Id)
                                        .Where(p => p == startupRequest.Context.Operation.Id);

                // Just expect the "Executing" and "Executed" logs from the actual request.
                Assert.Equal(2, logsWithRequestId.Count());

                // And each of the timer invocations should have a different operation id, and none
                // should match the request id.
                var distinctOpIds = timerLogs.Select(p => p.Context.Operation.Id).Distinct();
                Assert.Equal(timerLogs.Count(), distinctOpIds.Count());
                Assert.Empty(timerLogs.Where(p => p.Context.Operation.Id == startupRequest.Context.Operation.Id));
            }
        }
예제 #11
0
 public void CombineWithEmptySegmentLeavesDelimiter()
 {
     Assert.Equal("parent:", ConfigurationPath.Combine("parent", ""));
     Assert.Equal("parent::", ConfigurationPath.Combine("parent", "", ""));
     Assert.Equal("parent:::key", ConfigurationPath.Combine("parent", "", "", "key"));
 }
예제 #12
0
 private void ExitContext()
 {
     _context.Pop();
     _currentPath = ConfigurationPath.Combine(_context.Reverse());
 }
 private void exitContext()
 {
     r_Context.Pop();
     m_CurrentPath = ConfigurationPath.Combine(r_Context.Reverse());
 }
 private void GoDescendant(string context)
 {
     _path.Push(context);
     _currentPath = ConfigurationPath.Combine(_path.Reverse());
 }
예제 #15
0
        /// <summary>
        /// Read a stream of XML values into a key/value dictionary.
        /// </summary>
        /// <param name="stream">The stream of XML data.</param>
        /// <param name="decryptor">The <see cref="XmlDocumentDecryptor"/> to use to decrypt.</param>
        /// <returns>The <see cref="IDictionary{String, String}"/> which was read from the stream.</returns>
        public static IDictionary <string, string> Read(Stream stream, XmlDocumentDecryptor decryptor)
        {
            var data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            var readerSettings = new XmlReaderSettings()
            {
                CloseInput       = false, // caller will close the stream
                DtdProcessing    = DtdProcessing.Prohibit,
                IgnoreComments   = true,
                IgnoreWhitespace = true
            };

            using (var reader = decryptor.CreateDecryptingXmlReader(stream, readerSettings))
            {
                var prefixStack = new Stack <string>();

                SkipUntilRootElement(reader);

                // We process the root element individually since it doesn't contribute to prefix
                ProcessAttributes(reader, prefixStack, data, AddNamePrefix);
                ProcessAttributes(reader, prefixStack, data, AddAttributePair);

                var preNodeType = reader.NodeType;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        prefixStack.Push(reader.LocalName);
                        ProcessAttributes(reader, prefixStack, data, AddNamePrefix);
                        ProcessAttributes(reader, prefixStack, data, AddAttributePair);

                        // If current element is self-closing
                        if (reader.IsEmptyElement)
                        {
                            prefixStack.Pop();
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (prefixStack.Any())
                        {
                            // If this EndElement node comes right after an Element node,
                            // it means there is no text/CDATA node in current element
                            if (preNodeType == XmlNodeType.Element)
                            {
                                var key = ConfigurationPath.Combine(prefixStack.Reverse());
                                data[key] = string.Empty;
                            }

                            prefixStack.Pop();
                        }
                        break;

                    case XmlNodeType.CDATA:
                    case XmlNodeType.Text:
                    {
                        var key = ConfigurationPath.Combine(prefixStack.Reverse());
                        if (data.ContainsKey(key))
                        {
                            throw new FormatException(SR.Format(SR.Error_KeyIsDuplicated, key,
                                                                GetLineInfo(reader)));
                        }

                        data[key] = reader.Value;
                        break;
                    }

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                    case XmlNodeType.Comment:
                    case XmlNodeType.Whitespace:
                        // Ignore certain types of nodes
                        break;

                    default:
                        throw new FormatException(SR.Format(SR.Error_UnsupportedNodeType, reader.NodeType,
                                                            GetLineInfo(reader)));
                    }
                    preNodeType = reader.NodeType;
                    // If this element is a self-closing element,
                    // we pretend that we just processed an EndElement node
                    // because a self-closing element contains an end within itself
                    if (preNodeType == XmlNodeType.Element &&
                        reader.IsEmptyElement)
                    {
                        preNodeType = XmlNodeType.EndElement;
                    }
                }
            }
            return(data);
        }
예제 #16
0
        public static IHostBuilder AddScriptHost(this IHostBuilder builder,
                                                 ScriptApplicationHostOptions applicationOptions,
                                                 ILoggerFactory loggerFactory,
                                                 IMetricsLogger metricsLogger,
                                                 Action <IWebJobsBuilder> configureWebJobs = null)
        {
            loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;

            builder.SetAzureFunctionsConfigurationRoot();
            // Host configuration
            builder.ConfigureLogging((context, loggingBuilder) =>
            {
                loggingBuilder.AddDefaultWebJobsFilters();

                string loggingPath = ConfigurationPath.Combine(ConfigurationSectionNames.JobHost, "Logging");
                loggingBuilder.AddConfiguration(context.Configuration.GetSection(loggingPath));

                loggingBuilder.Services.AddSingleton <IFileWriterFactory, DefaultFileWriterFactory>();
                loggingBuilder.Services.AddSingleton <ILoggerProvider, HostFileLoggerProvider>();
                loggingBuilder.Services.AddSingleton <ILoggerProvider, FunctionFileLoggerProvider>();

                loggingBuilder.AddConsoleIfEnabled(context);

                ConfigureApplicationInsights(context, loggingBuilder);
            })
            .ConfigureAppConfiguration((context, configBuilder) =>
            {
                if (!context.Properties.ContainsKey(ScriptConstants.SkipHostJsonConfigurationKey))
                {
                    configBuilder.Add(new HostJsonFileConfigurationSource(applicationOptions, SystemEnvironment.Instance, loggerFactory, metricsLogger));
                }
            });

            // WebJobs configuration
            builder.AddScriptHostCore(applicationOptions, configureWebJobs, loggerFactory);

            // Allow FunctionsStartup to add configuration after all other configuration is registered.
            builder.ConfigureAppConfiguration((context, configBuilder) =>
            {
                // Pre-build configuration here to load bundles and to store for later validation.
                var config = configBuilder.Build();
                var extensionBundleOptions = GetExtensionBundleOptions(config);
                var bundleManager          = new ExtensionBundleManager(extensionBundleOptions, SystemEnvironment.Instance, loggerFactory);
                var metadataServiceManager = applicationOptions.RootServiceProvider.GetService <IFunctionMetadataManager>();
                var languageWorkerOptions  = applicationOptions.RootServiceProvider.GetService <IOptions <LanguageWorkerOptions> >();

                var locator = new ScriptStartupTypeLocator(applicationOptions.ScriptPath, loggerFactory.CreateLogger <ScriptStartupTypeLocator>(), bundleManager, metadataServiceManager, metricsLogger, languageWorkerOptions);

                // The locator (and thus the bundle manager) need to be created now in order to configure app configuration.
                // Store them so they do not need to be re-created later when configuring services.
                context.Properties[BundleManagerKey]      = bundleManager;
                context.Properties[StartupTypeLocatorKey] = locator;

                // If we're skipping host initialization, this key will not exist and this will also be skipped.
                if (context.Properties.TryGetValue(DelayedConfigurationActionKey, out object actionObject) &&
                    actionObject is Action <IWebJobsStartupTypeLocator> delayedConfigAction)
                {
                    context.Properties.Remove(DelayedConfigurationActionKey);

                    delayedConfigAction(locator);

                    // store the snapshot for validation later, but only if there
                    // are any registered external configuration startups.
                    if (locator.HasExternalConfigurationStartups())
                    {
                        context.Properties[ConfigurationSnapshotKey] = config;
                    }
                }
            });

            return(builder);
        }
예제 #17
0
 private string GenerateKey(string key)
 {
     return(ConfigurationPath.Combine(_Source.RootPath, _Source.SystemName, key));
 }
 private void SetPath()
 {
     this.path = ConfigurationPath.Combine(this.scopes.Reverse());
 }
 void PopContext()
 {
     context.Pop();
     currentPath = ConfigurationPath.Combine(this.context.Reverse());
 }
예제 #20
0
        public void ConfigureServices(IServiceCollection services)
        {
            service = services;
            //If this type is present - we're on mono
            var runningOnMono       = Type.GetType("Mono.Runtime") != null;
            var sqlConnectionString = Configuration[ConfigurationPath.Combine("ConnectionStrings", "DefaultConnectionString")];
            var useInMemoryDatabase = string.IsNullOrWhiteSpace(sqlConnectionString);

            if (useInMemoryDatabase || runningOnMono)
            {
                sqlConnectionString = "";
            }

            // Add EF services to the services container
            services.AddDbContext <PartsUnlimitedContext>();


            // Add Identity services to the services container
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <PartsUnlimitedContext>()
            .AddDefaultTokenProviders();

            // Configure admin policies
            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(AdminConstants.Role,
                               authBuilder =>
                {
                    authBuilder.RequireClaim(AdminConstants.ManageStore.Name, AdminConstants.ManageStore.Allowed);
                });
            });

            // Add implementations
            services.AddSingleton <IMemoryCache, MemoryCache>();
            services.AddScoped <IOrdersQuery, OrdersQuery>();
            services.AddScoped <IRaincheckQuery, RaincheckQuery>();

            services.AddSingleton <ITelemetryProvider, EmptyTelemetryProvider>();
            services.AddScoped <IProductSearch, StringContainsProductSearch>();

            SetupRecommendationService(services);

            services.AddScoped <IWebsiteOptions>(p =>
            {
                var telemetry = p.GetRequiredService <ITelemetryProvider>();

                return(new ConfigurationWebsiteOptions(Configuration.GetSection("WebsiteOptions"), telemetry));
            });

            services.AddScoped <IApplicationInsightsSettings>(p =>
            {
                return(new ConfigurationApplicationInsightsSettings(Configuration.GetSection(ConfigurationPath.Combine("Keys", "ApplicationInsights"))));
            });

            services.AddApplicationInsightsTelemetry(Configuration);

            // Associate IPartsUnlimitedContext and PartsUnlimitedContext with context
            services.AddTransient <IPartsUnlimitedContext>(x => new PartsUnlimitedContext(sqlConnectionString));
            services.AddTransient(x => new PartsUnlimitedContext(sqlConnectionString));

            // We need access to these settings in a static extension method, so DI does not help us :(
            ContentDeliveryNetworkExtensions.Configuration = new ContentDeliveryNetworkConfiguration(Configuration.GetSection("CDN"));

            // Add MVC services to the services container
            services.AddMvc();

            //Add InMemoryCache
            services.AddSingleton <IMemoryCache, MemoryCache>();

            // Add session related services.
            //services.AddCaching();
            services.AddSession();
        }
예제 #21
0
 public ConfigPathAttribute(params string[] parts)
 {
     Name = ConfigurationPath.Combine(parts);
 }
 private void enterContext(string i_Context)
 {
     r_Context.Push(i_Context);
     m_CurrentPath = ConfigurationPath.Combine(r_Context.Reverse());
 }
 private void GoAncestor()
 {
     _path.Pop();
     _currentPath = ConfigurationPath.Combine(_path.Reverse());
 }
예제 #24
0
 private void EnterContext(string context)
 {
     _context.Push(context);
     _currentPath = ConfigurationPath.Combine(System.Linq.Enumerable.Reverse(_context));
 }
예제 #25
0
        private void SetupRecommendationService(IServiceCollection services)
        {
            var azureMlConfig = new AzureMLFrequentlyBoughtTogetherConfig(Configuration.GetSection(ConfigurationPath.Combine("Keys", "AzureMLFrequentlyBoughtTogether")));

            // If keys are not available for Azure ML recommendation service, register an empty recommendation engine
            if (string.IsNullOrEmpty(azureMlConfig.AccountKey) || string.IsNullOrEmpty(azureMlConfig.ModelName))
            {
                services.AddSingleton <IRecommendationEngine, EmptyRecommendationsEngine>();
            }
            else
            {
                services.AddSingleton <IAzureMLAuthenticatedHttpClient, AzureMLAuthenticatedHttpClient>();
                services.AddSingleton <IAzureMLFrequentlyBoughtTogetherConfig>(azureMlConfig);
                services.AddScoped <IRecommendationEngine, AzureMLFrequentlyBoughtTogetherRecommendationEngine>();
            }
        }
예제 #26
0
 private void ExitContext()
 {
     _context.Pop();
     _currentPath = ConfigurationPath.Combine(System.Linq.Enumerable.Reverse(_context));
 }
예제 #27
0
 private void EnterContext(string context)
 {
     _context.Push(context);
     _currentPath = ConfigurationPath.Combine(_context.Reverse());
 }
예제 #28
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddSingleton <IPostsMetaDataRepositry>(new JsonPostsMetaDataRepository(ConfigurationPath.Combine("posts.json")));
     services.Configure <RazorViewEngineOptions>(o => { o.ViewLocationExpanders.Add(new FolderEnumerationViewExpander()); });
     services.AddMvc();
 }
예제 #29
0
            private void ProcessToken(JToken token)
            {
                switch (token.Type)
                {
                case JTokenType.Object:
                    ProcessObject(token.Value <JObject>());
                    break;

                case JTokenType.Array:
                    ProcessArray(token.Value <JArray>());
                    break;

                case JTokenType.Integer:
                case JTokenType.Float:
                case JTokenType.String:
                case JTokenType.Boolean:
                case JTokenType.Null:
                case JTokenType.Date:
                case JTokenType.Raw:
                case JTokenType.Bytes:
                case JTokenType.TimeSpan:
                    string key = ConfigurationSectionNames.JobHost + ConfigurationPath.KeyDelimiter + ConfigurationPath.Combine(_path.Reverse());
                    Data[key] = token.Value <JValue>().ToString(CultureInfo.InvariantCulture);
                    break;

                default:
                    break;
                }
            }
 /// <summary>
 /// Gets a configuration sub-section with the specified key.
 /// </summary>
 /// <param name="key">The key of the configuration section.</param>
 /// <returns>The <see cref="IConfigurationSection"/>.</returns>
 /// <remarks>
 ///     This method will never return <c>null</c>. If no matching sub-section is found with the specified key,
 ///     an empty <see cref="IConfigurationSection"/> will be returned.
 /// </remarks>
 public IConfigurationSection GetSection(string key) => _root.GetSection(ConfigurationPath.Combine(Path, key));