Represents a response to a connection.
Inheritance: IJsonWritable
Beispiel #1
0
        protected virtual Task <bool> OnMessageReceived(PersistentResponse response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            response.Reconnect = HostShutdownToken.IsCancellationRequested;

            if (IsTimedOut || response.Aborted)
            {
                _busRegistration.Dispose();

                if (response.Aborted)
                {
                    // If this was a clean disconnect raise the event.
                    return(Abort().Then(() => TaskAsyncHelper.False));
                }
            }

            if (response.Terminal)
            {
                // End the request on the terminal response
                _transportLifetime.Complete();

                return(TaskAsyncHelper.False);
            }

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return(Send(response).Then(() => TaskAsyncHelper.True));
        }
            public void GroupTokenIsNotNullWhenGroupsChange()
            {
                var response = new PersistentResponse();
                var groupSet = new DiffSet<string>(new string[] { "a:1", "b:2", "c", "d" });

                groupSet.DetectChanges();

                groupSet.Add("g");

                var serializer = JsonUtility.CreateDefaultSerializer();
                string results = string.Empty;
                var protectedData = new Mock<IProtectedData>();
                protectedData.Setup(m => m.Protect(It.IsAny<string>(), It.IsAny<string>()))
                    .Returns<string, string>((value, purpose) =>
                             {
                                 results = value;
                                 return value;
                             });

                protectedData.Setup(m => m.Unprotect(It.IsAny<string>(), It.IsAny<string>()))
                             .Returns<string, string>((value, purpose) => value);

                Connection.PopulateResponseState(response, groupSet, serializer, protectedData.Object, connectionId: "myconnection");

                Assert.NotNull(response.GroupsToken);
                var parts = response.GroupsToken.Split(new[] { ':' }, 2);
                Assert.Equal(2, parts.Length);
                Assert.Equal("myconnection", parts[0]);
                Assert.True(results.Contains("a:1"));
                Assert.True(results.Contains("b:2"));
                Assert.True(results.Contains("c"));
                Assert.True(results.Contains("d"));
                Assert.True(results.Contains("g"));
            }
 private void AddTransportData(PersistentResponse response)
 {
     if (_pollDelay != TimeSpan.Zero)
     {
         response.LongPollDelay = (long)_pollDelay.TotalMilliseconds;
     }
 }
Beispiel #4
0
            public void GroupTokenIsNotNullWhenGroupsChangeToEmpty()
            {
                var response = new PersistentResponse();
                var groupSet = new DiffSet<string>(new string[] { "b", "d" });

                groupSet.DetectChanges();

                groupSet.Remove("b");
                groupSet.Remove("d");

                var serializer = new Mock<IJsonSerializer>();
                HashSet<string> results = null;
                serializer.Setup(m => m.Serialize(It.IsAny<object>(), It.IsAny<TextWriter>()))
                          .Callback<object, TextWriter>((obj, tw) =>
                          {
                              results = new HashSet<string>((IEnumerable<string>)obj);
                              var jsonNet = new JsonNetSerializer();
                              jsonNet.Serialize(obj, tw);
                          });
                var protectedData = new Mock<IProtectedData>();
                protectedData.Setup(m => m.Protect(It.IsAny<string>(), It.IsAny<string>()))
                    .Returns<string, string>((value, purpose) => value);

                protectedData.Setup(m => m.Unprotect(It.IsAny<string>(), It.IsAny<string>()))
                             .Returns<string, string>((value, purpose) => value);

                Connection.PopulateResponseState(response, groupSet, serializer.Object, protectedData.Object, connectionId: "myconnection");

                Assert.NotNull(response.GroupsToken);
                var parts = response.GroupsToken.Split(new[] { ':' }, 2);
                Assert.Equal(2, parts.Length);
                Assert.Equal("myconnection", parts[0]);
                Assert.Equal(0, results.Count);
            }
