本文整理汇总了C#中ConnectionMetadata类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionMetadata类的具体用法?C# ConnectionMetadata怎么用?C# ConnectionMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionMetadata类属于命名空间,在下文中一共展示了ConnectionMetadata类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AddConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
bool isNewConnection = true;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
oldMetadata = old;
return newMetadata;
});
if (oldMetadata != null)
{
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
oldMetadata.Connection.End();
// If we have old metadata this isn't a new connection
isNewConnection = false;
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
// Set the keep alive time
newMetadata.UpdateKeepAlive(_configurationManager.KeepAlive);
return isNewConnection;
}
开发者ID:klintz,项目名称:SignalR,代码行数:34,代码来源:TransportHeartBeat.cs
示例2: AddOrUpdateConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public ITrackingConnection AddOrUpdateConnection(ITrackingConnection connection)
{
if (connection == null)
{
throw new ArgumentNullException("connection");
}
var newMetadata = new ConnectionMetadata(connection);
bool isNewConnection = true;
ITrackingConnection oldConnection = null;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
Logger.LogVerbose(String.Format("Connection {0} exists. Closing previous connection.", old.Connection.ConnectionId));
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
old.Connection.ApplyState(TransportConnectionStates.Replaced);
// Don't bother disposing the registration here since the token source
// gets disposed after the request has ended
old.Connection.End();
// If we have old metadata this isn't a new connection
isNewConnection = false;
oldConnection = old.Connection;
return newMetadata;
});
if (isNewConnection)
{
Logger.LogInformation(String.Format("Connection {0} is New.", connection.ConnectionId));
connection.IncrementConnectionsCount();
}
lock (_counterLock)
{
_counters.ConnectionsCurrent.RawValue = _connections.Count;
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
newMetadata.Connection.ApplyState(TransportConnectionStates.Added);
return oldConnection;
}
开发者ID:bestwpw,项目名称:SignalR-Server,代码行数:52,代码来源:TransportHeartBeat.cs
示例3: AddConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
bool isNewConnection = true;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
oldMetadata = old;
return newMetadata;
});
if (oldMetadata != null)
{
Trace.TraceInformation("Connection exists. Closing previous connection. Old=({0}, {1}) New=({2})", oldMetadata.Connection.IsAlive, oldMetadata.Connection.Url, connection.Url);
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
oldMetadata.Connection.End();
// If we have old metadata this isn't a new connection
isNewConnection = false;
}
else
{
Trace.TraceInformation("Connection is New=({0}).", connection.Url);
}
lock (_counterLock)
{
_counters.ConnectionsCurrent.RawValue = _connections.Count;
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
// Set the keep alive time
newMetadata.UpdateKeepAlive(_configurationManager.KeepAlive);
return isNewConnection;
}
开发者ID:neiz,项目名称:SignalR,代码行数:45,代码来源:TransportHeartBeat.cs
示例4: AddConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
_trace.Source.TraceInformation("TransportHeartBeat: Adding connection {0}", connection.ConnectionId);
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
bool isNewConnection = true;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
oldMetadata = old;
return newMetadata;
});
if (oldMetadata != null)
{
_trace.Source.TraceInformation("TransportHeartBeat: Connection {0} already exists and alive={1}. Closing previous connection id.", oldMetadata.Connection.ConnectionId, oldMetadata.Connection.IsAlive);
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
oldMetadata.Connection.End();
// If we have old metadata this isn't a new connection
isNewConnection = false;
}
else
{
_trace.Source.TraceInformation("TransportHeartBeat: Connection {0} is new.", connection.ConnectionId);
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
// Set the keep alive time
newMetadata.UpdateKeepAlive(_configurationManager.KeepAlive);
return isNewConnection;
}
开发者ID:rmarinho,项目名称:SignalR,代码行数:42,代码来源:TransportHeartBeat.cs
示例5: RaiseTimeout
private bool RaiseTimeout(ConnectionMetadata metadata)
{
// The connection already timed out so do nothing
if (metadata.Connection.IsTimedOut)
{
return false;
}
TimeSpan? keepAlive = _configurationManager.KeepAlive;
// If keep alive is configured and the connection supports keep alive
// don't ever time out
if (keepAlive != null && metadata.Connection.SupportsKeepAlive)
{
return false;
}
TimeSpan elapsed = DateTime.UtcNow - metadata.Initial;
// Only raise timeout if we're past the configured connection timeout.
return elapsed >= _configurationManager.ConnectionTimeout;
}
开发者ID:neiz,项目名称:SignalR,代码行数:21,代码来源:TransportHeartBeat.cs
示例6: RaiseKeepAlive
private bool RaiseKeepAlive(ConnectionMetadata metadata)
{
TimeSpan? keepAlive = _configurationManager.KeepAlive;
if (keepAlive == null)
{
return false;
}
// Raise keep alive if the keep alive value has passed
return DateTime.UtcNow >= metadata.KeepAliveTime;
}
开发者ID:neiz,项目名称:SignalR,代码行数:12,代码来源:TransportHeartBeat.cs
示例7: CheckTimeoutAndKeepAlive
private void CheckTimeoutAndKeepAlive(ConnectionMetadata metadata)
{
if (RaiseTimeout(metadata))
{
// If we're past the expiration time then just timeout the connection
metadata.Connection.Timeout();
RemoveConnection(metadata.Connection);
}
else
{
// The connection is still alive so we need to keep it alive with a server side "ping".
// This is for scenarios where networing hardware (proxies, loadbalancers) get in the way
// of us handling timeout's or disconnects gracefully
if (RaiseKeepAlive(metadata))
{
metadata.Connection.KeepAlive().Catch();
metadata.UpdateKeepAlive(_configurationManager.KeepAlive);
}
MarkConnection(metadata.Connection);
}
}
开发者ID:neiz,项目名称:SignalR,代码行数:23,代码来源:TransportHeartBeat.cs
示例8: CheckTimeoutAndKeepAlive
private void CheckTimeoutAndKeepAlive(ConnectionMetadata metadata)
{
if (RaiseTimeout(metadata))
{
RemoveConnection(metadata.Connection);
// If we're past the expiration time then just timeout the connection
metadata.Connection.Timeout();
// End the connection
metadata.Connection.End();
}
else
{
// The connection is still alive so we need to keep it alive with a server side "ping".
// This is for scenarios where networking hardware (proxies, loadbalancers) get in the way
// of us handling timeout's or disconnects gracefully
if (RaiseKeepAlive(metadata))
{
Trace.TraceInformation("KeepAlive(" + metadata.Connection.ConnectionId + ")");
// If the keep alive send fails then kill the connection
metadata.Connection.KeepAlive()
.Catch(ex =>
{
Trace.TraceInformation("Failed to send keep alive: " + ex.GetBaseException());
RemoveConnection(metadata.Connection);
metadata.Connection.End();
});
metadata.UpdateKeepAlive(_configurationManager.KeepAlive);
}
MarkConnection(metadata.Connection);
}
}
开发者ID:rustd,项目名称:SignalR,代码行数:38,代码来源:TransportHeartBeat.cs
示例9: RaiseKeepAlive
private bool RaiseKeepAlive(ConnectionMetadata metadata)
{
var keepAlive = _configurationManager.KeepAlive;
// Don't raise keep alive if it's set to 0 or the transport doesn't support
// keep alive
if (keepAlive == null || !metadata.Connection.SupportsKeepAlive)
{
return false;
}
// Raise keep alive if the keep alive value has passed
return _heartbeatCount % (ulong)ConfigurationExtensions.HeartBeatsPerKeepAlive == 0;
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:14,代码来源:TransportHeartBeat.cs
示例10: CheckDisconnect
private void CheckDisconnect(ConnectionMetadata metadata)
{
try
{
if (RaiseDisconnect(metadata))
{
// Remove the connection from the list
RemoveConnection(metadata.Connection);
// Fire disconnect on the connection
metadata.Connection.Disconnect();
}
}
catch (Exception ex)
{
// Swallow exceptions that might happen during disconnect
Trace.TraceEvent(TraceEventType.Error, 0, "Raising Disconnect failed: {0}", ex);
}
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:19,代码来源:TransportHeartBeat.cs
示例11: CheckDisconnect
private void CheckDisconnect(ConnectionMetadata metadata)
{
try
{
if (RaiseDisconnect(metadata))
{
// Remove the connection from the list
RemoveConnection(metadata.Connection);
// Fire disconnect on the connection
metadata.Connection.Disconnect();
}
}
catch (Exception ex)
{
// Swallow exceptions that might happen during disconnect
Logger.LogError(String.Format("Raising Disconnect failed: {0}", ex));
}
}
开发者ID:REALTOBIZ,项目名称:SignalR-Server,代码行数:19,代码来源:TransportHeartBeat.cs
示例12: CheckDisconnect
private void CheckDisconnect(ConnectionMetadata metadata)
{
try
{
if (RaiseDisconnect(metadata))
{
// Remove the connection from the list
RemoveConnection(metadata.Connection);
// Fire disconnect on the connection
metadata.Connection.Disconnect();
}
}
catch (Exception ex)
{
// Swallow exceptions that might happen during disconnect
_trace.Source.TraceInformation("TransportHeartBeat: Raising Disconnect failed: {0}", ex);
}
}
开发者ID:rmarinho,项目名称:SignalR,代码行数:19,代码来源:TransportHeartBeat.cs
示例13: AddConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
if (connection == null)
{
throw new ArgumentNullException("connection");
}
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
bool isNewConnection = true;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
oldMetadata = old;
return newMetadata;
});
if (oldMetadata != null)
{
Trace.TraceInformation("Connection {0} exists. Closing previous connection.", oldMetadata.Connection.ConnectionId);
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
// Don't bother disposing the registration here since the token source
// gets disposed after the request has ended
EndConnection(oldMetadata, disposeRegistration: false);
// If we have old metadata this isn't a new connection
isNewConnection = false;
}
else
{
Trace.TraceInformation("Connection {0} is New.", connection.ConnectionId);
}
lock (_counterLock)
{
_counters.ConnectionsCurrent.RawValue = _connections.Count;
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
// Register for disconnect cancellation
newMetadata.Registration = connection.CancellationToken.SafeRegister(OnConnectionEnded, newMetadata);
return isNewConnection;
}
开发者ID:stirno,项目名称:SignalR,代码行数:53,代码来源:TransportHeartBeat.cs
示例14: CheckTimeoutAndKeepAlive
private void CheckTimeoutAndKeepAlive(ConnectionMetadata metadata)
{
if (RaiseTimeout(metadata))
{
// If we're past the expiration time then just timeout the connection
metadata.Connection.Timeout();
EndConnection(metadata);
}
else
{
// The connection is still alive so we need to keep it alive with a server side "ping".
// This is for scenarios where networking hardware (proxies, loadbalancers) get in the way
// of us handling timeout's or disconnects gracefully
if (RaiseKeepAlive(metadata))
{
Trace.TraceEvent(TraceEventType.Verbose, 0, "KeepAlive(" + metadata.Connection.ConnectionId + ")");
metadata.Connection.KeepAlive()
.Catch(ex =>
{
Trace.TraceEvent(TraceEventType.Error, 0, "Failed to send keep alive: " + ex.GetBaseException());
});
}
MarkConnection(metadata.Connection);
}
}
开发者ID:stirno,项目名称:SignalR,代码行数:28,代码来源:TransportHeartBeat.cs
示例15: EndConnection
private static void EndConnection(ConnectionMetadata metadata, bool disposeRegistration = true)
{
if (disposeRegistration)
{
// Dispose of the registration
if (metadata.Registration != null)
{
metadata.Registration.Dispose();
}
}
// End the connection
metadata.Connection.End();
}
开发者ID:stirno,项目名称:SignalR,代码行数:14,代码来源:TransportHeartBeat.cs
示例16: EndConnection
private static void EndConnection(ConnectionMetadata metadata)
{
// End the connection
metadata.Connection.End();
// Dispose of the registration
if (metadata.Registration != null)
{
metadata.Registration.Dispose();
}
}
开发者ID:bjarteskogoy,项目名称:SignalR,代码行数:11,代码来源:TransportHeartBeat.cs
示例17: CheckTimeoutAndKeepAlive
private void CheckTimeoutAndKeepAlive(ConnectionMetadata metadata)
{
if (RaiseTimeout(metadata))
{
// If we're past the expiration time then just timeout the connection
metadata.Connection.Timeout();
}
else
{
// The connection is still alive so we need to keep it alive with a server side "ping".
// This is for scenarios where networking hardware (proxies, loadbalancers) get in the way
// of us handling timeout's or disconnects gracefully
if (RaiseKeepAlive(metadata))
{
Trace.TraceEvent(TraceEventType.Verbose, 0, "KeepAlive(" + metadata.Connection.ConnectionId + ")");
// Ensure delegate continues to use the C# Compiler static delegate caching optimization.
metadata.Connection.KeepAlive().Catch((ex, state) => OnKeepAliveError(ex, state), Trace);
}
MarkConnection(metadata.Connection);
}
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:23,代码来源:TransportHeartBeat.cs
示例18: OnConnectionEnded
private void OnConnectionEnded(ConnectionMetadata metadata)
{
Trace.TraceInformation("OnConnectionEnded({0})", metadata.Connection.ConnectionId);
// Release the request
metadata.Connection.ReleaseRequest();
if (metadata.Registration != null)
{
metadata.Registration.Dispose();
}
}
开发者ID:bjarteskogoy,项目名称:SignalR,代码行数:12,代码来源:TransportHeartBeat.cs
示例19: RaiseDisconnect
private bool RaiseDisconnect(ConnectionMetadata metadata)
{
// The transport is currently dead but it could just be reconnecting
// so we to check it's last active time to see if it's over the disconnect
// threshold
TimeSpan elapsed = DateTime.UtcNow - metadata.LastMarked;
// The threshold for disconnect is the transport threshold + (potential network issues)
var threshold = metadata.Connection.DisconnectThreshold + _configurationManager.DisconnectTimeout;
return elapsed >= threshold;
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:12,代码来源:TransportHeartBeat.cs
示例20: AddConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
if (connection == null)
{
throw new ArgumentNullException("connection");
}
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
bool isNewConnection = true;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
oldMetadata = old;
return newMetadata;
});
if (oldMetadata != null)
{
Trace.TraceInformation("Connection exists. Closing previous connection. Old=({0}, {1}) New=({2})", oldMetadata.Connection.IsAlive, oldMetadata.Connection.Url, connection.Url);
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
EndConnection(oldMetadata);
// If we have old metadata this isn't a new connection
isNewConnection = false;
}
else
{
Trace.TraceInformation("Connection is New=({0}).", connection.Url);
}
lock (_counterLock)
{
_counters.ConnectionsCurrent.RawValue = _connections.Count;
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
// Register for disconnect cancellation
newMetadata.Registration = connection.CancellationToken.SafeRegister(OnConnectionEnded, newMetadata);
return isNewConnection;
}
开发者ID:bjarteskogoy,项目名称:SignalR,代码行数:49,代码来源:TransportHeartBeat.cs
注:本文中的ConnectionMetadata类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论