/// <summary>
        /// Performs client database backups in a long running thread.
        /// </summary>
        private async Task CoreServiceClientDatabaseBackupsAsync()
        {
            var scheduler = new DatabaseBackupScheduler();

            try
            {
                while (true)
                {
                    try
                    {
                        // pull the timestamps that recents backups have been completed.
                        // ask the schedule which backup type (if any) should be performed based onthe recent history.
                        var recentBackups = await Database.GetClientDatabaseBackupStatusAsync().ConfigureAwait(false);

                        var backupToPerform = scheduler.NextDatabaseBackup(recentBackups);

                        if (backupToPerform != null)
                        {
                            // if a backup type was returned, then we can perform that backup type now.
                            await Database.CreateDatabaseBackupAsync(backupToPerform.Value).ConfigureAwait(false);

                            await Database.SetClientDatabaseBackupCompletedAsync(backupToPerform.Value).ConfigureAwait(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteTraceError("Failed to check for, or perform, a regularly scheduled backup of the client database.", ex, Logger.GenerateFullContextStackTrace());
                    }

                    await WaitAsync(TimeSpan.FromSeconds(60)).ConfigureAwait(false);

                    if (CancelSource.Token.IsCancellationRequested)
                    {
                        OnStopped(new EngineStoppedEventArgs(EngineStoppedReason.StopRequested, InstanceID));
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                OnStopped(new EngineStoppedEventArgs(ex, InstanceID));
            }
        }
 public void TestSetup()
 {
     Scheduler = new DatabaseBackupScheduler();
 }