public static void VideoCheck(string SearchPath, string ReportFile, Mode Mode) { DateTime PStart = DateTime.Now; Output_ProcessReport Report = new Output_ProcessReport(); List <string> videoList = Retriever.GetVideoFiles(SearchPath); if (!File.Exists(ReportFile)) { CreateReportFile(ReportFile, Mode, null); } if (videoList != null) { if (videoList.Any()) { for (var i = 0; i < videoList.Count; i++) { if (ExecuteFFMPEG(ReportFile, SearchPath, videoList[i], ProcessType.VideoCheck)) { Report.Damaged += 1; string frameTraceReport = Path.Combine(SearchPath, Path.GetFileName(videoList[i]) + OutputExtension.TXT); if (!File.Exists(frameTraceReport)) { CreateReportFile(frameTraceReport, Mode, null); } ExecuteFFMPEG(frameTraceReport, SearchPath, videoList[i], ProcessType.FrameTrace); if (File.Exists(frameTraceReport)) { if (new FileInfo(frameTraceReport).Length == 0) { try { File.Delete(frameTraceReport); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } } else { Report.Healthy += 1; } SetProgressBar(i, videoList.Count); Report.Total += 1; } } } TimeSpan Elapsed = DateTime.Now.Subtract(PStart); SummariseReport(ReportFile, Mode, Elapsed, Report); }
public static void Verify(string SearchPath, string ReportFile, Mode Mode, int StartingPoint = 0, DateTime?FilterDate = null, bool UseDateFilter = false) { DateTime PStart = DateTime.Now; List <FileItem> lists = new List <FileItem>(); List <string> md5List = Retriever.GetFiles(SearchPath, SearchExtension.MD5, FilterDate, UseDateFilter); Output_ProcessReport Result = new Output_ProcessReport(); Console.WriteLine("No. of md5 : " + md5List.Count); if (!File.Exists(ReportFile)) { if (!CreateReportFile(ReportFile, Mode, md5List)) { throw new Exception("Unable to create report file."); } } for (int i = StartingPoint; i < md5List.Count; i++) { lists = BuildFileItemList(md5List[i]); if (lists.Any()) { Result.Total += lists.Count; if (Mode != Mode.Combine_All_MD5) { using (StreamWriter file = File.AppendText(ReportFile)) { file.WriteLine(Convert.ToString(i + 1) + "/" + md5List.Count + "\t" + md5List[i].Replace(SearchPath, "") + " Proccessing..."); //md5List[i].Split('\'')[md5List[i].Split('\'').Length - 1] } } Output_ProcessReport ItemResult = ProcessMD5File(lists, Mode, ReportFile); Result.Healthy += ItemResult.Healthy; Result.Damaged += ItemResult.Damaged; Result.Missing += ItemResult.Missing; if (Mode != Mode.Combine_All_MD5) { using (StreamWriter file = File.AppendText(ReportFile)) { file.WriteLine("Verification Completed"); file.WriteLine("----------------------"); } } Console.WriteLine(Convert.ToString(i + 1) + "/" + md5List.Count + "\t" + md5List[i].Replace(SearchPath, "") + " Checked."); SetProgressBar(i, md5List.Count); lists.Clear(); } } TimeSpan Elapsed = DateTime.Now.Subtract(PStart); SummariseReport(ReportFile, Mode, Elapsed, Result); }
public static void ParalleRefresh(string SearchPath, string ReportFile, Mode Mode, ProcessingPower ProcessingPower, int StartingPoint = 0, DateTime?FilterDate = null, bool UseDateFilter = false) { DateTime PStart = DateTime.Now; Output_ProcessReport Report = new Output_ProcessReport(); List <FileItem> FileList = new List <FileItem>(); List <FileItem> HealthyList = new List <FileItem>(); List <FileItem> DamagedList = new List <FileItem>(); List <FileItem> MissingList = new List <FileItem>(); List <string> folderList = Retriever.Getfolders(SearchPath, FilterDate, UseDateFilter); List <string> md5List = Retriever.GetFiles(SearchPath, SearchExtension.MD5, FilterDate, UseDateFilter); if (!File.Exists(ReportFile)) { CreateReportFile(ReportFile, Mode, null); } Console.WriteLine("No. of md5 : " + md5List.Count); Console.WriteLine("No. of folders : " + folderList.Count); for (int i = StartingPoint; i < folderList.Count; i++) { string md5File = md5List.FirstOrDefault(s => Path.GetFileNameWithoutExtension(s) == Path.GetFileName(folderList[i])); if (!string.IsNullOrEmpty(md5File)) { FileList = BuildFileItemList(md5File); } FileList = ProcessFilesInFolder(folderList[i], ReportFile, FileList, DamagedList, ProcessingPower); if (FileList.Any()) { FileList = Sort(FileList, folderList[i]); HealthyList = FileList.Where(s => s.IsChecksummed != ChecksumStat.DuplicateNameOrCorrupted && s.IsChecksummed != ChecksumStat.Init).ToList(); if (HealthyList.Any()) { if (ProcessGeneratedList(HealthyList, ListType.Healthy, folderList[i])) { Report.Healthy += HealthyList.Count; } HealthyList.Clear(); } DamagedList = FileList.Where(s => s.IsChecksummed == ChecksumStat.DuplicateNameOrCorrupted).ToList(); if (DamagedList.Any()) { DamagedList = Sort(DamagedList, folderList[i]); if (ProcessGeneratedList(DamagedList, ListType.Damaged, folderList[i])) { Report.Damaged += DamagedList.Count; } DamagedList.Clear(); } MissingList = FileList.Where(s => s.IsChecksummed == ChecksumStat.Init).ToList(); if (MissingList.Any()) { MissingList = Sort(MissingList, folderList[i]); if (ProcessGeneratedList(MissingList, ListType.Missing, folderList[i])) { Report.Missing += MissingList.Count; } MissingList.Clear(); } FileList.Clear(); } SetProgressBar(i, folderList.Count); Console.WriteLine(Convert.ToString((i + 1)) + "/" + folderList.Count + "\t" + Path.GetFileName(folderList[i]) + OutputExtension.MD5 + " Generated."); using (StreamWriter file = File.AppendText(ReportFile)) { file.WriteLine(Convert.ToString((i + 1)) + "/" + folderList.Count + "\t" + Path.GetFileName(folderList[i]) + OutputExtension.MD5 + " Generated."); } Report.Total += 1; } TimeSpan Elapsed = DateTime.Now.Subtract(PStart); SummariseReport(ReportFile, Mode, Elapsed, Report); //DateTime PStart = DateTime.Now; //Output_ProcessReport Report = new Output_ProcessReport(); //List<FileItem> FileList = new List<FileItem>(); //List<FileItem> HealthyList = new List<FileItem>(); //List<FileItem> DamagedList = new List<FileItem>(); //List<FileItem> MissingList = new List<FileItem>(); //List<string> folderList = Retriever.Getfolders(SearchPath, FilterDate, UseDateFilter); //List<string> md5List = Retriever.GetFiles(SearchPath, SearchExtension.MD5, FilterDate, UseDateFilter); //if (!File.Exists(ReportFile)) //{ // CreateReportFile(ReportFile, Mode, null); //} //Console.WriteLine("No. of md5 : " + md5List.Count); //Console.WriteLine("No. of folders : " + folderList.Count); //int index = 0; //StreamWriter file = File.AppendText(ReportFile); ////using (StreamWriter file = File.AppendText(ReportFile)) ////{ //try //{ // var result = Parallel.ForEach(folderList, new ParallelOptions { MaxDegreeOfParallelism = 2 }, // folder => // { // string FolderPath = folder; // index += 1; // Task task = Task.Factory.StartNew(() => // Begin task // { // return TaskTest(md5List, FileList, HealthyList, DamagedList, MissingList, FolderPath, ReportFile); // }) // .ContinueWith(ant => // { // Report.Healthy += ant.Result.Healthy; // Report.Damaged += ant.Result.Damaged; // Report.Missing += ant.Result.Missing; // Report.Total += ant.Result.Total; // SetProgressBar(index, folderList.Count); // Console.WriteLine(Convert.ToString(index + 1) + "/" + folderList.Count + "\t" + Path.GetFileName(FolderPath) + OutputExtension.MD5 + " Generated."); // //using (StreamWriter file = File.AppendText(ReportFile)) // //{ // file.WriteLine(Convert.ToString(index + 1) + "/" + folderList.Count + "\t" + Path.GetFileName(FolderPath) + OutputExtension.MD5 + " Generated."); // //} // }); // }).IsCompleted; // //if (result) // // file.Dispose(); //} //finally //{ // file.Dispose(); //} ////} //TimeSpan Elapsed = DateTime.Now.Subtract(PStart); //SummariseReport(ReportFile, Mode, Elapsed, Report); }
private static List <FileItem> ProcessFilesInFolder(string SearchPath, string ReportFile, List <FileItem> fileList, List <FileItem> DamagedList, ProcessingPower ProcessingPower) { List <FileItem> Calculated = Retriever.GetFiles(SearchPath, SearchExtension.Everything, null, false).Select(x => new FileItem() { Filepath = x }).ToList(); ParallelOptions pOptions = new ParallelOptions(); switch (ProcessingPower) { case ProcessingPower.Half: pOptions.MaxDegreeOfParallelism = (Environment.ProcessorCount / 2); break; case ProcessingPower.Full: pOptions.MaxDegreeOfParallelism = Environment.ProcessorCount; break; case ProcessingPower.Single: default: pOptions.MaxDegreeOfParallelism = 1; break; } var result = Parallel.ForEach(Calculated, pOptions, file => { file.Hash = ComputeMD5(file.Filepath); }); if (Calculated.Any()) { foreach (FileItem file in Calculated) { try { FileItem fcs = fileList.FirstOrDefault(s => s.Hash == file.Hash && s.Filepath == file.Filepath); if (fcs != null) {//old file checksummed foreach (var fileItem in fileList.Where(s => s.Hash == file.Hash && s.Filepath == file.Filepath)) { fileItem.IsChecksummed = ChecksumStat.ExistingFileChecked; } } else { FileItem targetfcs = fileList.FirstOrDefault(s => s.Hash != file.Hash && s.Filepath == file.Filepath); if (targetfcs != null) {//different file with duplicate filename or file corrupted targetfcs.IsChecksummed = ChecksumStat.DuplicateNameOrCorrupted; DamagedList.Add(targetfcs); fileList.Remove(targetfcs); } //new file FileItem fs = new FileItem() { Hash = file.Hash, Filepath = file.Filepath, IsChecksummed = ChecksumStat.NewFileChecked }; fileList.Add(fs); } } catch (UnauthorizedAccessException uaex) { Console.WriteLine(uaex.Message); using (StreamWriter report = File.AppendText(ReportFile)) { report.WriteLine(uaex.Message); } } } } return(fileList); }