public Attachment CreateResponseAttachment(string documentSelfLink, IResponseContext responseContext, string attachmentId, string surveyData) { int maxRetries = 2; TimeSpan interval = TimeSpan.FromMilliseconds(100); RetryStrategies retryStrategy = new RetryStrategies(maxRetries, interval); var attachment = retryStrategy.ExecuteWithRetry <Attachment>(() => Client.CreateAttachmentAsync(documentSelfLink, new { id = attachmentId, contentType = "text/plain", media = "link to your media", RootResponseId = responseContext.RootResponseId, SurveyDocument = surveyData }).Result, (ex, consumedRetries, remainingRetries) => RetryHandlerForCreateResponseAttachment(ex, consumedRetries, remainingRetries, responseContext, attachmentId) ); return(attachment); }
protected async Task <bool> KeyExists(Guid projectId, string key, TimeSpan renewTimeout) { object transientTemp; var cacheKey = CacheExtenstions.ToCacheKey(projectId, key); bool exists = false; try { #if RunSynchronous if (_transientCache.Count > 0) { exists = _transientCache.TryGetValue(cacheKey, out transientTemp); } else { exists = _retryStrategy.ExecuteWithRetry(() => Cache.KeyExists(cacheKey), (ex, numberOfRetries, remainingRetries) => ex.GetType() == typeof(StackExchange.Redis.RedisConnectionException) ? new RetryResponse <bool> { Action = RetryAction.ReturnResult, Result = false } : new RetryResponse <bool> { Action = RetryAction.ContinueRetrying }); if (exists) { if (renewTimeout != NoTimeout) { Cache.KeyExpire(cacheKey, renewTimeout); } } } #else exists = _retryStrategy.ExecuteWithRetry(() => Cache.KeyExistsAsync(cacheKey)).Result; if (exists) { if (renewTimeout != NoTimeout) { var isSuccesful = _retryStrategy.ExecuteWithRetry(() => Cache.KeyExpireAsync(cacheKey, renewTimeout)).Result; } } #endif #if TrackStats UpdateStats(cacheKey, exists ? StatType.ExistHit : StatType.ExistMiss); #endif //TrackStats return(exists); } catch (Exception ex) { #if TrackStats UpdateStats(cacheKey, StatType.ExistException, ex); #endif //TrackStats if (ex.GetType() == typeof(StackExchange.Redis.RedisConnectionException)) { return(_transientCache.TryGetValue(cacheKey, out transientTemp)); } return(false); } }