예제 #1
0
        /// <summary>
        /// Private constructor used to construct the only instance which will
        /// exist of this class.
        /// </summary>
        private WebPipeline()
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddPipelineConfig()
                                    .Build();
            PipelineWebIntegrationOptions options = new PipelineWebIntegrationOptions();

            config.Bind("PipelineOptions", options);

            if (options == null ||
                options.Elements == null)
            {
                throw new PipelineConfigurationException(
                          Messages.ExceptionNoConfiguration);
            }

            // Add the sequence element.
            var sequenceConfig = options.Elements.Where(e =>
                                                        e.BuilderName.IndexOf(nameof(SequenceElement),
                                                                              StringComparison.OrdinalIgnoreCase) >= 0);

            if (sequenceConfig.Any() == false)
            {
                // The sequence element is not included so add it.
                options.Elements.Add(new ElementOptions()
                {
                    BuilderName = nameof(SequenceElement)
                });
            }

            if (ClientSideEvidenceEnabled)
            {
                // Client-side evidence is enabled so make sure the
                // JsonBuilderElement and JavaScriptBundlerElement has been
                // included.
                var jsonConfig = options.Elements.Where(e =>
                                                        e.BuilderName.IndexOf(nameof(JsonBuilderElement),
                                                                              StringComparison.OrdinalIgnoreCase) >= 0);
                if (jsonConfig.Any() == false)
                {
                    // The json builder is not included so add it.
                    options.Elements.Add(new ElementOptions()
                    {
                        BuilderName = nameof(JsonBuilderElement)
                    });
                }

                var builderConfig = options.Elements.Where(e =>
                                                           e.BuilderName.IndexOf(nameof(JavaScriptBuilderElement),
                                                                                 StringComparison.OrdinalIgnoreCase) >= 0);
                if (builderConfig.Any() == false)
                {
                    // The bundler is not included so add it.
                    options.Elements.Add(new ElementOptions()
                    {
                        BuilderName = nameof(JavaScriptBuilderElement)
                    });
                }
            }

            Pipeline = new PipelineBuilder(new LoggerFactory())
                       .BuildFromConfiguration(options);

            _options = options;
        }
예제 #2
0
        /// <summary>
        /// Private constructor used to construct the only instance which will
        /// exist of this class.
        /// </summary>
        private WebPipeline()
        {
            IConfiguration config = new ConfigurationBuilder()
                .AddPipelineConfig()
                .Build();
            _options = new PipelineWebIntegrationOptions();
            config.Bind("PipelineOptions", _options);
            
            if (_options == null ||
                _options.Elements == null)
            {
                throw new PipelineConfigurationException(
                   Messages.ExceptionNoConfiguration);
            }

            // Add the sequence element.
            var sequenceConfig = _options.Elements.Where(e =>
                e.BuilderName.IndexOf(nameof(SequenceElement),
                    StringComparison.OrdinalIgnoreCase) >= 0);
            if (sequenceConfig.Any() == false)
            {
                // The sequence element is not included so add it.
                // Make sure it's added as the first element.
                _options.Elements.Insert(0, new ElementOptions()
                {
                    BuilderName = nameof(SequenceElement)
                });
            }

            if (ClientSideEvidenceEnabled)
            {
                // Client-side evidence is enabled so make sure the 
                // JsonBuilderElement and JavaScriptBundlerElement has been 
                // included.
                var jsonConfig = _options.Elements.Where(e =>
                    e.BuilderName.StartsWith(nameof(JsonBuilderElement),
                        StringComparison.OrdinalIgnoreCase));
                var javascriptConfig = _options.Elements.Where(e =>
                    e.BuilderName.StartsWith(nameof(JavaScriptBuilderElement),
                        StringComparison.OrdinalIgnoreCase));

                var jsIndex = javascriptConfig.Any() ?
                    _options.Elements.IndexOf(javascriptConfig.First()) : -1;

                if (jsonConfig.Any() == false)
                {
                    // The json builder is not included so add it.
                    var newElementOptions = new ElementOptions()
                    {
                        BuilderName = nameof(JsonBuilderElement)
                    };
                    if (jsIndex > -1)
                    {
                        // There is already a javascript builder element
                        // so insert the json builder before it.
                        _options.Elements.Insert(jsIndex, newElementOptions);
                    }
                    else
                    {
                        _options.Elements.Add(newElementOptions);
                    }
                }

                if (jsIndex == -1)
                {
                    // The javascript builder is not included so add it.
                    _options.Elements.Add(new ElementOptions()
                    {
                        BuilderName = nameof(JavaScriptBuilderElement),
                        BuildParameters = new Dictionary<string, object>()
                        {
                            { "EndPoint", "/51dpipeline/json" }
                        }
                    });
                }
                else
                {
                    // There is already a JavaScript builder config so check if 
                    // the endpoint is specified. If not, add it.
                    if (javascriptConfig.Single().BuildParameters.ContainsKey("EndPoint") == false)
                    {
                        javascriptConfig.Single().BuildParameters.Add("EndPoint", "/51dpipeline/json");
                    }
                }
            }

            // Add the set headers
            var setHeadersConfig = _options.Elements.Where(e =>
                e.BuilderName.IndexOf(nameof(SetHeadersElement),
                    StringComparison.OrdinalIgnoreCase) >= 0);
            if (setHeadersConfig.Any() == false)
            {
                // The set headers element is not included, so add it.
                // Make sure it's added as the last element.
                _options.Elements.Add(new ElementOptions()
                {
                    BuilderName = nameof(SetHeadersElement)
                });
            }

            // Set up common services.
            var loggerFactory = new LoggerFactory();
            var updateService = new DataUpdateService(
                loggerFactory.CreateLogger<DataUpdateService>(),
                new System.Net.Http.HttpClient());
            var services = new FiftyOneServiceProvider();
            // Add data update and missing property services.
            services.AddService(updateService);
            services.AddService(MissingPropertyService.Instance);

            Pipeline = new PipelineBuilder(
                loggerFactory,
                services)
                .BuildFromConfiguration(_options);
        }