Esempio n. 1
0
        public Collector(MailBoxManager manager, MailQueueSettings settings, List <MessageHandlerBase> message_handlers)
        {
            _log = LoggerFactory.GetLogger(LoggerFactory.LoggerType.Nlog, "Collector");

            Environment.SetEnvironmentVariable("MONO_TLS_SESSION_CACHE_TIMEOUT", "0");

            _manager    = manager;
            _settings   = settings;
            _itemManger = new MailItemManager(_manager, message_handlers);
            _queue      = new MailWorkerQueue(settings.ConcurrentThreadCount, settings.CheckInterval, this);

            _log.Info("MailWorkerQueue: ConcurrentThreadCount = {0} and CheckInterval = {1}",
                      settings.ConcurrentThreadCount, settings.CheckInterval);

            var config_builder = new TasksConfig.Builder();

            if (settings.WorkOnUsersOnly != null && settings.WorkOnUsersOnly.Any())
            {
                var i     = 0;
                var users = string.Empty;
                settings.WorkOnUsersOnly.ForEach(user => users += string.Format("\r\n\t\t\t\t{0}. \"{1}\"", ++i, user));

                _log.Info("Aggreagtor will get tasks for this users only:" + users);
            }

            config_builder.SetUsersToWorkOn(settings.WorkOnUsersOnly);
            config_builder.SetOnlyTeamlabTasks(settings.OnlyTeamlabTasks);
            config_builder.SetActiveInterval(settings.ActivityTimeout);

            _tasksConfig = config_builder.Build();
        }
Esempio n. 2
0
        public Collector(MailBoxManager manager, MailQueueSettings settings)
        {
            _log        = LogManager.GetLogger("Collector");
            _manager    = manager;
            _settings   = settings;
            _itemManger = new MailItemManager(_manager);
            _queue      = new MailWorkerQueue(settings.ConcurrentThreadCount, settings.CheckInterval, this);

            _log.Info("MailWorkerQueue: ConcurrentThreadCount = {0} and CheckInterval = {1}",
                      settings.ConcurrentThreadCount, settings.CheckInterval);
        }
Esempio n. 3
0
        public Collector(MailBoxManager manager, MailQueueSettings settings, List <MessageHandlerBase> message_handlers)
        {
            _log        = LoggerFactory.GetLogger(LoggerFactory.LoggerType.Nlog, "Collector");
            _manager    = manager;
            _settings   = settings;
            _itemManger = new MailItemManager(_manager, message_handlers);
            _queue      = new MailWorkerQueue(settings.ConcurrentThreadCount, settings.CheckInterval, this);

            _log.Info("MailWorkerQueue: ConcurrentThreadCount = {0} and CheckInterval = {1}",
                      settings.ConcurrentThreadCount, settings.CheckInterval);

            if (settings.WorkOnUsersOnly != null && settings.WorkOnUsersOnly.Any())
            {
                var i     = 0;
                var users = string.Empty;
                settings.WorkOnUsersOnly.ForEach(user => users += string.Format("\r\n\t\t\t\t{0}. \"{1}\"", ++i, user));

                _log.Info("Aggreagtor will get tasks for this users only:" + users);
            }
        }
