コード例 #1
0
        /// <summary>
        /// The default <see cref="IPipeline"/> factory function.
        /// This looks for a 'PipelineOptions' configuration item and uses
        /// that to build the pipeline.
        /// </summary>
        /// <param name="config">
        /// The application configuration object
        /// </param>
        /// <param name="pipelineBuilder">
        /// a pipeline builder instance to use when constructing the
        /// <see cref="IPipeline"/>.
        /// </param>
        /// <returns>
        /// A new <see cref="IPipeline"/> instance
        /// </returns>
        private static IPipeline CreatePipelineFromConfig(
            IConfiguration config,
            IPipelineBuilderFromConfiguration pipelineBuilder)
        {
            // Get Pipeline options to check that it is present
            PipelineOptions options = new PipelineOptions();

            config.Bind("PipelineOptions", options);

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

            PipelineWebIntegrationOptions webOptions = new PipelineWebIntegrationOptions();

            config.Bind("PipelineWebIntegrationOptions", webOptions);

            // Add the sequence element.
            AddSequenceElement(options);

            if (webOptions.ClientSideEvidenceEnabled)
            {
                // Client-side evidence is enabled so make sure the
                // JsonBuilderElement and JavaScriptBundlerElement has been
                // included.
                AddJsElements(options);
            }

            // Add the SetHeaders element
            AddSetHeadersElement(options);

            return(pipelineBuilder.BuildFromConfiguration(options));
        }
コード例 #2
0
        /// <summary>
        /// The default <see cref="IPipeline"/> factory function.
        /// This looks for a 'PipelineOptions' configuration item and uses
        /// that to build the pipeline.
        /// </summary>
        /// <param name="config">
        /// The application configuration object
        /// </param>
        /// <param name="pipelineBuilder">
        /// a pipeline builder instance to use when constructing the
        /// <see cref="IPipeline"/>.
        /// </param>
        /// <returns>
        /// A new <see cref="IPipeline"/> instance
        /// </returns>
        private static IPipeline CreatePipelineFromConfig(
            IConfiguration config,
            IPipelineBuilderFromConfiguration pipelineBuilder)
        {
            // Get Pipeline options to check that it is present
            PipelineOptions options = new PipelineOptions();

            config.Bind("PipelineOptions", options);

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

            PipelineWebIntegrationOptions webOptions = new PipelineWebIntegrationOptions();

            config.Bind("PipelineWebIntegrationOptions", webOptions);

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

            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 (webOptions.ClientSideEvidenceEnabled)
            {
                // Client-side evidence is enabled so make sure the
                // JsonBuilderElement and JavaScriptBundlerElement has been
                // included.
                var jsonConfig = options.Elements.Where(e =>
                                                        e.BuilderName.Contains(nameof(JsonBuilderElement),
                                                                               StringComparison.OrdinalIgnoreCase));
                var javascriptConfig = options.Elements.Where(e =>
                                                              e.BuilderName.Contains(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 builder is not included so add it.
                    options.Elements.Add(new ElementOptions()
                    {
                        BuilderName     = nameof(JavaScriptBuilderElement),
                        BuildParameters = new Dictionary <string, object>()
                        {
                            { "EnableCookies", true }
                        }
                    });
                }
            }

            return(pipelineBuilder.BuildFromConfiguration(options));
        }