コード例 #1
0
ファイル: H2HService.cs プロジェクト: sachin5284/DotNet
        public override Task MultiDetails(H2HMultiRequest request, IServerStreamWriter <H2HMultiReply> responseStream, ServerCallContext context)
        {
            foreach (var opponent in request.Opponent)
            {
                // Grab raw data to return
                var h2h = GetHeadToHead(request.Player, opponent);

                // Fix data to return (ensure order of player IDs match)
                var item1 = new H2HItem();
                var item2 = new H2HItem();
                if (string.Equals(h2h.Id1, request.Player, StringComparison.InvariantCultureIgnoreCase))
                {
                    item1.Name = h2h.Id1;
                    item1.Won  = (uint)h2h.Record1;
                    item2.Name = h2h.Id2;
                    item2.Won  = (uint)h2h.Record2;
                }
                else
                {
                    item1.Name = h2h.Id2;
                    item1.Won  = (uint)h2h.Record2;
                    item2.Name = h2h.Id1;
                    item2.Won  = (uint)h2h.Record1;
                }

                var reply = new H2HMultiReply {
                    Player1 = item1, Player2 = item2
                };

                // Write back
                responseStream.WriteAsync(reply);
            }

            return(Task.CompletedTask);
        }
コード例 #2
0
ファイル: H2hController.cs プロジェクト: sachin5284/DotNet
        public async Task <IActionResult> Multi(string connId, string p1, string p2, string sender)
        {
            // Call the RPC service
            const string host = "localhost";
            const int    port = 50051;

            var serviceUrl = host + ":" + port;
            var channel    = new Channel(serviceUrl, ChannelCredentials.Insecure);
            var client     = new Tennis.H2H.H2HClient(channel);

            var request = new H2HMultiRequest()
            {
                Player = "F324"
            };

            request.Opponent.Add("W367");
            request.Opponent.AddRange(new[] { "D683", "F510" });

            var model = new H2HMultiViewModel();

            using (var response = client.MultiDetails(request))
            {
                while (await response.ResponseStream.MoveNext())
                {
                    var reply = response.ResponseStream.Current;
                    model.Matches.Add(new PlayerScore(reply.Player1.Name, reply.Player1.Won, reply.Player2.Name, reply.Player2.Won));

                    // SignalR here
                    await _h2hHubContext.Clients.Client(connId).SendAsync("responseReceived",
                                                                          reply.Player1.Name,
                                                                          reply.Player1.Won,
                                                                          reply.Player2.Name,
                                                                          reply.Player2.Won);
                }
            }

            return(View(model));
        }