public void DeserializeTest() { const string json = "[{\"Name\":\"proc1\",\"PPID\":3333,\"StartTime\":null,\"ActivityTime\":null,\"EndTime\":null,\"IsRunning\":true,\"Modules\":[{\"Name\":\"lib.dll\"}]}]"; ApplicationInfoCollection result = JsonSerializer.ConvertToObject(json); ApplicationInfo info = result.First(); Assert.AreEqual(info.Name, "proc1"); Assert.AreEqual(info.PPID, 3333); bool libExists = info.Modules.Any(item => item.Name == "lib.dll"); bool libIsSingle = info.Modules.Count == 1; Assert.IsTrue(libExists && libIsSingle); }
private bool CheckEndOfMessage(ConnectionInfo client, out ApplicationInfoCollection message) { try { String json = client.LastMessage.ToString(); message = null; if (json.Contains(CommonData.EndOfMessage)) { json = json.Substring(0, json.IndexOf(CommonData.EndOfMessage, System.StringComparison.Ordinal)); message = JsonSerializer.ConvertToObject(json); return(true); } return(false); } catch (Exception) { message = null; return(false); } }
private void SendingCallback(IAsyncResult result) { try { Socket socket = (Socket)result.AsyncState; int bytesSend = socket.EndSend(result); if (bytesSend != 0 && bytesSend == this.buffer.Length) { Console.WriteLine("Сообщение успешно отправлено;"); this.JustConnected = false; String json = Encoding.Unicode.GetString(this.buffer); this.lastSentInfo = JsonSerializer.ConvertToObject(json); } else { Console.WriteLine("Ничего не отправлено!"); } } catch (Exception exc) { Console.WriteLine(exc.Message); } }
private ApplicationInfoCollection ReadStorageInfo() { String json = File.ReadAllText(this.FilePath); return(JsonSerializer.ConvertToObject(json)); }