-> Bei neu Ausliefern, vorher alte Tabellen Droppen -> App8 zu App5 Kommunikation und mehr!
143 lines
3.4 KiB
C#
143 lines
3.4 KiB
C#
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BS.Shared;
|
|
using BS.Shared.AppSender;
|
|
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 = "Ungültige Eingabe";
|
|
|
|
private string GkvSecretKey { get; set; } = ConfigurationManager.AppSettings.Get("GkvSecretKey");
|
|
|
|
public GkvRequestDC GkvRequest { 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();
|
|
|
|
GkvRequest = GkvSender.DeserializeRequest<GkvRequestDC>(str, SendInvalidInputResponse);
|
|
|
|
switch (GkvRequest.Type)
|
|
{
|
|
case RequestType.GkvClientResult:
|
|
ClientResult(GkvSender.DeserializeRequest<GkvClientResultRequestDC>(str, SendInvalidInputResponse));
|
|
return;
|
|
default:
|
|
SendErrorResponse("RequestType unbekannt.");
|
|
return;
|
|
}
|
|
}
|
|
catch (ThreadAbortException eee)
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var ex_text = ex.Message + "\n" + ex.StackTrace;
|
|
SendErrorResponse(ex_text);
|
|
}
|
|
}
|
|
|
|
private void ClientResult(GkvClientResultRequestDC req)
|
|
{
|
|
if (GkvSecretKey is null)
|
|
SendErrorResponse(INVALID_INPUT + " 1");
|
|
|
|
if (GkvSecretKey != req.GkvSecretKey)
|
|
SendErrorResponse(INVALID_INPUT + " 2");
|
|
|
|
if (req.ResultDCs is null || !req.ResultDCs.Any())
|
|
SendInvalidInputResponse();
|
|
|
|
// Response
|
|
var response = new GkvResponseDC(false);
|
|
|
|
try
|
|
{
|
|
foreach (var result in req.ResultDCs)
|
|
{
|
|
HandleResult(result);
|
|
}
|
|
|
|
response.Success = true;
|
|
}
|
|
catch (GkvException e)
|
|
{
|
|
response.Message = e.Message;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
response.Message = e.Message;
|
|
}
|
|
|
|
SendResponse(response);
|
|
}
|
|
|
|
private void HandleResult(GkvServerResultDC result)
|
|
{
|
|
var protokoll = DAOFactory.GenericDAO.GetByID<GkvTransferProtokoll>(result.ProtokollOid);
|
|
|
|
protokoll.ResultType = result.ResultType;
|
|
protokoll.Fehlertitel = result.Titel;
|
|
protokoll.Fehlerdatum = result.Datum;
|
|
protokoll.Fehlernachricht = result.Nachricht;
|
|
|
|
switch (result.ResultType)
|
|
{
|
|
case GkvTransferResultType.Success:
|
|
protokoll.SentDakotaSuccess = true;
|
|
break;
|
|
case GkvTransferResultType.FailSoft:
|
|
protokoll.SentApp8Success = false;
|
|
break;
|
|
case GkvTransferResultType.FailFatal:
|
|
protokoll.SentApp8Success = false;
|
|
break;
|
|
case GkvTransferResultType.FailFollowUp:
|
|
protokoll.SentApp8Success = false;
|
|
break;
|
|
}
|
|
|
|
DAOFactory.GenericDAO.Update(protokoll);
|
|
}
|
|
|
|
#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
|
|
}
|
|
} |