Ver a proveniência

add tracingheader helper func

master
Savorboard há 6 anos
ascendente
cometimento
9d0a453a0c
1 ficheiros alterados com 18 adições e 1 eliminações
  1. +18
    -1
      src/DotNetCore.CAP/Infrastructure/Helper.cs

+ 18
- 1
src/DotNetCore.CAP/Infrastructure/Helper.cs Ver ficheiro

@@ -4,6 +4,7 @@
using System;
using System.ComponentModel;
using System.Reflection;
using DotNetCore.CAP.Diagnostics;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

@@ -48,7 +49,7 @@ namespace DotNetCore.CAP.Infrastructure
public static long ToTimestamp(DateTime value)
{
var elapsedTime = value - Epoch;
return (long) elapsedTime.TotalSeconds;
return (long)elapsedTime.TotalSeconds;
}


@@ -90,6 +91,12 @@ namespace DotNetCore.CAP.Infrastructure
return AddJsonProperty(json, "ExceptionMessage", jObject);
}

public static string AddTracingHeaderProperty(string json, TracingHeaders headers)
{
var jObject = ToJObject(headers);
return AddJsonProperty(json, "TracingHeaders", jObject);
}

public static bool IsInnerIP(string ipAddress)
{
bool isInnerIp;
@@ -156,6 +163,16 @@ namespace DotNetCore.CAP.Infrastructure
});
}

private static JObject ToJObject(TracingHeaders headers)
{
var jobj = new JObject();
foreach (var keyValuePair in headers)
{
jobj[keyValuePair.Key] = keyValuePair.Value;
}
return jobj;
}

private static string AddJsonProperty(string json, string propertyName, JObject propertyValue)
{
var jObj = JObject.Parse(json);


Carregando…
Cancelar
Guardar