diff --git a/Data/Access/LocalTenantFileStorageDAO.cs b/Data/Access/LocalTenantFileStorageDAO.cs index 003f6098b..c34327280 100644 --- a/Data/Access/LocalTenantFileStorageDAO.cs +++ b/Data/Access/LocalTenantFileStorageDAO.cs @@ -39,7 +39,7 @@ namespace BeWo.Data.Access } public StoredFile SaveHybridFile(BWPFeature feature, string pFileName, string pContentType, Stream content, - int? pBeWoObjectTid = null, long? pBeWoObjectOid = null, CancellationToken cancellationToken = default) + TableID? pBeWoObjectTid = null, long? pBeWoObjectOid = null, CancellationToken cancellationToken = default) { // Prüfe Namen if (SecurityUtils.ContainsInvalidFilenameChars(pFileName)) @@ -61,7 +61,7 @@ namespace BeWo.Data.Access storedfile.FileName = pFileName; storedfile.FilePath = lFilePath; storedfile.ContentType = pContentType; - storedfile.BeWoObjectTid = pBeWoObjectTid; + storedfile.BeWoObjectTid = (int?)pBeWoObjectTid; storedfile.BeWoObjectOid = pBeWoObjectOid; // Speichere FileAsync diff --git a/Service/ServiceImplementations/Enhanced/AccountingEnhancedServiceImp.cs b/Service/ServiceImplementations/Enhanced/AccountingEnhancedServiceImp.cs index e7de6f6fe..8fa807c45 100644 --- a/Service/ServiceImplementations/Enhanced/AccountingEnhancedServiceImp.cs +++ b/Service/ServiceImplementations/Enhanced/AccountingEnhancedServiceImp.cs @@ -19,6 +19,7 @@ using DevExpress.XtraRichEdit.Model; using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Security.Cryptography; using System.ServiceModel; @@ -45,7 +46,15 @@ namespace BeWo.Service.ServiceImplementations.Enhanced if (lFile is object) { - + using (Stream file_stream = lStorage.GetFileContent(lFile)) + { + using (MemoryStream ms = new MemoryStream()) + { + file_stream.CopyTo(ms); + var bytes = ms.ToArray(); + return ApiResponse.SuccessResponse(bytes); + } + } } // Berechne XRechnung @@ -55,27 +64,32 @@ namespace BeWo.Service.ServiceImplementations.Enhanced var download_url = report_url + "&mode=pdf"; var token_url = new DownloadServiceImp().CreateTemporaryUrl(download_url, false); + // Response var response = ServiceFacade.XRechnung.Create(str, token_url); if (response.Success) { - //try - //{ - // var file = storage.SaveXRechnungPdf(tenant, invoice_base_oid, response.ResponseBytes); - // ServiceHelper.CoreLogger.Log(LogLevel.Info, $"Tenant: {tenant}, FilePath: {file.FilePath}", $"{nameof(LocalFileStorageDAO)}.{nameof(storage.SaveXRechnungPdf)}"); - //} - //catch (Exception ex) - //{ - // try - // { - // ServiceHelper.CoreLogger.LogError(ex, nameof(GetXRechnung)); - // } - // catch(Exception ex2) - // { - // response.Errors.Add("AccountingEnhancedServiceImp: " + ex2.ToString()); - // } - // response.Errors.Add("AccountingEnhancedServiceImp: " + ex.ToString()); - //} + try + { + var bytes = response.Data; + using (MemoryStream ms = new MemoryStream(bytes)) + { + var file = lStorage.SaveHybridFile(BWPFeature.XRechnung, lFileName, "application/pdf", ms, TableID.InvoiceBase, invoice_base_oid); + ServiceHelper.CoreLogger.Log(LogLevel.Info, $"Tenant: {lStorage.Tenant}, FilePath: {file.FilePath}", $"{nameof(LocalFileStorageDAO)}.{nameof(lStorage.SaveHybridFile)}"); + } + } + catch (Exception ex) + { + try + { + ServiceHelper.CoreLogger.LogError(ex, nameof(GetXRechnung)); + } + catch (Exception ex2) + { + response.ErrorStrings.Add("AccountingEnhancedServiceImp: " + ex2.ToString()); + } + response.ErrorStrings.Add("AccountingEnhancedServiceImp: " + ex.ToString()); + } } return response; diff --git a/Shared/Interface/IStoredFile.cs b/Shared/Interface/IStoredFile.cs index 508a58ca0..9c65b9bba 100644 --- a/Shared/Interface/IStoredFile.cs +++ b/Shared/Interface/IStoredFile.cs @@ -11,8 +11,8 @@ namespace BS.Shared.Interface string FileName { get; } string FilePath { get; } string ContentType { get; } - long Size { get; } - string Checksum { get; } + long Size { get; set; } + string Checksum { get; set; } int? BeWoObjectTid { get; } long? BeWoObjectOid { get; } }