예제 #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetTablesResponse response = new GetTablesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("TableList", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Table, TableUnmarshaller>(TableUnmarshaller.Instance);
                    response.TableList = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
예제 #2
0
        /// <summary>
        /// Display messages and peform any actions
        /// </summary>
        /// <param name="composite"></param>
        public void ProcessMessage(CompositeType composite)
        {
            IRequest request = Newtonsoft.Json.JsonConvert.DeserializeObject <RPCRequest>(composite.Message);

            this.InComingRequests.Add(request);
            this.LastMessage = composite.Message;

            switch (request.Method)
            {
            case "NewPeer":
                NewPeerRequest newPeer = Newtonsoft.Json.JsonConvert.DeserializeObject <NewPeerRequest>(request.Params.ToString());
                NetworkPlayers.Add(newPeer.Player);

                break;

            case "NewTable":     //Peer has announced a new table

                BitPoker.Models.Contracts.Table newTable = Newtonsoft.Json.JsonConvert.DeserializeObject <BitPoker.Models.Contracts.Table>(request.Params.ToString());
                TableViewModel newTableViewModel         = new TableViewModel(newTable);
                //this.Tables.Add(newTableViewModel);

                break;

            case "GetTables":     //Give me your tables

                using (BitPoker.Repository.ITableRepository tableRepo = new BitPoker.Repository.LiteDB.TableRepository("data.db"))
                {
                    IEnumerable <BitPoker.Models.Contracts.Table> tables = tableRepo.All();

                    //now send
                    IResponse response = new RPCResponse()
                    {
                        Id     = request.Id,
                        Result = tables
                    };

                    this.SentRequests.Add(request);
                    Backend.SendResponse(response);

                    break;
                }

            case "GetTablesResponse":     //Add resultant tables
                GetTablesResponse tableResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <GetTablesResponse>(request.Params.ToString());

                foreach (BitPoker.Models.Contracts.Table table in tableResponse.Tables)
                {
                    //TableViewModel tableViewModel = new TableViewModel(table);
                    this.Tables.Add(table);
                }

                break;

            case "ActionMessage":
                ActionMessage actionMessage = Newtonsoft.Json.JsonConvert.DeserializeObject <ActionMessage>(request.Params.ToString());

                //actionMessage.HandId;

                break;
            }
        }