コード例 #1
0
        public async Task AutoControlClientService()
        {
            var request = new AutoControlRequest()
            {
                Status = StatusEnum.Active, DestinationSystem = SpaceSystemEnum.Hoth
            };

            try
            {
                using (var call = _client.AutoControl(request))
                {
                    Console.WriteLine("Start AutoControl");
                    while (await call.ResponseStream.MoveNext(_tokenSource.Token))
                    {
                        Console.WriteLine($"Speed = {call.ResponseStream.Current.Speed.ToString()}, Distance = {call.ResponseStream.Current.Distance.ToString()}");
                    }
                    Console.WriteLine("End AutoControl");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
コード例 #2
0
        public override async Task AutoControl(AutoControlRequest request, IServerStreamWriter <AutoControlResponse> responseStream, ServerCallContext context)
        {
            var response = new AutoControlResponse()
            {
                Distance = 0, Speed = 0
            };

            try
            {
                if (request.Status == StatusEnum.Active)
                {
                    switch (request.DestinationSystem)
                    {
                    case SpaceSystemEnum.Alderaan:
                        response.Speed    = 1;
                        response.Distance = 50;
                        break;

                    case SpaceSystemEnum.Endor:
                        response.Speed    = 2;
                        response.Distance = 60;
                        break;

                    case SpaceSystemEnum.Hoth:
                        response.Speed    = 4;
                        response.Distance = 80;
                        break;

                    default:
                        response.Speed    = 5;
                        response.Distance = 500;
                        break;
                    }
                    while (response.Distance > 0)
                    {
                        response.Distance -= response.Speed;
                        await Task.Delay(100);

                        await responseStream.WriteAsync(response);
                    }
                }
                else
                {
                    await responseStream.WriteAsync(response);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }