예제 #1
0
        public static void StartService(string serviceHostName, string servicePort, string modulKassaBaseAddress,
                                        IEnumerable <CashBox> cashboxes)
        {
            _logger.Info("Запуск службы фискализации и печати кассовых чеков...");

            var parametersProvider = new ParametersProvider();

            var fiscalizationWorker = new FiscalizationWorker(
                new OrderRepository(),
                new SalesReceiptSender(modulKassaBaseAddress),
                new OrderParametersProvider(parametersProvider),
                cashboxes
                );

            fiscalizationWorker.Start();

            _logger.Info("Служба фискализации запущена");

            var salesReceiptsInstanceProvider = new SalesReceiptsInstanceProvider(
                new BaseParametersProvider(parametersProvider),
                new OrderRepository(),
                new OrderParametersProvider(parametersProvider)
                );
            WebServiceHost salesReceiptsHost = new SalesReceiptsServiceHost(salesReceiptsInstanceProvider);

            salesReceiptsHost.AddServiceEndpoint(
                typeof(ISalesReceiptsService),
                new WebHttpBinding(),
                $"http://{serviceHostName}:{servicePort}/SalesReceipts"
                );
            salesReceiptsHost.Open();
            _logger.Info("Запущена служба мониторинга отправки чеков");
        }
예제 #2
0
        public static void StartService(IConfig serviceConfig, IConfig kassaConfig, IConfig[] cashboxesConfig)
        {
            string          serviceHostName;
            string          servicePort;
            string          baseAddress;
            IList <CashBox> cashboxes;

            try {
                cashboxes = new List <CashBox>();
                foreach (var cashboxConfig in cashboxesConfig)
                {
                    cashboxes.Add(new CashBox {
                        Id          = cashboxConfig.GetInt("cash_box_id"),
                        RetailPoint = cashboxConfig.GetString("retail_point"),
                        UserName    = new Guid(cashboxConfig.GetString("user_name")),
                        Password    = cashboxConfig.GetString("password")
                    });
                }
                serviceHostName = serviceConfig.GetString("service_host_name");
                servicePort     = serviceConfig.GetString("service_port");

                baseAddress = kassaConfig.GetString("base_address");
            }
            catch (Exception ex) {
                logger.Fatal(ex, "Ошибка чтения конфигурационного файла.");
                return;
            }

            logger.Info("Запуск службы фискализации и печати кассовых чеков...");

            var fiscalizationWorker = new FiscalizationWorker(
                OrderSingletonRepository.GetInstance(),
                new SalesReceiptSender(baseAddress),
                new OrderParametersProvider(ParametersProvider.Instance),
                new OrganizationParametersProvider(ParametersProvider.Instance),
                cashboxes
                );

            fiscalizationWorker.Start();

            logger.Info("Служба фискализации запущена");

            var salesReceiptsInstanceProvider = new SalesReceiptsInstanceProvider(
                new BaseParametersProvider(),
                OrderSingletonRepository.GetInstance(),
                new OrderParametersProvider(ParametersProvider.Instance),
                new OrganizationParametersProvider(ParametersProvider.Instance)
                );
            WebServiceHost salesReceiptsHost = new SalesReceiptsServiceHost(salesReceiptsInstanceProvider);

            salesReceiptsHost.AddServiceEndpoint(
                typeof(ISalesReceiptsService),
                new WebHttpBinding(),
                $"http://{serviceHostName}:{servicePort}/SalesReceipts"
                );
            salesReceiptsHost.Open();
            logger.Info("Запущена служба мониторинга отправки чеков");
        }
        public static void StartService(IConfig serviceConfig, IConfig kassaConfig)
        {
            string serviceHostName;
            string servicePort;

            string baseAddress;
            string userNameForService;
            string pwdForService;

            try {
                serviceHostName = serviceConfig.GetString("service_host_name");
                servicePort     = serviceConfig.GetString("service_port");

                baseAddress        = kassaConfig.GetString("base_address");
                userNameForService = kassaConfig.GetString("user_name");
                pwdForService      = kassaConfig.GetString("password");
            }
            catch (Exception ex) {
                logger.Fatal(ex, "Ошибка чтения конфигурационного файла.");
                return;
            }
            var authentication = new AuthenticationHeaderValue(
                "Basic",
                Convert.ToBase64String(
                    Encoding.GetEncoding("ISO-8859-1")
                    .GetBytes(string.Format("{0}:{1}", userNameForService, pwdForService))
                    )
                );

            logger.Info("Запуск службы фискализации и печати кассовых чеков...");

            orderRoutineTimer          = new System.Timers.Timer(30000d);
            orderRoutineTimer.Elapsed += (sender, e) => {
                orderRoutineTimer.Interval = 120000d;                 //2 минуты
                if (DateTime.Now.Hour >= 1 && DateTime.Now.Hour < 5)
                {
                    var fiveHrsOfToday = DateTime.Today.AddHours(5);
                    orderRoutineTimer.Interval = fiveHrsOfToday.Subtract(DateTime.Now).TotalMilliseconds;                    //миллисекунд до 5 утра
                    logger.Info("Ночь. Не пытаемся отсылать чеки с 1 до 5 утра.");
                    return;
                }

                try {
                    Fiscalization.RunAsync(baseAddress, authentication).GetAwaiter().GetResult();
                }
                catch (Exception ex) {
                    logger.Error(ex, "Исключение при выполение фоновой задачи.");
                }
            };
            orderRoutineTimer.Start();
            logger.Info("Служба фискализации запущена");

            SalesReceiptsInstanceProvider salesReceiptsInstanceProvider = new SalesReceiptsInstanceProvider(
                new BaseParametersProvider(),
                OrderSingletonRepository.GetInstance()
                );
            WebServiceHost salesReceiptsHost = new SalesReceiptsServiceHost(salesReceiptsInstanceProvider);

            salesReceiptsHost.AddServiceEndpoint(
                typeof(ISalesReceiptsService),
                new WebHttpBinding(),
                String.Format("http://{0}:{1}/SalesReceipts", serviceHostName, servicePort)
                );
            salesReceiptsHost.Open();
            logger.Info("Запущена служба мониторинга отправки чеков");
        }