public void ReadHistoryFromFiles() { ConsolePrintHelpers.PrintYellowText("\n\n\n Reading And Validating History Files"); ConsolePrintHelpers.PrintWhiteText(" ► "); bool cancelProgressTicker = false; Task ticker = Task.Run(() => ConsolePrintHelpers.PrintProgressTicker(ref cancelProgressTicker)); List <Task> readingTasks = new List <Task>(); readingTasks.Add(Task.Run(() => ReadApprovedLoadSheetRowsFromFile())); readingTasks.Add(Task.Run(() => ReadAlreadyEncodedFilesFromFile())); Task.WaitAll(readingTasks.ToArray()); DeleteSeveredAlreadyEncodedFiles(); GC.Collect(); cancelProgressTicker = true; ticker.Wait(); ConsolePrintHelpers.PrintYellowText("Done"); }
public void WriteEncodingHistoryToFile(bool printProgress) { bool cancelProgressTicker = false; Task ticker = null; if (printProgress) { ConsolePrintHelpers.PrintYellowText("\n\n\n [DO NOT CLOSE CONSOLE WINDOW] Updating Encoding History File"); ConsolePrintHelpers.PrintWhiteText(" ► "); int cursorLeft = Console.CursorLeft; Console.WriteLine("\n\n"); Console.CursorTop -= 3; Console.CursorLeft = cursorLeft; ticker = Task.Run(() => ConsolePrintHelpers.PrintProgressTicker(ref cancelProgressTicker)); } foreach (AlreadyEncodedFile file in _AlreadyEncodedFiles.Skip(Globals.MaximumLinesForHistoryFiles)) //If history is too large, delete oldest files (end of list) { DeleteAlreadyEncodedFile(file); } List <string> linesList = new List <string>(); foreach (AlreadyEncodedFile file in _AlreadyEncodedFiles.Take(Globals.MaximumLinesForHistoryFiles)) //If history is too large, only keep records of newest files (front of list) { if (file.IsValid) //No Re-checkIfValid() because when lines are read back in from file they are re-checked. { string line = file.EncodedFilePath + "*" + file.EncodedFileModifiedDate + "*" + file.EncodedFileSize.ToString() + "*" + file.SourceFilePath + "*" + file.SourceFileModifiedDate + "*" + file.SourceFileSize.ToString() + "*" + file.EncodedStatus; linesList.Add(line); } } try { File.WriteAllLines(_EncodingHistoryFilePath, linesList); } catch (Exception) { } if (printProgress) { cancelProgressTicker = true; ticker.Wait(); ConsolePrintHelpers.PrintYellowText("Updated"); } }
public void WriteApprovalHistoryToFile(bool printProgress) { bool cancelProgressTicker = false; Task ticker = null; if (printProgress) { ConsolePrintHelpers.PrintYellowText("\n\n\n [DO NOT CLOSE CONSOLE WINDOW] Updating Approval History File"); ConsolePrintHelpers.PrintWhiteText(" ► "); ticker = Task.Run(() => ConsolePrintHelpers.PrintProgressTicker(ref cancelProgressTicker)); } List <string> linesList = new List <string>(); foreach (ApprovedLoadSheetRow approvedLSR in _ApprovedLoadSheetRows.Take(Globals.MaximumLinesForHistoryFiles)) //Trim history if too large (long term performance concerns) { if (approvedLSR.IsValid) //No Re-checkIfValid() because when lines are read back in from file they are re-checked. { string line = approvedLSR.SourceFilePath + "*" + approvedLSR.SourceFileModifiedDate + "*" + approvedLSR.SourceFileSize.ToString() + "*" + approvedLSR.LoadSheetRowHash + "*" + approvedLSR.TotalPoints + "*" + approvedLSR.AccuracyScore.ToString() + "*" + approvedLSR.AccuracyType.ToString(); linesList.Add(line); } } try { File.WriteAllLines(_ApprovalHistoryFilePath, linesList); } catch (Exception) { } if (printProgress) { cancelProgressTicker = true; ticker.Wait(); ConsolePrintHelpers.PrintYellowText("Updated"); } }
private void DetermineSkippedLoadsheetRows() { ConsolePrintHelpers.PrintYellowText("\n\n\n Determining Skipped Loadsheet Rows"); ConsolePrintHelpers.PrintWhiteText(" ► "); bool cancelProgressTicker = false; Task ticker = Task.Run(() => ConsolePrintHelpers.PrintProgressTicker(ref cancelProgressTicker)); foreach (AODLoadSheetRow lsr in _Controller.LoadSheet.GetAODLoadSheetRows) { if (IsLSREligibleForEncodingOrCopying(lsr)) { _TempEncodingOrCopyList.Add(lsr); //Ordered by load sheet row number (1 -> n) } else { _TempSkippedList.Add(lsr); //Ordered by load sheet row number (1 -> n) } } PrepareManualOptions(); foreach (AODLoadSheetRow skippedRow in _TempSkippedList.ToList()) { CheckApprovalHistoryAgain(skippedRow); //Approval history can look at the 'Manual Options' list for each skippedRow and possibly find an approved source file included in that list } cancelProgressTicker = true; ticker.Wait(); ConsolePrintHelpers.PrintYellowText("Done"); ConsolePrintHelpers.PrintWhiteText("\n\n\n Skipped Loadsheet Rows Count : "); ConsolePrintHelpers.PrintCyanText(_TempSkippedList.Count.ToString()); }
private void MigrateAlreadyEncodedFiles() { ConsolePrintHelpers.PrintYellowText("\n\n\n Migrating Files...\n\n"); int count = 1; foreach (AlreadyEncodedFile file in _AlreadyEncodedFiles) { ConsolePrintHelpers.PrintWhiteText(" Copying File: "); ConsolePrintHelpers.PrintCyanText(count.ToString() + " of " + _AlreadyEncodedFiles.Count); Console.WriteLine(); string oldFilePath = file.EncodedFilePath; string newFilePath = _Config.HistoryFilesArchiveDirectory + "\\" + Guid.NewGuid().ToString() + file.EncodedFileExtension; ConsolePrintHelpers.PrintWhiteText(" Old Path: "); ConsolePrintHelpers.PrintCyanText(oldFilePath); Console.WriteLine(); ConsolePrintHelpers.PrintWhiteText(" New Path: "); ConsolePrintHelpers.PrintCyanText(newFilePath); Console.WriteLine(); ConsolePrintHelpers.PrintYellowText(" Copying History File"); ConsolePrintHelpers.PrintWhiteText(" ► "); bool cancelProgressTicker = false; Task ticker = Task.Run(() => ConsolePrintHelpers.PrintProgressTicker(ref cancelProgressTicker)); File.Copy(oldFilePath, newFilePath); cancelProgressTicker = true; ticker.Wait(); ConsolePrintHelpers.PrintYellowText("Done"); Console.WriteLine(); file.SetEncodedFilePath(newFilePath); ConsolePrintHelpers.PrintWhiteText(" File Encoded Path: "); ConsolePrintHelpers.PrintCyanText(file.EncodedFilePath); Console.WriteLine(); file.ReCheckIfValid(); ConsolePrintHelpers.PrintWhiteText(" File isValid: "); if (file.IsValid) { ConsolePrintHelpers.PrintCyanText("Valid"); } else { ConsolePrintHelpers.PrintRedText("NOT Valid"); ConsolePrintHelpers.PressAnyKeyToContinue(); } Console.WriteLine("\n\n\n"); count++; } ConsolePrintHelpers.PrintYellowText(" Press Any Key to Update Already Encoded History File..."); ConsolePrintHelpers.PressAnyKeyToContinue(); WriteEncodingHistoryToFile(true); ConsolePrintHelpers.PressAnyKeyToContinue(); }
private void ManuallyAssignSkippedEncodings() { if (_TempSkippedList.Count == 0) { return; } if (!PromptToManuallyAssignSkippedEncodings()) { return; } ConsolePrintHelpers.PrintWhiteText("\n\n\n Select Source Files..."); Console.WriteLine("\n"); ConsolePrintHelpers.PrintFullWidthLine(); Console.CursorTop -= 2; int remainingRows = _TempSkippedList.Count; foreach (AODLoadSheetRow skippedLSR in _TempSkippedList.ToList()) { skippedLSR.PrintBasicLSRInfo(); skippedLSR.AssignSuggestedAudioFile(); //If this row is sharing a SearchCollection with another row (identical LSR Hashes; Copied SearchCollection in quick search 'Past LSR' section) then re-assign it for following approval check if (CheckApprovalHistoryAgain(skippedLSR)) { ConsolePrintHelpers.PrintWhiteText(" Historically Approved...\n\n"); skippedLSR.SuggestedAudioFile.PrintSuggestedAudioFileInfo(true); Console.WriteLine("\n\n\n"); ConsolePrintHelpers.PrintFullWidthLine(); Console.CursorTop -= 5; } else { skippedLSR.SuggestedAudioFile.PrintSuggestedAudioFileInfo(false); int selection = SelectManualOption(skippedLSR); if (selection == -2) { ConsolePrintHelpers.PrintWhiteText("\n\n\n Skipping All Remaining Rows..."); remainingRows--; ConsolePrintHelpers.PrintWhiteText("\n\n\n Remaining Skipped Rows : "); ConsolePrintHelpers.PrintCyanText(remainingRows.ToString()); break; } if (selection == -1) { ConsolePrintHelpers.PrintWhiteText("\n\n\n Skipping This Row..."); } else { AudioFileOption selectedOption = skippedLSR.SearchCollection.GetSelectedOption(selection); skippedLSR.AssignSuggestedAudioFileFromManualApproval(selectedOption); if (CheckApprovalHistoryAgain(skippedLSR)) { _Controller.History.AddNewApprovedLoadSheetRow(skippedLSR); } } } remainingRows--; ConsolePrintHelpers.PrintWhiteText("\n\n\n Remaining Skipped Rows : "); ConsolePrintHelpers.PrintCyanText(remainingRows.ToString()); Thread.Sleep(1000); } if (_TempSkippedList.Count > 0) { int skippedCountBefore = _TempSkippedList.Count; ConsolePrintHelpers.PrintYellowText("\n\n\n Checking Approvals On Remaining Rows"); ConsolePrintHelpers.PrintWhiteText(" ► "); bool cancelProgressTicker = false; Task ticker = Task.Run(() => ConsolePrintHelpers.PrintProgressTicker(ref cancelProgressTicker)); foreach (AODLoadSheetRow skippedRow in _TempSkippedList.ToList()) { CheckApprovalHistoryAgain(skippedRow); } cancelProgressTicker = true; ticker.Wait(); ConsolePrintHelpers.PrintYellowText("Done"); if (_TempSkippedList.Count < skippedCountBefore) { ConsolePrintHelpers.PrintWhiteText("\n\n\n Skipped Loadsheet Rows Count (Before) : "); ConsolePrintHelpers.PrintCyanText(skippedCountBefore.ToString()); ConsolePrintHelpers.PrintWhiteText("\n Skipped Loadsheet Rows Count (After) : "); ConsolePrintHelpers.PrintCyanText(_TempSkippedList.Count.ToString()); } } }
private void FinishEncodingQueue() { ConsolePrintHelpers.PrintYellowText("\n\n\n Optimizing Encoding Queue"); ConsolePrintHelpers.PrintWhiteText(" ► "); bool cancelProgressTicker = false; Task ticker = Task.Run(() => ConsolePrintHelpers.PrintProgressTicker(ref cancelProgressTicker)); _TempEncodingOrCopyList = _TempEncodingOrCopyList.OrderBy(lsr => lsr.LoadSheetRowNumber).ToList(); //Ordered by load sheet row number (1 -> n) _TempSkippedList = _TempSkippedList.OrderBy(lsr => lsr.LoadSheetRowNumber).ToList(); //Ordered by load sheet row number (1 -> n) if (!Globals.IsDevelopmentEnvironment) { List <AODLoadSheetRow> encodingList = new List <AODLoadSheetRow>(); List <AODLoadSheetRow> uniqueEncodingList = new List <AODLoadSheetRow>(); List <AODLoadSheetRow> copyFromAlreadyEncodedFilesList = new List <AODLoadSheetRow>(); List <AODLoadSheetRow> copyFromPendingEncodedFilesList = new List <AODLoadSheetRow>(); _TempEncodingOrCopyList = _TempEncodingOrCopyList.OrderByDescending(lsr => lsr.SuggestedAudioFile.FileSize).ToList(); //Order by largest -> smallest source files (speeds up parallel encoding) foreach (AODLoadSheetRow lsr in _TempEncodingOrCopyList) { AlreadyEncodedFile file = _Controller.History.GetAlreadyEncodedFile(lsr); if (file == null) { encodingList.Add(lsr); //Files that need to be encoded (and some that could be copied, we'll check in the next step) (ordered by DESCENDING source file size) } else { copyFromAlreadyEncodedFilesList.Add(lsr); //Files that are strictly able to be copied (not waiting on any encodes to finish) (ordered by DESCENDING source file size) } } foreach (AODLoadSheetRow lsr in encodingList) { if (!uniqueEncodingList.Any(uniqueLSREncoding => lsr.IsLSREncodingEligibleForCopying(uniqueLSREncoding.PotentialFile))) { uniqueEncodingList.Add(lsr); //Files that absolutely have to be encoded from scratch (ordered by DESCENDING source file size) } else { copyFromPendingEncodedFilesList.Add(lsr); //Any additional files added here can be copied once the uniquely encoded list above creates those encoded files (ordered by DESCENDING source file size) } } int encodingID = 1; foreach (AODLoadSheetRow lsr in uniqueEncodingList) { _EncodingQueue.Enqueue(new AudioFileEncoding(lsr, encodingID, false)); //Files that NEED to be encoded, added first (ordered by DESCENDING source file size) encodingID++; } foreach (AODLoadSheetRow lsr in copyFromAlreadyEncodedFilesList) { _EncodingQueue.Enqueue(new AudioFileEncoding(lsr, encodingID, true)); //Files that can be copied from already encoded files added next (The are not waiting on any prior encodes to finish) (ordered by DESCENDING source file size) encodingID++; } foreach (AODLoadSheetRow lsr in copyFromPendingEncodedFilesList) { _EncodingQueue.Enqueue(new AudioFileEncoding(lsr, encodingID, true)); //Files that can be copied from pending encodes once they complete (ordered by DESCENDING source file size) encodingID++; } } else //Keep original load sheet row number ordering for better debugging in Development Environment { int encodingID = 1; foreach (AODLoadSheetRow lsr in _TempEncodingOrCopyList) { _EncodingQueue.Enqueue(new AudioFileEncoding(lsr, encodingID, false)); //Ordered by load sheet row number (1 -> n) encodingID++; } } foreach (AODLoadSheetRow skippedLSR in _TempSkippedList) { _SkippedQueue.Enqueue(skippedLSR); //Ordered by load sheet row number (1 -> n) } //Temporary lists no longer needed _TempEncodingOrCopyList = null; _TempSkippedList = null; GC.Collect(); cancelProgressTicker = true; ticker.Wait(); ConsolePrintHelpers.PrintYellowText("Done"); ConsolePrintHelpers.Wait(); }