예제 #1
0
파일: Program.cs 프로젝트: delormej/trucks
        private static void ProcessDownloaded(PantherClient panther, string convertApiKey)
        {
            System.Console.WriteLine("Processing local converted xlsx files.");

            List <SettlementHistory> settlementHeaders     = null;
            List <SettlementHistory> downloadedSettlements = null;
            var getSettlementHeaders = Task.Run(async() => {
                settlementHeaders = await panther.GetSettlementsAsync();
            });
            var parseLocalFiles = Task.Run(() =>
                                           downloadedSettlements = SettlementHistoryParser.ParseLocalFiles(panther.Company));

            Task.WaitAll(getSettlementHeaders, parseLocalFiles);

            if (downloadedSettlements.Count > 0)
            {
                System.Console.WriteLine($"Found {downloadedSettlements.Count} to process.");
                List <SettlementHistory> mergedSettlements =
                    MergeSettlements(settlementHeaders, downloadedSettlements).ToList();
                System.Console.WriteLine($"Merged {mergedSettlements.Count}.");

                if (mergedSettlements.Count > 0)
                {
                    SettlementRepository repository = new SettlementRepository();
                    repository.SaveSettlements(mergedSettlements);
                }
            }
            else
            {
                System.Console.WriteLine($"No settlements found for company {panther.Company}.");
            }
        }
예제 #2
0
        /// <summary>
        /// Downloads converted files from converter site, processes them as SettlementHistory
        /// and persists them to the database.
        /// <summary>
        public void Process(PantherClient pantherClient)
        {
            var getConverterResults  = converter.QueryAllAsync();
            var getSettlementHeaders = pantherClient.GetSettlementsAsync();

            Task.WaitAll(getConverterResults, getSettlementHeaders);

            IEnumerable <ZamzarResult> results           = getConverterResults.Result;
            List <SettlementHistory>   settlementHeaders = getSettlementHeaders.Result;

            List <Task> tasks = new List <Task>();

            foreach (ZamzarResult result in results)
            {
                string            settlementId     = GetSettlementId(result);
                SettlementHistory settlementHeader = GetBySettlementId(settlementHeaders, settlementId);
                if (settlementHeader != null)
                {
                    tasks.Add(ProcessResultAsync(result, settlementHeader));
                }
                else
                {
                    System.Console.WriteLine($"SettlementId {settlementId} not found on panther.");
                }
            }
            Task.WaitAll(tasks.ToArray());
        }
예제 #3
0
파일: Program.cs 프로젝트: delormej/trucks
        private static void ProcessUploaded(PantherClient panther, string convertApiKey)
        {
            System.Console.WriteLine("Processing files already uploaded to converter.");
            ConvertedExcelFiles converted = new ConvertedExcelFiles(convertApiKey);

            converted.Process(panther);
        }
예제 #4
0
        public async Task <IEnumerable <ConversionJob> > StartConversion(PantherClient panther, ExcelConverter converter, int max = 10)
        {
            System.Console.WriteLine("Downloading settlements from panther and uploading to conversion service.");

            List <KeyValuePair <string, SettlementHistory> > downloads =
                await DownloadMissingSettlements(panther, max);

            List <ConversionJob> jobs = new List <ConversionJob>();

            foreach (var download in downloads)
            {
                string filename = download.Key;

                ConversionJob job = new ConversionJob();
                job.Result = await converter.UploadAsync(filename);

                job.Company        = download.Value.CompanyId.ToString();
                job.SettlementId   = download.Value.SettlementId;
                job.SettlementDate = download.Value.SettlementDate;

                QueueUploaded(job);
                jobs.Add(job);
            }

            return(jobs);
        }
예제 #5
0
        public string[] UpdateHeadersFromPanther(PantherClient panther)
        {
            System.Console.WriteLine($"Updating settlements for company: {panther.Company}.");
            List <SettlementHistory> settlementsToUpdate = null;

            var task = Task.Run(async() =>
            {
                List <SettlementHistory> settlements = await panther.GetSettlementsAsync();

                SettlementRepository repository           = new SettlementRepository();
                List <SettlementHistory> savedSettlements = await repository.GetSettlementsAsync();

                settlementsToUpdate =
                    settlements.Intersect(savedSettlements, new SettlementHistoryComparer())
                    .ToList();
                repository.SaveSettlements(settlementsToUpdate);
            });

            task.Wait();

            string[] settlementIds = settlementsToUpdate?.Select(s => s.SettlementId).ToArray();
            return(settlementIds);
        }
