public async Task GivenAutofacOnlyRegistration_WithResolveOptional_ShouldPass() { var builder = new ContainerBuilder(); builder.RegisterType <StringCache>().As <ICache>(); ILifetimeScope container = builder.Build(); IWorkContext context = new WorkContextBuilder() .Set(new ServiceProviderProxy(x => container.Resolve <ICache>(), x => container.ResolveOptional <ICache>())) .Build(); IActorManager?manager = new ActorConfigurationBuilder() .Set(context) .Build() .ToActorManager(); using (container.BeginLifetimeScope()) { ActorKey key = new ActorKey("cache/test"); ICache cache = await manager.CreateProxy <ICache>(key); (await cache.GetCount()).Should().Be(1); await manager.Deactivate <ICache>(key); (await cache.GetCount()).Should().Be(2); } await manager.DeactivateAll(); }
public async Task Invoke(HttpContext context) { //Do not process for exist exception var exceptionFeature = context.Features.Get <IExceptionHandlerFeature>(); if (exceptionFeature != null) { await _next(context); return; } var builder = new WorkContextBuilder(context, _options); var workContext = builder.WorkContext; workContext.ApplicationSettings = _applicationSettings; //The important to preserve the order of initialization await builder.WithCountriesAsync(); await builder.WithStoresAsync(_options.DefaultStore); await builder.WithCurrentUserAsync(); await builder.WithCurrenciesAsync(workContext.CurrentLanguage, workContext.CurrentStore); await builder.WithCatalogsAsync(); await builder.WithDefaultShoppingCartAsync("default", workContext.CurrentStore, workContext.CurrentUser, workContext.CurrentCurrency, workContext.CurrentLanguage); await builder.WithMenuLinksAsync(workContext.CurrentStore, workContext.CurrentLanguage); await builder.WithPagesAsync(workContext.CurrentStore, workContext.CurrentLanguage); await builder.WithBlogsAsync(workContext.CurrentStore, workContext.CurrentLanguage); await builder.WithPricelistsAsync(); if (workContext.CurrentStore.QuotesEnabled) { await builder.WithQuotesAsync(workContext.CurrentStore, workContext.CurrentUser, workContext.CurrentCurrency, workContext.CurrentLanguage); await builder.WithUserQuotesAsync(); } await builder.WithUserOrdersAsync(); await builder.WithUserSubscriptionsAsync(); await builder.WithVendorsAsync(workContext.CurrentStore, workContext.CurrentLanguage); await builder.WithFulfillmentCentersAsync(); workContext.AvailableRoles = SecurityConstants.Roles.AllRoles; _workContextAccessor.WorkContext = workContext; await _next(context); }
private async Task <int> Run(string[] args) { Console.WriteLine(_programTitle); Console.WriteLine(); IOption option = Option.Build(args); if (option.Help) { option.FormatHelp() .ForEach(x => Console.WriteLine(x)); return(_ok); } CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); using (ILifetimeScope container = CreateContainer(option).BeginLifetimeScope(_lifetimeScopeTag)) { ITelemetry logger = container.Resolve <ITelemetry>(); IWorkContext context = new WorkContextBuilder() .Set(cancellationTokenSource.Token) .Set(logger) .Set(new ServiceProviderProxySimple(x => container.Resolve(x))) .Build(); option .FormatSettings() .ForEach(x => context.Telemetry.Info(context, x)); List <Task> runningTasks = new IAction?[] { option.Send?container.Resolve <SendEvents>() : null, option.Receive ? container.Resolve <ReceiveEvents>() : null, } .Where(x => x != null) .Select(x => Task.Run(() => x !.Run(context))) .ToList(); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; cancellationTokenSource.Cancel(); Console.WriteLine("Canceling..."); }; Console.WriteLine("Hit Ctrl C to quite"); Console.WriteLine(); await Task.WhenAll(runningTasks); return(_ok); } }
private async Task <int> Run(string[] args) { Console.WriteLine(_programTitle); Console.WriteLine(); IOption option = Option.Build(args); if (option.Help) { option.FormatHelp() .ForEach(x => Console.WriteLine(option.SecretManager.Mask(x))); return(_ok); } CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); using (ILifetimeScope container = CreateContainer(option).BeginLifetimeScope(_lifetimeScopeTag)) { ITelemetry logger = container.Resolve <ITelemetry>(); IWorkContext context = new WorkContextBuilder() .Set(cancellationTokenSource.Token) .Set(logger) .Set(new ServiceProviderProxySimple(x => container.Resolve(x))) .Build(); option .FormatSettings() .ForEach(x => context.Telemetry.Info(context, x)); Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => { e.Cancel = true; cancellationTokenSource.Cancel(); Console.WriteLine("Canceling..."); }; Console.WriteLine("Hit Ctrl C to quit"); Console.WriteLine(); IExecutionContext executionContext = new ExecutionContext(); await new IAction[] { container.Resolve <LoadAssemblyAction>(), } .ForEachAsync(x => x.Run(context, executionContext)); return(_ok); } }
public async Task Invoke(HttpContext httpContext) { IWorkContext workContext = httpContext.Items.Get <IWorkContext>() ?? WorkContext.Empty; var builder = new WorkContextBuilder(workContext); builder.SetContainer(_serviceConfiguration.Container); foreach (var item in httpContext.Request.Headers) { var property = _headerFactory.Create(item.Key, item.Value); if (property != null) { builder.Properties.Set(property, derivedType: property.GetType()); } } // Correlation Vector var headerCv = builder.Properties.Get <CvHeader>(); if (headerCv != null) { builder.Cv = new CorrelationVector(headerCv.Value); } workContext = builder.Build(); Uri url = new Uri(httpContext.Request.GetEncodedUrl()); var requestContext = new RequestContext(workContext, httpContext.Request.Method, url); httpContext.Items.Set(requestContext); using (var scope = new TimerScope( () => _webLogEvent.HttpRequestStart(workContext, requestContext), (x) => _webLogEvent.HttpRequestStop(workContext, requestContext, x))) { await _next.Invoke(httpContext); if (httpContext?.Response?.StatusCode != null) { AspMvcEventSource.Log.Verbose(workContext, $"REST response result: {httpContext.Response.StatusCode}"); } } }
public void TestDimensionsTest() { IWorkContext wrk = new WorkContextBuilder() { Dimensions = new EventDimensionsBuilder() .Add("Key1", "Value1") .Add("Key2", "Value2") .Build(), }.Build(); wrk.Dimensions.Count.Should().Be(2); wrk.Dimensions["Key1"].Should().Be("Value1"); wrk.Dimensions["Key2"].Should().Be("Value2"); var dim = new EventDimensionsBuilder() .Add("Key3", "Value3") .Add("Key4", "Value4") .Build(); wrk.Dimensions.Count.Should().Be(2); dim["Key3"].Should().Be("Value3"); dim["Key4"].Should().Be("Value4"); wrk = wrk.With(dim); wrk.Dimensions.Count.Should().Be(4); wrk.Dimensions["Key1"].Should().Be("Value1"); wrk.Dimensions["Key2"].Should().Be("Value2"); wrk.Dimensions["Key3"].Should().Be("Value3"); wrk.Dimensions["Key4"].Should().Be("Value4"); var dim2 = new EventDimensionsBuilder() .Add("Key3", "Value33") .Add("Key4", "Value44") .Build(); wrk = wrk.With(dim2); wrk.Dimensions.Count.Should().Be(4); wrk.Dimensions["Key1"].Should().Be("Value1"); wrk.Dimensions["Key2"].Should().Be("Value2"); wrk.Dimensions["Key3"].Should().Be("Value33"); wrk.Dimensions["Key4"].Should().Be("Value44"); }
public async Task Invoke(HttpContext context) { //Do not process for exist exception var exceptionFeature = context.Features.Get <IExceptionHandlerFeature>(); if (exceptionFeature != null) { await _next(context); return; } var builder = new WorkContextBuilder(context, _options); var workContext = builder.WorkContext; workContext.IsDevelopment = _hostingEnvironment.IsDevelopment(); workContext.ApplicationSettings = _applicationSettings; //The important to preserve the order of initialization await builder.WithCountriesAsync(); await builder.WithStoresAsync(_options.DefaultStore); await builder.WithCurrentUserAsync(); await builder.WithCurrenciesAsync(workContext.CurrentLanguage, workContext.CurrentStore); await builder.WithCatalogsAsync(); await builder.WithDefaultShoppingCartAsync("default", workContext.CurrentStore, workContext.CurrentUser, workContext.CurrentCurrency, workContext.CurrentLanguage); await builder.WithMenuLinksAsync(workContext.CurrentStore, workContext.CurrentLanguage); await builder.WithPagesAsync(workContext.CurrentStore, workContext.CurrentLanguage); await builder.WithBlogsAsync(workContext.CurrentStore, workContext.CurrentLanguage); await builder.WithPricelistsAsync(); if (workContext.CurrentStore.QuotesEnabled) { await builder.WithQuotesAsync(workContext.CurrentStore, workContext.CurrentUser, workContext.CurrentCurrency, workContext.CurrentLanguage); await builder.WithUserQuotesAsync(); } await builder.WithUserOrdersAsync(); if (workContext.CurrentStore.SubscriptionEnabled) { await builder.WithUserSubscriptionsAsync(); } await builder.WithVendorsAsync(workContext.CurrentStore, workContext.CurrentLanguage); await builder.WithFulfillmentCentersAsync(); //EU General Data Protection Regulation (GDPR) support var consentFeature = context.Features.Get <ITrackingConsentFeature>(); if (consentFeature != null) { workContext.CanTrack = !consentFeature?.CanTrack ?? false; workContext.ConsentCookie = consentFeature?.CreateConsentCookie(); } workContext.AvailableRoles = SecurityConstants.Roles.AllRoles; workContext.BusinessToBusinessRoles = SecurityConstants.Roles.B2BRoles; _workContextAccessor.WorkContext = workContext; await _next(context); }