Newtonsoft.Json.JsonConvert.SerializeObject(object)

Here are the examples of the csharp api Newtonsoft.Json.JsonConvert.SerializeObject(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1206 Examples 7

19 Source : ConfigInfo.cs
with GNU General Public License v2.0
from Cdorey

private string HistoryTaskListToJson()
        {
            return JsonConvert.SerializeObject(HistoryTaskList);
        }

19 Source : Methods.cs
with GNU General Public License v2.0
from Cdorey

private void Send(JsonRpcReq SendMessage)//发消息
        {
            ws.Send(JsonConvert.SerializeObject(SendMessage));
        }

19 Source : Tasks.cs
with GNU General Public License v2.0
from Cdorey

private void Save(Object Sender, EventArgs e)//读写代码有待优化
        {
            if (KickCount <= 60)
            {
                KickCount++;
            }
            else
            {
                lock (HistorayListIsSaving)
                {
                    IList<FinishedTask> Historys = Items;
                    File.WriteAllText(@"HistoryList.log", JsonConvert.SerializeObject(Historys));
                    KickCount = 0;
                }
            }
        }

19 Source : JsonRpcConnection.cs
with GNU General Public License v2.0
from Cdorey

public void Send(Request SendMessage)
            {
                WebSocket.Send(JsonConvert.SerializeObject(SendMessage));
            }

19 Source : HttpContext.cs
with GNU General Public License v3.0
from chenyinxin

public static void Set<T>(this ISession session, string key, T value)
        {
            session.SetString(key, JsonConvert.SerializeObject(value));
        }

19 Source : FaceCompareBLL.cs
with GNU General Public License v3.0
from chenyinxin

public static void AddUserFace(SysUser user)
        {
            DataContext dbContext = new DataContext();

            var faceFeature = FaceCompareHelper.ExtractFeature(HttpContextCore.MapPath(user.UserImage));
            if (string.IsNullOrEmpty(faceFeature))
                return;

            //保存人脸特征
            var feature = dbContext.Set<SysUserFaceFeature>().FirstOrDefault(x => x.UserId == user.UserId);
            if (feature == null)
            {
                feature = new SysUserFaceFeature
                {
                    UserId = user.UserId,
                    UserName = user.UserName,
                    UserType = "User",
                    FaceImage = user.UserImage,
                    FaceFeature = faceFeature,
                    FaceFeatureType = "",
                    FaceTimeOut = DateTime.Now.AddYears(100),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                dbContext.Set<SysUserFaceFeature>().Add(feature);
            }
            else
            {
                feature.UserName = user.UserName;
                feature.FaceImage = user.UserImage;
                feature.FaceFeature = faceFeature;
                feature.UpdateTime = DateTime.Now;
            }

            //更新客户端队列(根据业务修改)
            var data = new Dictionary<string, string>
            {
                ["ActionName"] = "AddFace",
                ["Id"] = user.UserId.ToString(),
                ["Name"] = user.UserName,
                ["ImageUrl"] = user.UserImage,
                ["FaceFeature"] = faceFeature,
                ["TimeOut"] = DateTime.Now.AddYears(100).ToString()
            };

            SysQueue queue = new SysQueue
            {
                Id = Guid.NewGuid(),
                ClientId = user.DepartmentId.ToString(),
                ActionName = "AddFace",
                ActionObjectId = user.UserId.ToString(),
                ActionData = JsonConvert.SerializeObject(data),
                CreateTime = DateTime.Now
            };

            dbContext.Set<SysQueue>().Add(queue);
            dbContext.SaveChanges();
        }

19 Source : FaceCompareBLL.cs
with GNU General Public License v3.0
from chenyinxin

public static void DeleteUserFace(SysUser user)
        {
            DataContext dbContext = new DataContext();

            //更新客户端队列(根据业务修改)
            var data = new Dictionary<string, string>
            {
                ["ActionName"] = "DeleteFace",
                ["Id"] = user.UserId.ToString()
            };

            SysQueue queue = new SysQueue
            {
                Id = Guid.NewGuid(),
                ClientId = user.DepartmentId.ToString(),
                ActionName = "DeleteFace",
                ActionObjectId = user.UserId.ToString(),
                ActionData = JsonConvert.SerializeObject(data),
                CreateTime = DateTime.Now
            };

            dbContext.Set<SysQueue>().Add(queue);
            dbContext.SaveChanges();
        }

19 Source : Handler.cs
with GNU General Public License v3.0
from chenyinxin

protected void WriteJson(object response)
        {
            string jsonpCallback = Context.Request.Query["callback"],
                json = JsonConvert.SerializeObject(response);
            if (String.IsNullOrWhiteSpace(jsonpCallback))
            {
                Response.Headers.Add("Content-Type", "text/plain");
                Response.WriteAsync(json);
            }
            else
            {
                Response.Headers.Add("Content-Type", "application/javascript");
                Response.WriteAsync(String.Format("{0}({1});", jsonpCallback, json));
            }
        }

19 Source : BitNoticeService.cs
with GNU General Public License v3.0
from chenyinxin

public static async Task SendStringAsync(BitNoticeMessage message,bool isLocal=false)
        {
            foreach (var user in sockets)
            {
                if (user.Key != message.Receiver) continue;
                foreach (var socket in user.Value)
                {
                    //LogHelper.SaveLog("WebSockets", string.Format("发送消息:{0}:{1}:{2}:{3}", socket.IsRemote, socket.RemoteIp, socket.RemoteTime, JsonConvert.SerializeObject(message)));
                    if (socket.IsRemote && !isLocal)
                    {//远程通道
                        try
                        {
                            WebClient wc = new WebClient();
                            byte[] sendByte = Encoding.Default.GetBytes(JsonConvert.SerializeObject(message));
                            var url = string.Format("http://{0}:1899/BitService/SendWebSocketString", socket.RemoteIp);
                            //LogHelper.SaveLog("WebSockets", string.Format("发送远程消息:{0}", url));
                            var result = wc.UploadData(url, sendByte);
                            var strResult = Encoding.Default.GetString(result);
                        }
                        catch (Exception ex) { LogHelper.SaveLog(ex); }
                    }
                    else if (socket.WebSocket.State == WebSocketState.Open)
                    {//本地通道
                        await SendStringAsync(socket.WebSocket, JsonConvert.SerializeObject(message), socket.HttpContext.RequestAborted);
                    }
                }
            }
        }

19 Source : DepartmentController.cs
with MIT License
from chi8708

public ActionResult DeptTreeSelect(string selectNode,bool isRequired=true,bool isMul=false) 
        {
            ViewBag.isRequired = isRequired;
            ViewBag.selectNode = selectNode;
            ViewBag.isMul = isMul;
            ViewBag.DeptTreeData =JsonConvert.SerializeObject(GetDeptTreeFSTree());
            return View();
        }

19 Source : FunctionController.cs
with MIT License
from chi8708

public ActionResult FunctionTreeSelect(string selectNode, bool isRequired = true, bool isMul = false)
        {
            ViewBag.isRequired = isRequired;
            ViewBag.selectNode = selectNode;
            ViewBag.isMul = isMul;
            ViewBag.TreeData = JsonConvert.SerializeObject(GetFunctionTreeFSTree());
            return View();
        }

19 Source : WebApiConfig.cs
with MIT License
from chi8708

public void SetValue(object target, object value)
                {

                    //var props = (_MemberInfo.PropertyType).GetProperties();
                    //if (props != null && props.Length > 0)
                    //{
                    //    //解决对象嵌套对象问题
                    //    _MemberInfo.SetValue(target, JsonConvert.DeserializeObject(JsonConvert.SerializeObject(value), _MemberInfo.PropertyType));
                    //}
                    //else
                    //{
                    //    _MemberInfo.SetValue(target, value, null);
                    //}
                    try
                    {
                        _MemberInfo.SetValue(target, JsonConvert.DeserializeObject(JsonConvert.SerializeObject(value), _MemberInfo.PropertyType));
                    }
                    catch (Exception)
                    {
                        _MemberInfo.SetValue(target, value);
                    }

                }

19 Source : Configuracion.cs
with GNU General Public License v3.0
from chilesystems

public void GenerarArchivo()
        {
            File.WriteAllText("configuracion.json", JsonConvert.SerializeObject(this), Encoding.GetEncoding("ISO-8859-1"));
        }

19 Source : ManagedClientTest.cs
with MIT License
from chkr1011

public Task SaveQueuedMessagesAsync(IList<ManagedMqttApplicationMessage> messages)
            {
                File.WriteAllText(Filename, JsonConvert.SerializeObject(messages));
                return Task.FromResult(0);
            }

19 Source : Program.cs
with MIT License
from chkr1011

public Task SaveRetainedMessagesAsync(IList<MqttApplicationMessage> messages)
        {
            var directory = Path.GetDirectoryName(Filename);
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            File.WriteAllText(Filename, JsonConvert.SerializeObject(messages));
            return Task.FromResult(0);
        }

19 Source : DdcClient.cs
with GNU General Public License v2.0
from CHKZL

public void getUrl(string url, string key, out string str)
            {
                try
                {
                    var wc = new WebClient();
                    wc.Headers.Add("Accept: */*");
                    wc.Headers.Add("User-Agent: " + MMPU.UA.Ver.UA());
                    wc.Headers.Add("Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4");
                    if (url.Contains("bilibili"))
                    {
                        if (!string.IsNullOrEmpty(MMPU.Cookie))
                        {
                            wc.Headers.Add("Cookie", MMPU.Cookie);
                        }
                    }
                    //发送HTTP请求
                    byte[] roomHtml = wc.DownloadData(url);
                    JsonTask a = new JsonTask() { key = key, data = Encoding.UTF8.GetString(roomHtml) };
                    JsonConvert.SerializeObject(a);
                    str = JsonConvert.SerializeObject(a);
                }
                catch (Exception)
                {
                    str = null;
                }
              
            }

19 Source : 更新推送.cs
with GNU General Public License v2.0
from CHKZL

public static void 更新提示(更新Info Info)
        {
            if (MMPU.WebhookEnable)
            {
               Webhook.post P = new Webhook.post()
                {
                    jsonParam = JsonConvert.SerializeObject(Info),
                    cmd = "UPDATE"
                };
                do
                {
                    if (P.尝试次数 > 3)
                    {
                        InfoLog.InfoPrintf($"WebHook——{P.cmd}信息发送失败,重试三次均超时,放弃该hook请求;(配置的webhook地址为:{MMPU.WebhookUrl})", InfoLog.InfoClreplaced.下载系统信息);
                        break;
                    }
                    P.hookpost(Info);
                } while (!P.是否成功);
            }
        }

19 Source : RoomInit.cs
with GNU General Public License v2.0
from CHKZL

public static void InitializeRoomList(int roomId, bool Rem,bool Rst)
        {
            InfoLog.InfoPrintf("开始刷新本地房间列表", InfoLog.InfoClreplaced.Debug);
            var rlc = new RoomBox();
            try
            {
                rlc = JsonConvert.DeserializeObject<RoomBox>(ReadConfigFile(RoomConfigFile));
            }
            catch (Exception)
            {
                rlc = JsonConvert.DeserializeObject<RoomBox>("{}");
                InfoLog.InfoPrintf("房间json配置文件格式错误!请检测核对!", InfoLog.InfoClreplaced.系统错误信息);
                InfoLog.InfoPrintf("房间json配置文件格式错误!请检测核对!", InfoLog.InfoClreplaced.系统错误信息);
                InfoLog.InfoPrintf("房间json配置文件格式错误!请检测核对!", InfoLog.InfoClreplaced.系统错误信息);
                return;
            }
            List<RoomCadr> RoomConfigList = new List<RoomCadr>();//房间信息1List
            RoomConfigList = rlc?.data;
            if (RoomConfigList == null)
                RoomConfigList = new List<RoomCadr>();
            bilibili.RoomList.Clear();
            youtube.RoomList.Clear();
            if (初始化储存房间储存一次)
            {
                string JOO = JsonConvert.SerializeObject(rlc);
                MMPU.储存文本(JOO, RoomConfigFile);
                初始化储存房间储存一次 = false;
            }

            foreach (var item in RoomConfigList)
            {
                if (item.Types == "bilibili")
                {
                    //if(首次启动)
                    //{
                       
                    //    BiliWebSocket BWS = new BiliWebSocket();
                    //    BWS.WebSocket(int.Parse(item.RoomNumber));
                    //    biliWebSocket.Add(BWS);
                    //}
                    bilibili.RoomList.Add(new RoomInfo
                    {
                        房间号 = item.RoomNumber,
                        标题 = "",
                        是否录制弹幕 = item.VideoStatus,
                        是否录制视频 = item.VideoStatus,
                        UID = item.UID.ToString(),
                        直播开始时间 = "",
                        名称 = item.Name,
                        直播状态 = item.LiveStatus,
                        原名 = item.OfficialName,
                        是否提醒 = item.RemindStatus,
                        平台="bilibili",
                        Like=item.Like
                    });
                    if (首次启动)
                    {
                        bilibili.RoomList[bilibili.RoomList.Count - 1].直播状态 = false;
                    }
                }
                else if (item.Types == "youtube")
                {

                    youtube.RoomList.Add(new RoomInfo
                    {
                        房间号 = item.RoomNumber,
                        标题 = "",
                        是否录制弹幕 = item.VideoStatus,
                        是否录制视频 = item.VideoStatus,
                        UID = item.UID.ToString(),
                        直播开始时间 = "",
                        名称 = item.Name,
                        直播状态 = item.LiveStatus,
                        原名 = item.OfficialName,
                        是否提醒 = item.RemindStatus,
                        平台="youtube",
                        Like = item.Like
                    });
                    if (首次启动)
                    {
                        youtube.RoomList[youtube.RoomList.Count - 1].直播状态 = false;
                    }
                }
            }
            if (首次启动)
            {
                InfoLog.InfoPrintf("监控列表中有" + (bilibili.RoomList.Count()+ youtube.RoomList.Count()) + "个单推对象,开始监控", InfoLog.InfoClreplaced.下载系统信息);
            }
            首次启动 = false;
            InfoLog.InfoPrintf("刷新本地房间列表完成", InfoLog.InfoClreplaced.Debug);
        }

19 Source : AddMonitoringList.xaml.cs
with GNU General Public License v2.0
from CHKZL

private void BT1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(平台.SelectedItem.ToString()))
                {
                    MessageBox.Show("未选择平台");
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("未选择平台");
                return;
            }
            if (string.IsNullOrEmpty(中文名称.Text) || string.IsNullOrEmpty(平台.SelectedItem.ToString()) || string.IsNullOrEmpty(唯一码.Text))
            {
                MessageBox.Show("不能留空");
                return;
            }
            if (this.replacedle == "添加新单推"|| this.replacedle == "从网络添加房间")
            {
                if (平台.SelectedItem.ToString() == "bilibili")
                {
                    foreach (var item in RoomInit.bilibili房间主表)
                    {
                        if (item.唯一码 == 唯一码.Text)
                        {
                            MessageBox.Show("已存在相同的房间号!\r\n" + item.名称 + " " + item.平台 + " " + item.唯一码);
                            return;
                        }
                    }
                }
                else if(平台.SelectedItem.ToString()=="youtube")
                {
                    foreach (var item in RoomInit.youtube房间主表)
                    {
                        if (item.唯一码 == 唯一码.Text)
                        {
                            MessageBox.Show("已存在相同的房间号!\r\n" + item.名称 + " " + item.平台 + " " + item.唯一码);
                            return;
                        }
                    }
                }
                新增V信息 NEWV = new 新增V信息() { CN_Name = 中文名称.Text, LA_Name = 官方名称.Text, Platform = 平台.SelectedItem.ToString(), GUID = 唯一码.Text };
                NewThreadTask.Run(() =>
                {
                    MMPU.TcpSend(Server.RequestCode.GET_NEW_MEMBER_LIST_CONTENT,
                        JsonConvert.SerializeObject(NEWV), true,50);
                });

                RoomBox rlc = JsonConvert.DeserializeObject<RoomBox>(ReadConfigFile(RoomConfigFile));
                RoomBox RB = new RoomBox();
                RB.data = new List<RoomCadr>();
                if (rlc.data != null)
                {
                    foreach (var item in rlc.data)
                    {
                        RB.data.Add(item);
                        if (RoomInit.根据唯一码获取直播状态(item.RoomNumber))
                        {
                            RB.data[RB.data.Count() - 1].LiveStatus = true;
                        }
                    }
                }
                RB.data.Add(new RoomCadr { Name = 中文名称.Text,RoomNumber = 唯一码.Text, Types = 平台.SelectedItem.ToString(), RemindStatus = false, status = false, VideoStatus = false, OfficialName = 官方名称.Text, LiveStatus = RoomInit.根据唯一码获取直播状态(GUID) });
                string JOO = JsonConvert.SerializeObject(RB);
                MMPU.储存文本(JOO, RoomConfigFile);
                if (平台.SelectedItem.ToString() == "bilibili")
                {
                    InitializeRoomList(int.Parse(唯一码.Text), false, false);
                }
                else
                {
                    InitializeRoomList(0, false, false);
                }

                  

                //更新房间列表(平台.SelectedItem.ToString(), 唯一码.Text,1);
                //MessageBox.Show("添加成功");

            }
            else if(this.replacedle=="修改单推属性")
            {
                新增V信息 NEWV = new 新增V信息() { CN_Name = 中文名称.Text, LA_Name = 官方名称.Text, Platform = 平台.SelectedItem.ToString(), GUID = 唯一码.Text };
                NewThreadTask.Run(() =>
                {
                    MMPU.TcpSend(Server.RequestCode.GET_NEW_MEMBER_LIST_CONTENT,
                        JsonConvert.SerializeObject(NEWV), true,50);
                });

                RoomBox rlc = JsonConvert.DeserializeObject<RoomBox>(ReadConfigFile(RoomConfigFile));
                RoomBox RB = new RoomBox();
                RB.data = new List<RoomCadr>();
                if (rlc.data != null)
                {
                    foreach (var item in rlc.data)
                    {
                        if (item.RoomNumber == GUID)
                        {
                            RB.data.Add(item);
                            RB.data[RB.data.Count - 1].Name = 中文名称.Text;
                            RB.data[RB.data.Count - 1].OfficialName = 官方名称.Text;
                            RB.data[RB.data.Count - 1].Types = 平台.SelectedItem.ToString();
                        }
                        else
                        {
                            RB.data.Add(item);
                            if (RoomInit.根据唯一码获取直播状态(item.RoomNumber))
                            {
                                RB.data[RB.data.Count() - 1].LiveStatus = true;
                            }
                        }
                    }
                }
               
                string JOO = JsonConvert.SerializeObject(RB);
                MMPU.储存文本(JOO, RoomConfigFile);
                InitializeRoomList(0,false, false);
                //var rlc2 = JsonConvert.DeserializeObject<RoomBox>(ReadConfigFile(RoomConfigFile));
                //RoomBox RB = new RoomBox();
                //RB.data = new List<RoomCadr>();
                //int rlclen = 房间主表.Count()-1;
                //int 覆盖的编号 = 0;
                //for (int i =0;i< rlclen; i++)
                //{
                //    if(房间主表[i].唯一码==GUID)
                //    {
                //        覆盖的编号 = i;
                //        //房间主表.Remove(房间主表[i]);
                //        //i--;
                //        RB.data.Add(new RoomCadr { Name = 中文名称.Text, RoomNumber = 唯一码.Text, Types = 平台.SelectedItem.ToString(), RemindStatus = false, status = false, VideoStatus = false, OfficialName = 官方名称.Text,LiveStatus= RoomInit.根据唯一码获取直播状态(GUID) });
                //    }
                //    else
                //    {
                //        RB.data.Add(new RoomCadr(){ LiveStatus= 房间主表[i] .直播状态,Name= 房间主表[i] .名称,OfficialName= 房间主表[i] .原名,RoomNumber= 房间主表[i] .唯一码,VideoStatus= 房间主表[i] .是否录制,Types= 房间主表[i] .平台, RemindStatus= 房间主表[i] .是否提醒,status=false });
                //        if (RoomInit.根据唯一码获取直播状态(房间主表[i].唯一码))
                //        {
                //            RB.data[RB.data.Count() - 1].LiveStatus = true;
                //        }
                //    }
                //}
                //房间主表.Clear();
                //foreach (var item in RB.data)
                //{
                //    房间主表.Add(new RL { 名称=item.Name,原名=item.OfficialName,唯一码=item.RoomNumber,平台=item.Types,是否录制=item.VideoStatus,是否提醒=item.RemindStatus,直播状态=item.LiveStatus});
                //}

                //新增V信息 NEWV = new 新增V信息() { CN_Name = 中文名称.Text, LA_Name = 官方名称.Text, Platform = 平台.SelectedItem.ToString(), GUID = 唯一码.Text };

                //new Task(() => { MMPU.TcpSend(20001, JsonConvert.SerializeObject(NEWV), true); }).Start();
                //string JOO = JsonConvert.SerializeObject(RB);
                //MMPU.储存文本(JOO, RoomConfigFile);
                //InitializeRoomList();
                ////MessageBox.Show("修改成功");

            }
            this.Close();
        }

