public OCRTemplate loadFile(string filename) { OCRTemplate ocrConfig = null; // check if file exists if (!File.Exists(filename)) { MessageBox.Show("OCR-File '" + filename + "' not found. OCR is not possible without the config-file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(OCRTemplate)); System.IO.FileStream file = System.IO.File.OpenRead(filename); try { ocrConfig = (OCRTemplate)ser.ReadObject(file); ocrConfig.init(); Properties.Settings.Default.ocrFile = filename; } catch (Exception e) { MessageBox.Show("File Couldn't be opened or read.\nErrormessage:\n\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } file.Close(); return(ocrConfig); }
public OCRTemplate loadFile(string filename) { OCRTemplate ocrConfig = null; // check if file exists if (!File.Exists(filename)) { MessageBox.Show($"OCR-File '{filename}' not found. OCR is not possible without the config-file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } using (FileStream file = File.OpenRead(filename)) { try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(OCRTemplate)); ocrConfig = (OCRTemplate)ser.ReadObject(file); ocrConfig.init(); } catch (Exception e) { MessageBox.Show("File Couldn't be opened or read.\nErrormessage:\n\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return(ocrConfig); }
public static OCRTemplate LoadFile(string filePath) { OCRTemplate ocrConfig = null; // check if file exists if (!File.Exists(filePath)) { MessageBoxes.ShowMessageBox($"OCR-File '{filePath}' not found. OCR is not possible without the config-file."); return(null); } using (FileStream file = File.OpenRead(filePath)) { try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(OCRTemplate)); ocrConfig = (OCRTemplate)ser.ReadObject(file); ocrConfig.init(); } catch (Exception ex) { MessageBoxes.ExceptionMessageBox(ex, "File Couldn't be opened or read."); } } return(ocrConfig); }