Example #1
0
        internal void DoMaintenanceNow()
        {
            lastFileMaintenanceTime = DateTimeEx.Now;
            foreach (var kvp in directoryNamesAndDays)
            {
                int days = kvp.Value;
                if (days < 0)
                {
                    continue;
                }

                if (Verbose)
                {
                    SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, kvp.Key + ": Deleting files older than " + days + " days.");
                }
                bool removeDirectory = false;
                if (directoryNamesAndRemoveDirectory.ContainsKey(kvp.Key))
                {
                    removeDirectory = directoryNamesAndRemoveDirectory[kvp.Key];
                }

                DeleteOldFiles(kvp.Key, days, removeDirectory);
            }

            if (Verbose)
            {
                SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, "Maintenance complete. Next maintenance time: " + DateTimeEx.ToStdDateTimeFormat(lastFileMaintenanceTime.AddMinutes(minutesBetweenMaintenance)));
            }
        }
Example #2
0
        public static void RecordException(string s, bool assert)
        {
            if (SameExceptionHappenedLessThanMillisecondAgo(s))
            {
                return;
            }

            SimpleFileWriter.WriteLineToEventFile(DirectoryName.EventLog, s);
            Debug.Assert(assert, s);
        }
Example #3
0
 // -1: do not delete files, 0: delete files immediately
 public void AddDirectory(string directoryName, int days, bool removeDirectoryIfEmpty = false)
 {
     if (Verbose)
     {
         SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, String.Format("Adding directory {0} under automatic maintenance. ", directoryName));
         SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, String.Format("Files older than {0} days will be deleted automatically", days.ToIcString()));
     }
     directoryNamesAndDays[directoryName]            = days;
     directoryNamesAndRemoveDirectory[directoryName] = removeDirectoryIfEmpty;
 }
Example #4
0
        private static void ProcessException(string s)
        {
            SimpleFileWriter.WriteStackToDiagnosticsLog(s);
            SimpleFileWriter.WriteLineToEventFile(DirectoryName.EventLog, s);
#if DEBUG
            //  Debugger.Break();
            string s1 = string.Format(CultureInfo.InvariantCulture, "{0}\t{1}\t{2}\r\n", DateTimeEx.NowToString, s,
                                      SimpleFileWriter.GetStack);
            Debug.Assert(false, s + Environment.NewLine + s1);
#endif
        }