19 Source : Webhook.cs
with GNU General Public License v2.0
from CHKZL

public static void 开播hook(开播Info Info)
        {
            if (MMPU.WebhookEnable)
            {
                post P = new post()
                {
                    jsonParam = JsonConvert.SerializeObject(Info),
                    cmd= "LIVE"
                };            
                do
                {
                    if (P.尝试次数 > 3)
                    {
                        InfoLog.InfoPrintf($"WebHook——{P.cmd}信息发送失败,重试三次均超时,放弃该hook请求;(配置的webhook地址为:{MMPU.WebhookUrl})", InfoLog.InfoClreplaced.下载系统信息);
                        break;
                    }
                    P.hookpost(Info);
                } while (!P.是否成功);
            }
        }

19 Source : Webhook.cs
with GNU General Public License v2.0
from CHKZL

public static void 下播hook(下播Info Info)
        {
            if (MMPU.WebhookEnable)
            {
                post P = new post()
                {
                    jsonParam = JsonConvert.SerializeObject(Info),
                    cmd = "PREPARING"
                };
                do
                {
                    if (P.尝试次数 > 3)
                    {
                        InfoLog.InfoPrintf($"WebHook——{P.cmd}信息发送失败,重试三次均超时,放弃该hook请求;(配置的webhook地址为:{MMPU.WebhookUrl})", InfoLog.InfoClreplaced.下载系统信息);
                        break;
                    }
                    P.hookpost(Info);
                } while (!P.是否成功);
            }
        }

