Ejemplo n.º 1
0
        public void Process(MonitorJob monitorJob)
        {
            Log.DebugFormat("Stepped into process for monitorjob '{0}'", monitorJob.ID);
            if (!Directory.Exists(monitorJob.Path))
            {
                Log.ErrorFormat("We could not find the directory '{0}'", monitorJob.Path);
                throw new DirectoryNotFoundException(monitorJob.Path);
            }

            var directoryInfo = new DirectoryInfo(monitorJob.Path);

            var allTheFiles = directoryInfo.GetFiles(monitorJob.FileExtensionToWatch);

            foreach (var fileInfo in allTheFiles)
            {
                if (fileInfo.CreationTime < _timeActions.Now().Subtract(GetTimeSpanToUse(monitorJob.Threshold, monitorJob.ThresholdType)))

                {
                    var message = string.Format("There is a file '{0}' of type '{1}' older than the threshold '{2}' {3} in the directory '{4}'",
                                                fileInfo.Name, monitorJob.FileExtensionToWatch, monitorJob.Threshold, monitorJob.ThresholdType, monitorJob.Path);
                    Log.InfoFormat(message);
                    _emailActions.SendAlert(message);
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        public bool ThisJobShouldRunNow(MonitorJob monitorJob)
        {
            if (!monitorJob.LastTimeThisJobRan.HasValue)
            {
                Log.DebugFormat("ThisJobShouldRunNow is returning 'true' for monitorJobId '{0}'", monitorJob.ID);
                return(true);
            }

            if (NextTimeThisJobShouldRun(monitorJob) < _timeActions.Now())
            {
                Log.DebugFormat("ThisJobShouldRunNow is returning 'true' for monitorJobId '{0}'", monitorJob.ID);
                return(true);
            }
            Log.DebugFormat("ThisJobShouldRunNow is returning 'false' for monitorJobId '{0}'", monitorJob.ID);
            return(false);
        }
Ejemplo n.º 3
0
        public void Process(MonitorJob monitorJob)
        {
            Log.DebugFormat("Stepped into process for monitorjob '{0}'", monitorJob.ID);
            if (!Directory.Exists(monitorJob.Path))
            {
                Log.ErrorFormat("We could not find the directory '{0}'", monitorJob.Path);
                throw new DirectoryNotFoundException(monitorJob.Path);
            }

            var lastWriteTime = Directory.GetLastWriteTime(monitorJob.Path);

            if (lastWriteTime < _timeActions.Now().Subtract(GetTimeSpanToUse(monitorJob.Threshold, monitorJob.ThresholdType)))
            {
                var emailMessage = string.Format("No new files have shown up in the directory '{0}' in the last '{1}' '{2}'", monitorJob.Path, monitorJob.Threshold, monitorJob.ThresholdType);
                Log.InfoFormat(emailMessage);
                _emailActions.SendAlert(emailMessage);
            }
        }