static void Main(string[] args) { if (EnvironmentSetup.IsProperlySetup(out var error) == false) { error.ConsoleWriteLine(); return; } if (args == null || args.Length == 0 || args.First().Equals("/?") || args.Any(a => a.StartsWith("-") && !a.StartsWith("--"))) { Arguments.GetArgumentInfo(typeof(Args)) .Select(x => new[] { $"--{x.LongName}", $"{x.HelpText}" }) .OrderBy(x => x[0]) .FormatIntoColumns(new[] { "Argument", "Help" }) .ConsoleWriteLine(); return; } Arguments.Populate(typeof(Args)); var arguments = Arguments.Parse(string.Join(" ", args), typeof(Args)); if (Args.SalesBinderInventoryDownload) { SalesBinderAPI.RetrieveAndSaveInventory(topup_: !Args.Force); } if (Args.SalesBinderImageDownload) { SalesBinderAPI.DownloadBookImages(Args.Force); } if (Args.SalesBinderContactsDownload) { SalesBinderAPI.RetrieveAndSaveContacts(); } if (Args.SalesBinderAccountsDownload) { SalesBinderAPI.RetrieveAndSaveAccounts(); } if (Args.SalesBinderInvoicesDownload) { SalesBinderAPI.RetrieveAndSaveInvoices(topup_: !Args.Force); } if (Args.SalesBinderInventoryList) { salesBinderInventoryList(arguments, Args.Keys.SalesBinderInventoryListKey, false); } if (Args.SalesBinderInventoryListCurrent) { salesBinderInventoryList(arguments, Args.Keys.SalesBinderInventoryListCurrentKey, true); } if (Args.KeepaLookupRefreshCurrentInventory) { keepaLookupRefreshCurrentInventory(); } if (Args.KeepaLookupPrimeRecords) { keepaLookupPrimeRecords(); } if (Args.GenerateSalesReport) { generateSalesReport(arguments); } if (Args.SalesBinderFindAndUploadImagesForInventoryWithoutAnImage) { salesBinderFindAndUploadImagesForInventoryWithoutAnImage(); } if (Args.GenerateStockListFromInventory) { generateStockListFromInventory(arguments); } if (Args.SalesBinderReportNegativeQuantities) { salesBinderReportNegativeQuantities(); } if (Args.SalesBinderInventoryUpdate) { salesBinderInventoryUpdate(arguments); } if (Args.ImagesForBarcodes) { imagesForBarcodes(arguments); } if (Args.Test) { test(); } }
private static void salesBinderInventoryList(Arguments arguments, string arg_, bool onlyCurrent_) { var targetPath = arguments.GetArgument(arg_); if (string.IsNullOrEmpty(targetPath)) { "Where should the inventory list be saved to (fullpath to csv)?: " .ConsoleWriteLine(); targetPath = Console.ReadLine(); } var list = SalesBinderAPI.RetrieveAndSaveInventory(true); if (onlyCurrent_) { list = list.Where(x => x.Quantity > 0).ToArray(); } if (Args.KeepaAugmentList) { var excludeFromtree = new HashSet <string>(new[] { "Books", "Subjects" }); var excludeBinding = new HashSet <string>(new[] { "Kindle Edition" }); list.Where(x => !string.IsNullOrEmpty(x.BarCode)) .Select(x => (Item: x, Keepa: KeepaAPI.GetRecordForIdentifier(x.BarCode))) .Where(x => x.Keepa != null) .ForEach(l => { if (string.IsNullOrEmpty(l.Item.Publisher)) { l.Item.Publisher = l.Keepa.Manufacturer; } if (!string.IsNullOrEmpty(l.Keepa.Binding) && !excludeBinding.Contains(l.Keepa.Binding)) { l.Item.Style = l.Keepa.Binding; } if (l.Keepa.CategoryTree != null) { var tree = l.Keepa.CategoryTree.Where(x => !excludeFromtree.Contains(x)); if (tree.Any()) { l.Item.ProductType = string.Join(" / ", tree); l.Item.ProductType2 = tree.Last(); } l.Item.KidsOrAdult = l.Keepa.CategoryTree.Any(x => x.ToLower().Contains("child")) ? "Kids" : "Adult"; } }); } using (var writer = new StreamWriter(targetPath)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) { csv.WriteRecords(list .OrderByDescending(x => Math.Abs(x.Quantity)) .ThenBy(x => x.Name)); } }