19 Source : Webhook.cs
with GNU General Public License v2.0
from CHKZL

public void hookpost<T>(T CL)
            {
                try
                {
                    string 版本 = "";
                    if (MMPU.启动模式 == 0)
                    {
                        版本 = MMPU.DDTV版本号;
                    }
                    else if (MMPU.启动模式 == 1)
                    {
                        版本 = MMPU.DDTVLiveRec版本号;
                    }
                    HttpWebRequest request;
                    request = (HttpWebRequest)WebRequest.Create(MMPU.WebhookUrl);
                    request.Method = "POST";
                    request.ContentType = "application/json; charset=UTF-8";
                    request.UserAgent = $"DDTVCore/{版本}";
                    string paraUrlCoded = JsonConvert.SerializeObject(new mess<T>()
                    {
                        cmd = cmd,
                        message = CL,
                        hookTime = DateTime.UtcNow
                    });
                    byte[] payload;
                    payload = Encoding.UTF8.GetBytes(paraUrlCoded);
                    request.ContentLength = payload.Length;
                    Stream writer = request.GetRequestStream();
                    writer.Write(payload, 0, payload.Length);
                    writer.Close();
                    HttpWebResponse resp = (HttpWebResponse)request.GetResponse();

                    if ((int)resp.StatusCode >= 200 && (int)resp.StatusCode < 300)
                    {
                        是否成功 = true;
                        InfoLog.InfoPrintf($"WebHook——{cmd}信息发送完成", InfoLog.InfoClreplaced.下载系统信息);
                    }
                    else
                    {
                        是否成功 = false;
                    }
                }
                catch (Exception)
                {
                    是否成功 = false;
                }
                 尝试次数++;
                Thread.Sleep(5000);
            }

