private void UpdateImagePart(string imageFilePath, PartBookmark bookmark, string variant) { // 1. find image part foreach (Part imgPart in _imageParts) { if (imgPart.Content.Location.Trim().EndsWith(imageFilePath)) { // replace for (int lineIndex = 0; lineIndex < imgPart.Lines.Count; lineIndex++) { string line = imgPart.Lines[lineIndex]; if (string.IsNullOrEmpty(line) || line.StartsWith(Mime.StartPart) || line.StartsWith(PartContent.ContentTransferEncoding) || line.StartsWith(PartContent.ContentType)) { continue; } if (line.StartsWith(PartContent.ContentLocation)) { int lastDotIndex = line.LastIndexOf(Mime.Dot); line = line.Insert(lastDotIndex, variant); imgPart.Lines[lineIndex] = line; continue; } imgPart.RemoveLine(lineIndex); } // insert for-each tag string startLine = string.Empty; string endLine = string.Empty; if (_isAddSection) { startLine = XslContent.XslStartForeachTag(GetSectionPath(), Core.MarkupConstant.XslVariableSection, Core.MarkupConstant.XslPosition); endLine = XslContent.XslFormat.XslEndForeach; } foreach (ForeachItem fItem in _foreach) { startLine = startLine + fItem.XslString; endLine = endLine + XslContent.XslFormat.XslEndForeach; } if (!string.IsNullOrEmpty(startLine)) { imgPart.Lines.Insert(0, XslContent.InsertBreakLine(startLine, true)); } imgPart.Lines.Add(bookmark.XslString); if (!string.IsNullOrEmpty(endLine)) { imgPart.Lines.Add(XslContent.InsertBreakLine(endLine, false)); } return; } } }
private void UpdateImageBookmark(PartBookmark bookmark) { //1. Find src=3D" attribute int index = bookmark.StartLineIndex; string line = _htmlPart.Lines[index]; while (index < _htmlPart.Lines.Count && !line.Contains(Mime.SourceImage)) { index++; line = _htmlPart.Lines[index]; } if (index >= _htmlPart.Lines.Count) { return; } //2. Find end of src3D attribute (Char: '"'), last position of Dot ('.') int dotLineIndex = index; int dotCharIndex = line.LastIndexOf(Mime.Dot); string imagePath = string.Empty; line = line.Substring(line.IndexOf(Mime.SourceImage) + Mime.SourceImage.Length); while (index < _htmlPart.Lines.Count && !string.IsNullOrEmpty(line) && !line.Contains(Mime.EndAttribute)) { imagePath += line.TrimEnd(new char[] { Mime.Equal }); index++; line = _htmlPart.Lines[index]; if (line.Contains(Mime.Dot)) { dotLineIndex = index; dotCharIndex = line.LastIndexOf(Mime.Dot); } } if (index >= _htmlPart.Lines.Count) { return; } //3. Insert xsl string and get result string variant = string.Empty; if (_foreach.Count > 0) { variant = _foreach[_foreach.Count - 1].VariantName; } if (!string.IsNullOrEmpty(variant)) { variant = XslContent.XslValueOfTag(variant, false, true); } if (_isAddSection) { variant = XslContent.XslValueOfTag(Core.MarkupConstant.XslVariableSection, false) + variant; } _htmlPart.Lines[dotLineIndex] = _htmlPart.Lines[dotLineIndex].Insert(dotCharIndex, variant); imagePath += line.Substring(0, line.IndexOf(Mime.EndAttribute)); UpdateImagePart(imagePath, bookmark, variant); }
private void UpdateBookmarkPart(PartBookmark bookmark, int count) { int startLineIndex = bookmark.StartLineIndex; int endLineIndex = bookmark.EndLineIndex; int startCharIndex = bookmark.StartCharIndexOfStartLine; int endCharIndex = bookmark.EndCharIndexOfEndLine; if (bookmark.Type == Core.BookmarkType.StartForeach || bookmark.Type == Core.BookmarkType.StartIf || bookmark.Type == Core.BookmarkType.EndForeach || bookmark.Type == Core.BookmarkType.EndIf) { _htmlPart.FindStartParagrap(bookmark.StartLineIndex, bookmark.StartCharIndexOfStartLine, out startLineIndex, out startCharIndex); _htmlPart.FindEndParagrap(bookmark.EndLineIndex, bookmark.EndCharIndexOfEndLine, out endLineIndex, out endCharIndex); } string line = _htmlPart.Lines[startLineIndex]; int change = line.Length; if (startLineIndex == endLineIndex) { int numberChar = Math.Min(endCharIndex - startCharIndex, line.Length - startCharIndex); line = _htmlPart.RemoveString(line, startCharIndex, numberChar); } else if (startLineIndex < endLineIndex) { for (int i = startLineIndex + 1; i < endLineIndex; i++) { _htmlPart.RemoveLine(i); } line = _htmlPart.RemoveString(line, startCharIndex); string endLineString = _htmlPart.Lines[endLineIndex]; endLineString = _htmlPart.RemoveString(endLineString, 0, endCharIndex); _htmlPart.Lines[endLineIndex] = endLineString; } line = line.Insert(startCharIndex, bookmark.XslString); _htmlPart.Lines[startLineIndex] = line; // update index change = line.Length - change; if (change != 0) { for (int bmIndex = count + 1; bmIndex < _bookmarks.Count; bmIndex++) { PartBookmark bm = _bookmarks[bmIndex]; if (bm.StartLineIndex == bookmark.StartLineIndex) { bm.StartCharIndexOfStartLine += change; } } } }
public List <PartBookmark> GetBookmarks() { List <PartBookmark> bookmarks = new List <PartBookmark>(); Dictionary <string, bool> checks = new Dictionary <string, bool>(); if (Lines == null) { return(bookmarks); } for (int lineIndex = 0; lineIndex < Lines.Count; lineIndex++) { string line = Lines[lineIndex]; if (string.IsNullOrEmpty(line)) { continue; } bool hasBookmark = true; int startIndexOfBm = 0; while (hasBookmark) { int startIndex = lineIndex; int endIndex = lineIndex; string endLine = line; if (!line.Substring(startIndexOfBm).Contains(Core.MarkupConstant.PrefixBookmark) && line.EndsWith(LinkedChar)) { string nextLine = Lines[startIndex + 1]; if (!nextLine.Contains(Core.MarkupConstant.PrefixBookmark)) { endIndex++; line = line.Remove(line.Length - 1) + nextLine; endLine = nextLine; } } if (line.Substring(startIndexOfBm).Contains(Core.MarkupConstant.PrefixBookmark)) { PartBookmark bookmark = new PartBookmark(); bookmark.StartLineIndex = startIndex; bookmark.StartCharIndexOfStartLine = PartBookmark.FindString(line, Core.MarkupConstant.PrefixBookmark, startIndexOfBm); string content = line; while (!content.Substring(startIndexOfBm).Contains(Core.MarkupConstant.SuffixEndBookmark) && content.EndsWith(LinkedChar)) { endIndex++; endLine = Lines[endIndex]; content = content.Remove(content.Length - 1) + endLine; } if (content.Substring(startIndexOfBm).Contains(Core.MarkupConstant.SuffixEndBookmark)) { bookmark.EndLineIndex = endIndex; bookmark.EndCharIndexOfEndLine = PartBookmark.FindString(content, Core.MarkupConstant.SuffixEndBookmark, bookmark.StartCharIndexOfStartLine) + Core.MarkupConstant.SuffixEndBookmark.Length; bookmark.EndCharIndexOfEndLine = bookmark.EndCharIndexOfEndLine - (content.Length - endLine.Length); startIndexOfBm = bookmark.EndCharIndexOfEndLine; bookmark.Content = content; if (!string.IsNullOrEmpty(bookmark.Key) && !string.IsNullOrEmpty(bookmark.BizName)) { if (!checks.ContainsKey(bookmark.Key)) { bookmarks.Add(bookmark); checks.Add(bookmark.Key, true); } } } if (startIndex == endIndex) { if (line.Length <= startIndexOfBm) { hasBookmark = false; } } else { hasBookmark = false; } } else { hasBookmark = false; } } } return(bookmarks); }
private void ReplaceBookmarkTag() { _foreach = new List <ForeachItem>(); for (int index = 0; index < _bookmarks.Count; index++) { PartBookmark bookmark = _bookmarks[index]; List <string> selectedTable = GetSelectedTables(bookmark); Relations relations = GetRelations(bookmark); if (!bookmark.IsDelete) { string xslPath = string.Empty; switch (bookmark.Type) { case Core.BookmarkType.EndForeach: bookmark.XslString = XslContent.XslFormat.XslEndForeach; if (_foreach.Count > 0) { _foreach.RemoveAt(_foreach.Count - 1); } UpdateBookmarkPart(bookmark, index); break; case Core.BookmarkType.EndIf: bookmark.XslString = XslContent.XslFormat.XslEndIf; UpdateBookmarkPart(bookmark, index); break; case Core.BookmarkType.Image: xslPath = GetXslPath(bookmark, bookmark.BizName, false, selectedTable, relations); bookmark.XslString = XslContent.XslValueOfTag(xslPath); UpdateImageBookmark(bookmark); break; case Core.BookmarkType.Select: xslPath = GetXslPath(bookmark, bookmark.BizName, false, selectedTable, relations); bookmark.XslString = XslContent.XslValueOfTag(xslPath, bookmark.BizName == ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwWatermark ? false : true); UpdateBookmarkPart(bookmark, index); break; case Core.BookmarkType.StartIf: xslPath = GetXslPath(bookmark, bookmark.BizName, true, selectedTable, relations); bookmark.XslString = XslContent.XslStartIfTag(xslPath); UpdateBookmarkPart(bookmark, index); break; case Core.BookmarkType.StartForeach: int indexForeach = _foreach.Count + 1; string variant = Core.MarkupConstant.XslVariableImage + index.ToString(); InternalBookmarkDomain ibmDomain = _ibm.GetInternalBookmarkDomainByItemKey(bookmark.Key); ForeachItem fItem = new ForeachItem(index, _bookmarks.Cast <Base.BaseBookmark>(), relations, ibmDomain.SelectedTables, indexForeach, variant, string.Empty); _foreach.Add(fItem); xslPath = GetXslPath(bookmark, string.Empty, false, selectedTable, relations); InternalBookmarkItem ibmItem = _ibm.GetInternalBookmarkItem(bookmark.Key); string sort = GetSortXsl(bookmark.BizName, ibmItem.DomainName, selectedTable, relations, true); bookmark.XslString = XslContent.XslStartForeachTag(xslPath, variant, Core.MarkupConstant.XslMultiPosition, sort); fItem.XslString = bookmark.XslString; UpdateBookmarkPart(bookmark, index); break; default: break; } } } }