示例#1
0
        void service_CommandsExecuted(object sender, EventArgs e)
        {
            try
            {
                LoggingModuleConfigurationManager configurationManager = ServiceLocator.Retrieve <LoggingModuleConfigurationManager> ( );
                CommandAsyncProcessor             service = ServiceLocator.Retrieve <CommandAsyncProcessor> ( );

                IOptionsDataAccessAgent optionsAgent = DataAccessServices.GetDataAccessService <IOptionsDataAccessAgent> ( );
                if (optionsAgent != null)
                {
                    if (null != service && configurationManager.GetLoggingState().EnableAutoSaveLog)
                    {
                        DateTime nextLogDate = DateTime.Now.AddDays(service.Interval.Days);

                        SetNextLogDate(nextLogDate,
                                       configurationManager.GetLoggingState(),
                                       optionsAgent);
                    }
                }
            }
            catch (Exception exception)
            {
                Log(LogType.Error, "Logging Config Error: " + exception.Message);
            }
        }
示例#2
0
        void loggingConfigManager_SettingsUpdated(object sender, EventArgs e)
        {
            try
            {
                LoggingModuleConfigurationManager loggingConfigManager = ServiceLocator.Retrieve <LoggingModuleConfigurationManager> ( );
                CommandAsyncProcessor             service = ServiceLocator.Retrieve <CommandAsyncProcessor> ( );

                ConfigureLogger(Logger.Global,
                                loggingConfigManager.GetLoggingState( ),
                                DataAccessServices.GetDataAccessService <ILoggingDataAccessAgent2> ( ));

                StartStopService(loggingConfigManager.GetLoggingState( ),
                                 service);

                IOptionsDataAccessAgent optionsAgent = DataAccessServices.GetDataAccessService <IOptionsDataAccessAgent> ( );
                if (optionsAgent != null)
                {
                    ConfigureServiceIntervals(loggingConfigManager.GetLoggingState(),
                                              service, optionsAgent);
                }
            }
            catch (Exception exception)
            {
                Log(LogType.Error, "Logging Config Error: " + exception.Message);
            }
        }
示例#3
0
        private static void StartStopService(LoggingState logState, CommandAsyncProcessor service)
        {
            if (service.Disposed)
            {
                return;
            }

            if (logState.EnableAutoSaveLog)
            {
                service.Start( );
            }
            else
            {
                service.Stop( );
            }
        }
示例#4
0
        public void Break(BreakType type)
        {
            if (type == BreakType.Shutdown)
            {
                if (ServiceLocator.IsRegistered <CommandAsyncProcessor> ( ))
                {
                    CommandAsyncProcessor processor = ServiceLocator.Retrieve <CommandAsyncProcessor> ( );

                    if (processor != null)
                    {
                        processor.Stop( );

                        processor.Dispose( );
                    }
                }
            }
        }
示例#5
0
        private void ConfigureServiceIntervals
        (
            LoggingState logState,
            CommandAsyncProcessor service,
            IOptionsDataAccessAgent optionsDataAccess
        )
        {
            DateTime dueDate = GetDueDate(logState);

            SetNextLogDate(dueDate, logState, optionsDataAccess);

            TimeSpan due      = dueDate.Subtract(DateTime.Now);
            TimeSpan interval = new TimeSpan(logState.AutoSaveDaysPeriod, 0, 0, 0);

            service.DueTime  = due;
            service.Interval = interval;

            service.RefreshDueIntervalTimes( );
        }
示例#6
0
        private CommandAsyncProcessor RegisterAutoSaveLogService(LoggingState logState)
        {
            AutoSaveLogCommand      autoSaveCommand;
            CommandAsyncProcessor   service           = null;
            IOptionsDataAccessAgent optionsDataAccess = null;

            optionsDataAccess = DataAccessServices.GetDataAccessService <IOptionsDataAccessAgent>();

            if (optionsDataAccess != null)
            {
                autoSaveCommand = new AutoSaveLogCommand(logState);
                service         = new CommandAsyncProcessor();

                if (logState.EnableAutoSaveLog)
                {
                    string nextLogDate;


                    nextLogDate = optionsDataAccess.Get <string>(NextLogDateSettingsName, null, new Type[0]);

                    if (!string.IsNullOrEmpty(nextLogDate))
                    {
                        DateTime nextLog = DateTime.Parse(nextLogDate);

                        if (DateTime.Now > nextLog)
                        {
                            autoSaveCommand.Execute();
                        }
                    }
                }

                service.Commands.Add(autoSaveCommand);

                ConfigureServiceIntervals(logState, service, optionsDataAccess);

                service.CommandsExecuted += new EventHandler(service_CommandsExecuted);

                ServiceLocator.Register <CommandAsyncProcessor>(service);
            }

            return(service);
        }