本文整理汇总了C#中TimeoutHelper.RemainingTime方法的典型用法代码示例。如果您正苦于以下问题:C# TimeoutHelper.RemainingTime方法的具体用法?C# TimeoutHelper.RemainingTime怎么用?C# TimeoutHelper.RemainingTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeoutHelper
的用法示例。
在下文中一共展示了TimeoutHelper.RemainingTime方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSessionAsync
protected override async Task<AmqpSession> CreateSessionAsync(TimeSpan timeout)
{
var timeoutHelper = new TimeoutHelper(timeout);
if (this.iotHubTokenRefresher != null)
{
this.iotHubTokenRefresher.Cancel();
}
AmqpSession amqpSession = await base.CreateSessionAsync(timeoutHelper.RemainingTime());
#if !WINDOWS_UWP
if (this.AmqpTransportSettings.ClientCertificate == null)
{
#endif
this.iotHubTokenRefresher = new IotHubTokenRefresher(
amqpSession,
this.ConnectionString,
this.ConnectionString.AmqpEndpoint.AbsoluteUri
);
// Send Cbs token for new connection first
await this.iotHubTokenRefresher.SendCbsTokenAsync(timeoutHelper.RemainingTime());
#if !WINDOWS_UWP
}
#endif
return amqpSession;
}
示例2: CreateSendingLinkAsync
public async Task<SendingAmqpLink> CreateSendingLinkAsync(string path, IotHubConnectionString connectionString, TimeSpan timeout)
{
this.OnCreateSendingLink(connectionString);
var timeoutHelper = new TimeoutHelper(timeout);
AmqpSession session;
if (!this.FaultTolerantSession.TryGetOpenedObject(out session))
{
session = await this.FaultTolerantSession.GetOrCreateAsync(timeoutHelper.RemainingTime());
}
var linkAddress = this.BuildLinkAddress(connectionString, path);
var linkSettings = new AmqpLinkSettings()
{
Role = false,
InitialDeliveryCount = 0,
Target = new Target() { Address = linkAddress.AbsoluteUri },
SndSettleMode = null, // SenderSettleMode.Unsettled (null as it is the default and to avoid bytes on the wire)
RcvSettleMode = null, // (byte)ReceiverSettleMode.First (null as it is the default and to avoid bytes on the wire)
LinkName = Guid.NewGuid().ToString("N") // Use a human readable link name to help with debugging
};
SetLinkSettingsCommonProperties(linkSettings, timeoutHelper.RemainingTime());
var link = new SendingAmqpLink(linkSettings);
link.AttachTo(session);
var audience = this.BuildAudience(connectionString, path);
await this.OpenLinkAsync(link, connectionString, audience, timeoutHelper.RemainingTime());
return link;
}
示例3: CreateSessionAsync
protected override async Task<AmqpSession> CreateSessionAsync(TimeSpan timeout)
{
var timeoutHelper = new TimeoutHelper(timeout);
if (this.iotHubTokenRefresher != null)
{
this.iotHubTokenRefresher.Cancel();
}
AmqpSession amqpSession = await base.CreateSessionAsync(timeoutHelper.RemainingTime());
this.iotHubTokenRefresher = new IotHubTokenRefresher(
amqpSession,
this.ConnectionString,
this.ConnectionString.AmqpEndpoint.AbsoluteUri
);
// Send Cbs token for new connection first
await this.iotHubTokenRefresher.SendCbsTokenAsync(timeoutHelper.RemainingTime());
return amqpSession;
}
示例4: OpenLinkAsync
static async Task OpenLinkAsync(AmqpObject link, TimeSpan timeout)
{
var timeoutHelper = new TimeoutHelper(timeout);
try
{
await link.OpenAsync(timeoutHelper.RemainingTime());
}
catch (Exception exception)
{
if (exception.IsFatal())
{
throw;
}
link.SafeClose(exception);
throw;
}
}
示例5: CreateClientWebSocketTransport
async Task<TransportBase> CreateClientWebSocketTransport(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
Uri websocketUri = new Uri(WebSocketConstants.Scheme + this.ConnectionString.HostName + ":" + WebSocketConstants.SecurePort + WebSocketConstants.UriSuffix);
var websocket = await this.CreateClientWebSocket(websocketUri, timeoutHelper.RemainingTime());
return new ClientWebSocketTransport(
websocket,
this.connectionString.IotHubName,
null,
null);
}
示例6: CreateSessionAsync
async Task<AmqpSession> CreateSessionAsync(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
this.refreshTokenTimer.Cancel();
var amqpSettings = this.CreateAmqpSettings();
TransportBase transport;
if (this.useWebSocketOnly)
{
// Try only Amqp transport over WebSocket
transport = await this.CreateClientWebSocketTransport(timeoutHelper.RemainingTime());
}
else
{
var tlsTransportSettings = this.CreateTlsTransportSettings();
var amqpTransportInitiator = new AmqpTransportInitiator(amqpSettings, tlsTransportSettings);
try
{
transport = await amqpTransportInitiator.ConnectTaskAsync(timeoutHelper.RemainingTime());
}
catch (Exception e)
{
if (Fx.IsFatal(e))
{
throw;
}
// Amqp transport over TCP failed. Retry Amqp transport over WebSocket
if (timeoutHelper.RemainingTime() != TimeSpan.Zero)
{
transport = await this.CreateClientWebSocketTransport(timeoutHelper.RemainingTime());
}
else
{
throw;
}
}
}
AmqpConnectionSettings amqpConnectionSettings = new AmqpConnectionSettings()
{
MaxFrameSize = AmqpConstants.DefaultMaxFrameSize,
ContainerId = Guid.NewGuid().ToString("N"),
HostName = this.connectionString.AmqpEndpoint.Host
};
var amqpConnection = new AmqpConnection(transport, amqpSettings, amqpConnectionSettings);
await amqpConnection.OpenAsync(timeoutHelper.RemainingTime());
var sessionSettings = new AmqpSessionSettings()
{
Properties = new Fields()
};
var amqpSession = amqpConnection.CreateSession(sessionSettings);
await amqpSession.OpenAsync(timeoutHelper.RemainingTime());
// This adds itself to amqpConnection.Extensions
var cbsLink = new AmqpCbsLink(amqpConnection);
await this.SendCbsTokenAsync(cbsLink, timeoutHelper.RemainingTime());
return amqpSession;
}
示例7: CreateRequestResponseLink
public async Task<RequestResponseAmqpLink> CreateRequestResponseLink(string path, TimeSpan timeout)
{
var timeoutHelper = new TimeoutHelper(timeout);
AmqpSession session;
if (!this.faultTolerantSession.TryGetOpenedObject(out session))
{
session = await this.faultTolerantSession.GetOrCreateAsync(timeoutHelper.RemainingTime());
}
var linkAddress = this.connectionString.BuildLinkAddress(path);
var linkSettings = new AmqpLinkSettings()
{
TotalLinkCredit = 0,
AutoSendFlow = false,
Source = new Source() { Address = linkAddress.AbsoluteUri },
SettleType = SettleMode.SettleOnDispose,
LinkName = Guid.NewGuid().ToString("N") // Use a human readable link name to help with debuggin
};
SetLinkSettingsCommonProperties(linkSettings, timeoutHelper.RemainingTime());
var link = new RequestResponseAmqpLink(session, linkSettings);
await OpenLinkAsync(link, timeoutHelper.RemainingTime());
return link;
}
示例8: CreateReceivingLink
public async Task<ReceivingAmqpLink> CreateReceivingLink(string path, TimeSpan timeout, uint prefetchCount)
{
var timeoutHelper = new TimeoutHelper(timeout);
AmqpSession session;
if (!this.faultTolerantSession.TryGetOpenedObject(out session))
{
session = await this.faultTolerantSession.GetOrCreateAsync(timeoutHelper.RemainingTime());
}
var linkAddress = this.connectionString.BuildLinkAddress(path);
var linkSettings = new AmqpLinkSettings()
{
Role = true,
TotalLinkCredit = prefetchCount,
AutoSendFlow = prefetchCount > 0,
Source = new Source() { Address = linkAddress.AbsoluteUri },
SndSettleMode = null, // SenderSettleMode.Unsettled (null as it is the default and to avoid bytes on the wire)
RcvSettleMode = (byte)ReceiverSettleMode.Second,
LinkName = Guid.NewGuid().ToString("N") // Use a human readable link name to help with debuggin
};
SetLinkSettingsCommonProperties(linkSettings, timeoutHelper.RemainingTime());
var link = new ReceivingAmqpLink(linkSettings);
link.AttachTo(session);
await OpenLinkAsync(link, timeoutHelper.RemainingTime());
return link;
}
示例9: CreateSessionAsync
async Task<AmqpSession> CreateSessionAsync(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
this.refreshTokenTimer.Cancel();
var amqpSettings = this.CreateAmqpSettings();
var tlsTransportSettings = this.CreateTlsTransportSettings();
var amqpTransportInitiator = new AmqpTransportInitiator(amqpSettings, tlsTransportSettings);
var transport = await amqpTransportInitiator.ConnectTaskAsync(timeoutHelper.RemainingTime());
AmqpConnectionSettings amqpConnectionSettings = new AmqpConnectionSettings()
{
MaxFrameSize = AmqpConstants.DefaultMaxFrameSize,
ContainerId = Guid.NewGuid().ToString("N"),
HostName = this.connectionString.AmqpEndpoint.Host
};
var amqpConnection = new AmqpConnection(transport, amqpSettings, amqpConnectionSettings);
await amqpConnection.OpenAsync(timeoutHelper.RemainingTime());
var sessionSettings = new AmqpSessionSettings()
{
Properties = new Fields()
};
var amqpSession = amqpConnection.CreateSession(sessionSettings);
await amqpSession.OpenAsync(timeoutHelper.RemainingTime());
// This adds itself to amqpConnection.Extensions
var cbsLink = new AmqpCbsLink(amqpConnection);
await this.SendCbsTokenAsync(cbsLink, timeoutHelper.RemainingTime());
return amqpSession;
}
示例10: CreateClientWebSocketTransportAsync
async Task<TransportBase> CreateClientWebSocketTransportAsync(TimeSpan timeout)
{
var timeoutHelper = new TimeoutHelper(timeout);
Uri websocketUri = new Uri(WebSocketConstants.Scheme + this.hostName + ":" + WebSocketConstants.SecurePort + WebSocketConstants.UriSuffix);
// Use Legacy WebSocket if it is running on Windows 7 or older. Windows 7/Windows 2008 R2 is version 6.1
if (Environment.OSVersion.Version.Major < 6 || (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor <= 1))
{
var websocket = await CreateLegacyClientWebSocketAsync(websocketUri, timeoutHelper.RemainingTime());
return new LegacyClientWebSocketTransport(
websocket,
this.AmqpTransportSettings.OperationTimeout,
null,
null);
}
else
{
var websocket = await this.CreateClientWebSocketAsync(websocketUri, timeoutHelper.RemainingTime());
return new ClientWebSocketTransport(
websocket,
null,
null);
}
}
示例11: CreateSessionAsync
protected virtual async Task<AmqpSession> CreateSessionAsync(TimeSpan timeout)
{
this.OnCreateSession();
var timeoutHelper = new TimeoutHelper(timeout);
AmqpSettings amqpSettings = CreateAmqpSettings();
TransportBase transport;
switch (this.AmqpTransportSettings.GetTransportType())
{
#if !WINDOWS_UWP
case TransportType.Amqp_WebSocket_Only:
transport = await this.CreateClientWebSocketTransportAsync(timeoutHelper.RemainingTime());
break;
#endif
case TransportType.Amqp_Tcp_Only:
TlsTransportSettings tlsTransportSettings = this.CreateTlsTransportSettings();
var amqpTransportInitiator = new AmqpTransportInitiator(amqpSettings, tlsTransportSettings);
transport = await amqpTransportInitiator.ConnectTaskAsync(timeoutHelper.RemainingTime());
break;
default:
throw new InvalidOperationException("AmqpTransportSettings must specify WebSocketOnly or TcpOnly");
}
var amqpConnectionSettings = new AmqpConnectionSettings()
{
MaxFrameSize = AmqpConstants.DefaultMaxFrameSize,
ContainerId = Guid.NewGuid().ToString("N"),
HostName = this.hostName
};
var amqpConnection = new AmqpConnection(transport, amqpSettings, amqpConnectionSettings);
await amqpConnection.OpenAsync(timeoutHelper.RemainingTime());
var sessionSettings = new AmqpSessionSettings()
{
Properties = new Fields()
};
var amqpSession = amqpConnection.CreateSession(sessionSettings);
await amqpSession.OpenAsync(timeoutHelper.RemainingTime());
// This adds itself to amqpConnection.Extensions
var cbsLink = new AmqpCbsLink(amqpConnection);
return amqpSession;
}
示例12: OpenLinkAsync
protected override async Task OpenLinkAsync(AmqpObject link, IotHubConnectionString connectionString, string audience, TimeSpan timeout)
{
var timeoutHelper = new TimeoutHelper(timeout);
try
{
// this is a device-scope connection string. We need to send a CBS token for this specific link before opening it.
var iotHubLinkTokenRefresher = new IotHubTokenRefresher(
this.FaultTolerantSession.Value,
connectionString,
audience
);
if (this.iotHubTokenRefreshers.TryAdd(link, iotHubLinkTokenRefresher))
{
link.SafeAddClosed((s, e) =>
{
if (this.iotHubTokenRefreshers.TryRemove(link, out iotHubLinkTokenRefresher))
{
iotHubLinkTokenRefresher.Cancel();
}
});
// Send Cbs token for new link first
await iotHubLinkTokenRefresher.SendCbsTokenAsync(timeoutHelper.RemainingTime());
}
// Open Amqp Link
await link.OpenAsync(timeoutHelper.RemainingTime());
}
catch (Exception exception)
{
if (exception.IsFatal())
{
throw;
}
link.SafeClose(exception);
throw;
}
}
示例13: CreateSessionAsync
async Task<AmqpSession> CreateSessionAsync(TimeSpan timeout)
{
var timeoutHelper = new TimeoutHelper(timeout);
this.refreshTokenTimer.Cancel();
AmqpSettings amqpSettings = this.CreateAmqpSettings();
TlsTransportSettings tlsTransportSettings = this.CreateTlsTransportSettings();
var amqpTransportInitiator = new AmqpTransportInitiator(amqpSettings, tlsTransportSettings);
TransportBase transport;
switch (this.amqpTransportSettings.GetTransportType())
{
case TransportType.Amqp_WebSocket_Only:
transport = await this.CreateClientWebSocketTransport(timeoutHelper.RemainingTime());
break;
case TransportType.Amqp_Tcp_Only:
transport = await amqpTransportInitiator.ConnectTaskAsync(timeoutHelper.RemainingTime());
break;
default:
throw new InvalidOperationException("AmqpTransportSettings must specify WebSocketOnly or TcpOnly");
}
var amqpConnectionSettings = new AmqpConnectionSettings()
{
MaxFrameSize = AmqpConstants.DefaultMaxFrameSize,
ContainerId = Guid.NewGuid().ToString("N"),
HostName = this.connectionString.AmqpEndpoint.Host
};
var amqpConnection = new AmqpConnection(transport, amqpSettings, amqpConnectionSettings);
await amqpConnection.OpenAsync(timeoutHelper.RemainingTime());
var sessionSettings = new AmqpSessionSettings()
{
Properties = new Fields()
};
var amqpSession = amqpConnection.CreateSession(sessionSettings);
await amqpSession.OpenAsync(timeoutHelper.RemainingTime());
// This adds itself to amqpConnection.Extensions
var cbsLink = new AmqpCbsLink(amqpConnection);
await this.SendCbsTokenAsync(cbsLink, timeoutHelper.RemainingTime());
return amqpSession;
}