private void SendData(BacktraceDatabaseRecord record) { var backtraceData = record?.BacktraceData; //meanwhile someone delete data from a disk if (backtraceData == null || backtraceData.Report == null) { Delete(record); } else { StartCoroutine( BacktraceApi.Send(backtraceData, (BacktraceResult sendResult) => { if (sendResult.Status == BacktraceResultStatus.Ok) { Delete(record); } else { record.Dispose(); BacktraceDatabaseContext.IncrementBatchRetry(); } record = BacktraceDatabaseContext.FirstOrDefault(); SendData(record); })); } }
private void IncrementBatchRetry() { var data = BacktraceDatabaseContext.GetRecordsToDelete(); BacktraceDatabaseContext.IncrementBatchRetry(); if (data != null && data.Count() != 0) { foreach (var item in data) { BacktraceDatabaseFileContext.Delete(item); } } }
private void SendData(BacktraceDatabaseRecord record) { var stopWatch = Configuration.PerformanceStatistics ? System.Diagnostics.Stopwatch.StartNew() : new System.Diagnostics.Stopwatch(); var backtraceData = record != null?record.BacktraceDataJson() : null; //check if report exists on hard drive // to avoid situation when someone manually remove data if (string.IsNullOrEmpty(backtraceData)) { Delete(record); } else { var queryAttributes = new Dictionary <string, string>(); if (Configuration.PerformanceStatistics) { stopWatch.Stop(); queryAttributes["performance.database.send"] = stopWatch.GetMicroseconds(); } queryAttributes["_mod_duplicate"] = record.Count.ToString(); StartCoroutine( BacktraceApi.Send(backtraceData, record.Attachments, queryAttributes, (BacktraceResult sendResult) => { record.Unlock(); if (sendResult.Status != BacktraceResultStatus.ServerError && sendResult.Status != BacktraceResultStatus.NetworkError) { Delete(record); } else { BacktraceDatabaseContext.IncrementBatchRetry(); return; } bool shouldProcess = _reportLimitWatcher.WatchReport(new DateTime().Timestamp()); if (!shouldProcess) { return; } record = BacktraceDatabaseContext.FirstOrDefault(); SendData(record); })); } }
private async void OnTimedEventAsync(object source, ElapsedEventArgs e) { if (!BacktraceDatabaseContext.Any() || _timerBackgroundWork) { return; } _timerBackgroundWork = true; _timer.Stop(); //read first record (keep in mind LIFO and FIFO settings) from memory database var record = BacktraceDatabaseContext.FirstOrDefault(); while (record != null) { var backtraceData = record.BacktraceData; //meanwhile someone delete data from a disk if (backtraceData == null || backtraceData.Report == null) { Delete(record); } else { //send record from database to API var result = await BacktraceApi.SendAsync(backtraceData); if (result.Status == BacktraceResultStatus.Ok) { Delete(record); } else { record.Dispose(); BacktraceDatabaseContext.IncrementBatchRetry(); break; } } record = BacktraceDatabaseContext.FirstOrDefault(); } _timer.Start(); _timerBackgroundWork = false; }
private void SendData(BacktraceDatabaseRecord record) { var backtraceData = record != null ? record.BacktraceData : null; //check if report exists on hard drive // to avoid situation when someone manually remove data if (backtraceData == null || backtraceData.Report == null) { Delete(record); } else { StartCoroutine( BacktraceApi.Send(backtraceData, (BacktraceResult sendResult) => { if (sendResult.Status == BacktraceResultStatus.Ok) { Delete(record); } else { record.Dispose(); BacktraceDatabaseContext.IncrementBatchRetry(); return; } bool limitHit = _reportLimitWatcher.WatchReport(new DateTime().Timestamp()); if (!limitHit) { _reportLimitWatcher.DisplayReportLimitHitMessage(); return; } record = BacktraceDatabaseContext.FirstOrDefault(); SendData(record); })); } }