private static ServiceParams BuildBaseParams(string connectionString, int?poolSize = null, PoolParams poolParams = null, ConnectionParams connectionParams = null, CachingParams cachingParams = null) { var parameters = new ServiceParams { ConnectionParams = connectionParams ?? new ConnectionParams { ConnectionString = connectionString }, PoolParams = poolParams ?? (poolSize == null ? null : new PoolParams { PoolSize = poolSize }) }; if (cachingParams != null) { parameters.IsCachingEnabled = true; parameters.CachingParams = cachingParams; } if (AutoSetMaxPerformanceParams) { parameters.AutoSetMaxPerformanceParams(); } return(parameters); }
public static async Task <IEnhancedOrgService> GetSelfBalancingService(ServiceParams parameters, IReadOnlyCollection <IServicePool <IOrganizationService> > pools, RouterRules rules = null) { parameters.Require(nameof(parameters)); pools.Require(nameof(pools)); if (AutoSetMaxPerformanceParams) { parameters.AutoSetMaxPerformanceParams(); } var routingService = new RoutingService <IOrganizationService>(); foreach (var pool in pools) { routingService.AddNode(pool); } if (rules != null) { routingService.DefineRules(rules); } await routingService.StartRouter(); var routingPool = new RoutingPool <IOrganizationService>(routingService); return(new EnhancedServiceFactory <IEnhancedOrgService, Services.Enhanced.EnhancedOrgService>(parameters) .CreateService(routingPool)); }
public static ServiceParams GetServiceParams(this IServiceProvider sp, IEnumerable <Type> assemblyTypes, IEnumerable <KeyValuePair <string, object> > extends = null) { var svcParams = new ServiceParams { { "assemblies", assemblyTypes.Append(typeof(ServiceCollectionExtensions)).GetAssembliesByTypes() } }; if (extends == null || !extends.Any()) { return(svcParams); } var conParams = svcParams.Concat(extends); // to avoid a side-effect then we don't manipulate directly ServiceParams in the input var result = new ServiceParams(); foreach (var param in conParams) { result.Add(param.Key, param.Value); } return(result); }
public void UpdateCart(ServiceParams taskParams) { Console.WriteLine($"[{DateTime.Now.ToString("hh:mm:ss.fff tt")}] {nameof(AccountService)}: {nameof(UpdateCart)}: Items are being added to Cart..."); taskParams.Count++; serviceCoordinator.Raise <CartUpdatedEvent>(taskParams).Wait(); Console.WriteLine($"[{DateTime.Now.ToString("hh:mm:ss.fff tt")}] {nameof(AccountService)}: {nameof(UpdateCart)}: Items added to cart..."); }
public void ConfigureServices(IServiceCollection services) { var assemblies = new HashSet <Assembly> { typeof(Startup).GetTypeInfo().Assembly, typeof(MiniServiceExtensions).GetTypeInfo().Assembly }; var claimToScopeMap = new Dictionary <string, string> { { "access_cart_api", "cart_api_scope" } }; var scopes = new Dictionary <string, string> { { "cart_api_scope", "Cart APIs" } }; var serviceParams = new ServiceParams { { "assemblies", assemblies }, { "audience", "api" }, { "claimToScopeMap", claimToScopeMap }, { "scopes", scopes } }; services.AddScoped(sp => serviceParams); services.AddEfCoreSqlServer(); services.AddScoped <NoTaxCaculator>(); services.AddScoped <TenPercentTaxCalculator>(); services.AddMiniService <CartDbContext>(); }
/// <summary> /// Event listener for the services controls /// </summary> /// <param name="service"></param> private void ListenServiceEvents(ServiceParams service) { Logger.Info("Recieved event to control service" + service.ServiceName, _type.FullName, "ListenServiceEvents"); ServiceControl serviceControl = new ServiceControl(); switch (service.CommandType) { case ServiceCommand.Start: serviceControl.StartService(service); break; case ServiceCommand.Stop: serviceControl.StopService(service); break; case ServiceCommand.Restart: serviceControl.RestartService(service); break; } //send the service status to update UI ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.ServiceName = service.ServiceName; serviceStatus.Status = serviceControl.ServiceStatus(service.ServiceName); EventSystem.Publish(serviceStatus); }
public async Task <ActionResult <IEnumerable <ServiceDto> > > GetServices([FromQuery] ServiceParams serviceParams) { var services = await _serviceRepository.GetServicesDtoAsync(serviceParams); Response.AddPaginationHeader(services.CurrentPage, services.PageSize, services.TotalCount, services.TotalPages); return(Ok(services)); }
/// <summary> /// Stop Oee Service /// </summary> public void StopOeeService() { ServiceParams service = new ServiceParams() { CommandType = ServiceCommand.Stop, ServiceName = "TradeHub OrderExecutionEngine Service" }; EventSystem.Publish <ServiceParams>(service); }
/// <summary> /// Stop Mde Service /// </summary> public void StopMdeService() { ServiceParams service = new ServiceParams() { CommandType = ServiceCommand.Stop, ServiceName = "TradeHub MarketDataEngine Service" }; EventSystem.Publish <ServiceParams>(service); }
public static Dictionary <string, string> GetClaims(this ServiceParams serviceParams) { if (serviceParams.TryGetValue("claimToScopeMap", out var claimToScopeMap)) { return(claimToScopeMap as Dictionary <string, string>); } throw new Exception("Couldn't parse and get [claimToScopeMap]."); }
/// <summary> /// Restart Pe Service /// </summary> public void RestartPeService() { ServiceParams service = new ServiceParams() { CommandType = ServiceCommand.Restart, ServiceName = "TradeHub PositionEngine Service" }; EventSystem.Publish <ServiceParams>(service); }
public async Task DeliverGoods(ServiceParams taskParams) { Console.WriteLine($"[{DateTime.Now.ToString("hh:mm:ss.fff tt")}] {nameof(InventoryService)}: {nameof(DeliverGoods)}: Delivery in progress..."); await Task.Delay(10000); taskParams.Count++; await serviceCoordinator.Raise <GoodsDeliveredEvent>(taskParams); Console.WriteLine($"[{DateTime.Now.ToString("hh:mm:ss.fff tt")}] {nameof(InventoryService)}: {nameof(DeliverGoods)}: Delivery completed..."); }
public async Task MakePayment(ServiceParams taskParams) { Console.WriteLine($"[{DateTime.Now.ToString("hh:mm:ss.fff tt")}] {nameof(PaymentService)}: {nameof(MakePayment)} payment in progress..."); await Task.Delay(10000); taskParams.Count++; await serviceCoordinator.Raise <PaymentReceivedEvent>(taskParams); Console.WriteLine($"[{DateTime.Now.ToString("hh:mm:ss.fff tt")}] {nameof(PaymentService)}: {nameof(MakePayment)} payment processed..."); }
public static IEnhancedServicePool <ICachingOrgService> GetCachingPool(ServiceParams serviceParams) { serviceParams.Require(nameof(serviceParams)); if (AutoSetMaxPerformanceParams) { serviceParams.AutoSetMaxPerformanceParams(); } var factory = new EnhancedServiceFactory <ICachingOrgService, CachingOrgService>(serviceParams); return(new EnhancedServicePool <ICachingOrgService, CachingOrgService>(factory, serviceParams.PoolParams)); }
/// <summary> /// Method to start all services status at the start up /// </summary> private void StartAllServices() { ServiceParams service = new ServiceParams() { ServiceName = "TradeHub MarketDataEngine Service", CommandType = ServiceCommand.Start }; EventSystem.Publish <ServiceParams>(service); service.ServiceName = "TradeHub OrderExecutionEngine Service"; EventSystem.Publish <ServiceParams>(service); service.ServiceName = "TradeHub PositionEngine Service"; EventSystem.Publish <ServiceParams>(service); }
public static ICachingOrgService GetCachingPoolingService(ServiceParams serviceParams) { serviceParams.Require(nameof(serviceParams)); if (AutoSetMaxPerformanceParams) { serviceParams.AutoSetMaxPerformanceParams(); } var pool = new DefaultServicePool(serviceParams); var factory = new EnhancedServiceFactory <ICachingOrgService, CachingOrgService>(serviceParams); return(factory.CreateService(pool)); }
public static IEnhancedOrgService GetPoolingService(ServiceParams serviceParams) { serviceParams.Require(nameof(serviceParams)); if (AutoSetMaxPerformanceParams) { serviceParams.AutoSetMaxPerformanceParams(); } var pool = new DefaultServicePool(serviceParams); var factory = new DefaultEnhancedFactory(serviceParams); return(factory.CreateService(pool)); }
public void ConfigureServices(IServiceCollection services) { var assemblies = new HashSet <Assembly> { typeof(Startup).GetTypeInfo().Assembly, typeof(MiniServiceExtensions).GetTypeInfo().Assembly }; var serviceParams = new ServiceParams { { "assemblies", assemblies } }; services.AddScoped(sp => serviceParams); services.AddEfCoreSqlServer(); services.AddMiniService <TodoDbContext>(); }
public async Task <IActionResult> GetUserSubscriptions([FromQuery] ServiceParams serviceParams) { var result = await subscriptionService.GetUserSubscriptions(await userManager.FindByNameAsync(User.Identity.Name), serviceParams); var metadata = new { result.TotalCount, result.PageSize, result.CurrentPage, result.TotalPages, result.HasNext, result.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(result)); }
public async Task <IActionResult> GetAllServices([FromQuery] ServiceParams serviceParams) { var result = await subscriptionService.GetServices(serviceParams); var metadata = new { result.TotalCount, result.PageSize, result.CurrentPage, result.TotalPages, result.HasNext, result.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(result)); }
public static ServiceParams ExtendServiceParams(this ServiceParams serviceParams, IEnumerable <KeyValuePair <string, object> > extends = null) { if (extends == null || !extends.Any()) { return(serviceParams); } var conParams = serviceParams.Concat(extends); // to avoid a side-effect then we don't manipulate directly ServiceParams in the input var result = new ServiceParams(); foreach (var param in conParams) { result.Add(param.Key, param.Value); } return(result); }
/// <summary> /// Close all services /// </summary> private void CloseAllServices() { ServiceControl serviceControl = new ServiceControl(); ServiceParams service = new ServiceParams() { CommandType = ServiceCommand.Stop, ServiceName = "TradeHub MarketDataEngine Service" }; serviceControl.StopService(service); service = new ServiceParams() { CommandType = ServiceCommand.Stop, ServiceName = "TradeHub OrderExecutionEngine Service" }; serviceControl.StopService(service); service = new ServiceParams() { CommandType = ServiceCommand.Stop, ServiceName = "TradeHub PositionEngine Service" }; serviceControl.StopService(service); }
public async Task <PagedList <ServiceDto> > GetServicesDtoAsync(ServiceParams serviceParams) { IQueryable <Service> services; if (!string.IsNullOrEmpty(serviceParams.Username)) { services = _context.Services.Include(s => s.AppUser).Where(s => s.AppUser.UserName.ToLower() == serviceParams.Username.ToLower()); } else { services = _context.Services; } services = serviceParams.OrderBy.ToLower() switch { "name" => services.OrderByDescending(s => s.Name), "description" => services.OrderByDescending(s => s.Description), _ => services.OrderByDescending(s => s.Name) }; return(await PagedList <ServiceDto> .CreateAsync(services.ProjectTo <ServiceDto>(_mapper.ConfigurationProvider).AsNoTracking(), serviceParams.PageNumber, serviceParams.PageSize)); }
public static Dictionary <string, string> GetScopes(this ServiceParams serviceParams) { return(serviceParams["scopes"] as Dictionary <string, string>); }
public DefaultServicePool(ServiceParams serviceParams) : this(serviceParams.ConnectionParams, serviceParams.PoolParams) { }
protected internal CachingOrgService(ServiceParams parameters) : base(parameters) { }
public static async Task <IEnhancedOrgService> GetSelfBalancingService(ServiceParams serviceParameters, IReadOnlyCollection <ServiceParams> poolParameters, RouterRules rules = null) { return(await GetSelfBalancingService(serviceParameters, poolParameters.Select(GetPool).ToArray(), rules)); }
public static string GetAudience(this ServiceParams serviceParams) { return(serviceParams["audience"].ToString()); }
public DefaultEnhancedFactory(ServiceParams parameters) : base(parameters) { }
protected internal EnhancedOrgService(ServiceParams parameters) : base(parameters) { }