/// <summary> /// Releases the lock. /// </summary> /// <param name="path">The path to the lock file.</param> protected virtual void RemoveLock(string path) { RetryUtil.Retry(() => { try { if (!File.Exists(path)) { return; } File.Delete(path); _lockStatus[path] = false; Debug.WriteLine("[Thread: {0}] Deleted lock: {1}", Thread.CurrentThread.ManagedThreadId, path); } catch (IOException) { Debug.WriteLine("[Thread: {0}] Error creating lock: {1}", Thread.CurrentThread.ManagedThreadId, path); throw; } }, 5); }
public void Listen() { Task.Factory.StartNew(() => { using (IRedisClient client = _redisClientsManager.GetReadOnlyClient()) { using (IRedisSubscription subscription = client.CreateSubscription()) { subscription.OnMessage = (channel, msg) => { if (msg == "ping" && Ping != null) { Ping(this, EventArgs.Empty); } string[] parts = msg.Split(':'); if (parts.Length != 2) { return; } NewError(parts[0], parts[1]); }; RetryUtil.Retry(() => subscription.SubscribeToChannels(NotifySignalRAction.NOTIFICATION_CHANNEL_KEY)); } } }); }
private List <string> GetDownloadFilePath() { List <string> result = new List <string>(); HtmlDocument htc = null; string baseUrl = @"http://www.tfex.co.th"; string downloadFolder = Path.Combine(configObj.FolderPath, "Download"); try { RetryUtil.Retry(5, TimeSpan.FromSeconds(2), true, delegate { htc = WebClientUtil.GetHtmlDocument(sourceUrl, 3000); }); if (htc == null) { throw new Exception(string.Format("open website: {0} error.", sourceUrl)); } HtmlNodeCollection trs = htc.DocumentNode.SelectNodes(".//table")[7].SelectNodes(".//tr"); List <string> urlFoundAll = GetUrlFoundAll(trs); if (!Directory.Exists(downloadFolder)) { Directory.CreateDirectory(downloadFolder); } string tdNewSeries = GetUrlFoundOne(urlFoundAll); if ((tdNewSeries + "").Trim().Length == 0) { return(null); } string dexsrp = Path.Combine(downloadFolder, string.Format("dexsrp{0}.txt", DateTimeConvert(configObj.DateOfSource, "yyyy-MM-dd", "yyyyMMdd"))); if (File.Exists(dexsrp)) { File.Delete(dexsrp); } RetryUtil.Retry(5, TimeSpan.FromSeconds(2), true, delegate { WebClientUtil.DownloadFile(string.Format("{0}{1}", baseUrl, tdNewSeries), 30000, dexsrp); }); if (File.Exists(dexsrp)) { result.Add(dexsrp); } } catch (Exception ex) { string msg = string.Format("\r\n ClassName: {0}\r\n MethodName: {1}\r\n Message: {2}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message); Logger.Log(msg, Logger.LogType.Error); } return(result); }
public override HttpResponseMessage Post(Error value) { if (value == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid error posted.")); } _stats.Counter(StatNames.ErrorsSubmitted); if (User != null && User.Project != null) { value.ProjectId = User.Project.Id; value.OrganizationId = User.Project.OrganizationId; } if (value.OccurrenceDate == DateTimeOffset.MinValue) { value.OccurrenceDate = DateTimeOffset.UtcNow; } string message = User == null?String.Format("Inserting error '{0}'.", value.Id) : String.Format("Inserting error '{0}' with API key '{1}'.", value.Id, User.Identity.Name); if (value.RequestInfo != null) { message += String.Format(" IP Address: {0}.", value.RequestInfo.ClientIpAddress); } if (value.ExceptionlessClientInfo != null) { message += String.Format(" Client Version: {0}.", value.ExceptionlessClientInfo.Version); } Log.Debug().Message(message).Write(); if (String.IsNullOrWhiteSpace(value.OrganizationId) || !User.IsInOrganization(value.OrganizationId)) { return(InvalidOrganizationErrorResponseMessage()); } string id = value.Id; if (String.IsNullOrEmpty(id)) { value.Id = ObjectId.GenerateNewId().ToString(); id = value.Id; } if (_messageFactory != null) { using (IMessageProducer messageProducer = _messageFactory.CreateMessageProducer()) { RetryUtil.Retry(() => messageProducer.Publish(value)); _stats.Counter(StatNames.ErrorsQueued); } } else { Log.Error().Message("Message Factory is null").Write(); } if (Request == null) { return(CreatedResponseMessage()); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id })); return(response); }
public static void Retry(Action action, int maxAttempts) { RetryUtil.Retry(action, maxAttempts); }
public static TResult Retry <TResult>(Func <TResult> func, int maxAttempts) { return(RetryUtil.Retry(func, maxAttempts)); }