added report about pdq and server disconnect
This commit is contained in:
parent
1c420dd01e
commit
c053868dd3
@ -218,6 +218,7 @@
|
||||
<Reference Include="System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
@ -247,6 +248,7 @@
|
||||
<Compile Include="Client.cs" />
|
||||
<Compile Include="ClientApp.cs" />
|
||||
<Compile Include="ConfigFileParser.cs" />
|
||||
<Compile Include="ErrorLogger.cs" />
|
||||
<Compile Include="ExtraParameter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
26
Client.cs
26
Client.cs
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace Creditcall.ChipDna.Client
|
||||
{
|
||||
@ -470,14 +471,14 @@ namespace Creditcall.ChipDna.Client
|
||||
}
|
||||
}
|
||||
|
||||
private void GetStatus()
|
||||
public Dictionary<string, string> GetStatus()
|
||||
{
|
||||
Console.WriteLine(ParameterKeys.VersionInformation + "\n" + ParameterKeys.ChipDnaStatus + "\n" + ParameterKeys.PaymentDeviceStatus + "\n" + ParameterKeys.RequestQueueStatus + "\n" + ParameterKeys.TmsStatus + "\n" + ParameterKeys.PaymentPlatformStatus);
|
||||
|
||||
var transactionResult = new Dictionary<string, string>();
|
||||
var parameterSet = new ParameterSet();
|
||||
var responseParameter = new List<Parameter>();
|
||||
|
||||
parameterSet.Add(GetExtraParams("GetStatus"));
|
||||
Response response = chipDnaClientLib.GetStatus(GetRequestedParameterSet(parameterSet));
|
||||
Response response = chipDnaClientLib.GetStatus(parameterSet);
|
||||
|
||||
string errors;
|
||||
var serverStatus = (ChipDnaStatus) null;
|
||||
@ -494,6 +495,13 @@ namespace Creditcall.ChipDna.Client
|
||||
{
|
||||
Console.WriteLine(serverStatus);
|
||||
}
|
||||
|
||||
responseParameter = response.ToList();
|
||||
responseParameter.ForEach(parameter =>
|
||||
{
|
||||
transactionResult.Add(parameter.Key, parameter.Value);
|
||||
});
|
||||
return transactionResult;
|
||||
}
|
||||
|
||||
private void GetMerchantData()
|
||||
@ -1451,6 +1459,7 @@ namespace Creditcall.ChipDna.Client
|
||||
|
||||
private void ChipDnaClientLibOnPaymentDeviceAvailabilityChangeEvent(object sender, EventParameters connectionEventArgs)
|
||||
{
|
||||
var transactionResult = new Dictionary<string, string>();
|
||||
var stringBuilder = new StringBuilder();
|
||||
connectionEventArgs.ToList().ForEach(param =>
|
||||
{
|
||||
@ -1467,8 +1476,10 @@ namespace Creditcall.ChipDna.Client
|
||||
else
|
||||
{
|
||||
stringBuilder.Append(string.Format("[{0}]", param.ToString()));
|
||||
}
|
||||
}
|
||||
transactionResult.Add(param.Key, param.Value);
|
||||
});
|
||||
_ = ErrorLogger.SendLogErrorAsync(transactionResult);
|
||||
Console.WriteLine("{0}: {1}", "Payment Device Availability Change Event", stringBuilder);
|
||||
}
|
||||
|
||||
@ -1494,6 +1505,11 @@ namespace Creditcall.ChipDna.Client
|
||||
|
||||
private void ChipDnaClientLibOnErrorEvent(object sender, ClientHelperErrorEventArgs errorEventArgs)
|
||||
{
|
||||
var result = new Dictionary<string, string>
|
||||
{
|
||||
{ ParameterKeys.Errors, errorEventArgs.RaisedException.Message}
|
||||
};
|
||||
_ = ErrorLogger.SendLogErrorAsync(result);
|
||||
PrintErrorEvent(errorEventArgs.RaisedException);
|
||||
}
|
||||
|
||||
|
||||
32
ClientApp.cs
32
ClientApp.cs
@ -76,6 +76,7 @@ namespace Creditcall.ChipDna.Client
|
||||
listener.Prefixes.Add("http://127.0.0.1:18181/start-and-confirm-transaction/");
|
||||
listener.Prefixes.Add("http://127.0.0.1:18181/transaction-information/");
|
||||
listener.Prefixes.Add("http://127.0.0.1:18181/void-transaction/");
|
||||
listener.Prefixes.Add("http://127.0.0.1:18181/chipdna-status/");
|
||||
listener.Start();
|
||||
|
||||
Console.WriteLine("Listening on:");
|
||||
@ -83,6 +84,7 @@ namespace Creditcall.ChipDna.Client
|
||||
Console.WriteLine(" http://127.0.0.1:18181/start-and-confirm-transaction/");
|
||||
Console.WriteLine(" http://127.0.0.1:18181/transaction-information/");
|
||||
Console.WriteLine(" http://127.0.0.1:18181/void-transaction/");
|
||||
Console.WriteLine(" http://127.0.0.1:18181/chipdna-status/");
|
||||
|
||||
while (true)
|
||||
{
|
||||
@ -115,7 +117,10 @@ namespace Creditcall.ChipDna.Client
|
||||
{
|
||||
HandleVoidTransaction(context);
|
||||
}
|
||||
else
|
||||
else if (rawUrl.StartsWith("/chipdna-status", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
HandleGetStatus(context);
|
||||
}
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.Close();
|
||||
@ -134,6 +139,27 @@ namespace Creditcall.ChipDna.Client
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleGetStatus(HttpListenerContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var statusResult = client.GetStatus();
|
||||
var responseSerializer = new XmlSerializer(typeof(SerializableKeyValueList));
|
||||
context.Response.ContentType = "application/xml";
|
||||
var wrappedResult = new SerializableKeyValueList(statusResult);
|
||||
responseSerializer.Serialize(context.Response.OutputStream, wrappedResult);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error in -status: " + ex.Message);
|
||||
context.Response.StatusCode = 500;
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.Response.OutputStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleTransactionInformation(HttpListenerContext context)
|
||||
{
|
||||
try
|
||||
@ -359,10 +385,6 @@ namespace Creditcall.ChipDna.Client
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static string GetAbsolutePath(string fileName)
|
||||
{
|
||||
|
||||
61
ErrorLogger.cs
Normal file
61
ErrorLogger.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Creditcall.ChipDna.Client
|
||||
{
|
||||
public static class ErrorLogger
|
||||
{
|
||||
private static readonly HttpClient httpClient = new HttpClient
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(10)
|
||||
};
|
||||
|
||||
public static async Task SendLogErrorAsync(Dictionary<string, string> statusResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (statusResult == null || statusResult.Count == 0)
|
||||
return;
|
||||
|
||||
var url = "http://127.0.0.1:9091/logerror";
|
||||
|
||||
var wrappedResult = new SerializableKeyValueList(statusResult);
|
||||
var serializer = new XmlSerializer(typeof(SerializableKeyValueList));
|
||||
|
||||
var ns = new XmlSerializerNamespaces();
|
||||
ns.Add(string.Empty, string.Empty);
|
||||
var settings = new XmlWriterSettings
|
||||
{
|
||||
OmitXmlDeclaration = false,
|
||||
Indent = false,
|
||||
Encoding = new UTF8Encoding(false)
|
||||
};
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (var xw = XmlWriter.Create(ms, settings))
|
||||
{
|
||||
serializer.Serialize(xw, wrappedResult, ns);
|
||||
}
|
||||
|
||||
var content = new ByteArrayContent(ms.ToArray());
|
||||
content.Headers.ContentType =
|
||||
new MediaTypeHeaderValue("application/xml");
|
||||
|
||||
await httpClient.PostAsync(url, content);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("SendLogErrorAsync failed: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user