Esempio n. 1
0
        public void SetUp ()
        {
            // Create a response object and get the binary representation of it
            var streamMessage = new StreamMessage ();

            var response1 = new Response ();
            response1.Time = 42;
            response1.Error = "Foo";

            var streamResponse1 = new StreamResponse (1263);
            streamResponse1.Response = response1;

            var response2 = new Response ();
            response2.Time = 123;
            response2.Error = "Bar";

            var streamResponse2 = new StreamResponse (3443);
            streamResponse2.Response = response2;

            streamMessage.Responses.Add (streamResponse1);
            streamMessage.Responses.Add (streamResponse2);

            expectedMessage = streamMessage;
            using (var stream = new MemoryStream ()) {
                expectedMessage.ToProtobufMessage ().WriteDelimitedTo (stream);
                messageBytes = stream.ToArray ();
            }
        }
Esempio n. 2
0
        void StreamServerUpdate ()
        {
            streamTimer.Reset ();
            streamTimer.Start ();
            uint rpcsExecuted = 0;

            for (int i = 0; i < servers.Count; i++)
                servers [i].StreamServer.Update ();

            // Run streaming requests
            if (streamRequests.Count > 0) {
                foreach (var entry in streamRequests) {
                    var streamClient = entry.Key;
                    var id = streamClient.Guid;
                    var requests = entry.Value;
                    if (requests.Count == 0)
                        continue;
                    if (!rpcClients.ContainsKey (id))
                        continue;
                    CallContext.Set (rpcClients [id]);
                    var streamMessage = new StreamMessage ();
                    foreach (var request in requests) {
                        // Run the RPC
                        Response response;
                        try {
                            response = KRPC.Service.Services.Instance.HandleRequest (request.Procedure, request.Arguments);
                        } catch (RPCException e) {
                            response = new Response ();
                            response.HasError = true;
                            response.Error = e.ToString ();
                        } catch (YieldException e) {
                            //FIXME: handle yields correctly
                            response = new Response ();
                            response.HasError = true;
                            response.Error = e.ToString ();
                        }
                        rpcsExecuted++;
                        // Don't send an update if it is the previous one
                        //FIXME: does the following comparison work?!? The objects have not been serialized
                        if (response.ReturnValue == streamResultCache [request.Identifier])
                            continue;
                        // Add the update to the response message
                        streamResultCache [request.Identifier] = response.ReturnValue;
                        response.Time = GetUniversalTime ();
                        var streamResponse = request.Response;
                        streamResponse.Response = response;
                        streamMessage.Responses.Add (streamResponse);
                    }
                    if (streamMessage.Responses.Count > 0)
                        streamClient.Stream.Write (streamMessage);
                }
            }

            streamTimer.Stop ();
            StreamRPCs = rpcsExecuted;
            StreamRPCsExecuted += rpcsExecuted;
            TimePerStreamUpdate = (float)streamTimer.ElapsedSeconds ();
        }
Esempio n. 3
0
 public override void Write (StreamMessage value)
 {
     codedOutputStream.WriteMessage (value.ToProtobufMessage ());
     codedOutputStream.Flush ();
 }