Beispiel #1
0
        public static CommunicationData Decode(string json)
        {
            CommunicationData data = new CommunicationData();

            data = JsonConvert.DeserializeObject <CommunicationData>(json);
            return(data);
        }
Beispiel #2
0
        private bool Execute()
        {
            string jsonData = ReciveFromClient();

            Debug.WriteLine(jsonData);
            if (jsonData == null)
            {
                return(false);
            }

            CommunicationData recivedData = ServerUtilities.Decode(jsonData);

            switch (recivedData.Action)
            {
            case "ExecuteCommand":
                switch (recivedData.Data.Trim().ToLower())
                {
                case "exit":
                    Close();
                    return(false);

                case "servertime":
                    int serverTime = ServerUtilities.Time;
                    SendToClient(new CommunicationData("OutPutMessage", "Server time: " + serverTime).Encode());
                    break;

                case "updateclientstest":
                    ServerUtilities.AuctionList[0].Notify();
                    break;

                default:
                    SendToClient(new CommunicationData("OutPutMessage", "Invalid command.").Encode());
                    break;
                }
                break;

            case "Bid":
                double x = 0;
                if (double.TryParse(recivedData.Data, out x))
                {
                    ServerUtilities.AuctionList[0].CheckNewBid(x, Name);
                }
                else
                {
                    SendToClient(new CommunicationData("OutPutMessage", "Invalid syntax").Encode());
                }
                break;

            case "SetClientName":
                Name = recivedData.Data;
                SendToClient(new CommunicationData("OutPutMessage", "You are signed in as - " + recivedData.Data + Environment.NewLine + "To exit type: exit").Encode());
                break;

            default:
                Console.WriteLine("Invalid action recived.");
                break;
            }
            return(true);
        }