private void PreprocessExistingFiles()
 {
     foreach (var section in FileSections)
     {
         var directory = Path.Combine(FilesLocation, section.Folder);
         foreach (var file in Directory.GetFiles(directory).Where(f => !f.Contains(Constants.ChangedString)))
         {
             if (IoHelper.LoadAllChanged(file).Any())
             {
                 continue;
             }
             FilePreprocessController.EnqueueFile(file);
         }
     }
 }
        private void HandleFileDeleteRequest(HttpListenerContext context, string filePath)
        {
            if (!File.Exists(filePath))
            {
                LogDebug($"File {filePath} does not exist and cannot be deleted");
                ResponseFactory.BuildResponse(context, HttpStatusCode.NotFound, null);
                return;
            }

            var compressed = IoHelper.LoadAllChanged(filePath);

            try
            {
                File.Delete(filePath);
                compressed.ForEach(File.Delete);
                ResponseFactory.BuildResponse(context, HttpStatusCode.OK, null);
            }
            catch (Exception ex)
            {
                LogException(LogLevel.Warning, ex);
                ResponseFactory.BuildResponse(context, HttpStatusCode.InternalServerError, null);
            }
        }
        public FileOperationStatus DeleteFile(string sectionName, string filename)
        {
            var section = FileSections.FirstOrDefault(s => s.Name == sectionName);

            if (section == null)
            {
                LogDebug($"Section {sectionName} not found");
                return(FileOperationStatus.NotFound);
            }

            if (filename.Contains("_CHANGED_"))
            {
                return(FileOperationStatus.BadParameters);
            }
            var filePath = FilesLocation + Path.DirectorySeparatorChar + section.Folder + Path.DirectorySeparatorChar + filename;

            if (!File.Exists(filePath))
            {
                LogDebug($"File {filePath} does not exist and cannot be deleted");
                return(FileOperationStatus.NotFound);
            }

            var compressed = IoHelper.LoadAllChanged(filePath);

            try
            {
                File.Delete(filePath);
                compressed.ForEach(File.Delete);
                return(FileOperationStatus.Ok);
            }
            catch (Exception ex)
            {
                LogException(LogLevel.Warning, ex);
                return(FileOperationStatus.Error);
            }
        }