Beispiel #1
0
        /// <summary>
        /// OnStop(): Put your stop code here
        /// - Stop threads, set final data, etc.
        /// </summary>
        protected override void OnStop()
        {
            try
            {
                _log.Info("Stoping service\r\n");

                if (_cancelTokenSource != null)
                {
                    _cancelTokenSource.Cancel();
                }

                StopTimer();

                if (_intervalTimer != null)
                {
                    _intervalTimer.Dispose();
                    _intervalTimer = null;
                }

                if (_resetEvent != null)
                {
                    _resetEvent.Set();
                }

                if (_eraser != null)
                {
                    _eraser.Dispose();
                    _eraser = null;
                }
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Stop service Error: {0}\r\n", ex.ToString());
            }
            finally
            {
                base.OnStop();

                if (_healthCheckServiceHost != null)
                {
                    _healthCheckServiceHost.Close();
                    _healthCheckServiceHost = null;
                }
            }

            _log.Info("Stop service\r\n");
        }
Beispiel #2
0
        public RemoveProgressItem(HttpContext context, int tenantId, UserInfo user, Guid currentUserId, bool notify)
        {
            _context     = context;
            _httpHeaders = QueueWorker.GetHttpHeaders(context.Request);

            _tenantId      = tenantId;
            _userId        = user.ID;
            _userName      = UserFormatter.GetUserName(user, DisplayUserNameFormat.Default);
            _currentUserId = currentUserId;
            _notify        = notify;

            _docService = Web.Files.Classes.Global.FileStorageService;
            _mailEraser = new MailGarbageEngine();

            Id          = QueueWorker.GetProgressItemId(tenantId, _userId, typeof(RemoveProgressItem));
            Status      = ProgressStatus.Queued;
            Error       = null;
            Percentage  = 0;
            IsCompleted = false;
        }
        public StorageCleanerService()
        {
            CanStop = true;

            AutoLog = true;

            _log = LogManager.GetLogger("ASC.Mail.Cleaner");

            _resetEvent = new ManualResetEvent(false);

            _cancelTokenSource = new CancellationTokenSource();

            _tsInterval = TimeSpan.FromMinutes(Convert.ToInt32(ConfigurationManager.AppSettings["cleaner.timer-wait-minutes"]));

            _log.InfoFormat("Service will clear mail storage every {0} minutes\r\n", _tsInterval.TotalMinutes);

            _eraser = new MailGarbageEngine(_log);

            _intervalTimer = new Timer(IntervalTimer_Elapsed, _cancelTokenSource.Token, Timeout.Infinite, Timeout.Infinite);
        }