本文整理汇总了C#中RetryPolicy类的典型用法代码示例。如果您正苦于以下问题:C# RetryPolicy类的具体用法?C# RetryPolicy怎么用?C# RetryPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RetryPolicy类属于命名空间,在下文中一共展示了RetryPolicy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:29,代码来源:StrategyTests.cs
示例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;
}
开发者ID:TiagoTerra,项目名称:cqrs-journey,代码行数:29,代码来源:ServiceBusConfig.cs
示例3: SimulatedLdapProfileStore
public SimulatedLdapProfileStore(Database database)
{
this.accessor = database.CreateSprocAccessor<ProfileStoreData>("aexpense_ProfileStore_GetProfileFromUser");
this.retryPolicy = RetryPolicyFactory.GetRetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>();
AExpenseEvents.Log.ProfileStoreInitialized();
}
开发者ID:shawnweisfeld,项目名称:20140912_SLAB,代码行数:7,代码来源:SimulatedLdapProfileStore.cs
示例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;
}
}
开发者ID:project-hu,项目名称:hu,代码行数:30,代码来源:CloudBlobStorage.cs
示例5: MakeRetryPolicy
private static RetryPolicy<SqlAzureTransientErrorDetectionStrategy> MakeRetryPolicy()
{
var fromMilliseconds = TimeSpan.FromMilliseconds(DelayMs);
var policy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>
(MaxRetry, fromMilliseconds);
return policy;
}
开发者ID:hossamdarwish,项目名称:Brisebois.WindowsAzure,代码行数:7,代码来源:BulkWriter.cs
示例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));
}
开发者ID:HaishiBai,项目名称:ReliableServiceBusClients,代码行数:26,代码来源:ReliableTopicClient.cs
示例7: GetDefaultSqlAzureCommandRetryPolicy
public static RetryPolicy GetDefaultSqlAzureCommandRetryPolicy()
{
var retryStrategy = RetryStrategy.DefaultFixed;
var retryPolicy = new RetryPolicy(new SqlAzureTransientErrorDetectionStrategy(), retryStrategy);
return retryPolicy;
}
开发者ID:ChrisNikkel,项目名称:Umbraco-CMS,代码行数:7,代码来源:RetryPolicyFactory.cs
示例8: GetDefaultSqlConnectionRetryPolicy
public static RetryPolicy GetDefaultSqlConnectionRetryPolicy()
{
var retryStrategy = RetryStrategy.DefaultExponential;
var retryPolicy = new RetryPolicy(new NetworkConnectivityErrorDetectionStrategy(), retryStrategy);
return retryPolicy;
}
开发者ID:ChrisNikkel,项目名称:Umbraco-CMS,代码行数:7,代码来源:RetryPolicyFactory.cs
示例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);
}
开发者ID:HaishiBai,项目名称:ReliableServiceBusClients,代码行数:7,代码来源:ReliableClientBase.cs
示例10: GetDefaultSqlCommandRetryPolicy
public static RetryPolicy GetDefaultSqlCommandRetryPolicy()
{
var retryStrategy = RetryStrategy.DefaultFixed;
var retryPolicy = new RetryPolicy(new NetworkConnectivityErrorDetectionStrategy(), retryStrategy);
return retryPolicy;
}
开发者ID:ChrisNikkel,项目名称:Umbraco-CMS,代码行数:7,代码来源:RetryPolicyFactory.cs
示例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();
}
开发者ID:matt40k,项目名称:data-catalog-dotnet-excel-register-data-assets,代码行数:25,代码来源:Program.cs
示例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);
}
开发者ID:TiagoTerra,项目名称:cqrs-journey,代码行数:29,代码来源:TopicSender.cs
示例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");
}
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:32,代码来源:Program.cs
示例14: MakeRetryPolicy
private static RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy> MakeRetryPolicy()
{
var fromMilliseconds = TimeSpan.FromMilliseconds(DELAY_MS);
var policy = new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>
(MAX_RETRY, fromMilliseconds);
return policy;
}
开发者ID:nexbit,项目名称:Brisebois.WindowsAzure,代码行数:7,代码来源:BulkWriter.cs
示例15: UpdateSessionManagerRetryDecorator
public UpdateSessionManagerRetryDecorator(IUpdateSessionManager updateSessionManager,
RetryStrategy retryStrategy,
ITransientErrorDetectionStrategy errorDetectionStrategy)
{
_updateSessionManager = updateSessionManager;
_retryPolicy = new RetryPolicy(errorDetectionStrategy, retryStrategy);
}
开发者ID:Microsoft,项目名称:Yams,代码行数:7,代码来源:UpdateSessionManagerRetryDecorator.cs
示例16: 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(MessagingSettings 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);
try
{
new NamespaceManager(this.serviceUri, this.tokenProvider)
.CreateTopic(
new TopicDescription(topic)
{
RequiresDuplicateDetection = true,
DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(30)
});
}
catch (MessagingEntityAlreadyExistsException)
{ }
// TODO: This could be injected.
this.retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy);
this.retryPolicy.Retrying +=
(s, e) =>
{
Trace.TraceError("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);
}
开发者ID:runerys,项目名称:cqrs-journey-code,代码行数:36,代码来源:TopicSender.cs
示例17: Instance
public Instance(Configuration configuration, string domain, Index index = null)
{
// Set instance on configuration
Configuration = configuration;
// Init things
ObjDb = new Db(Configuration.Object.Database.ConnectionString); // Database
CacheObj = new MemoryCache("instance-obj-" + domain); // Cache
//CacheQ = new MemoryCache("instance-q-" + domain); // Cache
if (null == index) {
// Create new index
Index = new Index(Configuration.Schema);
// Build base index
var retry = new RetryPolicy<DbRetryStrategy>(3, new TimeSpan(0, 0, 1));
using (var rdr = ObjDb.Query("SELECT [uid],[type],[serial],[properties] FROM [obj] WHERE [oid] NOT IN (SELECT [predecessor] FROM [obj])").ExecuteReaderWithRetry(retry)) {
while (rdr.Read()) {
Index.Set((string)rdr["uid"], (string)rdr["type"], (long)rdr["serial"], (string)rdr["properties"]);
}
}
} else {
Index = index;
}
// Init mode
Mode = Amos.ImplementationMode.Mode.Select(Configuration.Mode, this);
}
开发者ID:invertedtomato,项目名称:Amos2,代码行数:28,代码来源:Instance.cs
示例18: Get
// GET api/nextsession
public Session Get()
{
var retryStrategy = new Incremental(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
var retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(retryStrategy);
Session nextSession = new Session();
using (VidPackEntities db = new VidPackEntities())
{
retryPolicy.ExecuteAction(() =>
{
db.Database.Connection.Open();
});
ExistingSession dbSession = retryPolicy.ExecuteAction<ExistingSession>(() =>
db.ExistingSession.Where(item => item.IsNextSession == 1).FirstOrDefault()
);
if (dbSession != null)
nextSession = new VidPackModel.Session()
{
SessionDate = dbSession.SessionDate.ToString(),
SessionDescription = dbSession.SessionDescription,
SessionSubTitle = dbSession.SessionSubTitle,
SessionThumbnailUrl = String.Format("{0}{1}", ThumbnailStorageUrl, dbSession.SessionThumbnailUri),
SessionTitle = dbSession.SessionSubTitle,
SessionVideoUrl = dbSession.SessionVideoUri == null ? "" : dbSession.SessionVideoUri,
Speaker = dbSession.Speaker
};
}
return nextSession;
}
开发者ID:RobertEichenseer,项目名称:vidPACK,代码行数:32,代码来源:NextSessionController.cs
示例19: Exponential
/// <summary>
/// Create an exponential backoff retry policy given a detection strategy.
/// </summary>
/// <param name="strategy"></param>
/// <returns></returns>
private static RetryPolicy Exponential(ITransientErrorDetectionStrategy strategy, int retryCount)
{
if (retryCount == 0)
return RetryPolicy.NoRetry;
if (retryCount == 1)
{
var retryPolicy = new RetryPolicy(strategy, 1);
retryPolicy.RetryStrategy.FastFirstRetry = true;
return retryPolicy;
}
var minBackoff = TimeSpan.FromSeconds(1);
var maxBackoff = TimeSpan.FromSeconds(10);
var deltaBackoff = TimeSpan.FromSeconds(5);
// if retryCount is equal to Int16.MaxValue (32767)
// then increase the backoff intervals.
if (retryCount == Int16.MaxValue)
{
minBackoff = TimeSpan.FromSeconds(1);
maxBackoff = TimeSpan.FromSeconds(300);
deltaBackoff = TimeSpan.FromSeconds(10);
}
// 30 60 120 240
var exponentialBackoff = new ExponentialBackoff(retryCount, minBackoff, maxBackoff, deltaBackoff);
return new RetryPolicy(strategy, exponentialBackoff);
}
开发者ID:yovannyr,项目名称:bigstash-windows,代码行数:37,代码来源:CustomRetryPolicyFactory.cs
示例20: PostBackup
public PostBackup(CloudStorageAccount storageAccount, string endpointUrl, string authorizationKey)
{
_iDbService = new DbService(endpointUrl,authorizationKey);
CloudTableClient c = storageAccount.CreateCloudTableClient();
_table = c.GetTableReference("Post");
_table.CreateIfNotExists();
_retryPolicy = _iDbService.GetRetryPolicy();
}
开发者ID:tzkwizard,项目名称:ELS,代码行数:8,代码来源:PostBackup.cs
注:本文中的RetryPolicy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论