void Application_Start(object sender, EventArgs e)
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var cancellationToken = new CancellationToken();
            var scheduledTaskDeamon = new Task(token =>
            {
                var taskList = new IPeriodicTask[]
                {
                    new SendEmailPeriodicTask(),
                    new CheckDatabasePeriodicTask()
                };
                foreach (var scheduledTask in taskList)
                {
                    var timer = new System.Timers.Timer(scheduledTask.RunInterval);
                    timer.Elapsed += (o, args) =>
                    {
                        scheduledTask.TaskStart();
                        timer.Start();
                    };
                    timer.AutoReset = false;
                    timer.Start();
                }
            }, cancellationToken);
            scheduledTaskDeamon.Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///    Initializes this text log file.
        /// </summary>
        /// <param name="taskScheduler"></param>
        /// <param name="fileName"></param>
        /// <param name="format"></param>
        /// <param name="encoding"></param>
        internal StreamingTextLogSource(ITaskScheduler taskScheduler,
                                        string fileName,
                                        ILogFileFormat format,
                                        Encoding encoding)
        {
            _taskScheduler = taskScheduler;
            _encoding      = encoding;

            _listeners = new LogSourceListenerCollection(this);

            _sourceDoesNotExist     = new SourceDoesNotExist(fileName);
            _sourceCannotBeAccessed = new SourceCannotBeAccessed(fileName);

            _fileName         = fileName ?? throw new ArgumentNullException(nameof(fileName));
            _index            = new LogBufferList(StreamingTextLogSource.LineOffsetInBytes);
            _propertiesBuffer = new PropertiesBufferList();
            _propertiesBuffer.SetValue(Core.Properties.Name, _fileName);
            _propertiesBuffer.SetValue(Core.Properties.Format, format);
            _propertiesBuffer.SetValue(TextProperties.RequiresBuffer, true);
            _propertiesBuffer.SetValue(TextProperties.LineCount, 0);

            _properties = new ConcurrentPropertiesList(Core.Properties.Minimum);
            SynchronizeProperties();
            _cancellationTokenSource = new CancellationTokenSource();

            _columns = new IColumnDescriptor[] { Core.Columns.Index, StreamingTextLogSource.LineOffsetInBytes, Core.Columns.RawContent };

            _pendingReadRequests = new ConcurrentQueue <IReadRequest>();

            _fileScanTask = _taskScheduler.StartPeriodic(() => RunFileScan(_cancellationTokenSource.Token));
            _fileReadTask = _taskScheduler.StartPeriodic(() => RunFileRead(_cancellationTokenSource.Token));
        }
Ejemplo n.º 3
0
        void Application_Start(object sender, EventArgs e)
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var cancellationToken   = new CancellationToken();
            var scheduledTaskDeamon = new Task(token =>
            {
                var taskList = new IPeriodicTask[]
                {
                    new SendEmailPeriodicTask(),
                    new CheckDatabasePeriodicTask()
                };
                foreach (var scheduledTask in taskList)
                {
                    var timer      = new System.Timers.Timer(scheduledTask.RunInterval);
                    timer.Elapsed += (o, args) =>
                    {
                        scheduledTask.TaskStart();
                        timer.Start();
                    };
                    timer.AutoReset = false;
                    timer.Start();
                }
            }, cancellationToken);

            scheduledTaskDeamon.Start();
        }
