public static SearchMatch SearchFragment(this InfoOwner item, string value) { var result = item.Search(value).FirstOrDefault(); if (result == null) { return(null); } var match = result.Item; var diff = match.Length - result.StartIndex - value.Length; return(new SearchMatch( result.StartIndex > 0 ? match.Substring(0, result.StartIndex) : "", match.Substring(result.StartIndex, value.Length), diff > 0 ? match.Substring(result.StartIndex + value.Length, diff) : "" )); }
public void CopyAuthorsAndSources(SIDocument newDocument, InfoOwner infoOwner) { var length = infoOwner.Info.Authors.Count; for (int i = 0; i < length; i++) { var authorID = infoOwner.Info.Authors[i].ExtractLink(); if (authorID.Length > 0) { if (newDocument.Authors.All(author => author.Id != authorID)) { var newAuthor = Authors.FirstOrDefault(author => author.Id == authorID); if (newAuthor != null) { newDocument.Authors.Add(newAuthor.Clone()); } } } } length = infoOwner.Info.Sources.Count; for (int i = 0; i < length; i++) { var sourceID = infoOwner.Info.Sources[i].ExtractLink(true); if (sourceID.Length > 0) { if (newDocument.Sources.All(source => source.Id != sourceID)) { var newSource = Sources.FirstOrDefault(source => source.Id == sourceID); if (newSource != null) { newDocument.Sources.Add(newSource.Clone()); } } } } }
/// <summary> /// Заменить ссылки на их значения /// </summary> /// <param name="item">Объект, для которого проводится замена</param> private void InsertLinkValue(InfoOwner item) { for (int i = 0; i < item.Info.Authors.Count; i++) { var author = GetLink(item.Info.Authors, i); if (author != null) { item.Info.Authors[i].ExtractLink(out string tail); item.Info.Authors[i] = author.ToString() + tail; } } for (int i = 0; i < item.Info.Sources.Count; i++) { var source = GetLink(item.Info.Sources, i); if (source != null) { item.Info.Sources[i].ExtractLink(out string tail); item.Info.Sources[i] = source.ToString() + tail; } } }