/// <summary>
        ///  检查违禁词
        /// </summary>
        public string CheckWord(CheckWordRequestInfo info)
        {
            CheckWordResponseResult result = new CheckWordResponseResult();

            if (IsUserLogin())
            {
                try
                {
                    try
                    {
                        if (CheckWordHelper.WordModels.Count == 0 && !string.IsNullOrEmpty(SystemVar.UserToken))
                        {
                            CheckWordHelper.GetAllCheckWordByToken(SystemVar.UserToken, SystemVar.UrlStr);
                        }
                    }
                    catch (Exception ex)
                    { }
                    var listUnChekedWord = CheckWordHelper.GetUnChekedWordInfoList(info.Text).ToList();
                    result.Result            = true;
                    result.UncheckWordModels = listUnChekedWord;
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                }
            }
            else
            {
                result.Message = "LoginOut";
            }
            return(JsonConvert.SerializeObject(result));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 客户端发送消息
 /// </summary>
 /// <param name="message"></param>
 public void ClientSendMessage(string message)
 {
     try
     {
         ICallBackServices client         = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
         LoginInOutInfo    loginInOutInfo = JsonConvert.DeserializeObject <LoginInOutInfo>(message);
         if (loginInOutInfo.Type == "LoginIn")
         {
             SystemVar.UrlStr    = loginInOutInfo.UrlStr;
             SystemVar.UserToken = loginInOutInfo.Token;
             if (!string.IsNullOrEmpty(SystemVar.UserToken))
             {
                 CheckWordHelper.WordModels = CheckWordHelper.GetAllCheckWordByToken(SystemVar.UserToken, SystemVar.UrlStr);
             }
         }
         else
         {
             SystemVar.UserToken = "";
         }
     }
     catch (Exception ex)
     {
         WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message);
     }
 }
Ejemplo n.º 3
0
 private void DealSingleParagraph(object obj)
 {
     try
     {
         Range  item = obj as Range;
         string str  = CellGetStringValue(item);
         if (!string.IsNullOrEmpty(str))
         {
             List <UnChekedWordInfo> listUnChekedWord = new List <UnChekedWordInfo>();
             string hashWord = HashHelper.ComputeSHA1ByStr(str);
             try
             {
                 if (!CurrentWordsDictionary.ContainsKey(hashWord))
                 {
                     listUnChekedWord = CheckWordHelper.GetUnChekedWordInfoList(str).ToList();
                     if (listUnChekedWord != null)
                     {
                         try
                         {
                             CurrentWordsDictionary.Add(hashWord, listUnChekedWord);
                         }
                         catch
                         { }
                     }
                 }
                 else
                 {
                     listUnChekedWord = CurrentWordsDictionary[hashWord];
                 }
             }
             catch (Exception ex)
             {
                 CheckWordUtil.Log.TextLog.SaveError(ex.Message);
             }
             if (listUnChekedWord != null && listUnChekedWord.Count > 0)
             {
                 HasUnChenckedWordsParagraphs.Add(new UnChekedWordExcelRangeInfo {
                     Range = item, RangeText = str, UnChekedWordLists = listUnChekedWord
                 });
             }
         }
     }
     catch (Exception ex)
     {
         CheckWordUtil.Log.TextLog.SaveError(ex.Message);
     }
     try
     {
         // 以原子操作的形式递减指定变量的值并存储结果。
         if (Interlocked.Decrement(ref countDealParagraph) == 0)
         {
             // 将事件状态设置为有信号,从而允许一个或多个等待线程继续执行。
             myEvent.Set();
         }
     }
     catch
     { }
 }
