public DoNext Filter(ServiceArguments arguments) { string etag = null; arguments.Get <IRequestData>().ValuesFor(RequestDataSource.Header) .Value(HttpRequestHeaders.IfNoneMatch, value => etag = value.RawValue as string); if (etag == null) { return(DoNext.Continue); } var resourceHash = _hashing(arguments); var headers = _cache.Current(resourceHash); var currentEtag = headers.ValueFor(HttpResponseHeader.ETag); if (etag != currentEtag) { return(DoNext.Continue); } var writer = arguments.Get <IHttpWriter>(); writer.WriteResponseCode(HttpStatusCode.NotModified); headers.Each(x => x.Replay(writer)); return(DoNext.Stop); }
private void OnWindowsServiceStart(string[] args) { if (Arguments == null) { Arguments = new ServiceArguments(args); CurrentApplicationInfo.Init(ServiceName, Arguments.InstanceName, InfraVersion); } try { if (Arguments.ServiceStartupMode != ServiceStartupMode.WindowsService) { throw new InvalidOperationException($"Cannot start in {Arguments.ServiceStartupMode} mode when starting as a Windows service."); } if (Environment.UserInteractive == false) { throw new InvalidOperationException( "This Windows service requires to be run with 'user interactive' enabled to correctly read certificates. " + "Either the service wasn't configure with the 'Allow service to interact with desktop' option enabled " + "or the OS is ignoring the checkbox due to a registry settings. " + "Make sure both the checkbox is checked and following registry key is set to DWORD '0':\n" + @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\NoInteractiveServices"); } WindowsService.RequestAdditionalTime(60000); OnStart(); } catch { WindowsService.ExitCode = 1064; // "An exception occurred in the service when handling the control request." (net helpmsg 1064) throw; } }
public PartialFactory(BehaviorGraph graph, IBehaviorFactory factory, ServiceArguments arguments, ICurrentChain currentChain) { _graph = graph; _factory = factory; _arguments = arguments; _currentChain = currentChain; }
protected override void beforeEach() { graph = new BehaviorGraph(); Services.Inject(graph); args = new ServiceArguments(); Services.Inject(args); }
public NestedWindsorContainerBehavior(IWindsorContainer windsorContainer, ServiceArguments arguments, Guid behaviorId) { _windsorContainer = windsorContainer; _arguments = arguments; _behaviorId = behaviorId; }
public bool Invoke(Action invokeMvcPipeline, ActionDescriptor actionDescriptor, ControllerContext controllerContext) { //IMvcActionInvoker is httpcontext scoped var mvcActionInvoker = _mvcActionInvokerResolver(); mvcActionInvoker.Set(invokeMvcPipeline); var actionName = _actionNameProvider.GetName(actionDescriptor); //find uniqueId for behavior chain that corresponds to this action call var controllerType = controllerContext.Controller.GetType(); var parameterDescriptors = actionDescriptor.GetParameters(); var inputParameters = parameterDescriptors.ToDictionary(x => x.ParameterName, x => x.ParameterType); var uniqueId = _behaviorChainIdLookup.GetUniqueId(controllerType, actionName, inputParameters); //get the behavior chain and invoke it, using this instance of ControllerContext for it var arguments = new ServiceArguments(); //provide controller context to any behaviors that need to get at it arguments.Set(typeof(ControllerContext), controllerContext); using (var nestedContainer = _container.GetNestedContainer()) { var actionBehavior = nestedContainer.GetInstance<IActionBehavior>(arguments.ToExplicitArgs(), uniqueId.ToString()); actionBehavior.Invoke(); } return true; }
public async Task WorkloadMetricsCalledOnce() { var args = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, ConsoleOutputMode.Disabled, SiloClusterMode.PrimaryNode, DisposablePort.GetPort().Port, initTimeOutSec: 10); IWorkloadMetrics workloadMetricsFake = Substitute.For <IWorkloadMetrics>(); var srvHost = new ServiceHostFake <IWorkloadMetrics>( workloadMetricsFake, new HostEnvironment(new TestHostEnvironmentSource())) { FailServiceStartOnConfigError = false };; Task.Run(() => srvHost.Run(args)); await srvHost.WaitForServiceStartedAsync(); srvHost.Dispose(); workloadMetricsFake.Received(1).Init(); workloadMetricsFake.Received().Dispose(); }
public void Setup() { Metric.ShutdownContext("Workload"); Metric.ShutdownContext("Silo"); _serviceArguments = new ServiceArguments(); _dateTimeFake = new DateTimeFake { UtcNow = DateTime.UtcNow }; _kernel = new TestingKernel <ConsoleLog>(k => { k.Rebind <IHealthMonitor>().To <HealthMonitor>(); k.Rebind <ServiceArguments>().ToMethod(c => _serviceArguments); k.Rebind <IDateTime>().ToMethod(c => _dateTimeFake); }); _kernel.Get <Ninject.SystemInitializer.SystemInitializer>().Init(); _config = _kernel.Get <Func <WorkloadMetricsConfig> >()(); _config.ReadPerformanceCounters = true; _config.MinUnhealthyDuration = MinUnhealthyDuration; SetupOrleansQueueLength(); _workloadMetrics = _kernel.Get <IWorkloadMetrics>(); }
private void Initialize(ServiceArguments serviceArguments) { if (serviceArguments.BasePortOverride == null) { throw new ArgumentException("ServiceArguments.BasePortOverride should not be null."); } BasePort = serviceArguments.BasePortOverride.Value; Host = new TServiceHost(); _hostStopped = Task.Run(() => Host.Run(serviceArguments)); Task.WaitAny(_hostStopped, Host.WaitForServiceStartedAsync()); // Host is ready or failed to start if (_hostStopped.IsFaulted) { try { // Flatten aggregated exception _hostStopped.GetAwaiter().GetResult(); } catch (Exception e) { throw new Exception($"Host failed to start. The port: {BasePort}", e); } } else if (_hostStopped.IsCompleted) { throw new Exception($"Host failed to start. The port: {BasePort}"); } }
public async Task RunInConfigurationVerification_ShouldWriteResults() { var buffer = new StringBuilder(); var prOut = Console.Out; Console.SetOut(new StringWriter(buffer)); //ServiceStartupMode.VerifyConfigurations //ConsoleOutputMode.Standard var serviceArguments = new ServiceArguments(ServiceStartupMode.VerifyConfigurations, ConsoleOutputMode.Standard, SiloClusterMode.PrimaryNode, 8555); var config = new HostEnvironment( new TestHostEnvironmentSource( region: "us1", zone: "zone", deploymentEnvironment: "_Test", appName: "ICalculatorService")); var x = new CalculatorServiceHost(config); await Task.Run(() => x.Run(serviceArguments)); var canaryType = typeof(MetricsConfiguration); Console.SetOut(prOut); Regex.IsMatch(buffer.ToString(), $"(OK|ERROR).*{canaryType.FullName}") .ShouldBeTrue("Output should contain a row with validation of the type"); Console.WriteLine(buffer); }
public static Task RunAsync(this ServiceHostBase host, ServiceArguments arguments = null) { var stopTask = Task.Run(() => host.Run(arguments)); Task.WhenAny(stopTask, host.WaitForServiceStartedAsync()).GetAwaiter().GetResult().GetAwaiter().GetResult(); return(stopTask); }
public DoNext Filter(ServiceArguments arguments) { if (arguments.Has(typeof(Latch))) { return(DoNext.Stop); } var request = arguments.Get <IHttpRequest>(); if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding)) { return(DoNext.Continue); } var acceptEncoding = request .GetSingleHeader(HttpRequestHeaders.AcceptEncoding); var encoding = _encoders.MatchFor(acceptEncoding); var writer = arguments.Get <IHttpResponse>(); writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value); writer.UseEncoding(encoding); arguments.Set(typeof(Latch), new Latch()); return(DoNext.Continue); }
private TestingKernel <ConsoleLog> SetUpKernel(ServiceArguments serviceArguments, bool isSlotMode = true, bool withDefault = true, Func <HttpClientConfiguration, HttpMessageHandler> messageHandlerFactory = null) { var mockConfig = new Dictionary <string, string> { { "Discovery.PortAllocation.IsSlotMode", isSlotMode.ToString() }, }; if (withDefault) { mockConfig.Add($"Discovery.Services.{TestingKernel<ConsoleLog>.APPNAME}.DefaultSlotNumber", "1"); } return(new TestingKernel <ConsoleLog>( k => { k.Load <MicrodotHostingModule>(); k.Rebind <ServiceArguments>().ToConstant(serviceArguments); k.Rebind <IServiceInterfaceMapper>().ToConstant(new IdentityServiceInterfaceMapper(typeof(IDemoService))); k.Rebind <Func <HttpClientConfiguration, HttpMessageHandler> >().ToMethod(c => messageHandlerFactory ?? (_ => new MockHttpMessageHandler())); }, mockConfig)); }
public void Start(ServiceArguments serviceArguments, Func <IGrainFactory, Task> afterOrleansStartup = null) { AfterOrleansStartup = afterOrleansStartup; _serviceArguments = serviceArguments; Log.Info(_ => _("Build Bridges, Not Silos!")); Log.Info(_ => _("Starting Orleans silo...")); var builder = _orleansConfigurationBuilder.GetBuilder() .UseServiceProviderFactory(o => { _serviceProvider.ConfigureServices(o); return(_factoryServiceProvider()); }) .ConfigureLogging(op => op.AddProvider(_logProvider)) .AddStartupTask(StartupTask); if (_orleansConfig.EnableInterceptor) { builder.AddIncomingGrainCallFilter <MicrodotIncomingGrainCallFilter>() .AddOutgoingGrainCallFilter(async o => { TracingContext.SpanStartTime = DateTimeOffset.UtcNow; await o.Invoke(); }); } _siloHost = builder.Build(); try { int cancelAfter = _serviceArguments.InitTimeOutSec ?? 60; var cancel = new CancellationTokenSource(TimeSpan.FromSeconds(cancelAfter)).Token; var forceCancel = new CancellationTokenSource(TimeSpan.FromSeconds(cancelAfter + 10)).Token; _siloHost.StartAsync(cancel).Wait(forceCancel); } catch (Exception e) { throw new ProgrammaticException("Failed to start Orleans silo", unencrypted: new Tags { { "siloName", CurrentApplicationInfo.HostName } }, innerException: e); } if (_startupTaskExceptions != null) { throw new ProgrammaticException("Failed to start Orleans silo due to an exception thrown in the bootstrap method.", unencrypted: new Tags { { "siloName", CurrentApplicationInfo.HostName } }, innerException: _startupTaskExceptions); } Log.Info(_ => _("Successfully started Orleans silo", unencryptedTags: new { siloName = CurrentApplicationInfo.HostName })); _orleansConfigurator.AfterOrleansStartup(_siloHost.Services.GetService <IGrainFactory>()); Log.Info(_ => _("afterOrleansStartup done", unencryptedTags: new { siloName = CurrentApplicationInfo.HostName })); HttpServiceListener.StartGettingTraffic(); Log.Info(_ => _("start getting traffic", unencryptedTags: new { siloName = CurrentApplicationInfo.HostName })); }
protected override void PreConfigure(IKernel kernel, ServiceArguments Arguments) { var env = new HostEnvironment(new TestHostEnvironmentSource(appName: ServiceName)); kernel.Rebind <IEnvironment>().ToConstant(env).InSingletonScope(); kernel.Rebind <CurrentApplicationInfo>().ToConstant(env.ApplicationInfo).InSingletonScope(); base.PreConfigure(kernel, Arguments); }
public static void WithRepository(this ITransaction transaction, Guid tenantId, Action <IEntityRepository> action) { var arguments = new ServiceArguments().With <ITenantContext>(new SimpleTenantContext { CurrentTenant = tenantId }); transaction.Execute(arguments, action); }
public void Invoke(ServiceArguments arguments) { var completion = new RequestCompletion(); completion.SafeStart(() => { Invoke(arguments, new Dictionary<string, object>(), completion); }); }
public void Invoke(ServiceArguments arguments) { var completion = new RequestCompletion(); completion.SafeStart(() => { Invoke(arguments, new Dictionary <string, object>(), completion); }); }
public void set_should_add_plugin() { var args = new ServiceArguments(); var plugin = new Plugin(); args.Has(typeof(Plugin)).ShouldBeFalse(); args.Set(typeof(Plugin), plugin); args.Has(typeof(Plugin)).ShouldBeTrue(); }
public static ExplicitArguments ToExplicitArgs(this ServiceArguments arguments) { var explicits = new ExplicitArguments(); arguments.EachService((type, o) => explicits.Set(type, o)); return(explicits); }
public IHttpHandler GetHttpHandler(RequestContext requestContext) { var dictionary = new AggregateDictionary(requestContext); ServiceArguments arguments = new ServiceArguments().With(dictionary); IActionBehavior behavior = GetBehavior(arguments); return(new FubuHttpHandler(behavior)); }
public NonOrleansServiceTester() { var args = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, ConsoleOutputMode.Disabled, SiloClusterMode.PrimaryNode, _port.Port, initTimeOutSec: 10); Initialize(args); }
public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId) { Arguments = arguments.ShouldBeOfType <FubuTransportation.Runtime.Invocation.InvocationContext>(); _cascadingMessages.Each(x => Arguments.EnqueueCascading(x)); _chain.UniqueId.ShouldEqual(behaviorId); return(_behavior); }
public IHttpHandler GetHttpHandler(RequestContext requestContext) { var dictionary = new AggregateDictionary(requestContext); ServiceArguments arguments = new ServiceArguments().With(dictionary); IActionBehavior behavior = GetBehavior(arguments); return new FubuHttpHandler(behavior); }
public void ServiceArguments() { var args = new ServiceArguments(new[] { "--SlotNumber:5" }); args.SlotNumber.Should().Be(5); args = new ServiceArguments(slotNumber: 5); args.SlotNumber.Should().Be(5); }
public override void Execute <T>(ServiceArguments arguments, Action <T> action) { using (var nested = _container.GetNestedContainer()) { var explicits = new ExplicitArguments(); arguments.EachService(explicits.Set); action(nested.GetInstance <T>(explicits)); } }
public void build_by_explicit_arguments() { var hulk = new TheHulk(); var thor = new Thor(); var args = new ServiceArguments().With(hulk).With(thor); var thing = facility.Build <ContainerThing>(args); thing.Hulk.ShouldBeTheSameAs(hulk); thing.Thor.ShouldBeTheSameAs(thor); }
protected override void PreConfigure(IKernel kernel, ServiceArguments Arguments) { kernel.Rebind <IEnvironment>().ToConstant(environment).InSingletonScope(); kernel.Rebind <CurrentApplicationInfo>().ToConstant(environment.ApplicationInfo).InSingletonScope(); base.PreConfigure(kernel, Arguments); kernel.Rebind <TFake>().ToConstant(_fake); kernel.Rebind <IEventPublisher <CrashEvent> >().ToConstant(Substitute.For <IEventPublisher <CrashEvent> >()); kernel.Rebind <ICertificateLocator>().To <DummyCertificateLocator>().InSingletonScope(); kernel.Rebind <IMetricsInitializer>().ToConstant(Substitute.For <IMetricsInitializer>()); }
public ConfigurationResponseBuilder(ConfigCache configCache, IEnvironmentVariableProvider envs, IAssemblyProvider assemblyProvider, UsageTracking usageTracking, ServiceArguments serviceArguments) { UsageTracking = usageTracking; ServiceArguments = serviceArguments; ConfigCache = configCache; Envs = envs; AssemblyProvider = assemblyProvider; }
protected override void PreConfigure(IKernel kernel, ServiceArguments Arguments) { var env = environment ?? new HostEnvironment(new TestHostEnvironmentSource( zone: "zone", deploymentEnvironment: "env", appName: "ICalculatorService")); kernel.Rebind <IEnvironment>().ToConstant(env).InSingletonScope(); kernel.Rebind <CurrentApplicationInfo>().ToConstant(env.ApplicationInfo).InSingletonScope(); base.PreConfigure(kernel, Arguments); }
public override void Execute <T>(ServiceArguments arguments, Action <T> action) { using (IContainer nested = _container.GetNestedContainer()) { nested.Apply(arguments); var service = nested.GetInstance <T>(); action(service); nested.GetInstance <ISessionBoundary>().SaveChanges(); } }
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { Controller result = null; if (controllerType != null) { var arguments = new ServiceArguments(); arguments.Set(typeof (ControllerContext), null); result = (Controller) _container.GetInstance(controllerType, arguments.ToExplicitArgs()); result.ActionInvoker = _container.GetInstance<IActionInvoker>(); } return result; }
public ServiceTester(ServiceArguments serviceArguments = null, Type customSerializer = null) { _customSerializer = customSerializer; ServiceArguments = serviceArguments ?? new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, ConsoleOutputMode.Disabled, SiloClusterMode.PrimaryNode, _port.Port, initTimeOutSec: 15); Initialize(); }
protected override void PreConfigure(IKernel kernel, ServiceArguments Arguments) { var env = new HostEnvironment(new TestHostEnvironmentSource()); kernel.Rebind <IEnvironment>().ToConstant(env).InSingletonScope(); kernel.Rebind <CurrentApplicationInfo>().ToConstant(env.ApplicationInfo).InSingletonScope(); base.PreConfigure(kernel, Arguments); Console.WriteLine($"-----------------------------Silo is RebindForTests"); kernel.Rebind <ServiceValidator>().To <CalculatorServiceHost.MockServiceValidator>().InSingletonScope(); kernel.RebindForTests(); }
/// <summary> /// Used to configure Kernel in abstract base-classes, which should apply to any concrete service that inherits from it. /// Should be overridden when creating a base-class that should include common behaviour for a family of services, without /// worrying about concrete service authors forgetting to call base.Configure(). Nevertheless, when overriding this method, /// you should always call base.PreConfigure(), and if all inheritors of the class are concrete services, you should also /// mark this method as sealed to prevent confusion with Configure(). /// </summary> /// <param name="kernel">Kernel that should contain bindings for the service.</param> protected virtual void PreConfigure(IKernel kernel, ServiceArguments Arguments) { kernel.Rebind <IActivator>().To <InstanceBasedActivator <TInterface> >().InSingletonScope(); kernel.Rebind <IServiceInterfaceMapper>().To <IdentityServiceInterfaceMapper>().InSingletonScope().WithConstructorArgument(typeof(TInterface)); kernel.Load <MicrodotModule>(); kernel.Load <MicrodotHostingModule>(); kernel.Bind <IRequestListener>().To <HttpServiceListener>(); GetLoggingModule().Bind(kernel.Rebind <ILog>(), kernel.Rebind <IEventPublisher>(), kernel.Rebind <Func <string, ILog> >()); kernel.Rebind <ServiceArguments>().ToConstant(Arguments).InSingletonScope(); }
public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId) { var diagnostics = _container.Get<DiagnosticBehavior>(); var writer = _container.Get<IOutputWriter>(); var report = _container.Get<IDebugReport>(); arguments.Set(typeof(IOutputWriter), new RecordingOutputWriter(report, writer)); var behavior = _inner.BuildBehavior(arguments, behaviorId); diagnostics.Inner = behavior; return diagnostics; }
public ICompilationContext Compile(ICommandContext context, ServiceArguments arguments, Guid behaviorId) { _container.EjectAllInstancesOf<ICommandContext>(); var container = _container.GetNestedContainer(); var command = new StructureMapContainerCommand(container, arguments, behaviorId); var compilationContext = new StructureMapCompilationContext(container, command); context.Set<ICompilationContext>(compilationContext); container.Configure(x => x.For<ICommandContext>().Use(context)); return compilationContext; }
public void Invoke(ServiceArguments arguments, IDictionary<string, object> routeValues) { var currentChain = new CurrentChain(_chain, routeValues); arguments.Set(typeof(ICurrentChain), currentChain); if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop)) { return; } var behavior = _factory.BuildBehavior(arguments, _chain.UniqueId); Invoke(behavior); }
public DoNext Filter(ServiceArguments arguments) { string etag = null; arguments.Get<AggregateDictionary>().Value(RequestDataSource.Header.ToString(), HttpRequestHeaders.IfNoneMatch, (key, value) => etag = (string) value); if (etag == null) return DoNext.Continue; var resourceHash = arguments.Get<ICurrentChain>().ResourceHash(); var currentEtag = _cache.Current(resourceHash); if (etag != currentEtag) return DoNext.Continue; arguments.Get<IHttpWriter>().WriteResponseCode(HttpStatusCode.NotModified); return DoNext.Stop; }
public DoNext Filter(ServiceArguments arguments) { arguments .Get<IRequestData>() .ValuesFor(RequestDataSource.Header) .Value(HttpRequestHeaders.AcceptEncoding, x => { var encoding = _encoders.MatchFor(x.RawValue as string); var writer = arguments.Get<IHttpWriter>(); writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value); writer.UseEncoding(encoding); }); return DoNext.Continue; }
public void can_inject_arguments_into_the_behavior_factory() { var standInCurrentHttpRequest = new StandInCurrentHttpRequest(); var inMemoryFubuRequest = new InMemoryFubuRequest(); var arguments = new ServiceArguments() .With<ICurrentHttpRequest>(standInCurrentHttpRequest) .With<IFubuRequest>(inMemoryFubuRequest); var behavior = ContainerFacilitySource .BuildBehavior(arguments, ObjectDef.ForType<GuyWhoNeedsRequest>(), x => { }) .As<GuyWhoNeedsRequest>(); behavior.Http.ShouldBeTheSameAs(standInCurrentHttpRequest); behavior.Request.ShouldBeTheSameAs(inMemoryFubuRequest); }
public DoNext Filter(ServiceArguments arguments) { string etag = null; arguments.Get<IRequestData>().ValuesFor(RequestDataSource.Header) .Value(HttpRequestHeaders.IfNoneMatch, value => etag = value.RawValue as string); if (etag == null) return DoNext.Continue; var resourceHash = arguments.Get<ICurrentChain>().ResourceHash(); var currentEtag = _cache.Current(resourceHash); if (etag != currentEtag) return DoNext.Continue; arguments.Get<IHttpWriter>().WriteResponseCode(HttpStatusCode.NotModified); return DoNext.Stop; }
public void SetUp() { theFactory = MockRepository.GenerateMock<IServiceFactory>(); theChain = new BehaviorChain() { Route = new RouteDefinition("something") }; theRouteData = new Dictionary<string, object>(); theArguments = new ServiceArguments(); theBehavior = MockRepository.GenerateMock<IActionBehavior>(); theFactory.Stub(x => x.BuildBehavior(theArguments, theChain.UniqueId)) .Return(theBehavior); theInvoker = new AsyncBehaviorInvoker(theFactory, theChain); }
public static IActionBehavior BuildBehavior(ServiceArguments arguments, ObjectDef behaviorDef, Action<IContainerFacility> configuration) { var id = Guid.NewGuid(); behaviorDef.Name = id.ToString(); var facility = New( x => { configuration(x); x.Register(typeof(IActionBehavior), behaviorDef); }); var behavior = facility.BuildBehavior(arguments, id); // StartInnerBehavior() is not part of the core interface, but I had to have something to get at the real top level // behavior within the context of an Autofac nested container. return behavior.As<NestedAutofacContainerBehavior>().StartInnerBehavior(); }
public void Invoke(ServiceArguments arguments, IDictionary<string, object> routeValues, IRequestCompletion requestCompletion) { var currentChain = new CurrentChain(_chain, routeValues); arguments.Set(typeof(ICurrentChain), currentChain); arguments.Set(typeof(IRequestCompletion), requestCompletion); if (arguments.Has(typeof (IChainExecutionLog))) { arguments.Get<IChainExecutionLog>().RootChain = _chain; } if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop)) { return; } IActionBehavior behavior = null; if (arguments.Has(typeof (IChainExecutionLog))) { arguments.Get<IChainExecutionLog>().Trace("Building the Behaviors", () => { behavior = _factory.BuildBehavior(arguments, _chain.UniqueId); }); } else { behavior = _factory.BuildBehavior(arguments, _chain.UniqueId); } requestCompletion.WhenCompleteDo(x => { var disposable = behavior as IDisposable; if (disposable != null) { disposable.Dispose(); } }); behavior.Invoke(); }
public DoNext Filter(ServiceArguments arguments) { if (arguments.Has(typeof(Latch))) return DoNext.Stop; arguments .Get<IRequestData>() .ValuesFor(RequestDataSource.Header) .Value(HttpRequestHeaders.AcceptEncoding, x => { var encoding = _encoders.MatchFor(x.RawValue as string); var writer = arguments.Get<IHttpResponse>(); writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value); writer.UseEncoding(encoding); }); arguments.Set(typeof(Latch), new Latch()); return DoNext.Continue; }
public void Invoke(ServiceArguments arguments, IDictionary<string, object> routeValues, IRequestCompletion requestCompletion) { var currentChain = new CurrentChain(_chain, routeValues); arguments.Set(typeof(ICurrentChain), currentChain); arguments.Set(typeof(IRequestCompletion), requestCompletion); if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop)) { return; } var behavior = _factory.BuildBehavior(arguments, _chain.UniqueId); requestCompletion.WhenCompleteDo(x => { var disposable = behavior as IDisposable; if (disposable != null) { disposable.Dispose(); } }); behavior.Invoke(); }
public DoNext Filter(ServiceArguments arguments) { if (arguments.Has(typeof (Latch))) return DoNext.Stop; var request = arguments.Get<IHttpRequest>(); if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding)) return DoNext.Continue; var acceptEncoding = request .GetSingleHeader(HttpRequestHeaders.AcceptEncoding); var encoding = _encoders.MatchFor(acceptEncoding); var writer = arguments.Get<IHttpResponse>(); writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value); writer.UseEncoding(encoding); arguments.Set(typeof (Latch), new Latch()); return DoNext.Continue; }
public DoNext Filter(ServiceArguments arguments) { string etag = null; arguments.Get<IRequestData>().ValuesFor(RequestDataSource.Header) .Value(HttpRequestHeaders.IfNoneMatch, value => etag = value.RawValue as string); if (etag == null) return DoNext.Continue; var resourceHash = _hashing(arguments); var headers = _cache.Current(resourceHash); var currentEtag = headers.ValueFor(HttpResponseHeader.ETag); if (etag != currentEtag) return DoNext.Continue; var writer = arguments.Get<IHttpWriter>(); writer.WriteResponseCode(HttpStatusCode.NotModified); headers.Each(x => x.Replay(writer)); return DoNext.Stop; }
public DoNext Filter(ServiceArguments arguments) { string etag = null; var request = arguments.Get<ICurrentHttpRequest>(); if (!request.HasHeader(HttpRequestHeader.IfNoneMatch)) return DoNext.Continue; etag = request.GetHeader(HttpRequestHeader.IfNoneMatch).FirstOrDefault(); if (etag.IsEmpty()) return DoNext.Continue; var resourceHash = _hashing(arguments); var headers = _cache.Current(resourceHash); var currentEtag = headers.ValueFor(HttpResponseHeader.ETag); if (etag != currentEtag) return DoNext.Continue; var writer = arguments.Get<IHttpWriter>(); writer.WriteResponseCode(HttpStatusCode.NotModified); headers.Each(x => x.Replay(writer)); return DoNext.Stop; }
public NestedStructureMapContainerBehavior(IContainer container, ServiceArguments arguments, Guid behaviorId) { _container = container; _arguments = arguments.ToExplicitArgs(); _behaviorId = behaviorId; }
public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId) { return _behaviorIds.Contains(behaviorId) ? new ActionBehavior(behaviorId) : null; }
public virtual IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId) { return new NestedStructureMapContainerBehavior(_container, arguments, behaviorId); }
public SessionlessAsynchronousHttpHandler(IBehaviorInvoker invoker, ServiceArguments arguments, IDictionary<string, object> routeData) { _invoker = invoker; _arguments = arguments; _routeData = routeData; }
public PartialFactory(BehaviorGraph graph, IBehaviorFactory factory, ServiceArguments arguments) { _graph = graph; _factory = factory; _arguments = arguments; }
public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId) { return Builder(_container, arguments, behaviorId); }
public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId) { return _container.GetInstance<IActionBehavior>(arguments.ToExplicitArgs(), behaviorId.ToString()); }
public static void Apply(this IContainer container, ServiceArguments arguments) { arguments.EachService(container.Inject); }