Example #1
0
 /// <summary>
 /// Start database tasks
 /// </summary>
 public void Start()
 {
     //database not exists
     if (DatabaseSettings == null)
     {
         return;
     }
     if (BacktraceDatabaseContext?.Any() == true)
     {
         _enable = true;
         return;
     }
     // load reports from hard drive
     LoadReports();
     // remove orphaned files
     RemoveOrphaned();
     // setup database timer events
     if (DatabaseSettings.RetryBehavior == RetryBehavior.ByInterval ||
         DatabaseSettings.AutoSendMode)
     {
         SetupTimer();
     }
     //Enable database
     _enable = true;
 }
        /// <summary>
        /// Backtrace database update event
        /// </summary>
        private void Update()
        {
            if (!Enable)
            {
                return;
            }
            LastFrameTime = Time.time;
            if (!DatabaseSettings.AutoSendMode)
            {
                return;
            }

            if (Time.time - _lastConnection > DatabaseSettings.RetryInterval)
            {
                _lastConnection = Time.time;
                if (_timerBackgroundWork || !BacktraceDatabaseContext.Any())
                {
                    return;
                }

                _timerBackgroundWork = true;
                SendData(BacktraceDatabaseContext.FirstOrDefault());
                _timerBackgroundWork = false;
            }
        }
Example #3
0
 /// <summary>
 /// Send and delete all records from database
 /// </summary>
 public void Flush()
 {
     if (!_enable || !BacktraceDatabaseContext.Any())
     {
         return;
     }
     FlushRecord(BacktraceDatabaseContext.FirstOrDefault());
 }
        /// <summary>
        /// Try to send all data from database
        /// </summary>
        public void Send()
        {
            if (!Enable || !BacktraceDatabaseContext.Any())
            {
                return;
            }

            SendData(BacktraceDatabaseContext.FirstOrDefault());
        }
Example #5
0
        private void Update()
        {
            if (!_enable)
            {
                return;
            }
            if (Time.time - _lastConnection > DatabaseSettings.RetryInterval)
            {
                _lastConnection = Time.time;
                if (!BacktraceDatabaseContext.Any() || _timerBackgroundWork)
                {
                    return;
                }

                _timerBackgroundWork = true;
                SendData(BacktraceDatabaseContext.FirstOrDefault());
                _timerBackgroundWork = false;
            }
        }
Example #6
0
        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;
        }