19 Source : RoomInit.cs
with GNU General Public License v2.0
from CHKZL

public static void InitializeRoomList()
        {
            var rlc = new RoomBox();
            rlc = JsonConvert.DeserializeObject<RoomBox>(ReadConfigFile(RoomConfigFile));
            List<RoomCadr> RoomConfigList = new List<RoomCadr>();//房间信息1List
            RoomConfigList = rlc?.data;
            if (RoomConfigList == null)
                RoomConfigList = new List<RoomCadr>();
            bilibili.RoomList.Clear();
            if(初始化储存房间储存一次)
            {
                string JOO = JsonConvert.SerializeObject(rlc);
                MMPU.储存文本(JOO, RoomConfigFile);
                初始化储存房间储存一次 = false;
            }

            foreach (var item in RoomConfigList)
            {
                if (item.Types == "bilibili")
                {

                    bilibili.RoomList.Add(new bilibili.RoomInfo
                    {
                        房间号 = item.RoomNumber,
                        标题 = "",
                        是否录制弹幕 = item.VideoStatus,
                        是否录制视频 = item.VideoStatus,
                        UID = "",
                        直播开始时间 = "",
                        名称 = item.Name,
                        直播状态 = item.LiveStatus,
                        原名 = item.OfficialName,
                        是否提醒=item.RemindStatus
                    });
                    if (首次启动)
                    {
                        bilibili.RoomList[bilibili.RoomList.Count - 1].直播状态 = false;
                    }
                }
            }
            首次启动 = false;
        }

