コード例 #1
0
        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);
        }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        private ApplicationInfoCollection ReadStorageInfo()
        {
            String json = File.ReadAllText(this.FilePath);

            return(JsonSerializer.ConvertToObject(json));
        }