Ejemplo n.º 1
0
        public static void CleanLogsFolder(params UserSettingsEnum.Options[] lOptions)
        {
            string logDirectory = GetLogDirectory();

            string[] files = Directory.GetFiles(logDirectory);

            bool cleanupThrownLogs  = lOptions.Contains(UserSettingsEnum.Options.CLEAN_FATAL_LOGS);
            bool cleanupBasedOnDate = lOptions.Contains(UserSettingsEnum.Options.CLEAN_LOGS_ONLY_BEFORE_TODAY);

            string[] logsBeforeToday = FindAllLogsCreatedBefore(DateTime.Today);

            foreach (string file in files)
            {
                bool   fileMarkedForDeletion = false;
                string ext = HelperFunc.GetFileExtension(file);

                if (ext != NORMAL_LOG_EXT && ext != THROWN_LOG_EXT)
                {
                    continue;
                }

                //TODO(Medium): Fix this copy paste job. It works but the fact Im copy pasting code is bad news.
                if (cleanupBasedOnDate && logsBeforeToday.Contains(file))
                {
                    if (cleanupThrownLogs)
                    {
                        fileMarkedForDeletion = true;
                    }
                    else
                    if (ext != THROWN_LOG_EXT)
                    {
                        fileMarkedForDeletion = true;
                    }
                }
                else
                {
                    if (cleanupThrownLogs)
                    {
                        fileMarkedForDeletion = true;
                    }
                    else
                    if (ext != THROWN_LOG_EXT)
                    {
                        fileMarkedForDeletion = true;
                    }
                }

                if (fileMarkedForDeletion)
                {
                    File.Delete(file);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Asserts that there are no files with the given extension in a folder.
        /// </summary>
        /// <param name="extension">Extension to check.</param>
        /// <param name="folder">Folder to find files in.</param>
        /// <returns>True if there are no files with the given extension otherwise false or a throw if there are files with the extension.</returns>
        public static bool NoFilesWithExtension(string extension, string folder)
        {
            string[] files = Directory.GetFiles(folder);

            foreach (string file in files)
            {
                if (HelperFunc.GetFileExtension(file) == extension)
                {
                    if (IsStrict)
                    {
                        throw new AssertionFailedException("File found containing extension " + extension + ", file: " + file);
                    }

                    return(false);
                }
            }

            return(true);
        }