private static void AnnotatePagesWithOpenAndCurrent(Guid pageId, List<XElement> pageElements) { string pageIdAsString = pageId.ToString(); XAttribute matchingPageIdAttrib = GetSiteMap().DescendantsAndSelf().Attributes(AttributeNames.Id).FirstOrDefault(f => f.Value == pageIdAsString); if (matchingPageIdAttrib != null) { List<string> openPageIdList = matchingPageIdAttrib.Parent.AncestorsAndSelf(PageElementName).Attributes(AttributeNames.Id).Select(f => f.Value).ToList(); foreach (XElement openPage in pageElements.DescendantsAndSelf(PageElementName).Where(f => openPageIdList.Contains(f.Attribute(AttributeNames.Id).Value))) { openPage.Add(new XAttribute("isopen", "true")); if (openPage.Attribute(AttributeNames.Id).Value == pageIdAsString) { openPage.Add(new XAttribute("iscurrent", "true")); } } } }
// Rules for sections // - if KeepSections for all documents in the source collection are false, then it takes the section // from the first document. // - if you specify true for any document, and if the last section is part of the specified content, // then that section is copied. If any paragraph in the content has a section, then that section // is copied. // - if you specify true for any document, and there are no sections for any paragraphs, then no // sections are copied. private static void AppendDocument(WordprocessingDocument sourceDocument, WordprocessingDocument newDocument, List<XElement> newContent, bool keepSection, string insertId, List<ImageData> images) { FixRanges(sourceDocument.MainDocumentPart.GetXDocument(), newContent); AddRelationships(sourceDocument.MainDocumentPart, newDocument.MainDocumentPart, newContent); CopyRelatedPartsForContentParts(sourceDocument.MainDocumentPart, newDocument.MainDocumentPart, newContent, images); // Append contents XDocument newMainXDoc = newDocument.MainDocumentPart.GetXDocument(); newMainXDoc.Declaration.Standalone = "yes"; newMainXDoc.Declaration.Encoding = "UTF-8"; if (keepSection == false) { List<XElement> adjustedContents = newContent.Where(e => e.Name != W.sectPr).ToList(); adjustedContents.DescendantsAndSelf(W.sectPr).Remove(); newContent = adjustedContents; } foreach (var sectPr in newContent.DescendantsAndSelf(W.sectPr)) AddSectionAndDependencies(sourceDocument, newDocument, sectPr, images); CopyStylesAndFonts(sourceDocument, newDocument, newContent); CopyNumbering(sourceDocument, newDocument, newContent, images); CopyComments(sourceDocument, newDocument, newContent, images); CopyFootnotes(sourceDocument, newDocument, newContent, images); CopyEndnotes(sourceDocument, newDocument, newContent, images); AdjustUniqueIds(sourceDocument, newDocument, newContent); RemoveGfxdata(newContent); CopyCustomXml(sourceDocument, newDocument, newContent); if (insertId != null) { XElement insertElementToReplace = newMainXDoc .Descendants(PtOpenXml.Insert) .FirstOrDefault(i => (string)i.Attribute(PtOpenXml.Id) == insertId); if (insertElementToReplace != null) insertElementToReplace.AddAnnotation(new ReplaceSemaphore()); newMainXDoc.Element(W.document).ReplaceWith((XElement)InsertTransform(newMainXDoc.Root, newContent)); } else newMainXDoc.Root.Element(W.body).Add(newContent); AdjustDocPrIds(newDocument); }
public static XElement withRuby(List <XAttribute> tattributes, List <XElement> tproperties, XNamespace w, string bottom, string topstr, int tone, bool topcolour = false, bool bottomcolour = false, List <string> colors = null) { string size = ""; foreach (XElement x in tproperties.DescendantsAndSelf(w + "sz")) { size = x.Attribute(w + "val").Value; } if (size == "") { size = "12"; } IEnumerable <XElement> tp = tproperties.Where(x => x.Name != w + "sz" || x.Name != w + "szCs"); // Properties without size XElement rubyPr = new XElement(w + "rubyPr", new XElement(w + "rubyAlign", new XAttribute(w + "val", "center")) ); XElement tcolour = new XElement(w + "color"); if (topcolour && !(colors == null)) { tcolour.SetAttributeValue(w + "val", colors[tone - 1]); } XElement top = new XElement(w + "rt", new XElement(w + "r", new XElement(w + "rPr", tp, new XElement(w + "rFonts", new XAttribute(w + "ascii", "Arial Unicode MS"), new XAttribute(w + "eastAsia", "Arial Unicode MS"), new XAttribute(w + "hAnsi", "Arial Unicode MS"), new XAttribute(w + "cs", "Arial Unicode MS"), new XAttribute(w + "hint", "eastAsia") ), tcolour ), new XElement(w + "t", gap + topstr + gap) ) ); XElement bcolour = new XElement(w + "color"); if (bottomcolour && !(colors == null)) { bcolour.SetAttributeValue(w + "val", colors[tone - 1]); } XElement bot = new XElement(w + "rubyBase", new XElement(w + "r", new XElement(w + "rPr", tproperties, bcolour ), new XElement(w + "t", bottom) ) ); return(new XElement(w + "r", new XElement(w + "ruby", rubyPr, top, bot ) )); }
// Внешние методы public override IEnumerable<XElement> SearchByName(string searchstring) { string[] predicates = new string[] { ONames.p_name }; DbCommand runcommand = RunStart(); int rdftype = RunGetRdftype(runcommand); // Список неизвестных предикатов string[] unknown = predicates.Where(p => !iENTS.ContainsKey(p)).ToArray(); var qu = EntityIndexes(unknown, runcommand); foreach (KeyValuePair<string, int> pair in qu) { iENTS.Add(pair.Key, pair.Value); } int[] i_predicates = predicates.Select(p => { int ires = -1; if (iENTS.TryGetValue(p, out ires)) {} return ires; }).ToArray(); string sql = "SELECT st.dsubject,ost.oobj,st.dpredicate,li.literalvalue FROM rdf_literals AS li " + "INNER JOIN rdf_dstatements AS st ON st.data = li.literalid " + "INNER JOIN rdf_ostatements AS ost ON st.dsubject=ost.osubject " + "WHERE (" + i_predicates.Select(ip => "st.dpredicate=" + ip).Aggregate((sum, s) => sum + " OR " + s) + ") AND li.literalvalue LIKE '" + searchstring + "%' AND ost.opredicate=" + rdftype + ";"; runcommand.CommandText = sql; DbDataReader reader = runcommand.ExecuteReader(); List<XElement> result = new List<XElement>(); while (reader.Read()) { result.Add(new XElement("record", new XAttribute("id", (int)reader[0]), new XAttribute("type", (int)reader[1]), new XElement("field", new XAttribute("prop", (int)reader[2]), new XText((string)reader[3])) )); } reader.Close(); var atts = result.DescendantsAndSelf() .SelectMany(el => el.Attributes().Where(att => att.Name == "id" || att.Name == "type" || att.Name == "prop")); int[] att_int_values = atts.Select(att => Int32.Parse(att.Value)) .Where(i_value => i_value >= 0 && !sENTS.ContainsKey(i_value)) .Distinct().ToArray(); var addition = EntityNames(att_int_values, runcommand); foreach (KeyValuePair<int, string> pair in addition) sENTS.Add(pair.Key, pair.Value); foreach (var att in atts) { int ii = Int32.Parse(att.Value); if (ii < 0) continue; att.Value = sENTS[ii]; } //connection.Close(); RunStop(runcommand); return result; }
// Методы доступа к базе данных public IEnumerable<XElement> SearchByName(string searchstring) { string sql = @"SELECT en.entityvalue,en.entitytype,st.dpredicate,li.literalvalue FROM rdf_literals AS li INNER JOIN rdf_dstatements AS st ON st.data = li.literalid INNER JOIN rdf_entities AS en ON en.entityid=st.dsubject WHERE li.literalvalue LIKE '" + searchstring + "%';"; DataTable dt = Queries.ExecuteQuery(sql); List<XElement> result = new List<XElement>(); foreach (DataRow row in dt.Rows) { result.Add(new XElement("record", new XAttribute("id", (string)row[0]), new XAttribute("type", (int)row[1]), new XElement("field", new XAttribute("prop", (int)row[2]), new XText((string)row[3])) )); } var atts = result.DescendantsAndSelf() .SelectMany(el => el.Attributes().Where(att => att.Name == "type" || att.Name == "prop")); int[] att_int_values = atts.Select(att => Int32.Parse(att.Value)) .Where(i_value => !sENTS.ContainsKey(i_value)) .Distinct().ToArray(); var addition = EntityNames(att_int_values); foreach (KeyValuePair<int, string> pair in addition) sENTS.Add(pair.Key, pair.Value); foreach (var att in atts) att.Value = sENTS[Int32.Parse(att.Value)]; return result; }
// Rules for sections // - if KeepSections for all documents in the source collection are false, then it takes the section // from the first document. // - if you specify true for any document, and if the last section is part of the specified content, // then that section is copied. If any paragraph in the content has a section, then that section // is copied. // - if you specify true for any document, and there are no sections for any paragraphs, then no // sections are copied. private static void AppendDocument(WordprocessingDocument sourceDocument, WordprocessingDocument newDocument, List<XElement> newContent, bool keepSection, List<ImageData> images) { FixRanges(sourceDocument.MainDocumentPart.GetXDocumentWithTracking(), newContent); AddRelationships(sourceDocument.MainDocumentPart, newDocument.MainDocumentPart, newContent); CopyRelatedPartsForContentParts(sourceDocument.MainDocumentPart, newDocument.MainDocumentPart, newContent, images); // Append contents XDocument newMainXDoc = newDocument.MainDocumentPart.GetXDocumentWithTracking(); newMainXDoc.Declaration.Standalone = "yes"; newMainXDoc.Declaration.Encoding = "UTF-8"; if (keepSection == false) { List<XElement> adjustedContents = newContent.Where(e => e.Name != W.sectPr).ToList(); adjustedContents.DescendantsAndSelf(W.sectPr).Remove(); newContent = adjustedContents; } foreach (var sectPr in newContent.DescendantsAndSelf(W.sectPr)) AddSectionAndDependencies(sourceDocument, newDocument, sectPr, images); CopyStylesAndFonts(sourceDocument, newDocument, newContent); CopyNumbering(sourceDocument, newDocument, newContent, images); CopyComments(sourceDocument, newDocument, newContent, images); CopyFootnotes(sourceDocument, newDocument, newContent, images); CopyEndnotes(sourceDocument, newDocument, newContent, images); AdjustUniqueIds(sourceDocument, newDocument, newContent); RemoveGfxdata(newContent); CopyCustomXml(sourceDocument, newDocument, newContent); newMainXDoc.Root.Element(W.body).Add(newContent); AdjustDocPrIds(newDocument); }