예제 #6
0
파일: Program.cs 프로젝트: delormej/trucks
        private static void Process(SettlementService settlementService, ExcelConverter converter, PantherClient panther)
        {
            var conversionTask = Task <IEnumerable <ConversionJob> > .Run(() =>
                                                                          settlementService.StartConversion(panther, converter, int.MaxValue));

            conversionTask.Wait();
            foreach (var result in conversionTask.Result)
            {
                System.Console.WriteLine($"Settlement {result.SettlementId} uploaded for conversion.");
            }
        }
예제 #7
0
파일: Program.cs 프로젝트: delormej/trucks
        static void Main(string[] args)
        {
            ShowUsage(args);

            string company       = Environment.GetEnvironmentVariable("TRUCKCOMPANY");
            string password      = Environment.GetEnvironmentVariable("TRUCKPASSWORD");
            string convertApiKey = Environment.GetEnvironmentVariable("ZAMZARKEY");

            if (string.IsNullOrWhiteSpace(company) ||
                string.IsNullOrWhiteSpace(password) ||
                string.IsNullOrWhiteSpace(convertApiKey))
            {
                System.Console.WriteLine("Must set TRUCKCOMPANY, TRUCKPASSWORD, ZAMZARKEY env variables.");
                return;
            }

            SettlementService settlementService = new SettlementService();
            PantherClient     panther           = new PantherClient(company, password);

            if (args.Length < 1)
            {
                ExcelConverter converter = new ExcelConverter(convertApiKey);
                Process(settlementService, converter, panther);
            }
            else
            {
                string command = args[0].ToLower();
                if (command == "uploaded")
                {
                    ProcessUploaded(panther, convertApiKey);
                }
                else if (command == "downloaded")
                {
                    ProcessDownloaded(panther, convertApiKey);
                }
                else if (command == "update")
                {
                    settlementService.UpdateHeadersFromPanther(panther);
                }
                else if (command == "updateall")
                {
                    settlementService.UpdateAll();
                }
                else if (command == "report")
                {
                    GetReport();
                }
                else if (command == "settlement")
                {
                    int year = int.Parse(args[1]);
                    int week = int.Parse(args[2]);
                    int truck;
                    if (args.Length > 3 && int.TryParse(args[3], out truck))
                    {
                        settlementService.CreateSettlementStatement(year, new int[] { week }, truck);
                    }
                    else
                    {
                        settlementService.CreateSettlementStatement(year, new int[] { week });
                    }
                }
                else if (command == "year")
                {
                    settlementService.CreateSettlementsForYear(int.Parse(args[1]));
                }
                else if (command == "fixtemplate")
                {
                    FixTemplate(args[1]);
                }
                else if (command == "savefuel")
                {
                    SaveFuelCharges(args[1]);
                }
                else if (command == "get")
                {
                    PrintSettlementHeader(args[1], args[2]);
                }
                else if (command == "setup")
                {
                    Setup();
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Downloads and returns 'max' settlements from panther that we have not persisted, ordered by
        /// descending date.
        /// <summary>
        private async Task <List <KeyValuePair <string, SettlementHistory> > > DownloadMissingSettlements(PantherClient panther, int max = 10)
        {
            List <SettlementHistory> settlements = await panther.GetSettlementsAsync();

            SettlementRepository     repository       = new SettlementRepository();
            List <SettlementHistory> savedSettlements = await repository.GetSettlementsAsync();

            // Don't try to convert settlements we've already persisted.
            List <SettlementHistory> settlementsToDownload = settlements.Except(savedSettlements, new SettlementHistoryComparer())
                                                             .OrderByDescending(s => s.SettlementDate)
                                                             .Take(max)
                                                             .ToList();

            List <KeyValuePair <string, SettlementHistory> > settlementsToConvert =
                await panther.DownloadSettlementsAsync(settlementsToDownload);

            return(settlementsToConvert);
        }