static async Task Main(string[] args) { IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); IConfigurationRoot configuration = builder.Build(); ZohoApiClient client = new ZohoApiClient(configuration["api_host"], configuration["api_auth_token"], configuration["organization_id"]); Task <JObject> accountsJson = client.GetAccounts(); Console.Write("Start date [01 Jan 2000]: "); string from = Console.ReadLine(); Console.Write($"End date [{DateTime.UtcNow.ToString("dd MMM yyyy")}]: "); string to = Console.ReadLine(); AccountCompletionHandler chartOfAccounts = new AccountCompletionHandler(await accountsJson); ReadLine.AutoCompletionHandler = chartOfAccounts; ReadLine.HistoryEnabled = false; string accountName = ReadLine.Read("Account: "); string accountId = chartOfAccounts.GetAccountId(accountName); DateTime fromDate; DateTime toDate; if (!DateTime.TryParseExact(from, "d MMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out fromDate)) { fromDate = new DateTime(2000, 1, 1); } if (!DateTime.TryParseExact(to, "d MMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out toDate)) { toDate = DateTime.UtcNow; } Console.WriteLine(); ProgressBarOptions options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow, ForegroundColorDone = ConsoleColor.DarkGreen, BackgroundColor = ConsoleColor.DarkGray, BackgroundCharacter = '\u2593' }; using (ProgressBar progressBar = new ProgressBar(1, " Starting download", options)) { TransactionListProcessor listProcessor = new TransactionListProcessor(client, accountId, (current, total) => UpdateProgress(progressBar, current, total)); IReadOnlyList <Transaction> transactions = await listProcessor.GetList(fromDate, toDate); await WriteCsv($"{accountName} - From {fromDate.ToString("dd MMM yyyy")} to {toDate.ToString("dd MMM yyyy")}.csv", transactions); } }
public TransactionListProcessor(ZohoApiClient client, string accountId, Action <int, int> onProgress) { this.client = client; this.accountId = accountId; this.onProgress = onProgress; }