19 Source : WeChatSDK.cs
with MIT License
from cixingguangming55555

private void RequerContactList()
        {
            Dictionary<string, object> _dic = new Dictionary<string, object>();
            _dic.Add("id", getId());
            _dic.Add("type", USER_LIST);
            _dic.Add("content", "user list");
            _dic.Add("wxid", "ROOT");
            //Trace.WriteLine(JsonConvert.SerializeObject(_dic));
            Send(WeChatHelper, JsonConvert.SerializeObject(_dic));
            Trace.WriteLine(String.Format("获取通讯录列表,请求消息内容:[{0}]", JsonConvert.SerializeObject(_dic)));
        }

19 Source : WeChatSDK.cs
with MIT License
from cixingguangming55555

public void SetDebugInfo(Hook_Degbug_flg _flg = Hook_Degbug_flg.on) {
            Dictionary<string, object> _dic = new Dictionary<string, object>();
            _dic.Add("id", getId());
            _dic.Add("type", DEBUG_MESSAGE);
            _dic.Add("content", _flg.ToString());
            _dic.Add("wxid", "ROOT");
            Trace.WriteLine(JsonConvert.SerializeObject(_dic));
            Send(WeChatHelper, JsonConvert.SerializeObject(_dic));
        }

19 Source : WeChatSDK.cs
with MIT License
from cixingguangming55555

public void SendImageMessage(string _wxid, string _imagePath) {
            Dictionary<string, object> _dic = new Dictionary<string, object>();
            _dic.Add("id", getId());
            _dic.Add("type", IMAGE_MESSAGE);
            _dic.Add("content",_imagePath);
            _dic.Add("wxid",_wxid);
            Trace.WriteLine(JsonConvert.SerializeObject(_dic));
            Send(WeChatHelper,JsonConvert.SerializeObject(_dic));
        }

19 Source : WeChatSDK.cs
with MIT License
from cixingguangming55555

public void ChatroomUserList(String _chatroomId=null) {
            Dictionary<string, object> _dic = new Dictionary<string, object>();
            if (_chatroomId is null) {
                _dic.Add("id", getId());
                _dic.Add("type", CHATROOM_USER_LIST);
                _dic.Add("content", "op:list member");
                _dic.Add("wxid", "null");
            }
            else
            {
                _dic.Add("id", getId());
                _dic.Add("type", CHATROOM_USER_NAME);
                _dic.Add("content", _chatroomId);
                _dic.Add("wxid", "ROOT");
            }
            Trace.WriteLine(JsonConvert.SerializeObject(_dic));
            Send(WeChatHelper, JsonConvert.SerializeObject(_dic));
        }

19 Source : WeChatSDK.cs
with MIT License
from cixingguangming55555

private void requestUserInfo(string _wxid = null)
        {
            Dictionary<string, object> _dic = new Dictionary<string, object>();
            if (_wxid == null)
            {
                _dic.Add("id", getId().ToString());
                _dic.Add("type", PERSONAL_INFO);
                _dic.Add("content", "op:personal info");
                _dic.Add("wxid", "ROOT");

            }
            else
            {
                _dic.Add("id", getId().ToString());
                _dic.Add("type", USER_INFO);
                _dic.Add("content", "op:personal detail");
                _dic.Add("wxid", _wxid);

            }
            Trace.WriteLine(JsonConvert.SerializeObject(_dic));
            Send(WeChatHelper, JsonConvert.SerializeObject(_dic));

        }

19 Source : WeChatSDK.cs
with MIT License
from cixingguangming55555

public void SendTextMessage(string wxid="null",string msg="null") {
            Dictionary<string, object> _dic = new Dictionary<string, object>();
            _dic.Add("id", getId());
            _dic.Add("type",TEXT_MESSAGE);
            _dic.Add("content",msg);
            _dic.Add("wxid", wxid);
            Trace.WriteLine(JsonConvert.SerializeObject(_dic));
            Send(WeChatHelper, JsonConvert.SerializeObject(_dic));
        }

19 Source : WeChatSDK.cs
with MIT License
from cixingguangming55555

public void SendAtMessage(string _wxid, string _chatroom, string _msg ) {
            Dictionary<string, object> _dic = new Dictionary<string, object>();
            _dic.Add("id", getId());
            _dic.Add("type", AT_MESSAGE);
            _dic.Add("content", _msg);
            _dic.Add("wxid", _wxid);
            _dic.Add("nickname", this.FindNickNameAtChatroomForId(_wxid,_chatroom));
            _dic.Add("roomid",_chatroom);
            Trace.WriteLine(JsonConvert.SerializeObject(_dic));
            Send(WeChatHelper, JsonConvert.SerializeObject(_dic));
        }

