private void listbox_saves_SelectionChanged(object sender, RoutedEventArgs e) { currWork = listbox_saves.SelectedItem as LabelWork; clearFileNames(); autoFillFileNames(); checkReadyConditions(); }
private void resetOnFailure() { reloadSaves(); currWork = null; clearFileNames(); checkReadyConditions(); }
public LabelWork loadSavedLabelWork(string name) { LabelWork rv = null; checkSaveDirectory(); string filePath = Path.Combine(getSaveDirectory(), name); if (File.Exists(filePath)) { StreamReader reader = new StreamReader(filePath, Encoding.UTF8, true); string sourceFilePath = reader.ReadLine(); if (!File.Exists(sourceFilePath)) { reader.Close(); throw new SourceFileNotFoundException(); } string contentFilePath = reader.ReadLine(); string startingLineNum = reader.ReadLine(); string outputFileName = reader.ReadLine(); string uncertainOutputFileName = reader.ReadLine(); string outputFileExt = reader.ReadLine(); string uncertainOutputFileExt = reader.ReadLine(); rv = new LabelWork(sourceFilePath, int.Parse(startingLineNum), outputFileName, uncertainOutputFileName, contentFilePath, outputFileExt, uncertainOutputFileExt, name); reader.Close(); } else { throw new IOException(); } return(rv); }
public void deleteSaveFile(LabelWork work) { string filePath = Path.Combine(getSaveDirectory(), work.ProgressFileName); if (File.Exists(filePath)) { File.Delete(filePath); } }
public void InitNewsFileHandler(LabelWork work) { if (handler != null) { DestroyNewsFileHandler(); } labelWork = work; handler = new NewsFileHandler(new NewsFileHandlerConfig(), onContentUpdate, work); OnNewsFileHandlerInit?.Invoke(); }
private void button_new_label_click(object sender, RoutedEventArgs e) { NewLabelWindow newLabel = new NewLabelWindow(); newLabel.ShowDialog(); LabelWork result = newLabel.Result; if (result != null) { controller.WriteProgress(); startNewLabelWork(result); } }
public void createNewSaveFile(int currLineNum, LabelWork work) { StreamWriter writer = new StreamWriter(new FileStream(Path.Combine(PROGRESS_DIRECTORY_NAME, work.ProgressFileName), FileMode.Create, FileAccess.Write), Encoding.UTF8); writer.WriteLine(work.SourceFilePath); writer.WriteLine(work.ContentFilePath); writer.WriteLine(currLineNum); writer.WriteLine(work.OutputFileName); writer.WriteLine(work.UncertainOutputFileName); writer.WriteLine(work.OutputFileExtension); writer.WriteLine(work.UncertainOutputFileExtension); writer.Flush(); writer.Close(); }
private void startNewLabelWork(LabelWork work) { disableFileControlButtons(); controller.InitNewsFileHandler(work); refresh(); enableLabelControlButtons(); controller.InitActiveNewsPairList(); textblock_sourcefilepath.Text = SRC_FILE_HEADER + work.SourceFilePath; textblock_newsfilepath.Text = NEWS_CONTENT_FILE_HEADER + work.ContentFilePath; textblock_outputfilepath.Text = OUTPUT_FILE_HEADER + controller.getOutputFileName(); textblock_linenum.Text = LINE_NUM_HEADER + controller.getCurrentLineNum(); textblock_commontitlewords.Text = COMMON_TITLE_WORDS_HEADER + controller.CurrentNewsPair?.CommonTitleWords.ToString(); enableFileControlButtons(); }
private void button_start_click(object sender, RoutedEventArgs e) { if (!checkStartCondition()) { return; } if (!checkFileExists(sourceFilePath)) { sourceFilePath = ""; contentFilePath = ""; clearFileNames(); updateFilePath(); checkStartCondition(); return; } if (contentFilePath.Length > 0 && !checkFileExists(contentFilePath)) { contentFilePath = ""; updateFilePath(); } string outputFileName = textbox_outputfile.Text.ToString(); if (checkFileExists(outputFileName)) { if (!displayYesNoDialog(string.Format(OUTPUT_FILE_EXISTS_MSG, outputFileName))) { return; } } string uncertainOutputFileName = textbox_uncertainfile.Text.ToString(); if (checkFileExists(uncertainOutputFileName)) { if (!displayYesNoDialog(string.Format(OUTPUT_FILE_EXISTS_MSG, uncertainOutputFileName))) { return; } } string progressFileName = textbox_savefile.Text.ToString(); if (progressFileName.Length > 0 && checkFileExists(progressFileName, ProgressManager.PROGRESS_DIRECTORY_NAME)) { if (!displayYesNoDialog(string.Format(PROGRESS_FILE_EXISTS_MSG, progressFileName))) { return; } } Result = new LabelWork(sourceFilePath, 1, outputFileName, uncertainOutputFileName, contentFilePath, EXTENSION_NONE, EXTENSION_NONE, progressFileName); Close(); }
public NewsFileHandler(NewsFileHandlerConfig conf, OnNewsContentUpdateDelegate del, LabelWork work) { config = conf; labelWork = work; inputFileReader = new StreamReader(labelWork.SourceFilePath, Encoding.UTF8, true); contentReadQ = new ConcurrentQueue <NewsPair>(); if (labelWork.ContentFilePath.Length != 0) { newsFileReader = new StreamReader(new FileStream(labelWork.ContentFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite), Encoding.UTF8, true); } OutputFileName = labelWork.OutputFileName + labelWork.OutputFileExtension; outputFileWriter = new StreamWriter(new FileStream(OutputFileName, FileMode.Append, FileAccess.Write), Encoding.UTF8); OnNewsContentUpdate = del; advanceReaderToLine(work.StartingLineNum); }
private void button_load_click(object sender, RoutedEventArgs e) { LoadWindow win = new LoadWindow(controller.ProgressManager); win.ShowDialog(); LabelWork result = win.Result; if (result != null) { controller.WriteProgress(); if (result.StartingLineNum > 100) { displayLoadingScreen(); } startNewLabelWork(result); } }
private void button_load_click(object sender, RoutedEventArgs e) { try { currWork = progressManager.loadSavedLabelWork(currWork.ProgressFileName); } catch (SourceFileNotFoundException) { displayMsgDialog(SOURCE_FILE_NOT_FOUND_MSG); resetOnFailure(); return; } catch (Exception e1) { displayMsgDialog(string.Format(UNKNOWN_ERROR_MSG, e1.StackTrace.ToString())); resetOnFailure(); return; } Result = currWork; Close(); }
public List <LabelWork> loadAllSaved(List <string> corruptedSaveFiles = null) { List <LabelWork> rv = new List <LabelWork>(); checkSaveDirectory(); string[] files = Directory.GetFiles(getSaveDirectory()); foreach (string name in files) { try { LabelWork work = loadSavedLabelWork(Path.GetFileNameWithoutExtension(name)); if (work != null) { rv.Add(work); } } catch (Exception e) { Console.WriteLine(e.StackTrace); corruptedSaveFiles?.Add(name); } } return(rv); }