Beispiel #5
0
            public void GroupTokenIsNotNullWhenGroupsChange()
            {
                var response = new PersistentResponse();
                var groupSet = new DiffSet<string>(new string[] { "a", "b", "c", "d" });

                groupSet.GetDiff();

                groupSet.Add("g");

                var serializer = new Mock<IJsonSerializer>();
                HashSet<string> results = null;
                serializer.Setup(m => m.Serialize(It.IsAny<object>(), It.IsAny<TextWriter>()))
                          .Callback<object, TextWriter>((obj, tw) => {
                              results = new HashSet<string>((IEnumerable<string>)obj);
                              var jsonNet = new JsonNetSerializer();
                              jsonNet.Serialize(obj, tw);
                          });
                var protectedData = new Mock<IProtectedData>();
                protectedData.Setup(m => m.Protect(It.IsAny<string>(), It.IsAny<string>()))
                    .Returns<string, string>((value, purpose) => value);

                protectedData.Setup(m => m.Unprotect(It.IsAny<string>(), It.IsAny<string>()))
                             .Returns<string, string>((value, purpose) => value);

                Connection.PopulateResponseState(response, groupSet, serializer.Object, protectedData.Object);

                Assert.NotNull(response.GroupsToken);
                Assert.True(results.Contains("a"));
                Assert.True(results.Contains("b"));
                Assert.True(results.Contains("c"));
                Assert.True(results.Contains("d"));
                Assert.True(results.Contains("g"));
            }
Beispiel #6
0
 private static void AddTransportData(PersistentResponse response)
 {
     if (LongPollDelay > 0)
     {
         response.LongPollDelay = LongPollDelay;
     }
 }
Beispiel #7
0
        public Task Send(PersistentResponse response)
        {
            Heartbeat.MarkConnection(this);

            AddTransportData(response);

            return(Send((object)response));
        }
Beispiel #8
0
        protected virtual void OnSendingResponse(PersistentResponse response)
        {
            HeartBeat.MarkConnection(this);

            if (SendingResponse != null)
            {
                SendingResponse(response);
            }
        }
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            var context = new ForeverFrameTransportContext(this, response);

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return(EnqueueOperation(s => PerformSend(s), context));
        }
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            var context = new SendContext(this, response);

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return EnqueueOperation(state => PerformSend(state), context);
        }
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            OutputWriter.Write("<script>r(c, ");
            JsonSerializer.Serialize(response, OutputWriter);
            OutputWriter.Write(");</script>\r\n");
            OutputWriter.Flush();

            return Context.Response.FlushAsync().Catch(IncrementErrorCounters);
        }
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            OutputWriter.Write("<script>r(c, ");
            JsonSerializer.Serialize(response, OutputWriter);
            OutputWriter.Write(");</script>\r\n");
            OutputWriter.Flush();

            return(Context.Response.FlushAsync().Catch(IncrementErrorCounters));
        }
Beispiel #13
0
 private void AddTransportData(PersistentResponse response)
 {
     if (LongPollDelay > 0)
     {
         if (response.TransportData == null)
         {
             response.TransportData = new Dictionary <string, object>();
         }
         response.TransportData["LongPollDelay"] = LongPollDelay;
     }
 }
        public override Task Send(PersistentResponse response)
        {
            Heartbeat.MarkConnection(this);

            AddTransportData(response);

            // This overload is only used in response to /connect, /poll and /reconnect requests,
            // so the response will have already been initialized by ProcessMessages.
            var context = new LongPollingTransportContext(this, response);

            return(EnqueueOperation(state => PerformPartialSend(state), context));
        }
        public virtual Task Send(PersistentResponse response)
        {
            Heartbeat.MarkConnection(this);

            if (SendingResponse != null)
            {
                SendingResponse(response);
            }

            AddTransportData(response);

            return(Send((object)response));
        }
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            return(EnqueueOperation(() =>
            {
                HTMLOutputWriter.WriteRaw("<script>r(c, ");
                JsonSerializer.Serialize(response, HTMLOutputWriter);
                HTMLOutputWriter.WriteRaw(");</script>\r\n");
                HTMLOutputWriter.Flush();

                return Context.Response.FlushAsync();
            }));
        }
        protected override Task <bool> OnMessageReceived(PersistentResponse response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            response.Reconnect = HostShutdownToken.IsCancellationRequested;

            Task task = TaskAsyncHelper.Empty;

            if (response.Aborted)
            {
                // If this was a clean disconnect then raise the event
                task = Abort();
            }

            if (response.Terminal)
            {
                // If the response wasn't sent, send it before ending the request
                if (!_responseSent)
                {
                    // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                    return(task.Then((transport, resp) => transport.Send(resp), this, response)
                           .Then(() =>
                    {
                        _transportLifetime.Complete();

                        return TaskAsyncHelper.False;
                    }));
                }

                // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                return(task.Then(() =>
                {
                    _transportLifetime.Complete();

                    return TaskAsyncHelper.False;
                }));
            }

            // Mark the response as sent
            _responseSent = true;

            // Send the response and return false
            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return(task.Then((transport, resp) => transport.Send(resp), this, response)
                   .Then(() => TaskAsyncHelper.False));
        }