Esempio n. 4
0
        public Collector(MailBoxManager manager, MailQueueSettings settings, List<MessageHandlerBase> message_handlers) 
        {
            _log = LoggerFactory.GetLogger(LoggerFactory.LoggerType.Nlog, "Collector");
            _manager = manager;
            _settings = settings;
            _itemManger = new MailItemManager(_manager, message_handlers);
            _queue = new MailWorkerQueue(settings.ConcurrentThreadCount, settings.CheckInterval, this);

            _log.Info("MailWorkerQueue: ConcurrentThreadCount = {0} and CheckInterval = {1}", 
                settings.ConcurrentThreadCount, settings.CheckInterval);

            if (settings.WorkOnUsersOnly != null && settings.WorkOnUsersOnly.Any())
            {
                var i = 0;
                var users = string.Empty;
                settings.WorkOnUsersOnly.ForEach(user => users += string.Format("\r\n\t\t\t\t{0}. \"{1}\"", ++i, user));

                _log.Info("Aggreagtor will get tasks for this users only:" + users);
            }
        }
        public AggregatorService(IEnumerable <string> workOnThisUsersOnly = null)
        {
            ServiceName  = AscMailCollectionServiceName;
            EventLog.Log = "Application";

            // These Flags set whether or not to handle that specific
            // type of event. Set to true if you need it, false otherwise.
            CanHandlePowerEvent         = false;
            CanHandleSessionChangeEvent = false;
            CanPauseAndContinue         = false;
            CanShutdown = true;
            CanStop     = true;
            try
            {
                XmlConfigurator.Configure();

                _log = LoggerFactory.GetLogger(LoggerFactory.LoggerType.Log4Net, "MainThread");

                Environment.SetEnvironmentVariable("MONO_TLS_SESSION_CACHE_TIMEOUT", "0");

                _queueSettings = MailQueueSettings.FromConfig;

                if (workOnThisUsersOnly != null)
                {
                    _queueSettings.WorkOnUsersOnly = workOnThisUsersOnly.ToList();
                }
                else
                {
                    var userToWorkOn = ConfigurationManager.AppSettings["mail.OneUserMode"];
                    if (!string.IsNullOrEmpty(userToWorkOn))
                    {
                        _queueSettings.WorkOnUsersOnly.Add(userToWorkOn);
                    }
                }

                var authErrorWarningTimeout =
                    ConfigurationManager.AppSettings["mail.auth-error-warning-in-minutes"] != null
                        ? TimeSpan.FromMinutes(
                        Convert.ToInt32(ConfigurationManager.AppSettings["mail.auth-error-warning-in-minutes"]))
                        : TimeSpan.FromHours(1);

                _log.Info("Auth login error warning timeout is {0}.", authErrorWarningTimeout.ToString());

                var authErrorDisableMailboxTimeout =
                    ConfigurationManager.AppSettings["mail.auth-error-disable-mailbox-in-minutes"] != null
                        ? TimeSpan.FromMinutes(
                        Convert.ToInt32(ConfigurationManager.AppSettings["mail.auth-error-disable-mailbox-in-minutes"]))
                        : TimeSpan.FromDays(3);

                _log.Info("Auth login error disable mailbox timeout is {0}.", authErrorDisableMailboxTimeout.ToString());

                _log.Info("MailWorkerQueue: ConcurrentThreadCount = {0} and CheckInterval = {1} CheckPOP3_UIDL_Chunck = {2}",
                          _queueSettings.ConcurrentThreadCount, _queueSettings.CheckInterval, _queueSettings.CheckPop3UidlChunk);

                var configBuilder = new TasksConfig.Builder();

                if (_queueSettings.WorkOnUsersOnly != null && _queueSettings.WorkOnUsersOnly.Any())
                {
                    var i     = 0;
                    var users = string.Empty;
                    _queueSettings.WorkOnUsersOnly.ForEach(user => users += string.Format("\r\n\t\t\t\t{0}. \"{1}\"", ++i, user));

                    _log.Info("Aggregator will get tasks for this users only:" + users);
                }

                var queueLifetime = ConfigurationManager.AppSettings["mail.queue-lifetime-seconds"] != null
                        ? TimeSpan.FromSeconds(
                    Convert.ToInt32(ConfigurationManager.AppSettings["mail.queue-lifetime-seconds"]))
                        : TimeSpan.FromSeconds(30);

                var showActiveUpLogs = ConfigurationManager.AppSettings["mail.show-activeup-logs"] != null &&
                                       Convert.ToBoolean(
                    ConfigurationManager.AppSettings["mail.show-activeup-logs"]);

                _tasksConfig = configBuilder.SetUsersToWorkOn(_queueSettings.WorkOnUsersOnly)
                               .SetOnlyTeamlabTasks(_queueSettings.OnlyTeamlabTasks)
                               .SetActiveInterval(_queueSettings.ActivityTimeout)
                               .SetChunkOfPop3CheckUidLinDb(_queueSettings.CheckPop3UidlChunk)
                               .SetEnableSignalr(_queueSettings.EnableSignalr)
                               .SetMaxMessagesPerSession(_queueSettings.MaxMessagesPerSession)
                               .SetMaxTasksAtOnce(_queueSettings.ConcurrentThreadCount)
                               .SetQueueLifetime(queueLifetime)
                               .SetTenantCachingPeriod(_queueSettings.TenantCachingPeriod)
                               .SetShowActiveUpLogs(showActiveUpLogs)
                               .SetInactiveMailboxesRatio(_queueSettings.InactiveMailboxesRatio)
                               .SetAuthErrorWarningTimeout(authErrorWarningTimeout)
                               .SetAuthErrorDisableMailboxTimeout(authErrorDisableMailboxTimeout)
                               .Build();

                _tsInterval = _queueSettings.CheckInterval;

                _manager = new MailBoxManager(_log)
                {
                    AuthErrorWarningTimeout = _tasksConfig.AuthErrorWarningTimeout,
                    AuthErrorDisableTimeout = _tasksConfig.AuthErrorDisableMailboxTimeout
                };

                _queueManager = new QueueManager(_manager, _tasksConfig, _log);

                _resetEvent = new ManualResetEvent(false);

                _cancelTokenSource = new CancellationTokenSource();

                _lcts = new LimitedConcurrencyLevelTaskScheduler(_tasksConfig.MaxTasksAtOnce);

                _taskFactory = new TaskFactory(_lcts);

                _tsTaskStateCheckInterval = ConfigurationManager.AppSettings["mail.task-check-state-seconds"] != null
                        ? TimeSpan.FromSeconds(
                    Convert.ToInt32(ConfigurationManager.AppSettings["mail.task-check-state-seconds"]))
                        : TimeSpan.FromSeconds(30);

                if (ConfigurationManager.AppSettings["mail.default-api-scheme"] != null)
                {
                    var defaultApiScheme = ConfigurationManager.AppSettings["mail.default-api-scheme"];

                    ApiHelper.SetupScheme(defaultApiScheme);
                }

                _log.Info("Service is ready.");
            }
            catch (Exception ex)
            {
                _log.Fatal("CollectorService error under construct: {0}", ex.ToString());
            }
        }