Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine();

            //Check if argument was provided
            if (args.Length == 0 || string.IsNullOrWhiteSpace(args[0]))
            {
                Console.WriteLine("You must run with the following program arguments:");
                Console.WriteLine("1) '<Path_to_orders_file>': path to the file to be processed");
                Console.WriteLine();
                Console.WriteLine("Examples:");
                Console.WriteLine("1) To run from source code: 'dotnet run orders.csv'");
                Console.WriteLine("2) To run from dll........: 'dotnet OrderBatch.dll orders.csv'");
            }
            else
            {
                try
                {
                    //Check argument and get file content
                    var fileHelper = new FileHelper(args[0]);

                    //Get file content and convert to list of commissions
                    var commissions = fileHelper.GetCommissions();

                    //Write to console the commission total grouped by boutique
                    CommissionHelper.GetCommissionsByBoutique(commissions).ForEach(e => Console.WriteLine(e));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Process aborted");
                    Console.WriteLine($"Error: {e.Message}");
                }
            }
        }
Esempio n. 2
0
        public static void Start()
        {
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();

            scheduler.Start();

            IJobDetail diretionToPayJob = JobBuilder.Create <DirectionToPayJob>().Build();
            ITrigger   trigger          = TriggerBuilder.Create()
                                          .WithDailyTimeIntervalSchedule
                                              (s =>
                                              s.WithIntervalInHours(24)
                                              .OnEveryDay()
                                              .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(3, 0))
                                              )
                                          .Build();

            // for test

            /*ITrigger trigger1 = TriggerBuilder.Create()
             *  .WithIdentity("trigger1", "group1")
             *  .StartNow()
             *  .WithSimpleSchedule(x => x
             *      .WithIntervalInSeconds(30)
             *      .RepeatForever())
             *  .Build();
             */
            scheduler.ScheduleJob(diretionToPayJob, trigger);

            IJobDetail coommissionNotificationJob     = JobBuilder.Create <CommissionNotificationJob>().Build();
            ITrigger   coommissionNotificationTrigger = TriggerBuilder.Create()
                                                        .WithDailyTimeIntervalSchedule
                                                            (s =>
                                                            s.WithIntervalInHours(24)
                                                            .OnEveryDay()
                                                            .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(3, 0))
                                                            )
                                                        .Build();

            scheduler.ScheduleJob(coommissionNotificationJob, coommissionNotificationTrigger);
            CommissionHelper.SendNotifications();//todo убрать после отладки

            IJobDetail checkSuspensionPeriodsJob     = JobBuilder.Create <CommissionNotificationJob>().Build();
            ITrigger   checkSuspensionPeriodsTrigger = TriggerBuilder.Create()
                                                       .WithDailyTimeIntervalSchedule
                                                           (s =>
                                                           s.WithIntervalInHours(24)
                                                           .OnEveryDay()
                                                           .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(3, 0))
                                                           )
                                                       .Build();

            scheduler.ScheduleJob(checkSuspensionPeriodsJob, checkSuspensionPeriodsTrigger);
        }
Esempio n. 3
0
        public PrintedDocumentsListDto GetPrintedList(DocumentType type)
        {
            try
            {
                _WriteLineConsole("get printed list");
                switch (type)
                {
                case DocumentType.CashTransaction:
                {
                    using (CashTransactionsHelper helper = new CashTransactionsHelper())
                    {
                        return(helper.GetPrintedList());
                    }
                }

                case DocumentType.CreditTransaction:
                {
                    using (var helper = new CreditTransactionHelper())
                    {
                        return(helper.GetPrintedList());
                    }
                }

                case DocumentType.Commission:
                {
                    using (var helper = new CommissionHelper())
                    {
                        return(helper.GetPrintedList());
                    }
                }

                default:
                    throw new NotImplementedException();
                }
            }
            catch (Exception ex)
            {
                _WriteLineError("get printed list", ex.Message);
                return(new PrintedDocumentsListDto()
                {
                    Error = true,
                    Message = ex.Message
                });
            }
        }
Esempio n. 4
0
        public void TestGetCommissionsByBoutique()
        {
            string[] orders = new string[]
            {
                "B10,O1000,100.00",
                "B11,O1001,100.00",
                "B10,O1002,200.00",
                "B10,O1003,300.00"
            };
            var fileHelper  = new FileHelper(orders);
            var commissions = fileHelper.GetCommissions();

            List <string> result = new List <string> {
                "B10,30", "B11,10"
            };

            Assert.IsTrue(result.SequenceEqual(CommissionHelper.GetCommissionsByBoutique(commissions).ToArray()));
        }
Esempio n. 5
0
        public SourcesTrancportDto GetSourceTrancport()
        {
            try
            {
                _WriteLineConsole("get source trancport");

                using (var helper = new CommissionHelper())
                    return(helper.GetSourcesTrancport());
            }
            catch (Exception ex)
            {
                _WriteLineError("get source trancport", ex.Message);
                return(new SourcesTrancportDto()
                {
                    Error = true,
                    Message = ex.Message
                });
            }
        }
Esempio n. 6
0
        public CommissionDto GetCommission(int id)
        {
            _WriteLineConsole($"get commission id:{id}");

            try
            {
                using (var helper = new CommissionHelper())
                    return(helper.GetCommission(id));
            }
            catch (Exception ex)
            {
                _WriteLineError("get commission", ex.Message);
                return(new CommissionDto()
                {
                    Error = true,
                    Message = ex.Message
                });
            }
        }
Esempio n. 7
0
        public CommissionsDto GetCommissions()
        {
            try
            {
                _WriteLineConsole("get commissions");

                using (var helper = new CommissionHelper())
                    return(helper.GetCommissions());
            }
            catch (Exception ex)
            {
                _WriteLineError("get commissions", ex.Message);
                return(new CommissionsDto()
                {
                    Error = true,
                    Message = ex.Message
                });
            }
        }
Esempio n. 8
0
        public Response DeleteCommission(CommissionDocument document)
        {
            try
            {
                _WriteLineConsole($"delete commission identity: {document.Identity}");
                using (var helper = new CommissionHelper())
                {
                    helper.DeleteCommission(document);
                }

                return(new Response()
                {
                    Message = "Документ удален"
                });
            }
            catch (Exception ex)
            {
                _WriteLineError($"delete commission identity: {document?.Identity}", ex.Message);
                return(new Response(ex));
            }
        }
Esempio n. 9
0
        public SaveEntityResult SaveCommission(CommissionDocument document)
        {
            try
            {
                _WriteLineConsole($"save commission identity: {document.Identity}");
                using (var helper = new CommissionHelper())
                    helper.SaveCommision(document);

                return(new SaveEntityResult()
                {
                    Message = "Данные успешно сохраненны", Id = document.Id, Number = document.Number
                });
            }
            catch (Exception ex)
            {
                _WriteLineError($"save commission identity: {document?.Identity}", ex.Message);
                return(new SaveEntityResult()
                {
                    Error = true,
                    Message = ex.Message
                });
            }
        }
Esempio n. 10
0
 public async Task <string> Process()
 {
     return($"{await RoyaltyHelper.Process()} {await CommissionHelper.Process()}");
 }
Esempio n. 11
0
 public void Execute(IJobExecutionContext context)
 {
     CommissionHelper.SendNotifications();
 }