134 lines
3.2 KiB
C#
134 lines
3.2 KiB
C#
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.ServiceImplementations;
|
|
using BS.Shared;
|
|
using BS.Shared.AppSender;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.GkvAbrechnung;
|
|
using BS.Shared.Exceptions;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace Host
|
|
{
|
|
public partial class GkvAbrechnungClient : Page
|
|
{
|
|
private readonly string INVALID_INPUT = "Bad Request";
|
|
|
|
private string GkvSecretKey { get; set; } = ConfigurationManager.AppSettings.Get("GkvSecretKey");
|
|
|
|
public GkvClientRequestDC GkvClientRequest { get; set; }
|
|
|
|
public void Sleep() => Thread.Sleep(5000);
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//https://app5.bewoplaner.de/Host/GkvAbrechungServer?tenant=12345
|
|
|
|
var str = new StreamReader(Request.InputStream).ReadToEnd();
|
|
|
|
GkvClientRequest = GkvSender.DeserializeRequest<GkvClientRequestDC>(str, SendInvalidInputResponse);
|
|
|
|
if (GkvSecretKey is null)
|
|
SendErrorResponse(INVALID_INPUT + " 1");
|
|
|
|
if (GkvSecretKey != GkvClientRequest.GkvSecretKey)
|
|
SendErrorResponse(INVALID_INPUT + " 2");
|
|
|
|
if (GkvClientRequest.Tenant is null)
|
|
SendErrorResponse(INVALID_INPUT + " 3");
|
|
|
|
switch (GkvClientRequest.Type)
|
|
{
|
|
case RequestType.GkvClientResult:
|
|
ClientResult(GkvSender.DeserializeRequest<GkvClientResultRequestDC>(str, SendInvalidInputResponse));
|
|
return;
|
|
case RequestType.GkvClientSum:
|
|
ClientSum(GkvSender.DeserializeRequest<GkvClientSumRequest>(str, SendInvalidInputResponse));
|
|
return;
|
|
default:
|
|
SendErrorResponse(INVALID_INPUT + " 4");
|
|
return;
|
|
}
|
|
}
|
|
catch (ThreadAbortException eee)
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var ex_text = $"Msg:{ex.Message}\n\n+Stack:{ex.StackTrace}";
|
|
SendErrorResponse(ex_text);
|
|
}
|
|
}
|
|
|
|
private void ClientResult(GkvClientResultRequestDC req)
|
|
{
|
|
if (req.ResultDCs is null || !req.ResultDCs.Any())
|
|
SendInvalidInputResponse();
|
|
|
|
// Response
|
|
var response = new GkvResponseDC(false);
|
|
|
|
try
|
|
{
|
|
var service = new AccountingServiceImp();
|
|
|
|
service.HandleGkvServerResults(req.ResultDCs);
|
|
|
|
response.Success = true;
|
|
}
|
|
catch (GkvException e)
|
|
{
|
|
response.Message = e.Message;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
response.Message = e.Message;
|
|
}
|
|
|
|
SendResponse(response);
|
|
}
|
|
|
|
private void ClientSum(GkvClientSumRequest req)
|
|
{
|
|
if (req.Start is null || req.End is null || req.Tenant is null)
|
|
SendInvalidInputResponse();
|
|
|
|
var start = req.Start.Value;
|
|
var end = req.End.Value;
|
|
|
|
if (req.Start > req.End)
|
|
SendInvalidInputResponse();
|
|
}
|
|
|
|
#region Senden
|
|
private void SendInvalidInputResponse() => SendErrorResponse(INVALID_INPUT);
|
|
private void SendErrorResponse(string message)
|
|
{
|
|
var response = new GkvResponseDC(false, message);
|
|
|
|
Sleep();
|
|
|
|
SendResponse(GkvSender.SerializeResponse(response));
|
|
}
|
|
private void SendResponse(GkvResponseDC res) => SendResponse(GkvSender.SerializeResponse(res));
|
|
private void SendResponse(string str)
|
|
{
|
|
Response.Write(str);
|
|
|
|
Response.End();
|
|
}
|
|
#endregion
|
|
}
|
|
} |