Ejemplo n.º 4
0
        public LogSourceSearch(ITaskScheduler taskScheduler, ILogSource logSource, string searchTerm, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
            {
                throw new ArgumentNullException(nameof(taskScheduler));
            }
            if (logSource == null)
            {
                throw new ArgumentNullException(nameof(logSource));
            }
            if (string.IsNullOrEmpty(searchTerm))
            {
                throw new ArgumentException("searchTerm may not be empty");
            }

            _logSource            = logSource;
            _filter               = new SubstringFilter(searchTerm, true);
            _matches              = new List <LogMatch>();
            _syncRoot             = new object();
            _listeners            = new LogFileSearchListenerCollection(this);
            _pendingModifications = new ConcurrentQueue <LogSourceModification>();
            _scheduler            = taskScheduler;

            const int maximumLineCount = 1000;

            _maximumWaitTime = maximumWaitTime;
            _logLinesArray   = new LogBufferArray(maximumLineCount, Columns.Index, Columns.RawContent);
            _matchesBuffer   = new List <LogLineMatch>();
            _logSource.AddListener(this, _maximumWaitTime, maximumLineCount);

            _task = _scheduler.StartPeriodic(FilterAllPending,
                                             TimeSpan.FromMilliseconds(100),
                                             string.Format("Search {0}", logSource));
        }
Ejemplo n.º 5
0
        public LogFileSearch(ITaskScheduler taskScheduler, ILogFile logFile, string searchTerm, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
                throw new ArgumentNullException("taskScheduler");
            if (logFile == null)
                throw new ArgumentNullException("logFile");
            if (string.IsNullOrEmpty(searchTerm))
                throw new ArgumentException("searchTerm may not be empty");

            _logFile = logFile;
            _filter = new SubstringFilter(searchTerm, true);
            _matches = new List<LogMatch>();
            _syncRoot = new object();
            _listeners = new LogFileSearchListenerCollection(this);
            _pendingModifications = new ConcurrentQueue<LogFileSection>();
            _scheduler = taskScheduler;

            const int maximumLineCount = 1000;
            _maximumWaitTime = maximumWaitTime;
            _logLinesBuffer = new LogLine[maximumLineCount];
            _matchesBuffer = new List<LogLineMatch>();
            _logFile.AddListener(this, _maximumWaitTime, maximumLineCount);

            _task = _scheduler.StartPeriodic(FilterAllPending,
                                             TimeSpan.FromMilliseconds(100),
                                             string.Format("Search {0}", logFile));
        }
Ejemplo n.º 6
0
        public EventsLogAnalyser(ITaskScheduler scheduler,
                                 ILogFile source,
                                 TimeSpan maximumWaitTime,
                                 EventsLogAnalyserConfiguration configuration)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _scheduler        = scheduler;
            _source           = source;
            _buffer           = new LogLine[MaximumLineCount];
            _events           = new InMemoryLogTable();
            _indices          = new List <LogLineIndex>();
            _eventDefinitions = new List <LogEventDefinition>(configuration.Events.Count);
            _eventDefinitions.AddRange(configuration.Events.Select(TryCreateDefinition).Where(x => x != null));
            _modifications = new ConcurrentQueue <LogFileSection>();

            _source.AddListener(this, maximumWaitTime, MaximumLineCount);
            _task = _scheduler.StartPeriodic(DoWork, TimeSpan.FromMilliseconds(100));
        }
