示例#1
0
        /// <summary>
        /// Gets the global environment.
        /// </summary>
        /// <returns>A <see cref="CommerceEnvironment"/></returns>
        private CommerceEnvironment GetGlobalEnvironment()
        {
            CommerceEnvironment environment;

            this._logger.LogInformation($"Loading Global Environment using Filesystem Provider from: {this._hostEnv.WebRootPath} s\\Bootstrap\\");

            // Use the default File System provider to setup the environment
            this.NodeContext.BootStrapProviderPath = this._hostEnv.WebRootPath + @"\Bootstrap\";
            var bootstrapProvider = new FileSystemEntityProvider(NodeContext.BootStrapProviderPath);

            var bootstrapFile = this._configuration.GetSection("AppSettings:BootStrapFile").Value;

            if (!string.IsNullOrEmpty(bootstrapFile))
            {
                this.NodeContext.BootStrapEnvironmentPath = bootstrapFile;

                this.NodeContext.AddDataMessage("NodeStartup", $"GlobalEnvironmentFrom='Configuration: {bootstrapFile}'");
                environment = bootstrapProvider.Find <CommerceEnvironment>(this.NodeContext, bootstrapFile, false).Result;
            }
            else
            {
                // Load the NodeContext default
                bootstrapFile = "Global";
                this.NodeContext.BootStrapEnvironmentPath = bootstrapFile;
                this.NodeContext.AddDataMessage("NodeStartup", $"GlobalEnvironmentFrom='{bootstrapFile}.json'");
                environment = bootstrapProvider.Find <CommerceEnvironment>(this.NodeContext, bootstrapFile, false).Result;
            }

            this.NodeContext.BootStrapEnvironmentPath = bootstrapFile;

            this.NodeContext.GlobalEnvironmentName = environment.Name;
            this.NodeContext.AddDataMessage("NodeStartup", $"Status='Started',GlobalEnvironmentName='{NodeContext.GlobalEnvironmentName}'");

            if (this._configuration.GetSection("AppSettings:BootStrapFile").Value != null)
            {
                this.NodeContext.ContactId = this._configuration.GetSection("AppSettings:NodeId").Value;
            }

            if (!string.IsNullOrEmpty(environment.GetPolicy <DeploymentPolicy>().DeploymentId))
            {
                this.NodeContext.ContactId = $"{environment.GetPolicy<DeploymentPolicy>().DeploymentId}_{this._nodeInstanceId}";
            }

            return(environment);
        }
示例#2
0
        public static CommerceEnvironment ConfigureCommerceEnvironment(this IServiceCollection services, IConfigurationRoot configuration, NodeContext node)
        {
            var logger = ApplicationLogging.CreateLogger("ConfigEnvironment");

            logger.LogInformation($"Loading Global Environment using Filesystem Provider from: {node.BootStrapProviderPath}");
            var bootstrapProvider = new FileSystemEntityProvider(node.BootStrapProviderPath);

            var appSettingBootstrapFileValue = configuration.GetSection("AppSettings:BootStrapFile").Value;

            if (!string.IsNullOrEmpty(appSettingBootstrapFileValue))
            {
                node.BootStrapEnvironmentPath = appSettingBootstrapFileValue;
            }

            node.AddDataMessage("NodeStartup", $"GlobalEnvironmentFrom='{node.BootStrapEnvironmentPath}.json'");

            var environment = bootstrapProvider.Find <CommerceEnvironment>(node, node.BootStrapEnvironmentPath, false).Result;

            services.AddSingleton(environment);

            return(environment);
        }