Exemplo n.º 1
0
        public void CleanupEngineCanStartAndStop()
        {
            var logger = new MockLogger();
            var db     = new SQLServerClientDatabase(TestConnectionString, new MockLogger(), SharedMockedCoreSettings);

            var engine = new CleanupEngine(db, logger, 0, SharedMockedCoreSettings);

            engine.BeginStart();
            engine.BeginStop();
        }
Exemplo n.º 2
0
        public void CleanupEngineTriggersStoppedEventWhenEngineHasStopped()
        {
            var logger = new MockLogger();
            var db     = new SQLServerClientDatabase(TestConnectionString, new MockLogger(), SharedMockedCoreSettings);

            var engine = new CleanupEngine(db, logger, 0, SharedMockedCoreSettings);

            var signalStoppedEvent = new AutoResetEvent(false);

            engine.Stopped += (s, e) => { signalStoppedEvent.Set(); };
            engine.BeginStart();
            engine.BeginStop();

            var engineStoppedSignaled = signalStoppedEvent.WaitOne(TimeSpan.FromSeconds(5));

            Assert.IsTrue(engineStoppedSignaled);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Starts the cleanup engine(s).
        /// </summary>
        /// <returns>True if successful, otherwise false.</returns>
        private async Task <bool> StartCleanupEnginesAsync()
        {
            // each cleanup engine instance shares the same logger.
            // this means a single log file for all engine instances- and each engine will prepend its log messages with a context tag.

            try
            {
                CleanupEngineInstances = new List <CleanupEngine>();

                var settingName   = ArchivialLibrary.Constants.RuntimeSettingNames.CleanupEngineInstancesCount;
                var instanceCount = Convert.ToInt32(await ClientDatabase.GetApplicationOptionAsync(settingName).ConfigureAwait(false));

                for (int i = 0; i < instanceCount; i++)
                {
                    var engineLog = new Logger(string.Format("{0}-{1}", ArchivialLibrary.Constants.Logging.CleanupComponentName, i));
                    engineLog.Start(
                        CoreSettings.GetEventlogName(),
                        CoreSettings.GetEventlogName(),
                        CoreSettings.GetLogFilesDirectory());

                    var instance = new CleanupEngine(ClientDatabase, engineLog, i, CoreSettings);
                    instance.Stopped += Cleanup_Stopped;
                    instance.BeginStart();

                    CleanupEngineInstances.Add(instance);

                    CoreLog.WriteSystemEvent(
                        string.Format("Cleanup Engine instance {0} has started.", i),
                        EventLogEntryType.Information, ArchivialLibrary.Constants.EventIDs.StartedCleanupEngine, true);
                }

                return(true);
            }
            catch (Exception ex)
            {
                var message = "Failed to start the cleanup engine(s).";
                var context = CoreLog.GenerateFullContextStackTrace();
                CoreLog.WriteSystemEvent(message, ex, context, ArchivialLibrary.Constants.EventIDs.FailedCleanupEngine, true);
                return(false);
            }
        }