public static CommunicationData Decode(string json) { CommunicationData data = new CommunicationData(); data = JsonConvert.DeserializeObject <CommunicationData>(json); return(data); }
public void Listener() { bool keepGoing = true; while (keepGoing) { string jsonData = RecieveFromServer(); if (jsonData == null) { keepGoing = false; } else { CommunicationData recivedData = Utilities.Decode(jsonData); switch (recivedData.Action) { case "OutPutMessage": Console.WriteLine(recivedData.Data); break; case "AddAuctionToList": Auction auction = JsonConvert.DeserializeObject <Auction>(recivedData.Data); if (Utilities.AuctionList.Count > 0) { int index = Utilities.AuctionList.FindIndex(a => a.ID == auction.ID); if (index != -1) { Utilities.AuctionList[index] = auction; } else { Utilities.AuctionList.Add(auction); } } break; default: Debug.WriteLine("Recived invalid action."); break; } } } }