Пример #1
0
 /// <summary>
 /// Gets all features contained within the given bounding rectangle.
 /// </summary>
 public async Task ListFeatures(Rectangle request, Grpc.Core.IServerStreamWriter<Feature> responseStream, Grpc.Core.ServerCallContext context)
 {
     var responses = features.FindAll( (feature) => feature.Exists() && request.Contains(feature.Location) );
     foreach (var response in responses)
     {
         await responseStream.WriteAsync(response);
     }
 }
Пример #2
0
        /// <summary>
        /// Gets all features contained within the given bounding rectangle.
        /// </summary>
        public async Task ListFeatures(Grpc.Core.ServerCallContext context, Rectangle request, Grpc.Core.IServerStreamWriter<Feature> responseStream)
        {
            int left = Math.Min(request.Lo.Longitude, request.Hi.Longitude);
            int right = Math.Max(request.Lo.Longitude, request.Hi.Longitude);
            int top = Math.Max(request.Lo.Latitude, request.Hi.Latitude);
            int bottom = Math.Min(request.Lo.Latitude, request.Hi.Latitude);

            foreach (var feature in features)
            {
                if (!RouteGuideUtil.Exists(feature))
                {
                    continue;
                }

                int lat = feature.Location.Latitude;
                int lon = feature.Location.Longitude;
                if (lon >= left && lon <= right && lat >= bottom && lat <= top)
                {
                    await responseStream.WriteAsync(feature);
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Receives a stream of message/location pairs, and responds with a stream of all previous
 /// messages at each of those locations.
 /// </summary>
 public async Task RouteChat(Grpc.Core.IAsyncStreamReader<RouteNote> requestStream, Grpc.Core.IServerStreamWriter<RouteNote> responseStream, Grpc.Core.ServerCallContext context)
 {
     while (await requestStream.MoveNext())
     {
         var note = requestStream.Current;
         List<RouteNote> prevNotes = AddNoteForLocation(note.Location, note);
         foreach (var prevNote in prevNotes)
         {
             await responseStream.WriteAsync(prevNote);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Receives a stream of message/location pairs, and responds with a stream of all previous
        /// messages at each of those locations.
        /// </summary>
        public async Task RouteChat(Grpc.Core.ServerCallContext context, Grpc.Core.IAsyncStreamReader<RouteNote> requestStream, Grpc.Core.IServerStreamWriter<RouteNote> responseStream)
        {
            while (await requestStream.MoveNext())
            {
                var note = requestStream.Current;
                List<RouteNote> notes = GetOrCreateNotes(note.Location);

                List<RouteNote> prevNotes;
                lock (notes)
                {
                    prevNotes = new List<RouteNote>(notes);
                }

                foreach (var prevNote in prevNotes)
                {
                    await responseStream.WriteAsync(prevNote);
                }                
                
                lock (notes)
                {
                    notes.Add(note);
                }
            }
        }