Exemplo n.º 1
0
        void UseWebApi(IPipelineBuilderEnvironment builderEnv)
        {
            _WebApiMiddleware.AreFormNamesCaseSensitive        = false;
            _WebApiMiddleware.AreQueryStringNamesCaseSensitive = false;

            builderEnv.UseMiddlewareBuilder(_WebApiMiddleware.AppFuncBuilder);
        }
Exemplo n.º 2
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="buildEnvironment"></param>
        public void Construct(IPipelineBuilderEnvironment buildEnvironment)
        {
            if (buildEnvironment == null)
            {
                throw new ArgumentNullException(nameof(buildEnvironment));
            }
            if (_MiddlewareApplicationDelegate != null)
            {
                throw new InvalidOperationException($"You cannot call {nameof(Construct)} twice");
            }

            _ExceptionLoggers = buildEnvironment.ExceptionLoggers.ToArray();

            _MiddlewareApplicationDelegate = ChainTerminatorAppFunc;
            foreach (var appFuncBuilder in buildEnvironment.MiddlewareBuilders.Reverse())
            {
                _MiddlewareApplicationDelegate = appFuncBuilder(_MiddlewareApplicationDelegate);
            }

            var streamManipulators = new List <AppFunc>();

            foreach (var appFuncBuilder in buildEnvironment.StreamManipulatorBuilders)
            {
                streamManipulators.Add(appFuncBuilder(ChainTerminatorAppFunc));
            }
            _StreamManipulators = streamManipulators.ToArray();

            _LogExceptions           = buildEnvironment.PipelineLogsExceptions && _ExceptionLoggers.Length > 0;
            _SwallowLoggedExceptions = buildEnvironment.PipelineSwallowsExceptions;
        }
 private void UseCompressionManipulator(IPipelineBuilderEnvironment builderEnv)
 {
     if (!IsLoopbackHost(builderEnv))
     {
         var manipulator = Factory.Resolve <IAutoConfigCompressionManipulator>();
         builderEnv.UseStreamManipulatorBuilder(manipulator.AppFuncBuilder);
     }
 }
        private void UseWebApi(IPipelineBuilderEnvironment builderEnv)
        {
            var webApi = Factory.Resolve <IWebApiMiddleware>();

            webApi.AreFormNamesCaseSensitive        = false;
            webApi.AreQueryStringNamesCaseSensitive = false;

            builderEnv.UseMiddlewareBuilder(webApi.AppFuncBuilder);
        }
Exemplo n.º 5
0
        void UseSetupTestEnvironment(IPipelineBuilderEnvironment builderEnv)
        {
            // The intention is for this to get called at the start of the pipeline
            Func <AppFunc, AppFunc> appFuncBuilder = (Func <IDictionary <string, object>, Task> next) =>
            {
                return(async(IDictionary <string, object> environment) => {
                    environment["server.RemoteIpAddress"] = _RemoteIpAddress;
                    await next(environment);
                });
            };

            builderEnv.UseMiddlewareBuilder(appFuncBuilder);
        }
Exemplo n.º 6
0
        public void TestInitialise()
        {
            _Snapshot            = Factory.TakeSnapshot();
            _SharedConfiguration = TestUtilities.CreateMockSingleton <ISharedConfiguration>();
            _Configuration       = new Configuration();
            _SharedConfiguration.Setup(r => r.Get()).Returns(_Configuration);
            _UserManager = TestUtilities.CreateMockSingleton <IUserManager>();

            _RemoteIpAddress           = "127.0.0.1";
            _AccessFilter              = MockAccessFilter.CreateAndRegister();
            _BasicAuthenticationFilter = MockBasicAuthenticationFilter.CreateAndRegister();
            _RedirectionFilter         = MockRedirectionFilter.CreateAndRegister();

            _RamHost                    = Factory.Resolve <IHostRam>();
            _PipelineBuilder            = Factory.Resolve <IPipelineBuilder>();
            _PipelineBuilderEnvironment = Factory.Resolve <IPipelineBuilderEnvironment>();
            _WebApiMiddleware           = Factory.Resolve <IWebApiMiddleware>();

            _PipelineBuilder.RegisterCallback(UseSetupTestEnvironment, StandardPipelinePriority.Access - 1);
            _PipelineBuilder.RegisterCallback(UseWebApi, StandardPipelinePriority.WebApi);

            _Context = new OwinContext();
            _Context.RequestHeaders  = new HeadersDictionary();
            _Context.ResponseHeaders = new HeadersDictionary();

            _RequestStream        = new MemoryStream();
            _ResponseStream       = new MemoryStream();
            _Context.RequestBody  = _RequestStream;
            _Context.ResponseBody = _ResponseStream;

            _Context.CallCancelled         = new CancellationToken();
            _Context.Version               = "1.0.0";
            _Context.RequestHost           = "127.0.0.1:80";
            _Context.RequestProtocol       = Formatter.FormatHttpProtocol(HttpProtocol.Http1_1);
            _Context.RequestScheme         = Formatter.FormatHttpScheme(HttpScheme.Http);
            _Context.RequestPathBase       = "/VirtualRadar";
            _Context.ServerLocalIpAddress  = "1.2.3.4";
            _Context.ServerLocalPortNumber = 80;

            ExtraInitialise();

            _RamHost.Initialise(_PipelineBuilder, _PipelineBuilderEnvironment);
            _RamHost.Start();
        }
Exemplo n.º 7
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="environment"></param>
        /// <returns></returns>
        public IPipeline CreatePipeline(IPipelineBuilderEnvironment environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }
            environment.Properties[ApplicationStartupKey.Version] = Constants.Version;

            foreach (var callback in _Callbacks.OrderBy(r => r.Priority))
            {
                callback.Callback(environment);
            }

            var hostFinalCallback = environment.Properties[ApplicationStartupKey.HostFinalCallback] as Action;

            hostFinalCallback?.Invoke();

            var result = Factory.Resolve <IPipeline>();

            result.Construct(environment);

            return(result);
        }
Exemplo n.º 8
0
 /// <summary>
 /// The callback. Pass this wherever a configuration callback is required.
 /// </summary>
 /// <param name="buildEnvironment"></param>
 public void Callback(IPipelineBuilderEnvironment buildEnvironment)
 {
     ++CallCount;
     AllEnvironments.Add(buildEnvironment);
     Action?.Invoke(buildEnvironment);
 }
Exemplo n.º 9
0
 private void UseShimAppFuncBuilder(IPipelineBuilderEnvironment builderEnv)
 {
     _OldServerShim = new WebServerShim(this);
     builderEnv.UseMiddlewareBuilder(_OldServerShim.AppFuncBuilder);
 }
Exemplo n.º 10
0
        private void UseCorsHandler(IPipelineBuilderEnvironment builderEnv)
        {
            var handler = Factory.Resolve <ICorsHandler>();

            builderEnv.UseMiddlewareBuilder(handler.AppFuncBuilder);
        }
Exemplo n.º 11
0
        private void UseRedirectionFilter(IPipelineBuilderEnvironment builderEnv)
        {
            var filter = Factory.Resolve <IRedirectionFilter>();

            builderEnv.UseMiddlewareBuilder(filter.AppFuncBuilder);
        }
Exemplo n.º 12
0
 private void UseExceptionHandler(IPipelineBuilderEnvironment builderEnv)
 {
     builderEnv.UseExceptionLogger(new OwinExceptionLogger());
 }
Exemplo n.º 13
0
 private bool IsLoopbackHost(IPipelineBuilderEnvironment builderEnv)
 {
     builderEnv.Properties.TryGetValue(ApplicationStartupKey.HostType, out var host);
     return(host as string == "VRS.LoopbackHost");
 }
Exemplo n.º 14
0
        private void UseJavaScriptManipulator(IPipelineBuilderEnvironment builderEnv)
        {
            var manipulator = Factory.Resolve <IJavascriptManipulator>();

            builderEnv.UseStreamManipulatorBuilder(manipulator.AppFuncBuilder);
        }
Exemplo n.º 15
0
        private void UseAudioServer(IPipelineBuilderEnvironment builderEnv)
        {
            var server = Factory.Resolve <IAudioServer>();

            builderEnv.UseMiddlewareBuilder(server.AppFuncBuilder);
        }
Exemplo n.º 16
0
        private void UseBasicAuthenticationFilter(IPipelineBuilderEnvironment builderEnv)
        {
            var filter = Factory.Resolve <IBasicAuthenticationFilter>();

            builderEnv.UseMiddlewareBuilder(filter.AppFuncBuilder);
        }
Exemplo n.º 17
0
 public void TestInitialise()
 {
     _Environment = Factory.Resolve <IPipelineBuilderEnvironment>();
 }