Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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>();
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 12
0
        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...");
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        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));
        }
Exemplo n.º 18
0
        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));
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        /// <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);
        }
Exemplo n.º 23
0
        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));
        }
Exemplo n.º 24
0
 public static Dictionary <string, string> GetScopes(this ServiceParams serviceParams)
 {
     return(serviceParams["scopes"] as Dictionary <string, string>);
 }
Exemplo n.º 25
0
 public DefaultServicePool(ServiceParams serviceParams) : this(serviceParams.ConnectionParams, serviceParams.PoolParams)
 {
 }
Exemplo n.º 26
0
 protected internal CachingOrgService(ServiceParams parameters) : base(parameters)
 {
 }
Exemplo n.º 27
0
 public static async Task <IEnhancedOrgService> GetSelfBalancingService(ServiceParams serviceParameters,
                                                                        IReadOnlyCollection <ServiceParams> poolParameters, RouterRules rules = null)
 {
     return(await GetSelfBalancingService(serviceParameters, poolParameters.Select(GetPool).ToArray(), rules));
 }
Exemplo n.º 28
0
 public static string GetAudience(this ServiceParams serviceParams)
 {
     return(serviceParams["audience"].ToString());
 }
Exemplo n.º 29
0
 public DefaultEnhancedFactory(ServiceParams parameters) : base(parameters)
 {
 }
 protected internal EnhancedOrgService(ServiceParams parameters) : base(parameters)
 {
 }