Ejemplo n.º 4
0
        /// <summary>
        ///  检查违禁词
        /// </summary>
        public string CheckWord(CheckWordRequestInfo info)
        {
            CheckWordResponseResult result = new CheckWordResponseResult();

            if (IsUserLogin())
            {
                try
                {
                    var listUnChekedWord = CheckWordHelper.GetUnChekedWordInfoList(info.Text).ToList();
                    result.Result            = true;
                    result.UncheckWordModels = listUnChekedWord;
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                }
            }
            else
            {
                result.Message = "LoginOut";
            }
            return(JsonConvert.SerializeObject(result));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///  获取替换词
        /// </summary>
        public string GetReplaceWord(ReplaceWordRequestInfo info)
        {
            ReplaceWordResponseResult result = new ReplaceWordResponseResult();

            if (IsUserLogin())
            {
                try
                {
                    var listReplaceWord = CheckWordHelper.GetReplaceWordInfos(info.Text).ToList();
                    result.Result            = true;
                    result.ReplaceWordModels = listReplaceWord;
                }
                catch (Exception ex)
                {
                    WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message);
                    result.Message = ex.Message;
                }
            }
            else
            {
                result.Message = "LoginOut";
            }
            return(JsonConvert.SerializeObject(result));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///  检查是否是违禁词
        /// </summary>
        public string CheckOneWord(CheckWordRequestInfo info)
        {
            CheckOnlyWordResponseResult result = new CheckOnlyWordResponseResult();

            if (IsUserLogin())
            {
                try
                {
                    var infoWord = CheckWordHelper.GetUnChekedWordInfo(info.Text);
                    result.Result   = true;
                    result.WordInfo = infoWord;
                }
                catch (Exception ex)
                {
                    WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message);
                    result.Message = ex.Message;
                }
            }
            else
            {
                result.Message = "LoginOut";
            }
            return(JsonConvert.SerializeObject(result));
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 解析处理段落
 /// </summary>
 /// <param name="ParagraphDataList"></param>
 private void DealSingleParagraph(object obj)
 {
     try
     {
         Microsoft.Office.Interop.Word.Paragraph paragraph = obj as Microsoft.Office.Interop.Word.Paragraph;
         if (paragraph != null)
         {
             string text = paragraph.Range.Text;
             if (!string.IsNullOrEmpty(text))
             {
                 List <UnChekedWordInfo> listUnChekedWord = new List <UnChekedWordInfo>();
                 string hashWord = HashHelper.ComputeSHA1ByStr(text);
                 try
                 {
                     if (!CurrentWordsDictionary.ContainsKey(hashWord))
                     {
                         listUnChekedWord = CheckWordHelper.GetUnChekedWordInfoList(text).ToList();
                         if (listUnChekedWord != null)
                         {
                             try
                             {
                                 CurrentWordsDictionary.Add(hashWord, listUnChekedWord);
                             }
                             catch
                             { }
                         }
                     }
                     else
                     {
                         listUnChekedWord = CurrentWordsDictionary[hashWord];
                     }
                 }
                 catch (Exception ex)
                 {
                     CheckWordUtil.Log.TextLog.SaveError(ex.Message);
                 }
                 if (listUnChekedWord != null && listUnChekedWord.Count > 0)
                 {
                     HasUnChenckedWordsParagraphs.Add(new UnChekedWordParagraphInfo {
                         Paragraph = paragraph, UnChekedWordLists = listUnChekedWord
                     });
                 }
             }
         }
     }
     catch (Exception ex)
     {
         CheckWordUtil.Log.TextLog.SaveError(ex.Message);
     }
     try
     {
         // 以原子操作的形式递减指定变量的值并存储结果。
         if (Interlocked.Decrement(ref countDealParagraph) == 0)
         {
             // 将事件状态设置为有信号,从而允许一个或多个等待线程继续执行。
             myEvent.Set();
         }
     }
     catch
     { }
 }
Ejemplo n.º 9
0
        public void InitData(string name)
        {
            ObservableCollection <ReplaceWordInfo> replaceWordInfos = new ObservableCollection <ReplaceWordInfo>(CheckWordHelper.GetReplaceWordInfos(name));

            for (int i = 0; i < replaceWordInfos.Count; i++)
            {
                replaceWordInfos[i].Index = i + 1;
            }
            ReplaceWordLists = replaceWordInfos;
        }