瀏覽代碼

add tracingheader helper func

master
Savorboard 6 年之前
父節點
當前提交
137af975aa
共有 1 個檔案被更改,包括 18 行新增1 行删除
  1. +18
    -1
      src/DotNetCore.CAP/Infrastructure/Helper.cs

+ 18
- 1
src/DotNetCore.CAP/Infrastructure/Helper.cs 查看文件

@@ -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);


Loading…
取消
儲存