19 Source : Util.cs
with MIT License
from cm-heclouds

public static BodyObj resolveBody(String body, bool encrypted)
        {
            if (string.IsNullOrEmpty(body))
            {
                body = "";
            }
            JObject jsonMsg = JObject.Parse(body);
            var obj = new BodyObj();
            obj.nonce = jsonMsg.GetValue("nonce").ToString();
            obj.msgSignature = jsonMsg.GetValue("msg_signature").ToString();
            if (encrypted)
            {
                if (jsonMsg.GetValue("enc_msg") == null)
                {
                    return null;
                }
                obj.msg = jsonMsg.GetValue("enc_msg");
                obj.msgStr = obj.msg == null ?  "" : obj.msg.ToString();
            }
            else
            {
                if (jsonMsg.GetValue("msg") == null)
                {
                    return null;
                }
                obj.msg = jsonMsg.GetValue("msg");
                obj.msgStr = JsonConvert.SerializeObject(obj.msg);
            }
            return obj;
        }

19 Source : GruntTaskAuthor.cs
with GNU General Public License v3.0
from cobbr

public string ToJson()
        {
            return JsonConvert.SerializeObject(this.ToSerializedGruntTaskAuthor());
        }

19 Source : GruntTaskComponents.cs
with GNU General Public License v3.0
from cobbr

public string ToJson()
        {
            return JsonConvert.SerializeObject(this.ToSerializedReferencereplacedembly());
        }

19 Source : GruntTaskComponents.cs
with GNU General Public License v3.0
from cobbr

public string ToJson()
        {
            return JsonConvert.SerializeObject(this.ToSerializedEmbeddedResource());
        }

19 Source : GruntTask.cs
with GNU General Public License v3.0
from cobbr

public string ToJson()
        {
            return JsonConvert.SerializeObject(this.ToSerializedGruntTask());
        }

19 Source : GruntTaskComponents.cs
with GNU General Public License v3.0
from cobbr

public string ToJson()
        {
            return JsonConvert.SerializeObject(this.ToSerializedReferenceSourceLibrary());
        }

19 Source : GruntTaskOption.cs
with GNU General Public License v3.0
from cobbr

public string ToJson()
        {
            return JsonConvert.SerializeObject(this.ToSerializedGruntTaskOption());
        }

19 Source : ApiClient.cs
with MIT License
from coinapi

public String Serialize(object obj)
        {
            try
            {
                return obj != null ? JsonConvert.SerializeObject(obj) : null;
            }
            catch (Exception e)
            {
                throw new ApiException(500, e.Message);
            }
        }

19 Source : FrmSettings.cs
with Apache License 2.0
from cqjjjzr

private void Settings_FormClosed(object sender, FormClosedEventArgs e)
        {
            var settings = new SettingsObj
            {
                Font = FontSerializationHelper.Serialize(_font),
                Color1 = btnColor1.BackColor,
                Color2 = btnColor2.BackColor,
                BorderColor = btnBorderColor.BackColor,
                GradientType = cbxGradientType.SelectedIndex
            };
            File.WriteAllText(_savePath, JsonConvert.SerializeObject(settings));
        }

19 Source : NeteaseLyrics.cs
with Apache License 2.0
from cqjjjzr

private void SaveSettingsInternal()
        {
            string configPath = Path.Combine(_mbApiInterface.Setting_GetPersistentStoragePath(), ConfigFilename);
            var json = JsonConvert.SerializeObject(_config);
            File.WriteAllText(configPath, json, Encoding.UTF8);
        }

19 Source : StructuredMessage.cs
with MIT License
from craignicholson

public string GetMessage(
            string correlationId,
            string methodName,
            string message = "",
            string error = null,
            string stackTrace = null,
            Exception exception = null,
            object anyObject = null,
            long elapsedMilliseconds = 0)
        {
            StructuredMessage msg = null;
            if (anyObject != null)
            {
                msg = new StructuredMessage
                {
                    CorrelationId = correlationId,
                    MethodName = methodName,
                    Message = message,
                    Error = error,
                    StackTrace = stackTrace,
                    ExceptionReceived = exception,
                    ElapsedMilliseconds = elapsedMilliseconds,
                    LocalDateTime = DateTime.Now,
                    ObjectType = anyObject.GetType(),
                    GenericObject = anyObject
                };
            }
            else
            {
                msg = new StructuredMessage
                {
                    CorrelationId = correlationId,
                    MethodName = methodName,
                    Message = message,
                    Error = error,
                    StackTrace = stackTrace,
                    ExceptionReceived = exception,
                    ElapsedMilliseconds = elapsedMilliseconds,
                    LocalDateTime = DateTime.Now,
                };
            }
            var response = JsonConvert.SerializeObject(msg);
            return response;
        }

19 Source : PortfolioService.cs
with GNU General Public License v3.0
from Crowley2012

public static void Save(string portfolio, List<CoinConfig> coinConfigs)
        {
            portfolio += FILEEXTENSION;

            if (UserConfigService.Encrypted)
                File.WriteAllText(portfolio, EncryptionService.AesEncryptString(JsonConvert.SerializeObject(coinConfigs)));
            else
                File.WriteAllText(portfolio, JsonConvert.SerializeObject(coinConfigs));
        }

19 Source : PortfolioService.cs
with GNU General Public License v3.0
from Crowley2012

public static void ToggleEncryption()
        {
            foreach (var portfolio in GetPortfolios())
                if (UserConfigService.Encrypted)
                    File.WriteAllText(portfolio.FileName, JsonConvert.SerializeObject(LoadEncrypted(portfolio.FileName)));
                else
                    File.WriteAllText(portfolio.FileName, EncryptionService.AesEncryptString(JsonConvert.SerializeObject(LoadUnencrypted(portfolio.FileName))));
        }

19 Source : ColorUtil.cs
with GNU General Public License v3.0
from d8ahazard

