public static PathnameAndSchedule Init(string pathname, int checklistStep, string startTime, string endTime, int intervalMins) { PathnameAndSchedule p = new PathnameAndSchedule(); p.Pathname = pathname; p.ChecklistStep = checklistStep; p.StartTime = p.parse(startTime); p.EndTime = p.parse(endTime); p.IntervalMins = intervalMins; return(p); }
/// <summary> /// This method will copulate the age of a file based on its interval and last scheduled time. /// </summary> /// <param name="folder"></param> /// <param name="dateTime"></param> /// <returns></returns> private int calculateAge(PathnameAndSchedule folder, DateTime dateTime) { if (folder.IntervalMins == 0) { return(99); } TimeSpan ts = lastScheduledTime(folder).Subtract(dateTime); var age = ts.Days * 1440 + ts.Hours * 60 + ts.Minutes; return(age); }
/// <summary> /// This method will determine the last scheduled time items in a folder should've been processed /// based on the folders start time, and time, and interval. /// </summary> /// <param name="folder"></param> /// <returns>Last scheduled time</returns> private DateTime lastScheduledTime(PathnameAndSchedule folder) { var lastRun = DateTime.Today.AddHours(folder.StartTime.Hour); lastRun = lastRun.AddMinutes(folder.StartTime.Minute); if (DateTime.Now < lastRun) { lastRun = DateTime.Today.AddDays(-1); lastRun = lastRun.AddHours(folder.EndTime.Hour); lastRun = lastRun.AddMinutes(folder.EndTime.Minute); return(lastRun); } while (lastRun < DateTime.Now) { lastRun = lastRun.AddMinutes(folder.IntervalMins); } lastRun = lastRun.AddMinutes(-1 * folder.IntervalMins); return(lastRun); }
/// <summary> /// This utility method is responsible for filtering the results based on scheduled times, /// and avoiding template files. It will also handle zero dollars files found in hold. /// </summary> /// <param name="folder"></param> /// <returns></returns> private List <ProblemFile> filterResults(PathnameAndSchedule folder) { List <ProblemFile> problems = new List <ProblemFile>(); var windowStart = DateTime.Today.AddHours(folder.StartTime.Hour).AddMinutes(folder.StartTime.Minute); var windowEnd = DateTime.Today.AddHours(folder.EndTime.Hour).AddMinutes(folder.EndTime.Minute); var di = new DirectoryInfo(folder.Pathname); var fileInfos = di.GetFiles(); var age = 0; if (folder.IntervalMins > 0) { this.Log.Write(Severity.Debug, "Checking for files created between {0:MM/dd/yyyy hh:mm} and {0:MM/dd/yyyy hh:mm}.", windowStart, windowEnd); } foreach (FileInfo fi in fileInfos) { if (folder.Pathname.ToLower().Contains("cardholder") && fi.Name.ToLower().Contains("template")) { continue; } if (folder.Pathname.ToLower().Contains(@"\hold") && fi.Name.ToLower().Contains("zerodoller")) { var holdPathname = @"W:\hold\Zero Files" + @"\" + fi.Name; if (File.Exists(holdPathname)) { holdPathname = Path.GetDirectoryName(holdPathname) + Path.GetFileNameWithoutExtension(holdPathname) + DateTime.Now.ToString("Hmmss") + Path.GetExtension(holdPathname); } this.Log.Write(Severity.Info, "Moving {0} to {1}.", fi.Name, holdPathname); FileSystem.Move(fi.FullName, holdPathname); continue; } if (folder.IntervalMins > 0) { if (fi.LastWriteTime < windowStart) { continue; } } if (folder.IntervalMins > 0) { if (fi.LastWriteTime > windowEnd) { continue; } } age = calculateAge(folder, fi.LastWriteTime); if (age > folder.IntervalMins) { problems.Add(new ProblemFile(fi.Name, fi.LastWriteTime, fi.Length, age)); } } return(problems); }
public static PathnameAndSchedule Init(string pathname, int checklistStep) { PathnameAndSchedule p = PathnameAndSchedule.Init(pathname, checklistStep, "", "", 0); return(p); }