Ejemplo n.º 7
0
        public async Task Start(ParseMessage parseMessage)
        {
            _source = new CancellationTokenSource();

            PeriodicTaskAction <object, CancellationToken> keepChannel = (async(object o, CancellationToken t) =>
            {
                if (_webSocketClient == null)
                {
                    _webSocketClient = new ClientWebSocket();
                    _webSocketClient.Options.KeepAliveInterval = new TimeSpan(keepAliveSocketInterval * TimeSpan.TicksPerSecond);
                    await SocketConnect(parseMessage);
                }
                else if (_webSocketClient.State != WebSocketState.Open && _webSocketClient.State != WebSocketState.Connecting)
                {
                    _webSocketClient.Dispose();
                    _webSocketClient = new ClientWebSocket();
                    _webSocketClient.Options.KeepAliveInterval = new TimeSpan(keepAliveSocketInterval * TimeSpan.TicksPerSecond);
                    await SocketConnect(parseMessage);
                }
            }
                                                                          );

            tickerchnl = new PeriodicTaskWrapper(_logger, _name);
            await tickerchnl.Start(keepChannel, new PeriodicTaskParams { period = (int)keepAliveSecs * 1000 }, _source.Token);
        }
 private static IDisposable SyncRepeatObservable(IPeriodicTask schedule)
 {
     return(Observable
            .FromAsync(schedule.StartJob)
            .Delay(schedule.Interval)
            .Repeat()
            .TakeWhile(e => e)
            .Subscribe());
 }
 public PeriodicCacheCleaner(InProcSessionsConfiguration configuration, IInProcSessionCache sessionCache, IPeriodicTaskFactory periodicTaskFactory, ICancellationTokenSourceFactory cancellationTokenSourceFactory) {
   if (configuration == null) throw new ArgumentNullException("configuration");
   if (sessionCache == null) throw new ArgumentNullException("sessionCache");
   if (periodicTaskFactory == null) throw new ArgumentNullException("periodicTaskFactory");
   if (cancellationTokenSourceFactory == null) throw new ArgumentNullException("cancellationTokenSourceFactory");
   _configuration = configuration;
   _cancellationTokenSourceFactory = cancellationTokenSourceFactory;
   _periodicTask = periodicTaskFactory.Create(sessionCache.Trim);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Construtor da classe, que recebe a tarefa a ser controlada e seus parâmetros de execução.
        /// Adicionalmente recebe o intervalo de execução da tarefa e o mecanismo de acesso ao banco.
        /// </summary>
        public JobController(IPeriodicTask task, NameValueCollection taskParams, DataAccess dataAccess, double interval)
        {
            this.taskList = new List <IPeriodicTask>();
            this.taskList.Add(task);
            this.taskParams = taskParams;
            this.dataAccess = dataAccess;

            jobTrigger          = new Timer(interval);
            jobTrigger.Elapsed += new ElapsedEventHandler(OnTimerEvent);
            jobTrigger.Enabled  = false;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// </summary>
        /// <param name="scheduler"></param>
        /// <param name="fileName"></param>
        internal EventLogSource(ITaskScheduler scheduler, string fileName)
        {
            _scheduler = scheduler;
            _fileName  = fileName;

            _buffer = new InMemoryLogSource();
            _buffer.SetValue(Core.Properties.Created, DateTime.Now);

            _cancellationTokenSource = new CancellationTokenSource();

            _readTask = _scheduler.StartPeriodic(RunOnce, ToString());
        }
Ejemplo n.º 12
0
        public LogFileProxy(ITaskScheduler taskScheduler, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
                throw new ArgumentNullException("taskScheduler");

            _taskScheduler = taskScheduler;
            _pendingSections = new ConcurrentQueue<KeyValuePair<ILogFile, LogFileSection>>();
            _listeners = new LogFileListenerCollection(this);

            _task = _taskScheduler.StartPeriodic(RunOnce, "Log File Proxy");
            _maximumWaitTime = maximumWaitTime;
        }
    public PeriodicCacheCleanerFixture() {
      _fakeSessionCache = A.Fake<IInProcSessionCache>();
      _fakePeriodicTaskFactory = A.Fake<IPeriodicTaskFactory>();
      _fakePeriodicTask = A.Fake<IPeriodicTask>();
      _fakeCancellationTokenSourceFactory = A.Fake<ICancellationTokenSourceFactory>();
      _validConfiguration = new InProcSessionsConfiguration();

      _cancellationTokenSource = new CancellationTokenSource();
      A.CallTo(() => _fakeCancellationTokenSourceFactory.Create()).Returns(_cancellationTokenSource);
      A.CallTo(() => _fakePeriodicTaskFactory.Create(A<Action>._)).Returns(_fakePeriodicTask);

      _periodicCacheCleaner = new PeriodicCacheCleaner(_validConfiguration, _fakeSessionCache, _fakePeriodicTaskFactory, _fakeCancellationTokenSourceFactory);
    }
 public void Register(IPeriodicTask task, TimeSpan period)
 {
     lock (lockObject)
     {
         if (tasks.ContainsKey(task.Id))
         {
             return;
         }
         var executor = new ThreadBasedPeriodicTaskExecutor(task, period, logger);
         executor.Start();
         tasks.Add(task.Id, executor);
     }
 }
        public PeriodicCacheCleanerFixture()
        {
            _fakeSessionCache                   = A.Fake <IInProcSessionCache>();
            _fakePeriodicTaskFactory            = A.Fake <IPeriodicTaskFactory>();
            _fakePeriodicTask                   = A.Fake <IPeriodicTask>();
            _fakeCancellationTokenSourceFactory = A.Fake <ICancellationTokenSourceFactory>();
            _validConfiguration                 = new InProcSessionsConfiguration();

            _cancellationTokenSource = new CancellationTokenSource();
            A.CallTo(() => _fakeCancellationTokenSourceFactory.Create()).Returns(_cancellationTokenSource);
            A.CallTo(() => _fakePeriodicTaskFactory.Create(A <Action> ._)).Returns(_fakePeriodicTask);

            _periodicCacheCleaner = new PeriodicCacheCleaner(_validConfiguration, _fakeSessionCache, _fakePeriodicTaskFactory, _fakeCancellationTokenSourceFactory);
        }
Ejemplo n.º 16
0
        public void Start()
        {
            lock (_syncRoot)
            {
                if (_isDisposed)
                {
                    Log.WarnFormat("Ignoring Start(): This analysis has already been disposed of");
                    return;
                }

                _analyser = TryCreateAnalyser();
                _task     = _scheduler.StartPeriodic(OnUpdate, TimeSpan.FromSeconds(0.5), "");
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     Initializes this object.
        /// </summary>
        /// <param name="taskScheduler"></param>
        /// <param name="maximumWaitTime"></param>
        public LogFileProxy(ITaskScheduler taskScheduler, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
            {
                throw new ArgumentNullException(nameof(taskScheduler));
            }

            _taskScheduler   = taskScheduler;
            _pendingSections = new ConcurrentQueue <KeyValuePair <ILogFile, LogFileSection> >();
            _listeners       = new LogFileListenerCollection(this);

            _task            = _taskScheduler.StartPeriodic(RunOnce, "Log File Proxy");
            _maximumWaitTime = maximumWaitTime;
        }
Ejemplo n.º 18
0
        public Generator(ITaskScheduler taskScheduler, ILog log)
        {
            if (taskScheduler == null)
                throw new ArgumentNullException("taskScheduler");
            if (log == null)
                throw new ArgumentNullException("log");

            _random = new Random();
            _taskScheduler = taskScheduler;
            _log = log;

            _messages = CreateMessages();

            _task = _taskScheduler.StartPeriodic(Update);
        }
Ejemplo n.º 19
0
        public PageBufferedLogSource(ITaskScheduler taskScheduler, ILogSource source, TimeSpan maximumWaitTime, IReadOnlyList <IColumnDescriptor> nonCachedColumns, int pageSize = DefaultPageSize, int maxNumPages = DefaultMaxPageCount)
        {
            _syncRoot      = new object();
            _taskScheduler = taskScheduler;
            _source        = source;
            _maxNumPages   = maxNumPages;
            _listeners     = new ProxyLogListenerCollection(source, this);
            _cachedColumns = source.Columns.Except(nonCachedColumns).ToList();
            _buffer        = new PagedLogBuffer(pageSize, maxNumPages, _cachedColumns);
            _fetchQueue    = new ConcurrentQueue <LogSourceSection>();
            _source.AddListener(this, maximumWaitTime, pageSize);

            _fetchBuffer = new LogBufferArray(pageSize, _cachedColumns);
            _fetchTask   = _taskScheduler.StartPeriodic(FetchPagesFromSource, maximumWaitTime);
        }
Ejemplo n.º 20
0
        public LogFileSearchProxy(ITaskScheduler taskScheduler, ILogFile logFile, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
                throw new ArgumentNullException("taskScheduler");
            if (logFile == null)
                throw new ArgumentNullException("logFile");

            _pendingMatches = new ConcurrentQueue<KeyValuePair<ILogFileSearch, List<LogMatch>>>();
            _logFile = logFile;
            _listeners = new List<ILogFileSearchListener>();
            _taskScheduler = taskScheduler;
            _syncRoot = new object();
            _matches = new List<LogMatch>();
            _maximumWaitTime = maximumWaitTime;

            _task = _taskScheduler.StartPeriodic(RunOnce, _maximumWaitTime, "Search Proxy");
        }
Ejemplo n.º 21
0
 private void UpdateFolderScan()
 {
     // Folder scans shall only be performed when the panel is selected (and thus visible to the user).
     // If the user doesn't see the panel then we don't really need to know what happened inside
     // the folder...
     if (IsSelected)
     {
         _snapshotScanTask = _taskScheduler.StartPeriodic(ScanSnapshotsFolder,
                                                          TimeSpan.FromSeconds(value: 5),
                                                          "Snapshot Scan");
     }
     else
     {
         _taskScheduler.StopPeriodic(_snapshotScanTask);
         _snapshotScanTask = null;
     }
 }
Ejemplo n.º 22
0
        public Generator(ITaskScheduler taskScheduler, ILog log)
        {
            if (taskScheduler == null)
            {
                throw new ArgumentNullException(nameof(taskScheduler));
            }
            if (log == null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            _random        = new Random();
            _taskScheduler = taskScheduler;
            _log           = log;

            _messages = CreateMessages();

            _task = _taskScheduler.StartPeriodic(Update);
        }
Ejemplo n.º 23
0
        private void RunThread(object state)
        {
            IPeriodicTask task = (IPeriodicTask)state;

            while (!_quitting)
            {
                task.RunCycle();
                Interlocked.Increment(ref _totalCycles);
                try
                {
                    Thread.Sleep(_interval);
                }
                catch (ThreadInterruptedException)
                {
                    return;
                }
                _mre.WaitOne();
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        ///     Initializes this object.
        /// </summary>
        /// <param name="taskScheduler"></param>
        /// <param name="maximumWaitTime"></param>
        /// <param name="maxEntryCount"></param>
        public LogSourceProxy(ITaskScheduler taskScheduler, TimeSpan maximumWaitTime, int maxEntryCount = DefaultMaxEntryCount)
        {
            if (taskScheduler == null)
            {
                throw new ArgumentNullException(nameof(taskScheduler));
            }

            _taskScheduler = taskScheduler;
            _properties    = new ConcurrentPropertiesList(Core.Properties.Minimum);
            _properties.SetValue(Core.Properties.EmptyReason, null);

            _sourceProperties = new PropertiesBufferList();
            _pendingSections  = new ConcurrentQueue <KeyValuePair <ILogSource, LogSourceModification> >();
            _listeners        = new LogSourceListenerCollection(this);

            _task            = _taskScheduler.StartPeriodic(RunOnce, "Log File Proxy");
            _maximumWaitTime = maximumWaitTime;
            _maxEntryCount   = maxEntryCount;
        }
Ejemplo n.º 25
0
        public SQLiteLogTable(ITaskScheduler scheduler, LogDataCache cache, string fileName)
        {
            if (scheduler == null)
                throw new ArgumentNullException("scheduler");
            if (cache == null)
                throw new ArgumentNullException("cache");
            if (fileName == null)
                throw new ArgumentNullException("fileName");

            _scheduler = scheduler;
            _cache = cache;
            _fileName = fileName;

            _listeners = new LogTableListenerCollection(this);
            _accessQueue = new LogDataAccessQueue<LogEntryIndex, LogEntry>();

            _schema = new SQLiteSchema(string.Empty);

            _task = _scheduler.StartPeriodic(Update, ToString());
        }
Ejemplo n.º 26
0
        public LogSourceSearchProxy(ITaskScheduler taskScheduler, ILogSource logSource, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
            {
                throw new ArgumentNullException(nameof(taskScheduler));
            }
            if (logSource == null)
            {
                throw new ArgumentNullException(nameof(logSource));
            }

            _pendingMatches  = new ConcurrentQueue <KeyValuePair <ILogSourceSearch, List <LogMatch> > >();
            _logSource       = logSource;
            _listeners       = new List <ILogFileSearchListener>();
            _taskScheduler   = taskScheduler;
            _syncRoot        = new object();
            _matches         = new List <LogMatch>();
            _maximumWaitTime = maximumWaitTime;

            _task = _taskScheduler.StartPeriodic(RunOnce, _maximumWaitTime, "Search Proxy");
        }
 public PeriodicCacheCleaner(InProcSessionsConfiguration configuration, IInProcSessionCache sessionCache, IPeriodicTaskFactory periodicTaskFactory, ICancellationTokenSourceFactory cancellationTokenSourceFactory)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException("configuration");
     }
     if (sessionCache == null)
     {
         throw new ArgumentNullException("sessionCache");
     }
     if (periodicTaskFactory == null)
     {
         throw new ArgumentNullException("periodicTaskFactory");
     }
     if (cancellationTokenSourceFactory == null)
     {
         throw new ArgumentNullException("cancellationTokenSourceFactory");
     }
     _configuration = configuration;
     _cancellationTokenSourceFactory = cancellationTokenSourceFactory;
     _periodicTask = periodicTaskFactory.Create(sessionCache.Trim);
 }
Ejemplo n.º 28
0
        public QuickInfoAnalyser(ITaskScheduler scheduler,
                                 ILogFile source,
                                 TimeSpan maximumWaitTime,
                                 QuickInfoAnalyserConfiguration configuration)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _scheduler         = scheduler;
            _pendingChanges    = new ConcurrentQueue <PendingChange>();
            _lastMatchingLines = new Dictionary <Guid, LogLine?>();
            var logFiles = new Dictionary <ILogFile, Guid>();

            _logFiles = logFiles;
            try
            {
                foreach (var pair in configuration.QuickInfos)
                {
                    var filter          = CreateFilter(pair.Value);
                    var filteredLogFile = source.AsFiltered(scheduler, filter, logEntryFilter: null);
                    logFiles.Add(filteredLogFile, pair.Key);
                    _lastMatchingLines.Add(pair.Key, value: null);
                    filteredLogFile.AddListener(this, maximumWaitTime, MaximumLineCount);
                }
            }
            catch (Exception)
            {
                Dispose(logFiles.Keys);
                throw;
            }

            _task = scheduler.StartPeriodic(OnUpdate, maximumWaitTime, "Quick Info Analyser");
        }
Ejemplo n.º 29
0
 public ChatService(IPeriodicTask periodicTask)
 {
     this.periodicTask = periodicTask;
 }
 public ThreadBasedPeriodicTaskExecutor(IPeriodicTask task, TimeSpan period)
 {
     this.task   = task;
     this.period = period;
 }
Ejemplo n.º 31
0
 /// <summary>
 ///     Any subclass MUST call this method in its constructor (preferably after the log file has been initialized,
 ///     as after this call, <see cref="RunOnce" /> will be called.
 /// </summary>
 protected virtual void StartTask()
 {
     _readTask = _scheduler.StartPeriodic(Run, ToString());
 }
 public ThreadBasedPeriodicTaskExecutor(IPeriodicTask task, TimeSpan period, ILog logger)
 {
     this.task   = task;
     this.period = period;
     this.logger = logger;
 }
Ejemplo n.º 33
0
 protected void StartTask()
 {
     _readTask = _scheduler.StartPeriodic(Run, ToString());
 }