public static int FindEdge(int sector) {
			Log.Debug("Finding edge for " + sector);
			SetSystemData();
			if (_deviceMode == DeviceMode.Video || !_useCenter) {
				return sector;
			}

			// First, create arrays of values that are on the edge
			var total = _hCount * _vCount;
			// Increment by 1 to use real numbers, versus array numbers...
			//sector += 1;
			// Corners
			const int br = 1;
			var bl = _hCount;
			var tr = total - _hCount + 1;

			var bottom = new List<int>();
			for (var i = 2; i < _hCount; i++) {
				bottom.Add(i);
			}

			var left = new List<int>();
			for (var i = 2; i < _vCount; i++) {
				left.Add(i * _hCount);
			}

			Log.Debug("Lefts: " + JsonConvert.SerializeObject(left));


			var top = new List<int>();
			for (var i = _hCount * (_vCount - 1) + 2; i < total; i++) {
				top.Add(i);
			}

			var right = new List<int>();
			for (var i = 1; i < _vCount - 1; i++) {
				right.Add(i * _hCount + 1);
			}

			var sectorMap = new Dictionary<int, int>();
			var dIdx = 1;
			sectorMap[1] = dIdx;
			dIdx++;

			foreach (var num in right) {
				sectorMap[num] = dIdx;
				dIdx++;
			}

			sectorMap[tr] = dIdx;
			dIdx++;

			foreach (var num in top) {
				sectorMap[num] = dIdx;
				dIdx++;
			}

			sectorMap[total] = dIdx;
			dIdx++;

			foreach (var num in left.ToArray().Reverse()) {
				sectorMap[num] = dIdx;
				dIdx++;
			}

			sectorMap[bl] = dIdx;
			dIdx++;

			foreach (var num in bottom.ToArray().Reverse()) {
				sectorMap[num] = dIdx;
				dIdx++;
			}


			var lDist = _hCount;
			var rDist = _hCount;
			var tDist = _vCount;
			var bDist = _vCount;

			var ln = 0;
			var rn = 0;
			var bn = 0;
			var tn = 0;


			for (var i = 1; i < _vCount / 2; i++) {
				tn = sector + _hCount * i;
				if (top.Contains(tn)) {
					tDist = i;
				}
			}

			for (var i = 1; i < _vCount / 2; i++) {
				bn = sector - _hCount * i;
				Log.Debug("BN: " + bn);
				if (!bottom.Contains(bn)) {
					continue;
				}

				bDist = i;
				break;
			}

			for (var i = 1; i < _hCount / 2; i++) {
				ln = sector + i;
				if (!left.Contains(ln)) {
					continue;
				}

				lDist = i;
				break;
			}

			for (var i = 1; i < _hCount / 2; i++) {
				rn = sector - i;
				if (!right.Contains(ln)) {
					continue;
				}

				rDist = i;
				break;
			}

			var minH = Math.Min(lDist, rDist);
			var minV = Math.Min(tDist, bDist);
			Log.Debug("SectorMap: " + JsonConvert.SerializeObject(sectorMap));
			foreach (var num in new[] { tr, total, br, bl }) {
				if (sector != num) {
					continue;
				}

				Log.Debug("Sector is in a corner: " + sector);
				return sectorMap[num];
			}

			foreach (var arr in new[] { left, right, top, bottom }) {
				foreach (var num in arr.Where(num => sector == num)) {
					return sectorMap[num];
				}
			}

			// bottom-right
			if (minV == bDist && minH == rDist && minV == minH) {
				return sectorMap[br];
			}


			// Bottom-left
			if (minV == bDist && minH == lDist && minV == minH) {
				return sectorMap[bl];
			}


			// top-left
			if (minV == tDist && minH == lDist && minV == minH) {
				return sectorMap[total];
			}


			// top-right
			if (minV == tDist && minH == rDist && minV == minH) {
				return sectorMap[tr];
			}


			if (minH == rDist && minH < minV) {
				return sectorMap[rn];
			}


			// bottom
			if (minV == bDist && minV < minH) {
				return sectorMap[bn];
			}


			// left
			if (minH == lDist && minH < minV) {
				return sectorMap[ln];
			}


			// top
			if (minV == tDist && minV < minH) {
				return sectorMap[tn];
			}


			return br;
		}

19 Source : ColorService.cs
with GNU General Public License v3.0
from d8ahazard

private async Task Demo(object o, DynamicEventArgs? dynamicEventArgs) {
			await StartStream();
			var ledCount = 300;
			var sectorCount = _systemData.SectorCount;
			try {
				ledCount = _systemData.LedCount;
			} catch (Exception) {
				// ignored 
			}

			var i = 0;
			var cols = ColorUtil.EmptyColors(ledCount);
			var secs = ColorUtil.EmptyColors(sectorCount);
			try {
				while (i < ledCount) {
					var pi = i * 1.0f;
					var progress = pi / ledCount;
					var sector = (int)Math.Round(progress * sectorCount);
					var rCol = ColorUtil.Rainbow(progress);
					cols[i] = rCol;
					if (sector < secs.Length) {
						secs[sector] = rCol;
					}

					try {
						await SendColors(cols, secs, 0, true).ConfigureAwait(false);
					} catch (Exception e) {
						Log.Warning("SEND EXCEPTION: " + JsonConvert.SerializeObject(e));
					}

					i++;
				}
			} catch (Exception f) {
				Log.Warning("Outer demo exception: " + f.Message);
			}

			await Task.Delay(500);
		}

19 Source : MessagesSenderService.cs
with MIT License
from Daniel-Krzyczkowski

public async Task<string> SendMessageAsync(string messageBody)
        {
            try
            {
                var correlationId = Guid.NewGuid().ToString("N");
                var messageToSend = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messageBody));
                var message = new ServiceBusMessage(messageToSend)
                {
                    ContentType = $"{System.Net.Mime.MediaTypeNames.Application.Json};charset=utf-8",
                    CorrelationId = correlationId
                };
                await _serviceBusSender.SendAsync(message);
                return correlationId;
            }

            catch (ServiceBusException ex)
            {
                _logger.LogError($"{nameof(ServiceBusException)} - error details: {ex.Message}");
                throw;
            }
        }

19 Source : ReceivedMessagesProcessor.cs
with MIT License
from Daniel-Krzyczkowski