Beispiel #18
0
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            return(EnqueueOperation(() =>
            {
                OutputWriter.Write("data: ");
                JsonSerializer.Serialize(response, OutputWriter);
                OutputWriter.WriteLine();
                OutputWriter.WriteLine();
                OutputWriter.Flush();

                return Context.Response.FlushAsync().Catch(IncrementErrorCounters);
            }));
        }
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            OutputWriter.Write("id: ");
            OutputWriter.Write(response.MessageId);
            OutputWriter.WriteLine();
            OutputWriter.Write("data: ");
            JsonSerializer.Serialize(response, OutputWriter);
            OutputWriter.WriteLine();
            OutputWriter.WriteLine();
            OutputWriter.Flush();

            return Context.Response.FlushAsync().Catch(IncrementErrorCounters);
        }
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            OutputWriter.Write("id: ");
            OutputWriter.Write(response.MessageId);
            OutputWriter.WriteLine();
            OutputWriter.Write("data: ");
            JsonSerializer.Serialize(response, OutputWriter);
            OutputWriter.WriteLine();
            OutputWriter.WriteLine();
            OutputWriter.Flush();

            return(Context.Response.FlushAsync().Catch(IncrementErrorCounters));
        }
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            return EnqueueOperation(() =>
            {
                OutputWriter.Write("data: ");
                JsonSerializer.Serialize(response, OutputWriter);
                OutputWriter.WriteLine();
                OutputWriter.WriteLine();
                OutputWriter.Flush();

                return Context.Response.Flush();
            });
        }
        public void WriteJsonSkipsNullTransportDaa()
        {
            // Arrange
            var writer = new StringWriter();
            var response = new PersistentResponse(m => m.Key == "key2");
            response.Messages = new List<ArraySegment<Message>>();
            response.MessageId = "Baz";
            response.Messages.Add(new ArraySegment<Message>(new[] { new Message("1", "key", "value1"),
                                                                    new Message("1", "key2", "value2") }, 0, 2));

            // Act
            ((IJsonWritable)response).WriteJson(writer);

            // Assert
            Assert.Equal(@"{""C"":""Baz"",""M"":[value1]}", writer.ToString());
        }
            public void GroupTokenIsNullWhenNoGroups()
            {
                var response = new PersistentResponse();
                var groupSet = new DiffSet<string>(new string[] { });
                var serializer = JsonUtility.CreateDefaultSerializer();
                var protectedData = new Mock<IProtectedData>();
                protectedData.Setup(m => m.Protect(It.IsAny<string>(), It.IsAny<string>()))
                    .Returns<string, string>((value, purpose) => value);

                protectedData.Setup(m => m.Unprotect(It.IsAny<string>(), It.IsAny<string>()))
                             .Returns<string, string>((value, purpose) => value);

                Connection.PopulateResponseState(response, groupSet, serializer, protectedData.Object, connectionId: null);

                Assert.Null(response.GroupsToken);
            }
        public void WriteJsonWritesSkipsCommands()
        {
            // Arrange
            var writer = new StringWriter();
            var response = new PersistentResponse(m => false);
            response.Messages = new List<ArraySegment<Message>>();
            response.MessageId = "Baz";
            response.Messages.Add(new ArraySegment<Message>(new[] { new Message("1", "key", "value1") { CommandId = "something"},
                                                                    new Message("1", "key2", "value2") }, 0, 2));

            // Act
            ((IJsonWritable)response).WriteJson(writer);

            // Assert
            Assert.Equal(@"{""C"":""Baz"",""M"":[value2]}", writer.ToString());
        }
