本文整理汇总了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"));
}
示例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"));
}
示例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);
}
示例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);
}
示例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);
}
示例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();
});
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例13: AddTransportData
private static void AddTransportData(PersistentResponse response)
{
if (LongPollDelay > 0)
{
response.LongPollDelay = LongPollDelay;
}
}
示例14: Send
public Task Send(PersistentResponse response)
{
Heartbeat.MarkConnection(this);
AddTransportData(response);
return Send((object)response);
}
示例15: OnSendingResponse
protected virtual void OnSendingResponse(PersistentResponse response)
{
HeartBeat.MarkConnection(this);
if (SendingResponse != null)
{
SendingResponse(response);
}
}