예제 #1
0
        /// <summary>
        /// Based on the state the controller will act and apply
        /// the logic needed to process the information. After taking action,
        /// it will notify the view of the result.
        /// </summary>
        /// <param name="state">The state passed in</param>
        /// <param name="args">The string associated given the state</param>
        public void InputHandler(State state, String args)
        {
            switch (state)
            {
            case State.START:

                observer(State.START);
                break;

            case State.LOGIN:
                //Call method for validation
                bool valid = ValidateLoginLocally(args);
                if (valid)
                {
                    //Serialize login object
                    AuctionLibrary.Message msg = CreateLoginMessage(args);
                    //Send serialized the object
                    ws.Send("Login#" + SerializeMessage(msg));
                }
                else
                {
                    observer(State.DECLINED);
                }
                break;

            case State.BID:
                bidObservor(State.BID);
                bool validBid = ValidateBidLocally(args);
                if (validBid)
                {
                    //Serialize login object
                    AuctionLibrary.Message msg = CreateBidMessage(args);
                    //Send serialized the object
                    ws.Send("Bid#" + SerializeMessage(msg));
                }
                else
                {
                    bidObservor(State.DECLINED);
                }
                break;

            default:
                break;
            }
        }
예제 #2
0
        private string SerializeMessage(AuctionLibrary.Message msg)
        {
            JSONSerializer serializer = new JSONSerializer(msg);

            return(serializer.SerializeMessage(msg));
        }