public async Task ExecuteAsync(CancellationToken stoppingToken, Action<T> callback = null)
        {
            if (callback == null)
            {
                callback = (obj) => _logger.LogInformation(JsonConvert.SerializeObject(obj));
            }

            using (stoppingToken.Register(() =>
                  _logger.LogInformation($"{nameof(ReceivedMessagesProcessor<T>)} background task is stopping."))) ;

            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    var message = await _messagesReceiverService.ReceiveMessageAsync(TimeSpan.FromSeconds(5), stoppingToken);
                    if (message != null)
                    {
                        var body = message.Body.ToArray();
                        callback(_deserializerFactory.Deserialize(message.ContentType, body));
                    }
                }

                catch (Exception ex)
                {
                    _logger.LogError(ex, "A problem occurred while invoking a callback method");
                }
            }

            _logger.LogInformation($"Cancellation token was requested");
        }

19 Source : ExceptionHandlerMiddleware.cs
with GNU General Public License v3.0
from Daniel-Krzyczkowski

public async Task Invoke(HttpContext context)
        {
            try
            {
                await _next(context);
            }

            catch (OperationNotAllowedForAccountTypeException ex)
            {
                LogException(ex);

                var statusCode = HttpStatusCode.InternalServerError;
                var result = JsonConvert.SerializeObject(Errors.User.OperationNotAllowedForSpecificUserProfileType(ex.AccountType));
                context.Response.ContentType = "application/json";
                context.Response.StatusCode = (int)statusCode;
                await context.Response.WriteAsync(result);
            }

            catch (Exception ex)
            {
                LogException(ex);

                var statusCode = HttpStatusCode.InternalServerError;
                var result = JsonConvert.SerializeObject(new Error("Unexpected error has occurred",
                                                "Unfortunately unexpected error has occured. Please try again later"));
                context.Response.ContentType = "application/json";
                context.Response.StatusCode = (int)statusCode;
                await context.Response.WriteAsync(result);
            }
        }

19 Source : UserConfig.cs
with MIT License
from Daniel-Griffiths

private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            //Save updated config object to file (UserConfig.json)
            System.IO.File.WriteAllText(configPath, JsonConvert.SerializeObject(_Config));
        }

19 Source : GamePassCatalogBrowserService.cs
with MIT License
from darklinkpower

public void ProcessGamePreplacedCatalog (List<GamePreplacedCatalogProduct> gamePreplacedCatalog, ProductType gameProductType)
        {
            var idsForDataRequest = new List<string>();
            // Check for games removed from the service
            var gamesRemoved = false;
            foreach (GamePreplacedGame game in gamePreplacedGamesList.ToList())
            {
                if (game.ProductType == ProductType.Game || game.ProductType == ProductType.Collection)
                {
                    if (gameProductType == ProductType.EaGame)
                    {
                        continue;
                    }
                }
                else if (game.ProductType == ProductType.EaGame)
                {
                    if (gameProductType == ProductType.Game)
                    {
                        continue;
                    }
                }

                var gameMatched = false;
                if (game.IsChildProduct == false)
                {
                    gameMatched = gamePreplacedCatalog.Any(x => x.Id == game.ProductId);
                }
                else
                {
                    gameMatched = gamePreplacedCatalog.Any(x => x.Id == game.ParentProductId);
                }

                if (gameMatched == false)
                {
                    var gameFilesPaths = new List<string>()
                    {
                            Path.Combine(imageCachePath, game.BackgroundImage),
                            Path.Combine(imageCachePath, game.CoverImage),
                            Path.Combine(imageCachePath, game.CoverImageLowRes)
                    };
                    if (game.Icon != null)
                    {
                        gameFilesPaths.AddMissing(Path.Combine(imageCachePath, game.Icon));
                    }

                    foreach (string filePath in gameFilesPaths)
                    {
                        DeleteFileFromPath(filePath);
                    }

                    var gameRemoved = false;
                    if (removeExpiredGames == true)
                    {
                        gameRemoved = xboxLibraryHelper.RemoveGamePreplacedGame(game);
                        if (gameRemoved == true)
                        {
                            // Notify user that game has been removed from the library
                            playniteApi.Notifications.Add(new NotificationMessage(
                            Guid.NewGuid().ToString(),
                                $"{game.Name} has been removed from the Game Preplaced catalog and Playnite library",
                                NotificationType.Info));
                        }
                    }
                    else if (addExpiredTagToGames == true)
                    {
                        xboxLibraryHelper.AddExpiredTag(game);
                    }

                    if (notifyCatalogUpdates == true && gameRemoved == false)
                    {
                        // Notify user that game has been removed
                        playniteApi.Notifications.Add(new NotificationMessage(
                        Guid.NewGuid().ToString(),
                            $"{game.Name} has been removed from the Game Preplaced catalog",
                            NotificationType.Info));
                    }

                    gamePreplacedGamesList.Remove(game);
                    gamesRemoved = true;
                }
            }

            if (gamesRemoved == true)
            {
                File.WriteAllText(gameDataCachePath, JsonConvert.SerializeObject(gamePreplacedGamesList));
            }

            foreach (GamePreplacedCatalogProduct gamePreplacedProduct in gamePreplacedCatalog)
            {
                if (gamePreplacedGamesList.Any(x => x.ProductId.Equals(gamePreplacedProduct.Id)) == false)
                {
                    idsForDataRequest.Add(gamePreplacedProduct.Id);
                }
            }

            if (idsForDataRequest.Count > 0)
            {
                var bigIdsParam = string.Join(",", idsForDataRequest);
                string catalogDataApiUrl = string.Format(catalogDataApiBaseUrl, bigIdsParam, countryCode, languageCode);
                try
                {
                    var response = client.GetAsync(string.Format(catalogDataApiUrl));
                    var contents = response.Result.Content.ReadreplacedtringAsync();
                    if (response.Status == TaskStatus.RanToCompletion)
                    {
                        addGamesFromCatalogData(JsonConvert.DeserializeObject<CatalogData>(contents.Result), true, gameProductType, false, string.Empty);
                        File.WriteAllText(gameDataCachePath, JsonConvert.SerializeObject(gamePreplacedGamesList));
                    }
                    else
                    {
                        logger.Info($"Request {catalogDataApiUrl} not completed");
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e, $"Error in ApiRequest {catalogDataApiUrl}");
                }
            }
        }

See More Examples