Admin Service in ApiService und ApiStreamService ausgelagert
This commit is contained in:
1
Host/ApiService.svc
Normal file
1
Host/ApiService.svc
Normal file
@@ -0,0 +1 @@
|
||||
<%@ ServiceHost Language="C#" Debug="true" Service="BeWo.Service.ServiceImplementations.ApiServiceImp" %>
|
||||
1
Host/ApiStreamService.svc
Normal file
1
Host/ApiStreamService.svc
Normal file
@@ -0,0 +1 @@
|
||||
<%@ ServiceHost Language="C#" Debug="true" Service="BeWo.Service.ServiceImplementations.ApiStreamServiceImp" %>
|
||||
@@ -175,6 +175,8 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="ApiStreamService.svc" />
|
||||
<Content Include="ApiService.svc" />
|
||||
<Content Include="AdminService.svc" />
|
||||
<Content Include="GkvAccountingService.svc" />
|
||||
<Content Include="Admin.aspx" />
|
||||
|
||||
@@ -178,6 +178,12 @@
|
||||
<service behaviorConfiguration="returnFaults" name="BeWo.Service.ServiceImplementations.AdminServiceImp">
|
||||
<endpoint behaviorConfiguration="webHttpBehaviorConfig" binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig" name="AdminServiceEndpoint" contract="BeWo.Service.ServiceContracts.IAdminService" />
|
||||
</service>
|
||||
<service behaviorConfiguration="returnFaults" name="BeWo.Service.ServiceImplementations.ApiServiceImp">
|
||||
<endpoint behaviorConfiguration="webHttpBehaviorConfig" binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig" name="ApiServiceEndpoint" contract="BeWo.Service.ServiceContracts.IApiService" />
|
||||
</service>
|
||||
<service behaviorConfiguration="returnFaults" name="BeWo.Service.ServiceImplementations.ApiStreamServiceImp">
|
||||
<endpoint behaviorConfiguration="webHttpBehaviorConfig" binding="webHttpBinding" bindingConfiguration="webHttpStreamBindingConfig" name="ApiStreamServiceEndpoint" contract="BeWo.Service.ServiceContracts.IApiStreamService" />
|
||||
</service>
|
||||
<service behaviorConfiguration="returnFaults" name="BeWo.Service.ServiceImplementations.OperationsEnhancedServiceImp">
|
||||
<endpoint behaviorConfiguration="SecurityAndSessionAndWCFErrorBehavior" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" name="OperationsEnhancedServiceEndpoint" contract="BeWo.Service.ServiceContracts.IOperationsEnhancedService" />
|
||||
</service>
|
||||
@@ -207,6 +213,12 @@
|
||||
<security mode="None" />
|
||||
<!-- Für ungesicherte Verbindungen (HTTP) -->
|
||||
</binding>
|
||||
<binding name="webHttpStreamBindingConfig" transferMode="Streamed">
|
||||
<!-- Optional: Maximale Nachrichten- und Puffergröße anpassen -->
|
||||
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
|
||||
<security mode="None" />
|
||||
<!-- Für ungesicherte Verbindungen (HTTP) -->
|
||||
</binding>
|
||||
</webHttpBinding>
|
||||
</bindings>
|
||||
<behaviors>
|
||||
|
||||
@@ -523,6 +523,8 @@
|
||||
<Compile Include="ServiceContracts\IAccountingService.cs" />
|
||||
<Compile Include="ServiceContracts\IAdminService.cs" />
|
||||
<Compile Include="ServiceContracts\IAnalysisService.cs" />
|
||||
<Compile Include="ServiceContracts\IApiStreamService.cs" />
|
||||
<Compile Include="ServiceContracts\IApiService.cs" />
|
||||
<Compile Include="ServiceContracts\IGkvAccountingService.cs" />
|
||||
<Compile Include="ServiceContracts\IMailService.cs" />
|
||||
<Compile Include="ServiceContracts\IAiEnhancedService.cs" />
|
||||
@@ -537,6 +539,8 @@
|
||||
<Compile Include="ServiceContracts\IStreamingService.cs" />
|
||||
<Compile Include="ServiceContracts\IResourceService.cs" />
|
||||
<Compile Include="ServiceImplementations\AccountingServiceImp.cs" />
|
||||
<Compile Include="ServiceImplementations\ApiStreamServiceImp.cs" />
|
||||
<Compile Include="ServiceImplementations\ApiServiceImp.cs" />
|
||||
<Compile Include="ServiceImplementations\AdminServiceImp.cs" />
|
||||
<Compile Include="ServiceImplementations\AnalysisServiceImp.cs" />
|
||||
<Compile Include="ServiceImplementations\GkvAccountingServiceImp.cs" />
|
||||
|
||||
27
Service/ServiceContracts/IApiService.cs
Normal file
27
Service/ServiceContracts/IApiService.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using BS.Shared.Attributes;
|
||||
using BS.Shared.DataContracts.AdminService;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.ServiceModel.Web;
|
||||
using System.ServiceModel;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BS.Shared.DataContracts.MikePHPContracts;
|
||||
using System.IO;
|
||||
|
||||
namespace BeWo.Service.ServiceContracts
|
||||
{
|
||||
[ServiceContract]
|
||||
public interface IApiService
|
||||
{
|
||||
[OperationContract]
|
||||
[WebGet(UriTemplate = "/Test", ResponseFormat = WebMessageFormat.Json)]
|
||||
[RequireNoTenant]
|
||||
ApiResponse<string> Test();
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(UriTemplate = "/GetGkvSum", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
|
||||
ApiResponse<decimal> GetGkvAbrechnungSumme(AdminServiceSumReqDC request);
|
||||
}
|
||||
}
|
||||
22
Service/ServiceContracts/IApiStreamService.cs
Normal file
22
Service/ServiceContracts/IApiStreamService.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using BS.Shared.Attributes;
|
||||
using BS.Shared.DataContracts.AdminService;
|
||||
using BS.Shared.DataContracts.MikePHPContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.ServiceModel.Web;
|
||||
using System.ServiceModel;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeWo.Service.ServiceContracts
|
||||
{
|
||||
[ServiceContract]
|
||||
public interface IApiStreamService
|
||||
{
|
||||
[OperationContract]
|
||||
[WebInvoke(UriTemplate = "/DownloadReport", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
|
||||
Stream DownloadReport();
|
||||
}
|
||||
}
|
||||
49
Service/ServiceImplementations/ApiServiceImp.cs
Normal file
49
Service/ServiceImplementations/ApiServiceImp.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Service.ServiceContracts;
|
||||
using BS.Shared.Core;
|
||||
using BS.Shared.DataContracts.AdminService;
|
||||
using BS.Shared.DataContracts.MikePHPContracts;
|
||||
using DevExpress.Pdf.Native.BouncyCastle.Ocsp;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Web;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeWo.Service.ServiceImplementations
|
||||
{
|
||||
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
|
||||
public class ApiServiceImp : IApiService
|
||||
{
|
||||
public ApiResponse<string> Test()
|
||||
{
|
||||
return ApiResponse<string>.SuccessResponse( "Api Service Test erfolgreich!");
|
||||
}
|
||||
|
||||
public ApiResponse<decimal> GetGkvAbrechnungSumme(AdminServiceSumReqDC request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
throw new ArgumentException("request darf nicht null sein");
|
||||
}
|
||||
|
||||
if(!Utils.TryParseISO8601(request.Start, out var start))
|
||||
{
|
||||
throw new ArgumentException("start entspricht nicht ISO8601 Norm.");
|
||||
}
|
||||
|
||||
if (!Utils.TryParseISO8601(request.End, out var end))
|
||||
{
|
||||
throw new ArgumentException("end entspricht nicht ISO8601 Norm.");
|
||||
}
|
||||
|
||||
var sum = DAOFactory.ScriptDAO.GetGkvSumByDateRange(start, end);
|
||||
|
||||
return ApiResponse<decimal>.SuccessResponse(sum ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
Service/ServiceImplementations/ApiStreamServiceImp.cs
Normal file
38
Service/ServiceImplementations/ApiStreamServiceImp.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Service.ServiceContracts;
|
||||
using BS.Shared.Core;
|
||||
using BS.Shared.DataContracts.AdminService;
|
||||
using BS.Shared.DataContracts.MikePHPContracts;
|
||||
using DevExpress.Pdf.Native.BouncyCastle.Ocsp;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Web;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeWo.Service.ServiceImplementations
|
||||
{
|
||||
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
|
||||
public class ApiStreamServiceImp : IApiStreamService
|
||||
{
|
||||
public Stream DownloadReport()
|
||||
{
|
||||
string filename = "xrechnung.pdf";
|
||||
|
||||
string filePath = Path.Combine(@"C:\Users\ownSoft\Desktop\XRechnung\", filename);
|
||||
if (!File.Exists(filePath))
|
||||
throw new FileNotFoundException("Datei nicht gefunden");
|
||||
|
||||
// Setze die Header
|
||||
WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";
|
||||
WebOperationContext.Current.OutgoingResponse.Headers.Add(
|
||||
"Content-Disposition", $"attachment; filename=\"{filename}\"");
|
||||
|
||||
return new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Shared/AppSender/ApiSender.cs
Normal file
12
Shared/AppSender/ApiSender.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BS.Shared.AppSender
|
||||
{
|
||||
public static class ApiSender
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,18 @@ namespace BS.Shared.Core
|
||||
{
|
||||
public string Code { get; set; }
|
||||
public string Message { get; set; }
|
||||
public Dictionary<string, string> Arguments { get; set; }
|
||||
public List<AppError> InnerErrors { get; set; }
|
||||
|
||||
public string Displayname => $"AppError {Code}: {Message}";
|
||||
|
||||
// Private damit zentral alle Errors
|
||||
private AppError(string code, string message)
|
||||
private AppError(string code, string message, Dictionary<string, string> arguments = null, List<AppError> innerErrors = null)
|
||||
{
|
||||
Code = code;
|
||||
Message = message;
|
||||
Arguments = arguments;
|
||||
InnerErrors = innerErrors;
|
||||
}
|
||||
|
||||
//public static readonly AppError Example = new AppError("Code", "Message");
|
||||
|
||||
54
Shared/DataContracts/MikePHPContracts/ApiResponse.cs
Normal file
54
Shared/DataContracts/MikePHPContracts/ApiResponse.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using BS.Shared.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BS.Shared.DataContracts.MikePHPContracts
|
||||
{
|
||||
public class ApiResponse<T>
|
||||
{
|
||||
public T Data { get; set; }
|
||||
|
||||
public List<AppError> Errors { get; set; }
|
||||
|
||||
public List<string> Messages { get; set; }
|
||||
|
||||
public Dictionary<string, object> Meta { get; set; }
|
||||
|
||||
public string TraceId { get; set; }
|
||||
|
||||
public DateTime Timestamp { get; set; } = DateTime.Now;
|
||||
|
||||
public int StatusCode { get; set; } = 200;
|
||||
|
||||
public bool Success => Errors.Count == 0;
|
||||
|
||||
//Factory Methods
|
||||
public static ApiResponse<T> SuccessResponse(T data, List<string> messages = null, Dictionary<string, object> meta = null)
|
||||
{
|
||||
return new ApiResponse<T>
|
||||
{
|
||||
Data = data,
|
||||
Messages = messages ?? new List<string>(),
|
||||
Meta = meta ?? new Dictionary<string, object>(),
|
||||
};
|
||||
}
|
||||
|
||||
public static ApiResponse<T> FailureResponse(List<AppError> errors, int statusCode = 400, string traceId = null)
|
||||
{
|
||||
return new ApiResponse<T>
|
||||
{
|
||||
Errors = errors,
|
||||
StatusCode = statusCode,
|
||||
TraceId = traceId
|
||||
};
|
||||
}
|
||||
|
||||
public static ApiResponse<T> FailureResponse(AppError error, int statusCode = 400, string traceId = null)
|
||||
{
|
||||
return FailureResponse(new List<AppError> { error }, statusCode, traceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,8 +134,8 @@
|
||||
<Reference Include="System.Xaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppSender\ApiSender.cs" />
|
||||
<Compile Include="AppSender\GkvSender.cs" />
|
||||
<Compile Include="AppSender\OwnSoftSender.cs" />
|
||||
<Compile Include="Attributes\RequireNoTenantAttribute.cs" />
|
||||
<Compile Include="Attributes\RequirePermissionAttribute.cs" />
|
||||
<Compile Include="BeWoEntityEnums.cs" />
|
||||
@@ -213,6 +213,7 @@
|
||||
<Compile Include="DataContracts\Invoicing\BankAccountDC.cs" />
|
||||
<Compile Include="DataContracts\Invoicing\XRechnung\XRechnungRequest.cs" />
|
||||
<Compile Include="DataContracts\Invoicing\XRechnung\XRechnungResponse.cs" />
|
||||
<Compile Include="DataContracts\MikePHPContracts\ApiResponse.cs" />
|
||||
<Compile Include="DataContracts\OwnSoftRequest.cs" />
|
||||
<Compile Include="DataContracts\OwnSoftResponse.cs" />
|
||||
<Compile Include="DataContracts\MikePHPContracts\AiMessageRequest2.cs" />
|
||||
|
||||
Reference in New Issue
Block a user