public void ApplyRuleToAll(ProcessingWordsRules rule) { List<string> wordparts = rule.word_parts; ; if (wordparts.Count == 0) return; // Find and replace complex words foreach (SubtitleItem sub in Subtitles.Items.OrderBy(x=>x.TimeStart)) { // speed optimization string SubTxt = sub.Text.ToLower(); if (!SubTxt.Contains(wordparts[0])) continue; if (wordparts.Count > 1) if (!SubTxt.Contains(wordparts[1])) continue; if(!sub.WordsCollection.Any(x=>x.word.ToLower() == wordparts[0])) continue; int CurrentWordIdx = -1; List<WordOfSubtitleItem> wrdcoll = sub.WordsCollection.OrderBy(x => x.number).ToList(); List<WordOfSubtitleItem> delete = new List<WordOfSubtitleItem>(); int TotalWords = wrdcoll.Count; while(++CurrentWordIdx < TotalWords) { WordOfSubtitleItem FoundWord = null; for(int i = 0;i < wordparts.Count; i++) { if(CurrentWordIdx + i >= TotalWords) { break; } if(wordparts[i] != wrdcoll[CurrentWordIdx + i].word.ToLower()) { break; } if (FoundWord == null) { FoundWord = wrdcoll[CurrentWordIdx + i]; } else { delete.Add(wrdcoll[CurrentWordIdx + i]); } } if (FoundWord==null) continue; // Found a word FoundWord.word = rule.word; FoundWord.word_of_dictionary = null; if (rule.Delete) delete.Add(FoundWord); CurrentWordIdx += rule.word_parts.Count - 1; } EFDbContext.Context.DeleteRange(delete); } EFDbContext.SaveChgs(); }
private void ProcessingWordCmdDispatcher(ProcessingWordsRules rule,string cmd) { switch (cmd) { case "ApplyRule": ApplyRuleToAll(rule); break; case "DeleteRule": //EFDbContext.DataBase.ProcessingWordsRules.Remove(rule); EFDbContext.Context.Delete(rule); break; default: throw new NotImplementedException(); } }