备份C#两个函数

            #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;
                }
            }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Risehuxyc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值