public IList <T>?ReadAs <T>(EFormatType format, string origin) { IList <T>?objectList; try { objectList = format switch { EFormatType.JSON => JsonSerializer.Deserialize <IList <T> >(origin), EFormatType.CSV => CsvRecords <T>(origin, ","), EFormatType.TSV => CsvRecords <T>(origin, "\t"), EFormatType.SCSV => CsvRecords <T>(origin, ";"), EFormatType.XML => XmlRecords <T>(origin), _ => throw LogAndThrow(format, $"{format} is not supported for reading") }; } catch (Exception ex) when( ex is JsonException || ex is InvalidOperationException) { _logger.LogError("Invalid input file. Check if format of the file is correct and if Id values of GLAccounts are valid"); throw; } return(objectList); }
private async Task CheckConnection(string query, EFormatType format, FileInfo?output) { var apiKey = _credentialService.GetApiKey(); try { //Check ApiKey if (string.IsNullOrWhiteSpace(apiKey)) { _logger.LogError( "Please contact Blue10 to receive an API key for your account and use the 'credentials set' command to update your credentials"); return; } //Get Me test var me = await _blue10.GetMeAsync();//.GetAwaiter().GetResult(); await _utilities.HandleOutput(format, me, output, query); } catch (Blue10ApiException apie) when(apie.Message.Contains("authentication required")) { _logger.LogError($"Your API : \"{apiKey}\" key is invalid, please contact Blue10 to receive a valid API Key and use the 'credentials set' command to update your credentials"); } catch (Blue10ApiException apie) { _logger.LogError(apie.Message); } catch (Exception e) { _logger.LogError(e.Message); } }
public async Task PullInvoiceHandler(string?query, EFormatType format, DirectoryInfo output) { var fInvoiceActions = await _service.GetNewPostInvoiceAction(); if (!Directory.Exists(output.FullName)) { Directory.CreateDirectory(output.FullName); } foreach (var fInvoiceAction in fInvoiceActions) { var(fPurchaseInvoice, fOriginalFileData) = await _service.PullInvoice(fInvoiceAction); var fFilePath = Path.Combine(output.FullName, fPurchaseInvoice.Id.ToString()); var fExtension = _utilities.GetExtension(format); var fHasResult = await _utilities.HandleOutput(format, fPurchaseInvoice, new FileInfo(fFilePath + fExtension), query); if (fHasResult) { File.WriteAllBytes(fFilePath + ".pdf", fOriginalFileData); } } }
public string GetExtension(EFormatType format) { return(format switch { EFormatType.JSON => ".json", EFormatType.CSV => ".csv", EFormatType.TSV => ".tsv", EFormatType.SCSV => ".scsv", EFormatType.XML => ".xml", _ => throw new ArgumentOutOfRangeException(nameof(format), format, $"{format} is not supported for getting extension") });
private async Task ImportVatCodesHandler( FileInfo input, EFormatType inputformat, FileInfo?output, EFormatType outputformat) { var fSyncFilePath = input.FullName; var fVatCodeList = File.ReadAllText(fSyncFilePath); var fVatCodes = _utilities.ReadAs <VatCode>(inputformat, fVatCodeList); if (fVatCodes is null) { return; } var fSuccessList = new List <VatCode>(); var fFailedList = new List <VatCode>(); var fCount = 1; var fTotalVATCodes = fVatCodes.Count; foreach (var fVatCode in fVatCodes) { var fResult = await _vatCodeService.CreateOrUpdate(fVatCode); if (fResult.Object == null) { fFailedList.Add(fVatCode); _logger.LogWarning($"{fCount}/{fTotalVATCodes}: Failed syncing VATCode '{fVatCode.Name}' - {fResult.ErrorMessage}"); } else { fSuccessList.Add(fResult.Object); Console.WriteLine($"{fCount}/{fTotalVATCodes} Successfully synced VATCode '{fVatCode.Name}'"); } fCount++; } Console.WriteLine($"{fSuccessList.Count}/{fTotalVATCodes} VATCodes have been successfully imported"); await _utilities.HandleOutput(outputformat, fSuccessList, output); if (output != null) { await _utilities.HandleOutputToFilePath(outputformat, fFailedList, $"{output?.Directory?.FullName}/failed_{output?.Name ?? "NO_FILE_PATH_PROVIDED"}"); await _utilities.HandleOutputToFilePath(outputformat, fSuccessList, $"{output?.Directory?.FullName}/succeed_{output?.Name ?? "NO_FILE_PATH_PROVIDED"}"); } }
public static string GetFriendlyString(this EFormatType type) { switch (type) { case EFormatType.Bold: return("Bold"); case EFormatType.Italic: return("Italic"); case EFormatType.Underline: return("Underline"); case EFormatType.Font: return("Font"); case EFormatType.Color: return("Color"); case EFormatType.TextSize: return("Size"); case EFormatType.AlignCenter: return("Align Center"); case EFormatType.AlignJustify: return("Align Justify"); case EFormatType.AlignLeft: return("Align Left"); case EFormatType.AlignRight: return("Align Right"); default: return(string.Empty); } }
public async Task SignInvoiceHandler(Guid invoiceId, string ledgerEntryCode, EFormatType format, FileInfo?output) { var fInvoiceActions = await _service.GetNewPostInvoiceAction(); var fTargetInvoiceAction = fInvoiceActions.FirstOrDefault(x => x.PurchaseInvoice.Id == invoiceId); if (fTargetInvoiceAction == null) { _logger.LogError($"Invoice with id {invoiceId} does not exist, is not ready to be posted or has already been signed off"); return; } var fResult = await _service.SignInvoice(fTargetInvoiceAction, ledgerEntryCode); if (fResult != null) { await _utilities.HandleOutput(format, fResult, output); } else { _logger.LogError($"Failed to sign-off invoice with id {invoiceId}"); } }
public void Success_ConsolOutput( EFormatType pFormat, TestConsole pConsoleCommandLine, InOutService pInOutService, [Frozen] IVendorService pVendorService, [Frozen] Vendor pVendor) { // Setup data pVendorService .CreateOrUpdate(Arg.Any <Vendor>()) .Returns(new BaseResultModel <Vendor>(pVendor, null)); var fCommandLine = $"-c IdCompany -a AdministrationCode --country CountryCode --currency CurrencyCode --iban Iban -f {pFormat}"; // Setup services var pCommand = new CreateVendorCommand(pVendorService, pInOutService, null); // Test pCommand.Invoke(fCommandLine, pConsoleCommandLine); // Validate pConsoleCommandLine.Error.ToString().Should().BeNullOrEmpty(); pVendorService.Received(1); }
public void Success_ConsolOutput( EFormatType pFormat, TestConsole pConsoleCommandLine, InOutService pInOutService, [Frozen] IVendorService pVendorService, [Frozen] IList <Vendor> pVendors) { // Setup data pVendorService .List(Arg.Any <string>()) .Returns(pVendors); var fCommandLine = $"-c IdCompany -f {pFormat}"; // Setup services var pCommand = new ListVendorsCommand(pVendorService, pInOutService, null); // Test pCommand.Invoke(fCommandLine, pConsoleCommandLine); // Validate pConsoleCommandLine.Error.ToString().Should().BeNullOrEmpty(); pVendorService.Received(1); }
public async Task PeekInvoiceHandler(string?query, EFormatType format, FileInfo?output) { var resultObject = await _service.PeekInvoices(); await _utilities.HandleOutput(format, resultObject, output, query); }
private async Task ListCompaniesHandler(string query, EFormatType format, FileInfo?output) { var resultObject = await _service.ListCompanies(); await _utilities.HandleOutput(format, resultObject, output, query); }
private async Task ListVendorsHandler(string companyid, string?query, EFormatType format, FileInfo?output) { var resultObject = await _vendorService.List(companyid); await _utilities.HandleOutput(format, resultObject, output, query); }