Beispiel #25
0
        private static Task <bool> OnMessageReceived(PersistentResponse response, object state)
        {
            var context = (MessageContext)state;

            response.TimedOut = context.Transport.IsTimedOut;

            Task task = TaskAsyncHelper.Empty;

            if (response.Aborted)
            {
                // If this was a clean disconnect then raise the event
                task = context.Transport.Abort();
            }

            if (response.Terminal)
            {
                // If the response wasn't sent, send it before ending the request
                if (!context.ResponseSent)
                {
                    // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                    return(task.Then((ctx, resp) => ctx.Transport.Send(resp), context, response)
                           .Then(() =>
                    {
                        context.Lifetime.Complete();

                        return TaskAsyncHelper.False;
                    }));
                }

                // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                return(task.Then(() =>
                {
                    context.Lifetime.Complete();

                    return TaskAsyncHelper.False;
                }));
            }

            // Mark the response as sent
            context.ResponseSent = true;

            // Send the response and return false
            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return(task.Then((ctx, resp) => ctx.Transport.Send(resp), context, response)
                   .Then(() => TaskAsyncHelper.False));
        }
        public void WriteJsonWritesMessagesThatAreNotExcluded()
        {
            // Arrange
            var writer = new StringWriter();
            var response = new PersistentResponse(m => m.Key == "key2");
            response.Messages = new List<ArraySegment<Message>>();
            response.AddedGroups = new List<string>
            {
                "g1"
            };
            response.MessageId = "Baz";
            response.Messages.Add(new ArraySegment<Message>(new[] { new Message("1", "key", "value1"),
                                                                    new Message("1", "key2", "value2") }, 0, 2));

            // Act
            ((IJsonWritable)response).WriteJson(writer);

            // Assert
            Assert.Equal(@"{""C"":""Baz"",""G"":[""g1""],""M"":[value1]}", writer.ToString());
        }
Beispiel #27
0
            public void GroupTokenIsNullWhenNoNewGroups()
            {
                var response = new PersistentResponse();
                var groupSet = new DiffSet<string>(new string[] { "a", "b", "c" });

                // Get the first diff
                groupSet.GetDiff();

                var serializer = new JsonNetSerializer();
                var protectedData = new Mock<IProtectedData>();
                protectedData.Setup(m => m.Protect(It.IsAny<string>(), It.IsAny<string>()))
                    .Returns<string, string>((value, purpose) => value);

                protectedData.Setup(m => m.Unprotect(It.IsAny<string>(), It.IsAny<string>()))
                             .Returns<string, string>((value, purpose) => value);

                Connection.PopulateResponseState(response, groupSet, serializer, protectedData.Object);

                Assert.Null(response.GroupsToken);
            }
Beispiel #28
0
        private static Task <bool> OnMessageReceived(PersistentResponse response, object state)
        {
            var context = (MessageContext)state;

            response.Reconnect = context.Transport.HostShutdownToken.IsCancellationRequested;

            // If we're telling the client to disconnect then clean up the instantiated connection.
            if (response.Disconnect)
            {
                // Send the response before removing any connection data
                return(context.Transport.Send(response).Then(c => OnDisconnectMessage(c), context)
                       .Then(() => TaskAsyncHelper.False));
            }
            else if (context.Transport.IsTimedOut || response.Aborted)
            {
                context.Registration.Dispose();

                if (response.Aborted)
                {
                    // If this was a clean disconnect raise the event.
                    return(context.Transport.Abort()
                           .Then(() => TaskAsyncHelper.False));
                }
            }

            if (response.Terminal)
            {
                // End the request on the terminal response
                context.Lifetime.Complete();

                return(TaskAsyncHelper.False);
            }

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return(context.Transport.Send(response)
                   .Then(() => TaskAsyncHelper.True));
        }
Beispiel #29
0
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            return(Send((object)response));
        }
Beispiel #30
0
 public override Task Send(PersistentResponse response)
 {
     return(Send((object)response));
 }
