//------------------------------------------------------------------------- public ProcessingIncomingFile(OcrAppConfig defaults, System.Collections.Generic.List<string> filesInInputOrTempFolder, bool isInputFolder) { this.defaults = defaults; foreach (var file in filesInInputOrTempFolder) { log.LogMessage("___" + "bgwForIncomingFile_DoWork file = " + file); if (utils.CanAccess(file)) { switch (isInputFolder.ToString().ToLower()) { case "true": FileInInputFolder(file); break; case "false": FileInTempFolder(file); break; } break; } else { log.LogMessage("___" + "Can not access to file: " + file); } } }
//------------------------------------------------------------------------- public ProcessingTempFrameFile(CancellationToken cancellationToken, OcrAppConfig defaults, string fileName, List<string> errorFiles, IOHelper ioHelper, ref string lastSheetId) { this.defaults = defaults; this.fileName = fileName; this.errorFiles = errorFiles; this.ioHelper = ioHelper; this.cancellationToken = cancellationToken; this.lastSheetIdentifier = lastSheetId; string shId; Working(out shId); lastSheetId = shId; }
//------------------------------------------------------------------------- public void SendMailToAdminWithError(string caption, string message) { if (!CanSendCommonMail) { OcrAppConfig def = new OcrAppConfig(); AppConfig = def.CreateDefaultAppConfig(); if (AppConfig == null) return; } if (AppConfig.email.host.StartsWith("/")) AppConfig.email.host = AppConfig.email.host.Replace("//", ""); string adminMail = @"*****@*****.**";//adminMailForError TestPeriod Send(caption, message, adminMail); }
//------------------------------------------------------------------------- public void SendMailToSupport(string message, string mail, string caption = "[OCR] Error report") { if (!CanSendCommonMail) { OcrAppConfig def = new OcrAppConfig(); AppConfig = def.CreateDefaultAppConfig(); if (AppConfig == null) return; } if (AppConfig.email.host.StartsWith("/")) AppConfig.email.host = AppConfig.email.host.Replace("//", ""); //var caption = "[OCR] Error report"; string[] mails = Regex.Split(mail, ";"); foreach (string item in mails) { if (!String.IsNullOrEmpty(item)) { Send(caption, message, item); } } }
//[Serializable] //public class Updates //{ // public string version { get; set; } // public string description { get; set; } // public string[] files { get; set; } //} //------------------------------------------------------------------------- //static public Updates GetUpdates(string input) //{ // Updates updates // = JsonConvert.DeserializeObject<Updates>(input); // return updates; //} private void MainForm_Shown(object sender, EventArgs e) { //"updateServerName": "http://edococr.etlspace.com/" //ftp://[email protected]/ edococr ooz9tai3Eing Refresh(); Application.DoEvents(); try { defaults = new OcrAppConfig(); if (string.IsNullOrEmpty(defaults.UpdateServerName)) { MessageBox.Show("Not set Updates server name." , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); upd = null; Close(); return; } WebClient client = new WebClient(); string input; if (defaults.UpdateServerName.StartsWith("http")) { input = client.DownloadString(Path.Combine(defaults.UpdateServerName, "updates.json")); } else { input = File.ReadAllText(Path.Combine(defaults.UpdateServerName, "updates.json")); } upd = Recognize.GetUpdates(input); if (upd.version.Equals(Application.ProductVersion.ToString())) { MessageBox.Show("You are using the latest version of the application." , Text, MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); return; } else { if (MessageBox.Show("There is new version" + upd.version + " found, your version is " + Application.ProductVersion.ToString() + Environment.NewLine + "----------------------------------" + Environment.NewLine + "Description:" + Environment.NewLine + upd.description + Environment.NewLine + "----------------------------------" + Environment.NewLine + "Do you want to install update?" , Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { Close(); return; } } label1.Text = "Installing updates, please wait..."; if (!Directory.Exists("Updates")) Directory.CreateDirectory("Updates"); else { DirectoryInfo dirInfo = new DirectoryInfo("Updates"); foreach (FileInfo file in dirInfo.GetFiles()) { file.Delete(); } } FileInfo fi = new FileInfo(Application.ExecutablePath); string currentDirectory = fi.Directory.ToString(); if (defaults.UpdateServerName.StartsWith("http")) { foreach (string item in upd.files) { fi = new FileInfo(item); string dest = Path.Combine("Updates", fi.Name); string source = Path.Combine(defaults.UpdateServerName, fi.Name); Uri uri = new Uri(source); label1.Text = "Loading " + fi.Name; Invoke(new MethodInvoker(delegate { label1.Refresh(); })); Application.DoEvents(); client.DownloadFile(uri, dest); } } else { foreach (string item in upd.files) { fi = new FileInfo(item); string dest = Path.Combine("Updates", fi.Name); label1.Text = "Loading " + fi.Name; Invoke(new MethodInvoker(delegate { label1.Refresh(); })); Application.DoEvents(); string source = Path.Combine(defaults.UpdateServerName, item); File.Copy(Path.Combine(defaults.UpdateServerName, item), dest); } } //Process[] processes = Process.GetProcessesByName("eDoctrinaOcrEd"); //foreach (Process proc in processes) //{ // string fn = proc.MainModule.FileName; // fi = new FileInfo(fn); // FileInfo fi2 = new FileInfo(Application.ExecutablePath); // if (fi.Directory.ToString().Equals(fi2.Directory.ToString())) // { // chbRunEditor.Checked = true; // proc.Kill(); // //proc.CloseMainWindow(); // //proc.WaitForExit(); // break; // } //} //processes = Process.GetProcessesByName("eDoctrinaOcrWPF"); //foreach (Process proc in processes) //{ // string fn = proc.MainModule.FileName; // fi = new FileInfo(fn); // FileInfo fi2 = new FileInfo(Application.ExecutablePath); // if (fi.Directory.ToString().Equals(fi2.Directory.ToString())) // { // chbRunService.Checked = true; // proc.Kill(); // break; // } //} //processes = Process.GetProcessesByName("eDoctrinaUtils.dll"); //foreach (Process proc in processes) //{ // string fn = proc.MainModule.FileName; // fi = new FileInfo(fn); // FileInfo fi2 = new FileInfo(Application.ExecutablePath); // if (fi.Directory.ToString().Equals(fi2.Directory.ToString())) // { // proc.Kill(); // break; // } //} //Thread.Sleep(500); //defaults = null; foreach (string item in upd.files) { fi = new FileInfo(item); if (!fi.Directory.ToString().Equals(currentDirectory) || item.StartsWith("Installer")) { if (!Directory.Exists(fi.Directory.ToString())) Directory.CreateDirectory(fi.Directory.ToString()); string source = Path.Combine("Updates", fi.Name); File.Delete(item); File.Move(source, item); File.SetAttributes(item, FileAttributes.Normal); } } label1.Text = "Loading completed successfully"; TopMost = false; Process.Start("Installer.exe"); Thread.Sleep(500); Close(); } catch (Exception ex) { label1.Text = "Installation failed!"; MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); Close(); } //btnExit.Enabled = true; //chbRunEditor.Enabled = true; //chbRunService.Enabled = true; }
private void LoadSettings() { try { defaults = new OcrAppConfig(); appSettings = new OcrEditorSettings(); appSettings.Load(); if (!appSettings.SettingsExists) { SaveSettings(); } else { this.WindowState = appSettings.Fields.WindowState; this.Location = appSettings.Fields.WindowLocation; if (appSettings.Fields.WindowSize != new Size()) this.Size = appSettings.Fields.WindowSize; try { this.splitContainer1.SplitterDistance = appSettings.Fields.SplitterDistanceActions; } catch (Exception) { //this.splitContainer1.SplitterDistance = 328; } this.splitContainer2.SplitterDistance = appSettings.Fields.SplitterDistanceBubble; this.splitContainer3.SplitterDistance = appSettings.Fields.SplitterDistanceMiniature; this.splitContainer4.SplitterDistance = appSettings.Fields.SplitterDistanceLens; this.DarknessManualySet.Checked = appSettings.Fields.DarknessManualySet; this.nudPerCentBestBubble.Value = appSettings.Fields.NudPerCentBestBubble; this.nudPerCentEmptyBubble.Value = appSettings.Fields.NudPerCentEmptyBubble; try { this.nudZoom.Value = appSettings.Fields.NudZoomValue; } catch (Exception) { this.nudZoom.Value = 2; } } } catch (Exception) { SaveSettings(); } }
//------------------------------------------------------------------------- private void Init() { ImagePanel.AutoScroll = false; LoadSettings(); editorTools = new Control[] { this.RotateLeftButton , this.RotateRightButton , this.btnRemoveNoise , this.rbtnRotate //, this.splitBtnRestore , this.rbtnClear , this.rbtnCut , this.btnInvert }; FileInfo fi = new FileInfo(Path.Combine(OcrAppConfigDefaults.BaseTempFolder, "testUids.json")); if (fi.Exists) { JavaScriptSerializer js = new JavaScriptSerializer(); //Dictionary<string, eDoctrinaOcrEd.TestUids.AreaSettings[]> temp; try { //temp = js.Deserialize<Dictionary<string, eDoctrinaOcrEd.TestUids.AreaSettings[]>>("testUids.json");//testUids string s = File.ReadAllText(Path.Combine(OcrAppConfigDefaults.BaseTempFolder, "testUids.json")); testUids = js.Deserialize<TestUids>(s); if (testUids == null) { testUids = new TestUids(); testUids.Test = new Dictionary<string, eDoctrinaOcrEd.TestUids.AreaSettings[]>(); } } catch (Exception) { testUids = new TestUids(); //testUids.Test = new Dictionary<TestUids.TestUid, RegionsArea[]>(); testUids.Test = new Dictionary<string, eDoctrinaOcrEd.TestUids.AreaSettings[]>(); } } else { testUids = new TestUids(); testUids.Test = new Dictionary<string, eDoctrinaOcrEd.TestUids.AreaSettings[]>(); } defaults = new OcrAppConfig(); if (defaults.exception != null) { UpdateUI("Exception", defaults.exception.Message); this.Close(); return; } defaults.DualControl = true; if (!VerifyDirectory(defaults.ManualConfigsFolder) || Directory.GetFiles(defaults.ManualConfigsFolder, "*.json").Length == 0) { string message = "Config files not found. The program will be closed."; log.LogMessage(message); UpdateUI("Exception", message); this.Close(); return; } if (!string.IsNullOrEmpty(OcrAppConfigDefaults.BaseTempFolder)) { VerifyDirectory(OcrAppConfig.TempEdFolder); } BoxSheet.Text = "Sheet identifier"; BoxSheet.DropDownStyle = ComboBoxStyle.DropDownList; AddMiniatureControlsAndSheetIdentifiers(); InitButtonsAndControls(); }
//------------------------------------------------------------------------- private void Completed(object sender, EventArgs e) { fileView.WorkingCompleted -= Completed; view.CVSSource = fileView.Files; ChangeGrouping("State"); view.FilesCount = fileView.CountFiles.ToString(); view.ErrorText = (view.IsTestingMode) ? CompletedTestingMode() : CompletedNotTestingMode(); if (view.IsTestingMode) { try { //StartButton.IsEnabled = false; var defaults = new OcrAppConfig(fileView.SourcePath); string jsonPath = defaults.OutputFolder_Success; string[] fnArr = Directory.GetFiles(jsonPath, "*.json*", SearchOption.TopDirectoryOnly); //string err = view.ErrorText; Utils utils = new Utils(); int count = fnArr.Length; foreach (var item in fnArr) { //view.ErrorText = count.ToString(); StartButton.Content = count.ToString(); StartButton.Refresh(); count--; string s = File.ReadAllText(item); AnswerVerification answerVerification = utils.GetAnswerVerification(s); s = File.ReadAllText(answerVerification.audit.dataFileName).Trim(); //s = File.ReadAllText(Path.Combine(defaults.SuccessFolder // , answerVerification.data.district_id + "_" // + answerVerification.data.student_uid + "_" // + answerVerification.data.test_id + "_" // + answerVerification.data.index_of_first_question + "_" // + answerVerification.data.amout_of_questions // + ".csv")).Trim(); string[] stringsCSV = Regex.Split(s, Environment.NewLine); if (answerVerification.answers.Length != stringsCSV.Length) { MessageBox.Show("answerVerification.answers.Length != .csv rows length"); break; } for (int i = 0; i < answerVerification.answers.Length; i++) { //this.Dispatcher.BeginInvoke(new Action(() => this.ErrorLabel.Content = i.ToString()), null); //Thread.Sleep(50); s = stringsCSV[i]; string s2 = answerVerification.data.district_id + "," + answerVerification.data.student_uid + "," + answerVerification.data.test_id + ","; if (s.IndexOf(s2) != 0) { MessageBox.Show("Problem №1 in answerVerification.answers " + item + " " + i, ToString()); break; } s = s.Remove(0, s2.Length); int index = s.IndexOf(",,EDOCOCR"); s = s.Substring(0, index); string[] ss2 = s.Split(','); if (ss2[0] != answerVerification.answers[i].idx.ToString()) { MessageBox.Show("Problem №2 in answerVerification.answers " + item + " " + i, ToString()); break; } ss2 = ss2[1].Split('~'); if (answerVerification.answers[i].answers.Length != ss2.Length) { MessageBox.Show("Problem №3 in answerVerification.answers " + item + " " + i, ToString()); break; } for (int j = 0; j < ss2.Length; j++) {//строки и подстроки var itm = ss2[j]; string[] ss3 = itm.Split('|'); //string[] ss4 = answerVerification.answers[i].answers[j].cols[k].Split('|'); for (int k = 0; k < ss3.Length; k++) {//несеолько пузырей в строке var item2 = ss3[k]; if (answerVerification.answers[i].answers[j].cols[k] != item2) { MessageBox.Show("Problem №4 in answerVerification.answers " + item + " " + i, ToString()); return; } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //view.ErrorText = err; //StartButton.IsEnabled = true; StartButton.Content = "Start"; } } }
//------------------------------------------------------------------------- private void LoadSettings() { try { defaults = new OcrAppConfig(); var appSettings = new OcrWPFSettings(); appSettings.Load(); if (!appSettings.SettingsExists) { SaveSettings(); } else { this.WindowState = appSettings.Fields.WindowState; this.Left = appSettings.Fields.WindowLeft; this.Top = appSettings.Fields.WindowTop; if (appSettings.Fields.WindowWidth > 0) this.Width = appSettings.Fields.WindowWidth; if (appSettings.Fields.WindowHeight > 0) this.Height = appSettings.Fields.WindowHeight; this.nudThreadsCount.Value = appSettings.Fields.ThreadsCount; } } catch (Exception) { SaveSettings(); } }
private void Init() { defaults = new OcrAppConfig(); if (defaults.exception != null) { UpdateUI("ExceptionClose", defaults.exception.Message); return; } if (string.IsNullOrEmpty(defaults.UpdateServerName)) { Dispatcher.BeginInvoke(new Action(delegate { MessageBox.Show("Not set update server", Title, MessageBoxButton.OK, MessageBoxImage.Warning); btnUpdate.IsEnabled = false; })); } else Dispatcher.BeginInvoke(new Action(delegate { btnUpdate.IsEnabled = true; })); if (defaults.DualControl) { defaults.NotConfidentFolder = defaults.ErrorFolder; } if (!defaults.AutoStart) { UpdateUI("toolStripStatusLabel1", "Stopped"); } if (defaults.DoNotProcess) { VerifyDirectory("TempIncFile"); VerifyDirectory("OUTPUT_NOT_WHITE"); VerifyDirectory("OUTPUT_WHITE");//Not white double VerifyDirectory("OUTPUT_NOT_WHITE_DOUBLE"); } if (!VerifyDirectory(defaults.ConfigsFolder) || Directory.GetFiles(defaults.ConfigsFolder, "*.json").Length == 0) { string message = "Config files not found\r\nThe program will be closed."; log.LogMessage(message); UpdateUI("ExceptionClose", message); return; } UpdateUI("nudThreadsCount", null); if (defaults.AutoRunEditorOnError && string.IsNullOrEmpty(defaults.ManualInputFolder)) { string message = "The eDoctrina OCR Editor can not be started\r\n because is not present \"ManualInputFolder\""; log.LogMessage(message); UpdateUI("Message", message); } }
public Recognize(string fileName, OcrAppConfig defaults, CancellationToken token, bool auto = false , bool normalizeBitmap = true) { SetCancellationToken(token); this.Auto = auto; this.defaults = defaults; recTools.frameFileName = fileName; //defaults.frameFileName = fileName; if (String.IsNullOrEmpty(fileName) || !File.Exists(fileName)) { Exception = new Exception("File name is incorrect: " + fileName); log.LogMessage(Exception); NotifyUpdated(ExceptionEvent, Exception, null); return; } FileName = fileName; AuditFileName = utils.GetFileAuditName(fileName); #region Get Bitmap FramesAndBitmap fab = new FramesAndBitmap(); Bitmap = fab.GetBitmapFromFile(FileName); if (fab.Exception != null) { Exception = fab.Exception; log.LogMessage(Exception); NotifyUpdated(ExceptionEvent, Exception, null); return; } //bool bppIndexed1 = false; //if (Bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format1bppIndexed) // bppIndexed1 = true; if (normalizeBitmap) Bitmap = recTools.NormalizeBitmap(Bitmap, out exception); if (exception != null) { log.LogMessage(Exception); NotifyUpdated(ExceptionEvent, Exception, null); return; } //if (exception != null) //{ // if (auto) // { // fab.Exception = exception; // Audit = new Audit(AuditFileName, out exception); // exception = fab.Exception; // Audit.error = exception.Message; // if (defaults.MoveToNextProccessingFolderOnSheetIdentifierError) // { // utils.MoveBadFile(OcrAppConfig.TempFramesFolder, defaults.ManualNextProccessingFolder, fileName, Audit, fab.Exception.Message);//сохраняем файл в папку для дальнейшей обработки и удаляем из ТЕМПА // File.Delete(fileName); // } // else // { // } // return; // } //} //else if (exception != null) //{ //Bitmap = recTools.GetMonohromeNoIndexBitmap(Bitmap, false, true); //Bitmap.SetResolution(96, 96); #endregion #region Get audit file Audit = new Audit(AuditFileName, out exception); if (Audit == null || !File.Exists(AuditFileName)) { log.LogMessage(Exception); NotifyUpdated(ExceptionEvent, Exception, null); return; } #endregion regionsList = recTools.GetAllRegions(ConfigsFolder); regionsListFLEX = recTools.GetAllRegionsFLEX(ConfigsFolder); }