Position ISearch.SearchNext(WantToDoType type) { Position position = null; GetDataResourceValue getDataResourceValue = new GetDataResourceValue(this); switch (type) { case WantToDoType.SearchNext: position = getDataResourceValue.SaveFindProperty(type); break; case WantToDoType.SearchAll: position = getDataResourceValue.SearchOrReplaceAll(type); break; case WantToDoType.ReplaceNext: position = getDataResourceValue.SaveFindProperty(type); break; case WantToDoType.ReplaceAll: position = getDataResourceValue.SearchOrReplaceAll(type); break; } return(position); }
/// <summary> /// 查找或替换全部 /// </summary> /// <param name="findContent"></param> /// <param name="type"></param> /// <returns></returns> public Position SearchOrReplaceAll(WantToDoType type) { this._type = type; int index = 0; if (_canSearchEleDic != null) { foreach (PropertyInfo canFindProperty in _canSearchEleDic.Values) { while (true) { object value = canFindProperty.GetValue(_doc, null); string strValue = value.ToString(); if (!string.IsNullOrEmpty(strValue) && !string.IsNullOrEmpty(this._findContent)) { //正则部分 if (FindOptions.Singler.IsUsingFindType) { string matchContent = Rule(strValue); if (!string.IsNullOrEmpty(matchContent)) { if (FindOptions.Singler.MatchCase) { } } MessageBox.Show("启动了使用正则和通配符,本部分为完善位置在PageXMlDocument的753行"); break; } else { //大小写匹配 strValue = MatchCase(strValue); index = SavePosition(strValue, canFindProperty); if (this._type == WantToDoType.ReplaceAll) { ReplaceFindContent(); } if (index < 0) { break; } } } else { break; } } } } return(null); }
/// <summary> /// 查找中....... /// </summary> /// <param name="wantToDoType"></param> private void Searching(WantToDoType wantToDoType) { GetSearchDocuments(); foreach (ISearch _document in _searchDocuments) { while (true) { //判断起始点 Position currentPosition = FindOptions.Singler.CurrentPosition; if (currentPosition != null && FindOptions.Singler.StartPosition == null) { PropertyInfo property = currentPosition.Property; string value = property.GetValue(currentPosition.GetDocument(), null).ToString(); string result = value.Substring(currentPosition.Index, currentPosition.Length); if (result.Equals(FindOptions.Singler.FindContent)) { FindOptions.Singler.StartPosition = currentPosition; } } Position hasPosition = _document.SearchNext(wantToDoType); if (hasPosition != null) { FindOptions.Singler.IsFindResult = true; Position position = FindOptions.Singler.StartPosition; if (position != null) { if (hasPosition.Index == position.Index && hasPosition.Length == position.Length && position.Property == hasPosition.Property) { DisplayFindedResult(hasPosition); MessageService.Show("搜索回到起点"); break; } else { DisplayFindedResult(hasPosition); break; } } if (FindOptions.Singler.StartPosition == null) { FindOptions.Singler.StartPosition = hasPosition; } DisplayFindedResult(hasPosition); break; } else { //标识未找到 if (!FindOptions.Singler.IsFindResult) { break; } if (FindOptions.Singler.UpWard) { FindOptions.Singler.CurrentPosition = FindOptions.Singler.LastPosition; } else { if (wantToDoType != WantToDoType.ReplaceNext) { FindOptions.Singler.CurrentPosition = null; } } if (wantToDoType == WantToDoType.ReplaceNext) { MessageService.Show("搜索回到起点"); break; } else { continue; } } } } //未搜索到结果 if (!FindOptions.Singler.IsFindResult) { DisplayFindedResult(null); } }
//查找或替换下一个 public Position SaveFindProperty(WantToDoType type) { this._type = type; int index = -1; //设置最后的Position GetLastPosition(); if (_canSearchEleDic != null) { //的到当前的属性 int tag = SreachPropertyFactory(); if (FindOptions.Singler.UpWard) { for (int tagindex = tag; tagindex >= 0; tagindex--) { object value = _canSearchEleDic[tagindex].GetValue(_doc, null); string strValue = value.ToString(); //TODO:正则问题 //大小写匹配 strValue = MatchCase(strValue); if (!string.IsNullOrEmpty(strValue) && !string.IsNullOrEmpty(this._findContent)) { while (true) { //正则问题 if (FindOptions.Singler.IsUsingFindType) { MessageBox.Show("启动了使用正则和通配符,本部分为完善位置在PageXMlDocument的583行"); break; } else { index = SaveSinglePosition(strValue, _canSearchEleDic[tagindex]); if (this._type == WantToDoType.ReplaceNext) { ReplaceFindContent(); } if (index >= 0) { if (this._positionForSingle != null) { FindOptions.Singler.CurrentPosition = _positionForSingle; return(this._positionForSingle); } else { return(FindOptions.Singler.CurrentPosition); } } else { break; } } } } if (tagindex == 0) { break; } else { continue; } } } else { for (int tagindex = tag; tagindex < _canSearchEleDic.Count; tagindex++) { object value = _canSearchEleDic[tagindex].GetValue(_doc, null); string strValue = value.ToString(); if (!string.IsNullOrEmpty(strValue) && !string.IsNullOrEmpty(this._findContent)) { while (true) { //正则部分 if (FindOptions.Singler.IsUsingFindType) { MessageBox.Show("启动了使用正则和通配符,本部分为完善位置在PageXMlDocument的631行"); break; } else { //大小写匹配 strValue = MatchCase(strValue); index = SaveSinglePosition(strValue, _canSearchEleDic[tagindex]); if (this._type == WantToDoType.ReplaceNext) { ReplaceFindContent(); } if (index >= 0) { if (this._positionForSingle != null) { FindOptions.Singler.CurrentPosition = _positionForSingle; return(this._positionForSingle); } else { return(FindOptions.Singler.CurrentPosition); } } else { break; } } } } else if (tagindex == _canSearchEleDic.Count - 1) { break; } else { continue; } } } } return(null); }
//Dictionary<string, Image> _dicImagesCache = new Dictionary<string, Image>(); //Image GetImage(string fileName) //{ // Image image = null; // if (!_dicImagesCache.TryGetValue(fileName, out image)) // { // //todo: // image = Image.FromFile(Path.Combine(Application.StartupPath, fileName)); // _dicImagesCache.Add(fileName, image); // } // return image; //} #endregion #region ISearch 成员 public Position SearchNext(WantToDoType type) { return(null); }