Beispiel #31
0
        private PersistentResponse GetResponse(MessageResult result)
        {
            // Do a single sweep through the results to process commands and extract values
            ProcessResults(result);

            Debug.Assert(GetCursor != null, "Unable to resolve the cursor since the method is null");

            // Resolve the cursor
            string id = GetCursor();

            var response = new PersistentResponse(ExcludeMessage)
            {
                MessageId = id,
                Messages = result.Messages,
                Disconnect = _disconnected,
                Aborted = _aborted,
                TotalCount = result.TotalCount,
            };

            PopulateResponseState(response);

            _counters.ConnectionMessagesReceivedTotal.IncrementBy(result.TotalCount);
            _counters.ConnectionMessagesReceivedPerSec.IncrementBy(result.TotalCount);

            return response;
        }
        public Task Send(PersistentResponse response)
        {
            Heartbeat.MarkConnection(this);

            AddTransportData(response);

            return Send((object)response);
        }
 private static void AddTransportData(PersistentResponse response)
 {
     if (LongPollDelay > 0)
     {
         response.LongPollDelay = LongPollDelay;
     }
 }
Beispiel #34
0
        internal static void PopulateResponseState(PersistentResponse response,
                                                   DiffSet<string> groupSet,
                                                   IJsonSerializer serializer,
                                                   IProtectedData protectedData,
                                                   string connectionId)
        {
            bool anyChanges = groupSet.DetectChanges();

            if (anyChanges)
            {
                // Create a protected payload of the sorted list
                IEnumerable<string> groups = groupSet.GetSnapshot();

                // Remove group prefixes before any thing goes over the wire
                string groupsString = connectionId + ':' + serializer.Stringify(PrefixHelper.RemoveGroupPrefixes(groups)); ;

                // The groups token
                response.GroupsToken = protectedData.Protect(groupsString, Purposes.Groups);
            }
        }
        private static void AssertEscaped(ForeverFrameTransport fft, MemoryStream ms, PersistentResponse input, string expectedOutput)
        {
            fft.Send(input).Wait();

            string rawResponse = Encoding.UTF8.GetString(ms.ToArray());

            // Doing contains due to all the stuff that gets sent through the buffer
            Assert.True(rawResponse.Contains(expectedOutput));
        }
        protected override Task<bool> OnMessageReceived(PersistentResponse response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            response.Reconnect = HostShutdownToken.IsCancellationRequested;

            Task task = TaskAsyncHelper.Empty;

            if (response.Aborted)
            {
                // If this was a clean disconnect then raise the event
                task = Abort();
            }

            if (response.Terminal)
            {
                // If the response wasn't sent, send it before ending the request
                if (!_responseSent)
                {
                    // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                    return task.Then((transport, resp) => transport.Send(resp), this, response)
                               .Then(() =>
                               {
                                   _transportLifetime.Complete();

                                   return TaskAsyncHelper.False;
                               });
                }

                // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                return task.Then(() =>
                {
                    _transportLifetime.Complete();

                    return TaskAsyncHelper.False;
                });
            }

            // Mark the response as sent
            _responseSent = true;

            // Send the response and return false
            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return task.Then((transport, resp) => transport.Send(resp), this, response)
                       .Then(() => TaskAsyncHelper.False);
        }
Beispiel #37
0
 protected virtual void OnSendingResponse(PersistentResponse response)
 {
     Heartbeat.MarkConnection(this);
 }
        private static Task<bool> OnMessageReceived(PersistentResponse response, object state)
        {
            var context = (MessageContext)state;

            response.Reconnect = context.Transport.HostShutdownToken.IsCancellationRequested;

            // If we're telling the client to disconnect then clean up the instantiated connection.
            if (response.Disconnect)
            {
                // Send the response before removing any connection data
                return context.Transport.Send(response).Then(c => OnDisconnectMessage(c), context)
                                        .Then(() => TaskAsyncHelper.False);
            }
            else if (context.Transport.IsTimedOut || response.Aborted)
            {
                context.Registration.Dispose();

                if (response.Aborted)
                {
                    // If this was a clean disconnect raise the event.
                    return context.Transport.Abort()
                                            .Then(() => TaskAsyncHelper.False);
                }
            }

            if (response.Terminal)
            {
                // End the request on the terminal response
                context.Lifetime.Complete();

                return TaskAsyncHelper.False;
            }

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return context.Transport.Send(response)
                                    .Then(() => TaskAsyncHelper.True);
        }
