本文整理汇总了C#中RetryPolicy类的典型用法代码示例。如果您正苦于以下问题:C# RetryPolicy类的具体用法?C# RetryPolicy怎么用?C# RetryPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RetryPolicy类属于命名空间,在下文中一共展示了RetryPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSqlAzureTransientErrorDetectionStrategyWithRetryableError
[Ignore] // REVIEW
public void TestSqlAzureTransientErrorDetectionStrategyWithRetryableError()
{
int[] errors = new int[] { 40197, 40501, 40540, 10053, 10054, 10060, 40549, 40550, 40551, 40552, 40553, 40613, 40143, 233, 64 };
Type type = typeof(SqlDatabaseTransientErrorDetectionStrategy).GetNestedType("ProcessNetLibErrorCode", BindingFlags.NonPublic);
errors = errors.AddRange((int[])Enum.GetValues(type));
Exception[] exceptions = FakeSqlExceptionGenerator.GenerateFakeSqlExceptions(errors);
exceptions = exceptions.AddRange(new TimeoutException(), new EntityException("Forced Exception"));
RetryPolicy defaultPolicy = new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>(exceptions.Length - 1, RetryStrategy.DefaultRetryInterval);
int execCount = 0;
try
{
defaultPolicy.ExecuteAction(() =>
{
Exception ex = exceptions[execCount];
execCount++;
throw ex;
});
}
catch (EntityException ex)
{
Assert.AreEqual("Forced Exception", ex.Message);
}
Assert.AreEqual<int>(exceptions.Length, execCount, "The action was not executed the expected amount of times");
}
示例2: Initialize
public void Initialize()
{
var retryStrategy = new Incremental(3, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
var retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy);
var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
var serviceUri = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);
var namespaceManager = new NamespaceManager(serviceUri, tokenProvider);
this.settings.Topics.AsParallel().ForAll(topic =>
{
retryPolicy.ExecuteAction(() => CreateTopicIfNotExists(namespaceManager, topic));
topic.Subscriptions.AsParallel().ForAll(subscription =>
{
retryPolicy.ExecuteAction(() => CreateSubscriptionIfNotExists(namespaceManager, topic, subscription));
retryPolicy.ExecuteAction(() => UpdateRules(namespaceManager, topic, subscription));
});
});
// Execute migration support actions only after all the previous ones have been completed.
foreach (var topic in this.settings.Topics)
{
foreach (var action in topic.MigrationSupport)
{
retryPolicy.ExecuteAction(() => UpdateSubscriptionIfExists(namespaceManager, topic, action));
}
}
this.initialized = true;
}
示例3: SimulatedLdapProfileStore
public SimulatedLdapProfileStore(Database database)
{
this.accessor = database.CreateSprocAccessor<ProfileStoreData>("aexpense_ProfileStore_GetProfileFromUser");
this.retryPolicy = RetryPolicyFactory.GetRetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>();
AExpenseEvents.Log.ProfileStoreInitialized();
}
示例4: CloudBlobStorage
/// <summary />
/// <param name="account"></param>
/// <param name="rootContainerName"></param>
public CloudBlobStorage(CloudStorageAccount account, string rootContainerName)
{
try
{
this.account = account;
this.rootContainerName = rootContainerName;
this.blobClient = account.CreateCloudBlobClient();
this.readRetryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(new Incremental(1, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)));
this.readRetryPolicy.Retrying += (s, e) => Trace.TraceWarning("An error occurred in attempt number {1} to read from blob storage: {0}", e.LastException.Message, e.CurrentRetryCount);
this.writeRetryPolicy = new RetryPolicy<StorageTransientErrorDetectionStrategy>(new FixedInterval(1, TimeSpan.FromSeconds(10)) { FastFirstRetry = false });
this.writeRetryPolicy.Retrying += (s, e) => Trace.TraceWarning("An error occurred in attempt number {1} to write to blob storage: {0}", e.LastException.Message, e.CurrentRetryCount);
var containerReference = this.blobClient.GetContainerReference(this.rootContainerName);
this.writeRetryPolicy.ExecuteAction(() => containerReference.CreateIfNotExists());
}
catch (Exception ex)
{
string msg = ex.Message;
throw;
}
}
示例5: MakeRetryPolicy
private static RetryPolicy<SqlAzureTransientErrorDetectionStrategy> MakeRetryPolicy()
{
var fromMilliseconds = TimeSpan.FromMilliseconds(DelayMs);
var policy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>
(MaxRetry, fromMilliseconds);
return policy;
}
示例6: ReliableTopicClient
public ReliableTopicClient(string sbNamespace, TokenProvider tokenProvider, string path, RetryPolicy<ServiceBusTransientErrorDetectionStrategy> policy)
: base(sbNamespace, tokenProvider, path, policy)
{
//create the queue if it doesn't exist
bool needsCreation = false;
try
{
needsCreation = !mRetryPolicy.ExecuteAction<bool>(() => mNamespaceManager.TopicExists(path));
}
catch (MessagingEntityNotFoundException)
{
needsCreation = true;
}
if (needsCreation)
{
try
{
mRetryPolicy.ExecuteAction<TopicDescription>(() => mNamespaceManager.CreateTopic(path));
}
catch (MessagingEntityAlreadyExistsException)
{
//ignore this exception because queue already exists
}
}
mRetryPolicy.ExecuteAction(() => mTopicClient = mMessagingFactory.CreateTopicClient(path));
}
示例7: GetDefaultSqlAzureCommandRetryPolicy
public static RetryPolicy GetDefaultSqlAzureCommandRetryPolicy()
{
var retryStrategy = RetryStrategy.DefaultFixed;
var retryPolicy = new RetryPolicy(new SqlAzureTransientErrorDetectionStrategy(), retryStrategy);
return retryPolicy;
}
示例8: GetDefaultSqlConnectionRetryPolicy
public static RetryPolicy GetDefaultSqlConnectionRetryPolicy()
{
var retryStrategy = RetryStrategy.DefaultExponential;
var retryPolicy = new RetryPolicy(new NetworkConnectivityErrorDetectionStrategy(), retryStrategy);
return retryPolicy;
}
示例9: ReliableClientBase
public ReliableClientBase(string sbNamespace, TokenProvider tokenProvider, string path, RetryPolicy<ServiceBusTransientErrorDetectionStrategy> policy)
{
mRetryPolicy = policy;
Uri address = ServiceBusEnvironment.CreateServiceUri("sb", sbNamespace, string.Empty);
mNamespaceManager = new NamespaceManager(address, tokenProvider);
mMessagingFactory = MessagingFactory.Create(address, tokenProvider);
}
示例10: GetDefaultSqlCommandRetryPolicy
public static RetryPolicy GetDefaultSqlCommandRetryPolicy()
{
var retryStrategy = RetryStrategy.DefaultFixed;
var retryPolicy = new RetryPolicy(new NetworkConnectivityErrorDetectionStrategy(), retryStrategy);
return retryPolicy;
}
示例11: Main
static void Main(string[] args)
{
DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
sampleRootPath = di.Parent.Parent.FullName;
//Register the data source container
string jsonContainerTemplate = new StreamReader(string.Format(@"{0}\AdHocContainerSample.json", sampleRootPath)).ReadToEnd();
string jsonContainerPayload = string.Format(jsonContainerTemplate, DateTime.UtcNow);
retryPolicy = new RetryPolicy(
new HttpRequestTransientErrorDetectionStrategy(),
5,
TimeSpan.FromMilliseconds(100),
TimeSpan.FromMilliseconds(500)
);
//To register a container, use "containers" as view type
string containerId = RegisterDataAsset(catalogName, jsonContainerPayload, "containers");
RegisterDataAssets(containerId);
Console.WriteLine();
Console.WriteLine("Data assets registered from Excel table. Press Enter");
Console.ReadLine();
}
示例12: TopicSender
/// <summary>
/// Initializes a new instance of the <see cref="TopicSender"/> class,
/// automatically creating the given topic if it does not exist.
/// </summary>
protected TopicSender(ServiceBusSettings settings, string topic, RetryStrategy retryStrategy)
{
this.settings = settings;
this.topic = topic;
this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
this.serviceUri = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);
// TODO: This could be injected.
this.retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy);
this.retryPolicy.Retrying +=
(s, e) =>
{
var handler = this.Retrying;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
Trace.TraceWarning("An error occurred in attempt number {1} to send a message: {0}", e.LastException.Message, e.CurrentRetryCount);
};
var factory = MessagingFactory.Create(this.serviceUri, this.tokenProvider);
this.topicClient = factory.CreateTopicClient(this.topic);
}
示例13: RetryPolityUsingCode
private static void RetryPolityUsingCode(IUnityContainer container, IBlockService service)
{
System.Diagnostics.Trace.WriteLine("Begin sample: RetryPolityUsingCode");
// Define your retry strategy: retry 5 times, starting 1 second apart
// and adding 2 seconds to the interval each retry.
var retryStrategy = new Incremental(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
// Define your retry policy using the retry strategy and the Windows Azure storage
// transient fault detection strategy.
var retryPolicy = new RetryPolicy<BlockServiceExceptionDetectionStrategy>(retryStrategy);
// Do some work that may result in a transient fault.
System.Threading.Tasks.Parallel.For(0, 100, index =>
{
try
{
retryPolicy.Retrying += OnRetryPolicyRetrying;
retryPolicy.ExecuteAction(() =>
{
_blockService.PutBlock(index.ToString(), index);
});
retryPolicy.Retrying -= OnRetryPolicyRetrying;
}
catch (Exception exception)
{
// All the retries failed.
System.Diagnostics.Trace.WriteLine(string.Format("An Exception has been thrown:\n{0}", exception));
}
});
System.Diagnostics.Trace.WriteLine("End sample: RetryPolityUsingCode");
}
示例14: MakeRetryPolicy
private static RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy> MakeRetryPolicy()
{
var fromMilliseconds = TimeSpan.FromMilliseconds(DELAY_MS);
var policy = new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>
(MAX_RETRY, fromMilliseconds);
return policy;
}
示例15: UpdateSessionManagerRetryDecorator
public UpdateSessionManagerRetryDecorator(IUpdateSessionManager updateSessionManager,
RetryStrategy retryStrategy,
ITransientErrorDetectionStrategy errorDetectionStrategy)
{
_updateSessionManager = updateSessionManager;
_retryPolicy = new RetryPolicy(errorDetectionStrategy, retryStrategy);
}