#region NtApp
private static async void NtApp(ref byte[] message, ref int messagebytes, ref AppCache cache)
{
NtApp:
try
{
switch (Nt.GetCmdNo(ref message))
{
case 1://获取Cploar并写缓存
{
//异步
var cpinfos = await DynamicCpolar.GetCpolarInfo();
// 写缓存到文件
CpolarCache cpolarCache = new CpolarCache();
cpolarCache.FurthestUpdate = DynamicCpolar.GetLastUpdateFromCpolarInfp(cpinfos);
cpolarCache.cpolarCache = cpinfos;
var cpjson = JsonConvert.SerializeObject(cpolarCache);
try
{
if (cpjson != null)
File.WriteAllText("./CpolarCache.json.cache", cpjson);//在服务里要用绝对路径
}
catch (Exception ex)
{
#if DEBUG
TempLog.logging(ex.ToString());
#endif
this.logBuffer.Add(new LogContent(LogLevel.Mistake, "写缓存文件错误\"./CpolarCache.json.cache\"", ex));
}
// 将CploarInfo对象序列化成JSON字符串
string jsonString = JsonConvert.SerializeObject(cpinfos);
ASCIIEncoding encod = new ASCIIEncoding();
message = encod.GetBytes(jsonString);
messagebytes = message.Length;
}
break;
case 2:
//读DynamicCpolar缓存文件
{
string jsonStr = string.Empty;
if (File.Exists("./CpolarCache.json.cache"))
{
var cpojson = File.ReadAllText("./CpolarCache.json.cache");
CpolarCache CpolarCache = new CpolarCache();
CpolarCache = JsonConvert.DeserializeObject<CpolarCache>(cpojson);
if (CpolarCache.FurthestUpdate > DateTime.Now.AddHours(-12))
{
// 将CploarInfo对象序列化成JSON字符串
jsonStr = JsonConvert.SerializeObject(CpolarCache.cpolarCache);
ASCIIEncoding encod = new ASCIIEncoding();
message = encod.GetBytes(jsonStr);
messagebytes = message.Length;
}
else
{
goto case 1;
}
}
else
{
goto case 1;
}
}
break;
case 3: //无缓存
{
//异步
var cpinfos = await DynamicCpolar.GetCpolarInfo();
// 将CploarInfo对象序列化成JSON字符串
string jsonString = JsonConvert.SerializeObject(cpinfos);
ASCIIEncoding encod = new ASCIIEncoding();
message = encod.GetBytes(jsonString);
messagebytes = message.Length;
}
break;
}
goto Turn;
}
catch (Exception e)
{
this.logBuffer.Add(new LogContent(LogLevel.Exception, e.Message, e));
goto End;
}
}
#endregion //NtApp
private static void bRB(ref byte[] message, ref int messagebytes, ref AppCache cache)
{
bRBApp:
if (bRB.CheckFlagRB(ref message, messagebytes) == true && messagebytes > 4)
{
byte key = bRB.GetKey(ref message, messagebytes);
#if DEBUG
Console.WriteLine("bRB应用来访");
Console.WriteLine("key:{0}", key);
#endif
byte[] data = new byte[messagebytes - 4];
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(message[i + 4] ^ key);
}
goto End;
}
}