Beispiel #39
0
        public virtual Task Send(PersistentResponse response)
        {
            Heartbeat.MarkConnection(this);

            if (SendingResponse != null)
            {
                SendingResponse(response);
            }

            AddTransportData(response);

            return Send((object)response);
        }
Beispiel #40
0
 protected virtual void OnSendingResponse(PersistentResponse response)
 {
     Heartbeat.MarkConnection(this);
 }
Beispiel #41
0
        private PersistentResponse GetResponse(MessageResult result)
        {
            // Do a single sweep through the results to process commands and extract values
            ProcessResults(result);

            Debug.Assert(WriteCursor != null, "Unable to resolve the cursor since the method is null");

            var response = new PersistentResponse(ExcludeMessage, WriteCursor);
            response.Terminal = result.Terminal;

            if (!result.Terminal)
            {
                // Only set these properties if the message isn't terminal
                response.Messages = result.Messages;
                response.Disconnect = _disconnected;
                response.Aborted = _aborted;
                response.TotalCount = result.TotalCount;
            }

            PopulateResponseState(response);

            _counters.ConnectionMessagesReceivedTotal.IncrementBy(result.TotalCount);
            _counters.ConnectionMessagesReceivedPerSec.IncrementBy(result.TotalCount);

            return response;
        }
Beispiel #42
0
 private void PopulateResponseState(PersistentResponse response)
 {
     PopulateResponseState(response, _groups, _serializer, _protectedData, _connectionId);
 }
Beispiel #43
0
        public override Task Send(PersistentResponse response)
        {
            OnSendingResponse(response);

            return Send((object)response);
        }
        private static PersistentResponse GetWrappedResponse(string raw)
        {
            var data = Encoding.Default.GetBytes(raw);
            var message = new Message("foo", "key", new ArraySegment<byte>(data));

            var response = new PersistentResponse
            {
                Messages = new List<ArraySegment<Message>> 
                {
                    new ArraySegment<Message>(new Message[] { message })
                }
            };

            return response;
        }
        public override Task Send(PersistentResponse response)
        {
            Heartbeat.MarkConnection(this);

            AddTransportData(response);

            // This overload is only used in response to /connect, /poll and /reconnect requests,
            // so the response will have already been initialized by ProcessMessages.
            var context = new LongPollingTransportContext(this, response);
            return EnqueueOperation(state => PerformPartialSend(state), context);
        }
        private static Task<bool> OnMessageReceived(PersistentResponse response, object state)
        {
            var context = (MessageContext)state;

            response.Reconnect = context.Transport.HostShutdownToken.IsCancellationRequested;

            Task task = TaskAsyncHelper.Empty;

            if (response.Aborted)
            {
                // If this was a clean disconnect then raise the event
                task = context.Transport.Abort();
            }

            if (response.Terminal)
            {
                // If the response wasn't sent, send it before ending the request
                if (!context.ResponseSent)
                {
                    // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                    return task.Then((ctx, resp) => ctx.Transport.Send(resp), context, response)
                               .Then(() =>
                               {
                                   context.Lifetime.Complete();

                                   return TaskAsyncHelper.False;
                               });
                }

                // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                return task.Then(() =>
                {
                    context.Lifetime.Complete();

                    return TaskAsyncHelper.False;
                });
            }

            // Mark the response as sent
            context.ResponseSent = true;

            // Send the response and return false
            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return task.Then((ctx, resp) => ctx.Transport.Send(resp), context, response)
                       .Then(() => TaskAsyncHelper.False);
        }
 private void AddTransportData(PersistentResponse response)
 {
     if (_pollDelay != TimeSpan.Zero)
     {
         response.LongPollDelay = (long)_pollDelay.TotalMilliseconds;
     }
 }
Beispiel #48
0
 public abstract Task Send(PersistentResponse response);
Beispiel #49
0
        protected virtual void OnSendingResponse(PersistentResponse response)
        {
            HeartBeat.MarkConnection(this);

            if (SendingResponse != null)
            {
                SendingResponse(response);
            }
        }
Beispiel #50
0
 public abstract Task Send(PersistentResponse response);