private void GoLookBtn_Click(object sender, RoutedEventArgs e) { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ExchangeBrowseTxTGoLook"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 SendMessage("WordAndImgOperationApp", jsonData); }
private void button2_Click(object sender, RibbonControlEventArgs e) { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowSettingWindow"; commonExchangeInfo.Data = ""; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 Win32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } }
private void MenuHide_Click(object sender, RoutedEventArgs e) { if (IsDealingData) { CancelBtn_Click(null, null); } CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ExchangeBrowseTxTHide"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 SendMessage("WordAndImgOperationApp", jsonData); }
private void SendDealDataStateToApp() { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "DealDataProcessingState"; DealDataProcessingStateInfo infoDeal = new DealDataProcessingStateInfo(); infoDeal.IsDealingData = this.IsDealingData; commonExchangeInfo.Data = JsonConvert.SerializeObject(infoDeal); string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 SendMessage("WordAndImgOperationApp", jsonData); } catch (Exception ex) { } }
private void CancelBtn_Click(object sender, RoutedEventArgs e) { IsCancelDeal = true; CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ExchangeBrowseTxTCancelDeal"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 SendMessage("WordAndImgOperationApp", jsonData); viewModel.DataProcessGridVisibility = Visibility.Collapsed; viewModel.InputCheckGridVisibility = IsInputCheckGridVisible ? Visibility.Visible : Visibility.Collapsed; viewModel.DataProcessResultGridVisibility = IsDataProcessResultVisible ? Visibility.Visible : Visibility.Collapsed; this.IsDealingData = false; SendDealDataStateToApp(); }
public static void CallWordAndImgApp() { try { var proc = System.Diagnostics.Process.GetProcessesByName("WordAndImgOperationApp"); if (proc != null && proc.Length == 1) { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowWordAndImgOperationApp"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 Win32Helper.SendMessage("WordAndImgOperationApp", jsonData); } else { string appPath = ""; string loginInOutInfos = string.Format(@"{0}\WordAndImgAppInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); var ui = DataParse.ReadFromXmlPath <string>(loginInOutInfos); if (ui != null && ui.ToString() != "") { try { var wordAndImgAppInfo = JsonConvert.DeserializeObject <WordAndImgAppInfo>(ui.ToString()); if (wordAndImgAppInfo != null) { appPath = wordAndImgAppInfo.Path; } } catch { } } if (!string.IsNullOrEmpty(appPath) && File.Exists(appPath)) { var info = new System.Diagnostics.ProcessStartInfo(appPath); info.WorkingDirectory = appPath.Substring(0, appPath.LastIndexOf(System.IO.Path.DirectorySeparatorChar)); System.Diagnostics.Process.Start(info); } } } catch (Exception ex) { CheckWordUtil.Log.TextLog.SaveError(ex.Message); } }
/// <summary> /// 获取所有校验数据 /// </summary> /// <param name="token"></param> /// <returns></returns> public static List <WordModel> GetAllCheckWordByToken(string token, string url) { List <WordModel> wordModelLists = new List <WordModel>(); try { //#region 假数据 //WordModels.Add(new WordModel { ID = "1", Name = "第一", IsCustumCi = true }); //WordModels.Add(new WordModel { ID = "2", Name = "最", IsCustumCi = false }); //WordModels.Add(new WordModel { ID = "3", Name = "冠军", IsCustumCi = false }); //WordModels.Add(new WordModel { ID = "4", Name = "防晒", IsCustumCi = true }); //#endregion string apiName = "words/word"; string resultStr = HttpHelper.HttpUrlSend(apiName, "GET", token, url); CommonResponse resultInfo = JsonConvert.DeserializeObject <CommonResponse>(resultStr); if (resultInfo != null && resultInfo.state) { List <DBWordModel> listDBWords = JsonConvert.DeserializeObject <List <DBWordModel> >(resultInfo.result); if (listDBWords != null) { foreach (var item in listDBWords) { WordModel word = new WordModel(); word.ID = item.id; word.Name = item.name; wordModelLists.Add(word); } WordModels = wordModelLists; } try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "HideNotifyMessageView"; commonExchangeInfo.Data = "4003"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 WPFClientCheckWordUtilWin32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } } else { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "4003"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 WPFClientCheckWordUtilWin32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } } } catch (Exception ex) { WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message); try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "4003"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 WPFClientCheckWordUtilWin32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } } return(WordModels); }
/// <summary> /// 获取所有校验数据 /// </summary> /// <param name="token"></param> /// <returns></returns> public static void GetAllCheckWordByToken(string token) { List <WordModel> wordModelLists = new List <WordModel>(); try { //#region 假数据 //WordModels.Add(new WordModel { ID = "1", Name = "第一", IsCustumCi = true }); //WordModels.Add(new WordModel { ID = "2", Name = "最", IsCustumCi = false }); //WordModels.Add(new WordModel { ID = "3", Name = "冠军", IsCustumCi = false }); //WordModels.Add(new WordModel { ID = "4", Name = "防晒", IsCustumCi = true }); //#endregion string apiName = "words/word"; string resultStr = HttpHelper.HttpUrlGet(apiName, "GET", token); CommonResponse resultInfo = JsonConvert.DeserializeObject <CommonResponse>(resultStr); if (resultInfo != null && resultInfo.state) { List <DBWordModel> listDBWords = JsonConvert.DeserializeObject <List <DBWordModel> >(resultInfo.result); if (listDBWords != null) { foreach (var item in listDBWords) { WordModel word = new WordModel(); word.ID = item.id; word.Name = item.name; wordModelLists.Add(word); } } try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "HideNotifyMessageView"; commonExchangeInfo.Data = "4003"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 Win32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } } else { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "4003"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 Win32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } } } catch (Exception ex) { wordModelLists = new List <WordModel>(); WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message); try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "4003"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 Win32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } } WordModels = wordModelLists; new Task(() => { try { string myWordModelsInfo = string.Format(@"{0}\MyWordModelsInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); //保存用户设置信息到本地 DataParse.WriteToXmlPath(JsonConvert.SerializeObject(WordModels), myWordModelsInfo); } catch (Exception ex) { WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message); } }).Start(); }
/// <summary> /// ORC自动分析图片 /// </summary> /// <param name="filePath"></param> private List <UnChekedWordInfo> AutoExcutePicOCR(string filePath, Microsoft.Office.Interop.Excel.Shape shape) { List <UnChekedWordInfo> listResult = new List <UnChekedWordInfo>(); try { try { APIService service = new APIService(); var userStateInfos = service.GetUserStateByToken(); if (!userStateInfos) { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "500"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 Win32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } return(null); } } catch { return(null); } countWhile = 0; isInitCompleted = false; Dispatcher.Invoke(new System.Action(() => { //清除框选 TextOverlay.Children.Clear(); //生成绑定图片 bitmap = Util.GetBitmapImage(filePath); img.Width = bitmap.PixelWidth; img.Height = bitmap.PixelHeight; img.Source = bitmap; })); ImgGeneralInfo resultImgGeneral = null; try { var image = File.ReadAllBytes(filePath); //集成云处理OCR APIService service = new APIService(); var result = service.GetOCRResultByToken(image); //反序列化 resultImgGeneral = JsonConvert.DeserializeObject <ImgGeneralInfo>(result.ToString().Replace("char", "Char")); ////////var options = new Dictionary<string, object>{ //////// {"recognize_granularity", "small"}, //////// {"vertexes_location", "true"} //////// }; ////////string apiName = ""; ////////try ////////{ //////// apiName = ConfigurationManager.AppSettings["CallAPIName"].ToString(); ////////} ////////catch (Exception ex) ////////{ } ////////DESHelper dESHelper = new DESHelper(); ////////OCR clientOCR = new OCR(dESHelper.DecryptString(ConfigurationManager.AppSettings["APIKey"].ToString()), dESHelper.DecryptString(ConfigurationManager.AppSettings["SecretKey"].ToString())); ////////var result = clientOCR.Accurate(apiName, image, options); //////////反序列化 ////////resultImgGeneral = JsonConvert.DeserializeObject<ImgGeneralInfo>(result.ToString().Replace("char", "Char")); } catch (Exception ex) { CheckWordUtil.Log.TextLog.SaveError(ex.Message); } while (!isInitCompleted && countWhile < 10) { System.Threading.Thread.Sleep(100); countWhile++; } if (resultImgGeneral != null && resultImgGeneral.words_result_num > 0) { string desiredFolderName = CheckWordTempPath + " \\" + Guid.NewGuid().ToString() + "\\"; if (!Directory.Exists(desiredFolderName)) { Directory.CreateDirectory(desiredFolderName); } List <WordInfo> listUnValidInfos = new List <WordInfo>(); foreach (var item in resultImgGeneral.words_result) { string lineWord = ""; List <Rect> rects = new List <Rect>(); foreach (var charInfo in item.Chars) { lineWord += charInfo.Char; rects.Add(new Rect() { X = charInfo.location.left * xScale, Y = charInfo.location.top * yScale, Width = charInfo.location.width * xScale, Height = charInfo.location.height * yScale }); } var listUnChekedWordInfo = CheckWordUtil.CheckWordHelper.GetUnChekedWordInfoList(lineWord); foreach (var itemInfo in listUnChekedWordInfo) { listUnValidInfos.Add(new WordInfo() { UnValidText = itemInfo.Name, AllText = lineWord, Rects = rects }); MatchCollection mc = Regex.Matches(lineWord, itemInfo.Name, RegexOptions.IgnoreCase); if (mc.Count > 0) { foreach (Match m in mc) { var infoResult = listResult.FirstOrDefault(x => x.Name == itemInfo.Name); if (infoResult == null) { itemInfo.UnChekedWordInLineDetailInfos.Add(new UnChekedInLineDetailWordInfo() { TypeTextFrom = "Img", UnCheckWordExcelRangeShape = shape, InLineText = lineWord, ImgResultPath = desiredFolderName + System.IO.Path.GetFileName(filePath) }); itemInfo.ErrorTotalCount++; listResult.Add(itemInfo); } else { infoResult.UnChekedWordInLineDetailInfos.Add(new UnChekedInLineDetailWordInfo() { TypeTextFrom = "Img", UnCheckWordExcelRangeShape = shape, InLineText = lineWord, ImgResultPath = desiredFolderName + System.IO.Path.GetFileName(filePath) }); infoResult.ErrorTotalCount++; } } } } } var list = CheckWordHelper.GetUnValidRects(listUnValidInfos); foreach (var item in list) { try { Dispatcher.Invoke(new System.Action(() => { WordOverlay wordBoxOverlay = new WordOverlay(item); var overlay = new System.Windows.Controls.Border() { Style = (System.Windows.Style) this.Resources["HighlightedWordBoxHorizontalLine"] }; overlay.SetBinding(System.Windows.Controls.Border.MarginProperty, wordBoxOverlay.CreateWordPositionBinding()); overlay.SetBinding(System.Windows.Controls.Border.WidthProperty, wordBoxOverlay.CreateWordWidthBinding()); overlay.SetBinding(System.Windows.Controls.Border.HeightProperty, wordBoxOverlay.CreateWordHeightBinding()); TextOverlay.Children.Add(overlay); })); } catch (Exception ex) { } } if (listUnValidInfos.Count > 0) { System.Threading.Thread.Sleep(50); SavePic(desiredFolderName + System.IO.Path.GetFileName(filePath)); } } } catch (Exception ex) { } return(listResult); }
private void MainWindow_Drop(object sender, DragEventArgs e) { viewModel.IsDetailPopWindowOpen = false; if (this.IsDealingData) { DragDealingTipGrid.Visibility = Visibility.Collapsed; DragTipGrid.Visibility = Visibility.Collapsed; return; } this.IsDealingData = true; SendDealDataStateToApp(); IsCancelDeal = false; IsInputCheckGridVisible = viewModel.InputCheckGridVisibility == Visibility.Visible; IsDataProcessResultVisible = viewModel.DataProcessResultGridVisibility == Visibility.Visible; DragDealingTipGrid.Visibility = Visibility.Collapsed; DragTipGrid.Visibility = Visibility.Collapsed; FilePathsList = new List <string>(); UnCheckFilePathsList = new List <string>(); UnReadFilePathsList = new List <string>(); if (e.Data.GetDataPresent(DataFormats.FileDrop)) { foreach (var path in ((System.Array)e.Data.GetData(DataFormats.FileDrop))) { if (File.Exists(path.ToString())) { if (listClass.Contains(System.IO.Path.GetExtension(path.ToString()).ToLower())) { if (!path.ToString().Contains("~$")) { FilePathsList.Add(path.ToString()); if (IsFileOpen(path.ToString()) && ".doc,.docx".Contains(System.IO.Path.GetExtension(path.ToString()).ToLower())) { UnReadFilePathsList.Add(path.ToString()); } } } else { UnCheckFilePathsList.Add(path.ToString()); } } else if (Directory.Exists(path.ToString())) { DirectoryInfo dir = new DirectoryInfo(path.ToString()); GetAllFiles(dir); } } if (FilePathsList.Count > 0) { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ExchangeBrowseTxTPaths"; ExchangeBrowseTxTPathsInfo exchangeBrowseTxTPathsInfo = new ExchangeBrowseTxTPathsInfo(); exchangeBrowseTxTPathsInfo.Paths = FilePathsList; commonExchangeInfo.Data = JsonConvert.SerializeObject(exchangeBrowseTxTPathsInfo); string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 SendMessage("WordAndImgOperationApp", jsonData); viewModel.InputCheckGridVisibility = Visibility.Collapsed; viewModel.DataProcessGridVisibility = Visibility.Visible; viewModel.DataProcessResultGridVisibility = Visibility.Collapsed; } else { if (UnCheckFilePathsList.Count > 0) { viewModel.CheckResultText = UnCheckFilePathsList.Count + "个文件类型不支持."; } else { viewModel.CheckResultText = "未发现支持的文件类型."; } viewModel.TongJiCheckResultVisibility = Visibility.Collapsed; viewModel.SinggleWordCheckResultVisibility = Visibility.Collapsed; viewModel.SinggleWordCheckResultNoUncheckVisibility = Visibility.Collapsed; viewModel.CommonCheckResultVisibility = Visibility.Visible; viewModel.InputCheckGridVisibility = Visibility.Collapsed; viewModel.DataProcessGridVisibility = Visibility.Collapsed; viewModel.DataProcessResultGridVisibility = Visibility.Visible; viewModel.TitleLogoVisibility = Visibility.Collapsed; viewModel.ReturnBtnVisibility = Visibility.Visible; this.IsDealingData = false; SendDealDataStateToApp(); } } }
/// <summary> /// 执行检索查词 /// </summary> /// <param name="inputTxt"></param> private void ExcuteSearchResult(string inputTxt) { if (!string.IsNullOrEmpty(inputTxt)) { int countWords = 0; countWords = inputTxt.Count(); try { string token = ""; try { string loginInOutInfos = string.Format(@"{0}\LoginInOutInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); var ui = CheckWordUtil.DataParse.ReadFromXmlPath <string>(loginInOutInfos); if (ui != null && ui.ToString() != "") { try { var loginInOutInfo = JsonConvert.DeserializeObject <LoginInOutInfo>(ui.ToString()); if (loginInOutInfo != null && loginInOutInfo.Type == "LoginIn") { token = loginInOutInfo.Token; } } catch { } } } catch (Exception ex) { } APIService service = new APIService(); var userStateInfos = service.GetUserStateByToken(token); if (userStateInfos != null) { if (userStateInfos.WordCount < countWords) { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "500"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 SendMessage("WordAndImgOperationApp", jsonData); } catch { } } else { ConsumeResponse consume = service.GetWordConsume(countWords, token); if (consume != null) { try { //处理逻辑 var resultInfo = CheckWordUtil.CheckWordHelper.GetUnChekedWordInfoList(inputTxt); viewModel.CurrentWordInfo.Name = inputTxt; viewModel.CurrentWordInfoResults = new System.Collections.ObjectModel.ObservableCollection <CheckWordModel.UnChekedWordInfo>(resultInfo); if (viewModel.CurrentWordInfoResults.Count > 0) { viewModel.HasUnChekedWordInfoCount = viewModel.CurrentWordInfoResults.Count; viewModel.TongJiCheckResultVisibility = Visibility.Collapsed; viewModel.SinggleWordCheckResultVisibility = Visibility.Visible; viewModel.SinggleWordCheckResultNoUncheckVisibility = Visibility.Collapsed; viewModel.CommonCheckResultVisibility = Visibility.Collapsed; } else { viewModel.TongJiCheckResultVisibility = Visibility.Collapsed; viewModel.SinggleWordCheckResultVisibility = Visibility.Collapsed; viewModel.SinggleWordCheckResultNoUncheckVisibility = Visibility.Visible; viewModel.CommonCheckResultVisibility = Visibility.Collapsed; } } catch (Exception ex) { } viewModel.TitleLogoVisibility = Visibility.Collapsed; viewModel.InputCheckGridVisibility = Visibility.Collapsed; viewModel.ReturnBtnVisibility = Visibility.Visible; viewModel.DataProcessResultGridVisibility = Visibility.Visible; } else { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "200"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 SendMessage("WordAndImgOperationApp", jsonData); } catch { } } } } else { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "200"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 SendMessage("WordAndImgOperationApp", jsonData); } catch { } } } catch { } } }
/// <summary> /// 获取所有校验数据 /// </summary> /// <param name="token"></param> /// <returns></returns> public static List <WordModel> GetAllCheckWordByToken(string token) { WordModels = new List <WordModel>(); try { string apiName = "word"; string resultStr = HttpHelper.HttpUrlSend(apiName, "GET", token); GetAllWordsInfoResponse resultInfo = JsonConvert.DeserializeObject <GetAllWordsInfoResponse>(resultStr); var listDBWords = resultInfo.data; if (listDBWords != null) { foreach (var item in listDBWords) { WordModel word = new WordModel(); word.ID = item.code; word.Name = item.name; word.SourceDBs = item.type; if (word.SourceDBs != null && word.SourceDBs.Count > 0) { word.SourceDB = word.SourceDBs.First().name; } word.NameTypes = item.category; if (word.NameTypes != null && word.NameTypes.Count > 0) { word.NameType = word.NameTypes.First().name; } WordModels.Add(word); } } } catch (Exception ex) { WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message); WordModels = new List <WordModel>(); } if (WordModels.Count > 0) { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "HideNotifyMessageView"; commonExchangeInfo.Data = "4003"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 WPFClientCheckWordUtilWin32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } } else { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "4003"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 WPFClientCheckWordUtilWin32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } } return(WordModels); }