예제 #1
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.");
            }
        }
예제 #2
0
        private async Task <string> DownloadFromConverter(ExcelConverter converter, ZamzarResult result, string company)
        {
            if (result.target_files.Length == 0)
            {
                throw new ApplicationException($"Unable to find a file for result: {result}");
            }

            string filename = Path.Combine(company, result.target_files[0].name);
            int    fileId   = result.target_files[0].id;

            if (await converter.DownloadAsync(fileId, filename))
            {
                System.Console.WriteLine($"Downloaded: {filename}");
                return(filename);
            }
            else
            {
                return(null);
            }
        }
예제 #3
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();
                }
            }
        }
예제 #4
0
 public ConvertedExcelFiles(string convertApiKey)
 {
     converter  = new ExcelConverter(convertApiKey);
     repository = new SettlementRepository();
 }
예제 #5
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);
        }