本文整理汇总了C#中Microsoft.AspNet.SignalR.Transports.PersistentResponse类的典型用法代码示例。如果您正苦于以下问题:C# PersistentResponse类的具体用法?C# PersistentResponse怎么用?C# PersistentResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PersistentResponse类属于Microsoft.AspNet.SignalR.Transports命名空间,在下文中一共展示了PersistentResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Send
public abstract Task Send(PersistentResponse response);
开发者ID:nonintanon,项目名称:SignalR,代码行数:1,代码来源:ForeverTransport.cs
示例17: OnMessageReceived
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);
}
开发者ID:RyanChristensen,项目名称:SignalR,代码行数:46,代码来源:LongPollingTransport.cs
示例18: AddTransportData
private void AddTransportData(PersistentResponse response)
{
if (_pollDelay != TimeSpan.Zero)
{
response.LongPollDelay = (long)_pollDelay.TotalMilliseconds;
}
}
开发者ID:bestwpw,项目名称:SignalR-Server,代码行数:7,代码来源:LongPollingTransport.cs
示例19: Send
public virtual Task Send(PersistentResponse response)
{
Heartbeat.MarkConnection(this);
if (SendingResponse != null)
{
SendingResponse(response);
}
AddTransportData(response);
return Send((object)response);
}
开发者ID:rustd,项目名称:SignalR,代码行数:13,代码来源:LongPollingTransport.cs
示例20: PopulateResponseState
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);
}
}
开发者ID:Djohnnie,项目名称:Sonarr,代码行数:20,代码来源:Connection.cs
注:本文中的Microsoft.AspNet.SignalR.Transports.PersistentResponse类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论