diff --git a/BeWo/DebugConfig.cs b/BeWo/DebugConfig.cs index fb941488d..dfb16be26 100644 --- a/BeWo/DebugConfig.cs +++ b/BeWo/DebugConfig.cs @@ -161,9 +161,9 @@ namespace BeWo AutoLogin = true, SelectView = UIContext.Finance, SelectIndex = 7, - //DefaultLoginUsername = "m1", - //DefaultLoginPassword = "bewobewo", - //DefaultProfilename = "5000000000", + DefaultLoginUsername = "m1", + DefaultLoginPassword = "bewobewo", + DefaultProfilename = "5000000000", EnableAutoRemoteDebugging = true }); diff --git a/BeWo/ServiceProxy/GeneratedOperationsEnhancedService.cs b/BeWo/ServiceProxy/GeneratedOperationsEnhancedService.cs index 21a6123cf..c7499dc80 100644 --- a/BeWo/ServiceProxy/GeneratedOperationsEnhancedService.cs +++ b/BeWo/ServiceProxy/GeneratedOperationsEnhancedService.cs @@ -20,6 +20,10 @@ namespace BeWo.ServiceProxy [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOperationsEnhancedService/HelloWorld", ReplyAction="http://tempuri.org/IOperationsEnhancedService/HelloWorldResponse")] [System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IOperationsEnhancedService/HelloWorldBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")] string HelloWorld(); + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOperationsEnhancedService/GetPdf", ReplyAction="http://tempuri.org/IOperationsEnhancedService/GetPdfResponse")] + [System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IOperationsEnhancedService/GetPdfBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")] + byte[] GetPdf(); } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] @@ -60,5 +64,10 @@ namespace BeWo.ServiceProxy { return base.Channel.HelloWorld(); } + + public byte[] GetPdf() + { + return base.Channel.GetPdf(); + } } } diff --git a/BeWo/View/Detail/Accounting/InvoiceOverview.xaml.cs b/BeWo/View/Detail/Accounting/InvoiceOverview.xaml.cs index c6f677ce8..9f0ac9d68 100644 --- a/BeWo/View/Detail/Accounting/InvoiceOverview.xaml.cs +++ b/BeWo/View/Detail/Accounting/InvoiceOverview.xaml.cs @@ -664,13 +664,7 @@ namespace BeWo.View.Detail.Accounting { File.WriteAllBytes(@"C:\Users\ownSoft\Desktop\XRechnung\test.pdf", bytes); - var t = Encoding.ASCII.GetString(bytes); - - File.WriteAllText(@"C:\Users\ownSoft\Desktop\XRechnung\test2.pdf", t); - - BeWoApp.MainControl.WindowService.ShowTextViewerWindow("Test", t); - - //BeWoApp.MainControl.WindowService.ShowERechnungWindow(new MemoryStream(bytes)); + BeWoApp.MainControl.WindowService.ShowERechnungWindow(new MemoryStream(bytes)); } else MessageBox.Show("cb is null"); diff --git a/Host/DownloadFile.aspx b/Host/DownloadFile.aspx deleted file mode 100644 index 7a6bdc15d..000000000 --- a/Host/DownloadFile.aspx +++ /dev/null @@ -1,3 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DownloadFile.aspx.cs" Inherits="Host.DownloadFile" %> - - diff --git a/Host/DownloadFile.aspx.cs b/Host/DownloadFile.aspx.cs deleted file mode 100644 index 3132521e0..000000000 --- a/Host/DownloadFile.aspx.cs +++ /dev/null @@ -1,49 +0,0 @@ -using BeWo.Data; -using BeWo.Service.Security; -using BS.Shared.Core; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Security; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; - -namespace Host -{ - public partial class DownloadFile : System.Web.UI.Page - { - protected void Page_Load(object sender, EventArgs e) - { - try - { - if (!SessionFacade.IsUserLoggedIn()) - { - throw new SecurityException("Invalid authentication"); - } - - var key = this.Request.Params["key"]; - - if (key != "jhkf4589141324h6543958") - { - throw new SecurityException("Invalid authentication"); - } - - string lPath = @"C:\BeWoPlaner\Test\test.pdf"; - - Response.AddHeader("content-disposition", "attachment;filename=test.pdf"); - Response.Charset = string.Empty; - Response.ContentType = "application/pdf"; - - Response.TransmitFile(lPath); - } - catch (Exception ex) - { - Response.Write(ex.ToString()); - } - - Response.End(); - } - } -} \ No newline at end of file diff --git a/Host/DownloadFile.aspx.designer.cs b/Host/DownloadFile.aspx.designer.cs deleted file mode 100644 index 36a6f969d..000000000 --- a/Host/DownloadFile.aspx.designer.cs +++ /dev/null @@ -1,17 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Dieser Code wurde von einem Tool generiert. -// -// Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn -// der Code neu generiert wird. -// -//------------------------------------------------------------------------------ - -namespace Host -{ - - - public partial class DownloadFile - { - } -} diff --git a/Host/Host.csproj b/Host/Host.csproj index 735db1c67..6b83ccb28 100644 --- a/Host/Host.csproj +++ b/Host/Host.csproj @@ -421,7 +421,6 @@ - @@ -495,13 +494,6 @@ Download.aspx - - DownloadFile.aspx - ASPXCodeBehind - - - DownloadFile.aspx - DX.aspx ASPXCodeBehind diff --git a/Host/ReportView.aspx.cs b/Host/ReportView.aspx.cs index d0a8a1a84..d14f15695 100644 --- a/Host/ReportView.aspx.cs +++ b/Host/ReportView.aspx.cs @@ -52,9 +52,10 @@ namespace Host { report.ExportToPdf(repxStream); - Response.AddHeader("content-disposition", "inline;filename=report.pdf"); - Response.Charset = string.Empty; + Response.Clear(); Response.ContentType = "application/pdf"; + Response.Charset = string.Empty; + Response.AddHeader("content-disposition", "inline;filename=report.pdf"); } else { diff --git a/Shared/Attributes/RequireApiKeyAttribute.cs b/Service/Attributes/RequireApiKeyAttribute.cs similarity index 63% rename from Shared/Attributes/RequireApiKeyAttribute.cs rename to Service/Attributes/RequireApiKeyAttribute.cs index 4a971edde..2ec9cfe95 100644 --- a/Shared/Attributes/RequireApiKeyAttribute.cs +++ b/Service/Attributes/RequireApiKeyAttribute.cs @@ -4,14 +4,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BS.Shared.Attributes +namespace BeWo.Service.Attributes { [AttributeUsage(AttributeTargets.Method, Inherited = true)] public class RequireApiKeyAttribute : Attribute { - public string ApiKeyName { get; set; } + public WebSecretConfigSetting ApiKeyName { get; set; } - public RequireApiKeyAttribute(string api_key_name) + public RequireApiKeyAttribute(WebSecretConfigSetting api_key_name) { ApiKeyName = api_key_name; } diff --git a/Shared/Attributes/RequireNoTenantAttribute.cs b/Service/Attributes/RequireNoTenantAttribute.cs similarity index 89% rename from Shared/Attributes/RequireNoTenantAttribute.cs rename to Service/Attributes/RequireNoTenantAttribute.cs index ec3a1be3f..b375e09c1 100644 --- a/Shared/Attributes/RequireNoTenantAttribute.cs +++ b/Service/Attributes/RequireNoTenantAttribute.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BS.Shared.Attributes +namespace BeWo.Service.Attributes { [AttributeUsage(AttributeTargets.Method, Inherited = true)] public class RequireNoTenantAttribute : Attribute diff --git a/Shared/Attributes/RequirePermissionAttribute.cs b/Service/Attributes/RequirePermissionAttribute.cs similarity index 94% rename from Shared/Attributes/RequirePermissionAttribute.cs rename to Service/Attributes/RequirePermissionAttribute.cs index bf8407079..16e52f74d 100644 --- a/Shared/Attributes/RequirePermissionAttribute.cs +++ b/Service/Attributes/RequirePermissionAttribute.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using BS.Shared; -namespace BS.Shared.Attributes +namespace BeWo.Service.Attributes { [AttributeUsage(AttributeTargets.Method, Inherited = true)] public class RequirePermissionAttribute : Attribute diff --git a/Service/BeWoServiceEnums.cs b/Service/BeWoServiceEnums.cs new file mode 100644 index 000000000..bb64b4a1d --- /dev/null +++ b/Service/BeWoServiceEnums.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service +{ + public enum WebConfigSetting + { + OpenWebUIUrl, + XRechnungApiUrl, + HelloWorldPdfLocation + } + + public enum WebSecretConfigSetting + { + OpenWebUIKey, + GetGkvSumApiKey, + DownloadReportApiKey, + OpenrouteServiceApiKey, + GoogleDistanceMatrixApiKey, + } +} diff --git a/Service/Core/MergedConfig.cs b/Service/Core/MergedConfig.cs index 13817e318..8e1e1621d 100644 --- a/Service/Core/MergedConfig.cs +++ b/Service/Core/MergedConfig.cs @@ -11,17 +11,22 @@ namespace BeWo.Service.Core { public static class MergedConfig { - public static string GetSetting(string key) + public static string GetSetting(WebConfigSetting config) { - // 1. Versuche, aus AppSettings.local.config zu lesen - if(GetSecretSetting(key) is string secret) - return secret; + return getSetting(config.ToString()); + } - // 2. Fallback: Standard-AppSettings + public static string GetSecretSetting(WebSecretConfigSetting webSecretConfigSetting) + { + return getSecretSetting(webSecretConfigSetting.ToString()); + } + + private static string getSetting(string key) + { return ConfigurationManager.AppSettings[key]; } - public static string GetSecretSetting(string key) + private static string getSecretSetting(string key) { var localConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web.Secrets.config"); if (!File.Exists(localConfigPath)) diff --git a/Service/Security/SecurityContextInitializer.cs b/Service/Security/SecurityContextInitializer.cs index 29a816e50..f5321f56b 100644 --- a/Service/Security/SecurityContextInitializer.cs +++ b/Service/Security/SecurityContextInitializer.cs @@ -11,9 +11,9 @@ using System.Xml; using BeWo.Data; using BeWo.Data.Access; using BeWo.Data.Entities; +using BeWo.Service.Attributes; using BeWo.Service.Core; using BeWo.Service.ServiceUtils; -using BS.Shared.Attributes; using BS.Shared.Extensions; using NHibernate.Hql.Ast.ANTLR.Tree; diff --git a/Service/Service.csproj b/Service/Service.csproj index dfcdd6cb0..c2a835069 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -228,6 +228,10 @@ + + + + diff --git a/Service/ServiceBehavior/AdminMultitenancyContextInitializer.cs b/Service/ServiceBehavior/AdminMultitenancyContextInitializer.cs index 8ddfc8df5..3edc261fd 100644 --- a/Service/ServiceBehavior/AdminMultitenancyContextInitializer.cs +++ b/Service/ServiceBehavior/AdminMultitenancyContextInitializer.cs @@ -1,4 +1,5 @@ using BeWo.Data; +using BeWo.Service.Attributes; using System; using System.Collections.Generic; using System.Linq; @@ -12,7 +13,6 @@ using System.ServiceModel.Dispatcher; using BeWo.Service.Core; using BS.Shared.Extensions; using BeWo.Service.ServiceUtils; -using BS.Shared.Attributes; using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel; using DevExpress.CodeParser; diff --git a/Service/ServiceBehavior/AdminServiceMessageInspector.cs b/Service/ServiceBehavior/AdminServiceMessageInspector.cs index 3871e250c..8c18a54df 100644 --- a/Service/ServiceBehavior/AdminServiceMessageInspector.cs +++ b/Service/ServiceBehavior/AdminServiceMessageInspector.cs @@ -8,8 +8,8 @@ using System.ServiceModel; using System.Text; using System.Threading.Tasks; using BeWo.Data; +using BeWo.Service.Attributes; using BeWo.Service.Core; -using BS.Shared.Attributes; using System.Runtime.Remoting.Channels; using DevExpress.PivotGrid.OLAP; using BeWo.Service.ServiceUtils; @@ -104,7 +104,7 @@ namespace BeWo.Service.ServiceBehavior // Extrahiert den API Key von Remote var prop = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name]; - var remoteApikey = prop?.Headers[api_key_name]; + var remoteApikey = prop?.Headers[api_key_name.ToString()]; // Vergleicht die API Keys if (remoteApikey == null || !string.Equals(remoteApikey, allowedApikey, StringComparison.Ordinal)) diff --git a/Service/ServiceContracts/Enhanced/IAccountingEnhancedService.cs b/Service/ServiceContracts/Enhanced/IAccountingEnhancedService.cs index 04825c651..cb8563f81 100644 --- a/Service/ServiceContracts/Enhanced/IAccountingEnhancedService.cs +++ b/Service/ServiceContracts/Enhanced/IAccountingEnhancedService.cs @@ -1,6 +1,5 @@ using BeWo.Data.Entities; using BS.Shared; -using BS.Shared.Attributes; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Feature.AI; diff --git a/Service/ServiceContracts/Enhanced/IAiEnhancedService.cs b/Service/ServiceContracts/Enhanced/IAiEnhancedService.cs index 615e2a8e9..e3d1ef6b6 100644 --- a/Service/ServiceContracts/Enhanced/IAiEnhancedService.cs +++ b/Service/ServiceContracts/Enhanced/IAiEnhancedService.cs @@ -1,6 +1,6 @@ using BeWo.Data.Entities; +using BeWo.Service.Attributes; using BS.Shared; -using BS.Shared.Attributes; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Feature.AI; diff --git a/Service/ServiceContracts/Enhanced/IOperationsEnhancedService.cs b/Service/ServiceContracts/Enhanced/IOperationsEnhancedService.cs index c026613be..4e5d1068d 100644 --- a/Service/ServiceContracts/Enhanced/IOperationsEnhancedService.cs +++ b/Service/ServiceContracts/Enhanced/IOperationsEnhancedService.cs @@ -1,6 +1,6 @@ using BeWo.Data.Entities; +using BeWo.Service.Attributes; using BS.Shared; -using BS.Shared.Attributes; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Feature.AI; @@ -19,5 +19,10 @@ namespace BeWo.Service.ServiceContracts.Enhanced [FaultContract(typeof(BeWoFault))] [OperationContract] string HelloWorld(); + + [FaultContract(typeof(BeWoFault))] + [OperationContract] + [RequireNoTenant] + byte[] GetPdf(); } } \ No newline at end of file diff --git a/Service/ServiceContracts/IAdminService.cs b/Service/ServiceContracts/IAdminService.cs index 89fe621ee..a2440329d 100644 --- a/Service/ServiceContracts/IAdminService.cs +++ b/Service/ServiceContracts/IAdminService.cs @@ -1,5 +1,4 @@ -using BS.Shared.Attributes; -using BS.Shared.DataContracts.AdminService; +using BS.Shared.DataContracts.AdminService; using System; using System.Collections.Generic; using System.Linq; @@ -7,6 +6,7 @@ using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Threading.Tasks; +using BeWo.Service.Attributes; namespace BeWo.Service.ServiceContracts { diff --git a/Service/ServiceContracts/IApiService.cs b/Service/ServiceContracts/IApiService.cs index 82a98818d..ae3d5c95c 100644 --- a/Service/ServiceContracts/IApiService.cs +++ b/Service/ServiceContracts/IApiService.cs @@ -1,5 +1,4 @@ -using BS.Shared.Attributes; -using BS.Shared.DataContracts.AdminService; +using BS.Shared.DataContracts.AdminService; using System; using System.Collections.Generic; using System.Linq; @@ -7,6 +6,7 @@ using System.ServiceModel.Web; using System.ServiceModel; using System.Text; using System.Threading.Tasks; +using BeWo.Service.Attributes; using BS.Shared.DataContracts.MikePHPContracts; using System.IO; @@ -17,12 +17,12 @@ namespace BeWo.Service.ServiceContracts { [OperationContract] [WebGet(UriTemplate = "/Test", ResponseFormat = WebMessageFormat.Json)] - [RequireNoTenant] + [Attributes.RequireNoTenant] ApiResponse Test(); [OperationContract] [WebInvoke(UriTemplate = "/GetGkvSum", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] - [RequireApiKey("GetGkvSumApiKey")] + [RequireApiKey(WebSecretConfigSetting.GetGkvSumApiKey)] ApiResponse GetGkvAbrechnungSumme(AdminServiceSumReqDC request); } } diff --git a/Service/ServiceContracts/IApiStreamService.cs b/Service/ServiceContracts/IApiStreamService.cs index 023af4ac3..2a7034291 100644 --- a/Service/ServiceContracts/IApiStreamService.cs +++ b/Service/ServiceContracts/IApiStreamService.cs @@ -1,5 +1,4 @@ -using BS.Shared.Attributes; -using BS.Shared.DataContracts.AdminService; +using BS.Shared.DataContracts.AdminService; using BS.Shared.DataContracts.MikePHPContracts; using System; using System.Collections.Generic; @@ -9,6 +8,7 @@ using System.ServiceModel.Web; using System.ServiceModel; using System.Text; using System.Threading.Tasks; +using BeWo.Service.Attributes; namespace BeWo.Service.ServiceContracts { @@ -17,7 +17,7 @@ namespace BeWo.Service.ServiceContracts { [OperationContract] [WebGet(UriTemplate = "/DownloadReport", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] - [RequireApiKey("DownloadReportApiKey")] + [RequireApiKey(WebSecretConfigSetting.DownloadReportApiKey)] [RequireNoTenant] Stream DownloadReport(); } diff --git a/Service/ServiceContracts/IGkvAccountingService.cs b/Service/ServiceContracts/IGkvAccountingService.cs index 92239c939..ef08c8b78 100644 --- a/Service/ServiceContracts/IGkvAccountingService.cs +++ b/Service/ServiceContracts/IGkvAccountingService.cs @@ -1,6 +1,6 @@ using BeWo.Data.Entities.Light; +using BeWo.Service.Attributes; using BS.Shared; -using BS.Shared.Attributes; using BS.Shared.Core; using BS.Shared.DataContracts.GkvAbrechnung; using BS.Shared.DataContracts.Light; diff --git a/Service/ServiceContracts/IUserService.cs b/Service/ServiceContracts/IUserService.cs index 7e955d3e0..318f4b71b 100644 --- a/Service/ServiceContracts/IUserService.cs +++ b/Service/ServiceContracts/IUserService.cs @@ -2,10 +2,10 @@ using System.Collections.Generic; using System.ServiceModel; using BeWo.Data.Entities; +using BeWo.Service.Attributes; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared; -using BS.Shared.Attributes; using BS.Shared.Core; namespace BeWo.Service.ServiceContracts diff --git a/Service/ServiceImplementations/Enhanced/OperationsEnhancedServiceImp.cs b/Service/ServiceImplementations/Enhanced/OperationsEnhancedServiceImp.cs index c5dc6828e..a2e302617 100644 --- a/Service/ServiceImplementations/Enhanced/OperationsEnhancedServiceImp.cs +++ b/Service/ServiceImplementations/Enhanced/OperationsEnhancedServiceImp.cs @@ -3,6 +3,7 @@ using BeWo.Data.Access; using BeWo.Data.Entities; using BeWo.Data.Models.XRechnung; using BeWo.Data.Security; +using BeWo.Service.Core; using BeWo.Service.DCEntityMapper; using BeWo.Service.ServiceContracts.Enhanced; using BeWo.Service.ServiceProxy; @@ -14,15 +15,18 @@ using BS.Shared.DataContracts.Feature.AI; using BS.Shared.DataContracts.Invoicing.XRechnung; using BS.Shared.DataContracts.MikePHPContracts; using DevExpress.Entity.Model.Metadata; +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; using System.Text; using System.Threading; using System.Threading.Tasks; +using static DevExpress.Drawing.Printing.Internal.DXPageSizeInfo; namespace BeWo.Service.ServiceImplementations.Enhanced { @@ -33,5 +37,14 @@ namespace BeWo.Service.ServiceImplementations.Enhanced { return "OperationEnhancedService: Hello World!"; } + + public byte[] GetPdf() + { + var lFilePath = MergedConfig.GetSetting(WebConfigSetting.HelloWorldPdfLocation); + + var bytes = File.ReadAllBytes(lFilePath); + + return bytes; + } } } diff --git a/Service/ServiceProxy/OpenWebUIFacade.cs b/Service/ServiceProxy/OpenWebUIFacade.cs index ce45130a8..15d2f161f 100644 --- a/Service/ServiceProxy/OpenWebUIFacade.cs +++ b/Service/ServiceProxy/OpenWebUIFacade.cs @@ -110,7 +110,7 @@ namespace BeWo.Service.ServiceProxy protected override string getKey() { - var key = Core.MergedConfig.GetSetting("OpenWebUIKey"); + var key = Core.MergedConfig.GetSecretSetting(WebSecretConfigSetting.OpenWebUIKey); if (string.IsNullOrEmpty(key)) throw new InvalidOperationException("OpenWebUIKey is missing"); diff --git a/Service/ServiceProxy/XRechnungFacade.cs b/Service/ServiceProxy/XRechnungFacade.cs index c15338a6d..6e9bb811b 100644 --- a/Service/ServiceProxy/XRechnungFacade.cs +++ b/Service/ServiceProxy/XRechnungFacade.cs @@ -26,14 +26,14 @@ namespace BeWo.Service.ServiceProxy pdf = url }; - var test = SendPostUploadValues(sub_url, payload); + var test = SendPostUploadValuesRaw(sub_url, payload); return test; } protected override string getUrl() { - var url = MergedConfig.GetSetting("XRechnungApiUrl"); + var url = MergedConfig.GetSetting(WebConfigSetting.XRechnungApiUrl); if (string.IsNullOrEmpty(url)) throw new InvalidOperationException("XRechnungApiUrl is missing"); @@ -43,7 +43,7 @@ namespace BeWo.Service.ServiceProxy protected override string getKey() { - var key = MergedConfig.GetSetting("OpenWebUIKey"); + var key = MergedConfig.GetSecretSetting(WebSecretConfigSetting.OpenWebUIKey); if (string.IsNullOrEmpty(key)) throw new InvalidOperationException("OpenWebUIKey is missing"); diff --git a/Service/ServiceUtils/DistanceCalculator/GoogleDistanceMatrixAPI.cs b/Service/ServiceUtils/DistanceCalculator/GoogleDistanceMatrixAPI.cs index 9838b6c92..873b1708f 100644 --- a/Service/ServiceUtils/DistanceCalculator/GoogleDistanceMatrixAPI.cs +++ b/Service/ServiceUtils/DistanceCalculator/GoogleDistanceMatrixAPI.cs @@ -64,7 +64,7 @@ namespace BeWo.Service.ServiceUtils.DistanceCalculator throw new Exception("GoogleDistanceMatrixApiUrl is not set in AppSettings."); } - Key = MergedConfig.GetSecretSetting("GoogleDistanceMatrixApiKey"); + Key = MergedConfig.GetSecretSetting(WebSecretConfigSetting.GoogleDistanceMatrixApiKey); if (string.IsNullOrEmpty(Key)) { throw new Exception("GoogleDistanceMatrixApiKey is not set."); diff --git a/Service/ServiceUtils/DistanceCalculator/OpenrouteServiceAPI.cs b/Service/ServiceUtils/DistanceCalculator/OpenrouteServiceAPI.cs index 0041bb2b0..f419f2ac0 100644 --- a/Service/ServiceUtils/DistanceCalculator/OpenrouteServiceAPI.cs +++ b/Service/ServiceUtils/DistanceCalculator/OpenrouteServiceAPI.cs @@ -60,7 +60,7 @@ namespace BeWo.Service.ServiceUtils.DistanceCalculator throw new Exception("OpenrouteServiceApiUrl is not set in AppSettings."); } - Key = MergedConfig.GetSecretSetting("OpenrouteServiceApiKey"); + Key = MergedConfig.GetSecretSetting(WebSecretConfigSetting.OpenrouteServiceApiKey); if (string.IsNullOrEmpty(Key)) { throw new Exception("OpenrouteServiceApiKey is not set."); diff --git a/Service/ServiceUtils/ServiceHelper.cs b/Service/ServiceUtils/ServiceHelper.cs index 578418bc7..98a45c630 100644 --- a/Service/ServiceUtils/ServiceHelper.cs +++ b/Service/ServiceUtils/ServiceHelper.cs @@ -9,7 +9,6 @@ using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher; using System.Text; using System.Threading.Tasks; -using BS.Shared.Attributes; using BS.Shared.Extensions; using NHibernate.Hql.Ast.ANTLR.Tree; diff --git a/Shared/Core/WebClientFacade.cs b/Shared/Core/WebClientFacade.cs index f3968d26f..05a45e314 100644 --- a/Shared/Core/WebClientFacade.cs +++ b/Shared/Core/WebClientFacade.cs @@ -31,10 +31,14 @@ namespace BS.Shared.Core => SendUploadString(sub_url, "POST", req, token); protected TRes SendPostUploadValues(string sub_url, TReq req, string token = null) => SendUploadValues(sub_url, "POST", req, token); + protected byte[] SendPostUploadValuesRaw(string sub_url, TReq req, string token = null) + => SendUploadValuesRaw(sub_url, "POST", req, token); protected Task SendPostUploadStringAsync(string sub_url, TReq req, string token = null) => SendUploadStringAsync(sub_url, "POST", req, token); protected Task SendPostUploadValuesAsync(string sub_url, TReq req, string token = null) => SendUploadValuesAsync(sub_url, "POST", req, token); + protected Task SendPostUploadValuesAsyncRaw(string sub_url, TReq req, string token = null) + => SendUploadValuesRawAsync(sub_url, "POST", req, token); #region private // @@ -66,6 +70,15 @@ namespace BS.Shared.Core return deserialize(response); } + private byte[] SendUploadValuesRaw(string sub_url, string method, TReq req, string token = null) + { + var data = serialize(req); + var url = getUrl(sub_url); + + var response = SendUploadValuesRaww(url, method, data, token); + + return response; + } private async Task GetAsync(string sub_url, string token = null) { var url = getUrl(sub_url); @@ -92,6 +105,15 @@ namespace BS.Shared.Core return deserialize(response); } + private async Task SendUploadValuesRawAsync(string sub_url, string method, TReq req, string token = null) + { + var data = serialize(req); + var url = getUrl(sub_url); + + var response = await SendUploadValuesRawAsync(url, method, data, token); + + return response; + } // // String @@ -102,12 +124,16 @@ namespace BS.Shared.Core => exec(false, client => client.UploadString(url, method, request), token); private string SendUploadValues(string url, string method, T request, string token = null) => exec(false, client => Encoding.UTF8.GetString(client.UploadValues(url, method, request?.ToNameValueCollection())), token); + private byte[] SendUploadValuesRaww(string url, string method, T request, string token = null) + => execraw(false, client => client.UploadValues(url, method, request?.ToNameValueCollection()), token); private Task GetAsync(string url, string token = null) => execasync(true, client => client.DownloadStringTaskAsync(url), token); private Task SendUploadStringAsync(string url, string method, string request, string token = null) => execasync(false, client => client.UploadStringTaskAsync(url, method, request), token); private Task SendUploadValuesAsync(string url, string method, T request, string token = null) => execasync(false, async client => Encoding.UTF8.GetString(await client.UploadValuesTaskAsync(url, method, request?.ToNameValueCollection()).ConfigureAwait(false)), token); + private Task SendUploadValuesRawAsync(string url, string method, T request, string token = null) + => execasyncraw(false, async client => await client.UploadValuesTaskAsync(url, method, request?.ToNameValueCollection()).ConfigureAwait(false), token); // // Base @@ -118,12 +144,33 @@ namespace BS.Shared.Core using (WebClient client = new WebClient()) { + //client.Encoding = Encoding.Default; client.Encoding = Encoding.UTF8; if (override_header) client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); - if(token != null) + if (token != null) + client.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + token); + + response = action(client); + } + + return response; + } + private byte[] execraw(bool override_header, Func action, string token = null) + { + byte[] response; + + using (WebClient client = new WebClient()) + { + //client.Encoding = Encoding.Default; + client.Encoding = Encoding.UTF8; + + if (override_header) + client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); + + if (token != null) client.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + token); response = action(client); @@ -137,9 +184,30 @@ namespace BS.Shared.Core using (WebClient client = new WebClient()) { + //client.Encoding = Encoding.Default; client.Encoding = Encoding.UTF8; - if(override_header) + if (override_header) + client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); + + if (token != null) + client.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + token); + + response = await action(client); + } + + return response; + } + private async Task execasyncraw(bool override_header, Func> action, string token = null) + { + byte[] response; + + using (WebClient client = new WebClient()) + { + //client.Encoding = Encoding.Default; + client.Encoding = Encoding.UTF8; + + if (override_header) client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); if (token != null) diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj index 371e4ff4c..cfa8df01e 100644 --- a/Shared/Shared.csproj +++ b/Shared/Shared.csproj @@ -136,9 +136,6 @@ - - -