示例#1
0
    /// <summary>
    /// This method front ends a gRPC client method which makes a call to the remote gRPC server, passing
    /// a SET of RouteNote Message types over an asynchronous STREAM.
    /// SIMULTANEOUSLY, The response from the gRPC server is an asynchronous STREAM of the collected Route Notes.
    /// Essentially - BI-DIRECTIONAL Client and Server STREAMING
    /// </summary>
    public async void RunRouteChat()
    {
        ClearTMPTextChildren();

        //Create bunch of Notes (each note contains a Point, and a Name), that will be
        //sent over via a STREAM
        RouteNote[] notes = new RouteNote[]
        {
            new RouteNote
            {
                Location = new Point {
                    Latitude = 0, Longitude = 1
                },
                Message = "First message",
            },
            new RouteNote
            {
                Location = new Point {
                    Latitude = 0, Longitude = 2
                },
                Message = "Second message",
            },
            new RouteNote
            {
                Location = new Point {
                    Latitude = 0, Longitude = 3
                },
                Message = "Third message",
            },
            new RouteNote
            {
                Location = new Point {
                    Latitude = 0, Longitude = 4
                },
                Message = "Fourth message",
            },
            new RouteNote
            {
                Location = new Point {
                    Latitude = 0, Longitude = 5
                },
                Message = "Fifth message",
            },
            new RouteNote
            {
                Location = new Point {
                    Latitude = 0, Longitude = 6
                },
                Message = "Sixth message",
            }
        };

        await _routeGuideClient.RouteChat(notes);

        Debug.Log("RunRouteChat Finished");
    }
示例#2
0
 /// <summary>
 /// Adds a note for location and returns a list of pre-existing notes for that location (not containing the newly added note).
 /// </summary>
 private List <RouteNote> AddNoteForLocation(Point location, RouteNote note)
 {
     lock (myLock)
     {
         List <RouteNote> notes;
         if (!routeNotes.TryGetValue(location, out notes))
         {
             notes = new List <RouteNote>();
             routeNotes.Add(location, notes);
         }
         var preexistingNotes = new List <RouteNote>(notes);
         notes.Add(note);
         return(preexistingNotes);
     }
 }
示例#3
0
 /// <summary>
 /// Adds a note for location and returns a list of pre-existing notes for that location (not containing the newly added note).
 /// </summary>
 private List<RouteNote> AddNoteForLocation(Point location, RouteNote note)
 {
     lock (myLock)
     {
         List<RouteNote> notes;
         if (!routeNotes.TryGetValue(location, out notes)) {
             notes = new List<RouteNote>();
             routeNotes.Add(location, notes);
         }
         var preexistingNotes = new List<RouteNote>(notes);
         notes.Add(note);
         return preexistingNotes;
     }
 }
示例#4
0
 private RouteNote NewNote(string message, int lat, int lon)
 {
     return(RouteNote.CreateBuilder().SetMessage(message).SetLocation(
                Point.CreateBuilder().SetLatitude(lat).SetLongitude(lat).Build()).Build());
 }
示例#5
0
        public async Task RouteChat()
        {
            try
            {
                using (var call = client.RouteChat())
                {
                    var responseReaderTask = Task.Run(async() =>
                    {
                        while (await call.ResponseStream.MoveNext())
                        {
                            var note = call.ResponseStream.Current;
                            //Log("Got message {0}", note.Datasend.ToStringUtf8());
                            strRpcMessage = string.Format("{0}", note.Datasend.ToStringUtf8());
                        }
                    });

                    string strTemp = "";
                    //FileStream fs = new FileStream("CloudPoint.txt", FileMode.Open);
                    //StreamReader sr = new StreamReader(fs);
                    RouteNote noteSend = new RouteNote();

                    int total    = 0;
                    int iCpyCunt = 0;
                    int index    = 0;
                    int size     = 4096 * 10;

                    //byte[] buffer = new byte[1024];
                    //fs.Read(buffer, index, 4096);
                    byte[] buffer = System.IO.File.ReadAllBytes("CloudPoint.txt");
                    total = buffer.Length;

                    while (total > 0)
                    {
                        byte[] bufWrite;
                        if (total > size)
                        {
                            iCpyCunt = size;
                        }
                        else
                        {
                            iCpyCunt = total;
                        }

                        bufWrite = new byte[iCpyCunt];
                        Array.Copy(buffer, index, bufWrite, 0, iCpyCunt);
                        strTemp           = Encoding.UTF8.GetString(bufWrite);
                        noteSend.Datasend = ByteString.CopyFromUtf8(strTemp);
                        noteSend.Size     = strTemp.Length;
                        await call.RequestStream.WriteAsync(noteSend);

                        total -= iCpyCunt;
                        index += iCpyCunt;
                    }

                    //while ((strTemp = sr.ReadLine()) != null)
                    //{
                    //    noteSend.Datasend = ByteString.CopyFromUtf8(strTemp);
                    //    noteSend.Size = strTemp.Length;
                    //    await call.RequestStream.WriteAsync(noteSend);
                    //}
                    await call.RequestStream.CompleteAsync();

                    await responseReaderTask;
                }
            }
            catch (RpcException e)
            {
                //Log("RPC failed", e);
                throw;
            }
        }