當前位置: 首頁>>代碼示例>>C#>>正文


C# Transports.PersistentResponse類代碼示例

本文整理匯總了C#中Microsoft.AspNet.SignalR.Transports.PersistentResponse的典型用法代碼示例。如果您正苦於以下問題:C# PersistentResponse類的具體用法?C# PersistentResponse怎麽用?C# PersistentResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PersistentResponse類屬於Microsoft.AspNet.SignalR.Transports命名空間,在下文中一共展示了PersistentResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GroupTokenIsNotNullWhenGroupsChange

            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"));
            }
開發者ID:stirno,項目名稱:SignalR,代碼行數:33,代碼來源:ConnectionFacts.cs

示例2: GroupTokenIsNotNullWhenGroupsChange

            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"));
            }
開發者ID:Choulla-Naresh8264,項目名稱:SignalR,代碼行數:34,代碼來源:ConnectionFacts.cs

示例3: GroupTokenIsNotNullWhenGroupsChangeToEmpty

            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);
            }
開發者ID:hallco978,項目名稱:SignalR,代碼行數:34,代碼來源:ConnectionFacts.cs

示例4: Send

        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);
        }
開發者ID:GaneshBachhao,項目名稱:SignalR,代碼行數:9,代碼來源:ServerSentEventsTransport.cs

示例5: Send

        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);
        }
開發者ID:mmonteleone,項目名稱:SignalR,代碼行數:11,代碼來源:ForeverFrameTransport.cs

示例6: Send

        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();
            });
        }
開發者ID:stirno,項目名稱:SignalR,代碼行數:15,代碼來源:ServerSentEventsTransport.cs

示例7: Send

        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);
        }
開發者ID:TerenceLewis,項目名稱:SignalR,代碼行數:15,代碼來源:ServerSentEventsTransport.cs

示例8: GroupTokenIsNullWhenNoGroups

            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);
            }
開發者ID:Choulla-Naresh8264,項目名稱:SignalR,代碼行數:16,代碼來源:ConnectionFacts.cs

示例9: WriteJsonSkipsNullTransportDaa

        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());
        }
開發者ID:Jozef89,項目名稱:SignalR,代碼行數:16,代碼來源:PersistentResponseFacts.cs

示例10: WriteJsonWritesSkipsCommands

        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());
        }
開發者ID:stirno,項目名稱:SignalR,代碼行數:16,代碼來源:PersistentResponseFacts.cs

示例11: WriteJsonWritesMessagesThatAreNotExcluded

        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());
        }
開發者ID:Jozef89,項目名稱:SignalR,代碼行數:20,代碼來源:PersistentResponseFacts.cs

示例12: GroupTokenIsNullWhenNoNewGroups

            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);
            }
開發者ID:stirno,項目名稱:SignalR,代碼行數:20,代碼來源:ConnectionFacts.cs

示例13: AddTransportData

 private static void AddTransportData(PersistentResponse response)
 {
     if (LongPollDelay > 0)
     {
         response.LongPollDelay = LongPollDelay;
     }
 }
開發者ID:bjarteskogoy,項目名稱:SignalR,代碼行數:7,代碼來源:LongPollingTransport.cs

示例14: Send

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

            AddTransportData(response);

            return Send((object)response);
        }
開發者ID:bjarteskogoy,項目名稱:SignalR,代碼行數:8,代碼來源:LongPollingTransport.cs

示例15: OnSendingResponse

        protected virtual void OnSendingResponse(PersistentResponse response)
        {
            HeartBeat.MarkConnection(this);

            if (SendingResponse != null)
            {
                SendingResponse(response);
            }
        }
開發者ID:nonintanon,項目名稱:SignalR,代碼行數:9,代碼來源:ForeverTransport.cs


注:本文中的Microsoft.AspNet.SignalR.Transports.PersistentResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。