public static string GetFormat(string id, out XElement rec_format) { string type_id; // Нам нужен формат. XElement f_primitive = new XElement("record"); XElement xtree0 = SObjects.GetItemById(id, f_primitive); // Проверка на существование решения или формата if (xtree0 == null || xtree0.Attribute("id") == null || xtree0.Attribute("type") == null) { rec_format = null; return(null); } ; // Как-то надо поступить с диагностикой ошибок// type_id = xtree0.Attribute("type").Value; // Теперь установим нужный формат XElement xformat = ModelCommon.formats.Elements("record") .FirstOrDefault(re => re.Attribute("type") != null && re.Attribute("type").Value == type_id); if (xformat == null) { xformat = new XElement("record", new XAttribute("type", type_id), new XElement("field", new XAttribute("prop", "http://fogid.net/o/name"))); } rec_format = xformat; return(type_id); }
public ActionResult GetItemById(string id, string format) { XElement res = SObjects.GetItemById(id, XElement.Parse(format)); return(new ContentResult { ContentType = "text/xml", Content = res.ToString(SaveOptions.DisableFormatting) }); }
// По идентификатору мы получаем 1) откорректированный идентификатор; 2) тип записи; 3) формат (раскрытия) записи // Эту информацию дополняем меткой типа, пытаемся прочитать и зафиксировать имя записи и uri документного контента public PortraitModel(string id, XElement rec_format) { DateTime tt0 = DateTime.Now; //XElement rec_format; if (rec_format == null) { this.type_id = GetFormat(id, out rec_format); if (rec_format == null) { ok = false; return; } } else { this.type_id = rec_format.Attribute("type").Value; } this.typelabel = ModelCommon.OntNames.Where(pair => pair.Key == type_id).Select(pair => pair.Value).FirstOrDefault(); if (this.typelabel == null) { this.typelabel = type_id; } // Получим портретное х-дерево this.xtree = SObjects.GetItemById(id, rec_format); if (this.xtree == null) { return; } // По дереву вычислим и зафиксируем остальные поля // поле идентификатора this.id = xtree.Attribute("id").Value; // поле имени XElement field_name = xtree.Elements("field") .Where(fi => fi.Attribute("prop").Value == "http://fogid.net/o/name") .OrderBy(fi => { XAttribute lang_att = fi.Attribute(ONames.xmllang); return(lang_att == null ? "" : lang_att.Value); }) .FirstOrDefault(); this.name = field_name == null ? "Noname" : field_name.Value; // поле uri if (type_id == "http://fogid.net/o/photo-doc" || type_id == "http://fogid.net/o/video-doc" || type_id == "http://fogid.net/o/audio-doc") { //var uri_el = GetUri(xtree); var uri_el = xtree.Elements("field") .FirstOrDefault(fi => fi.Attribute("prop").Value == "http://fogid.net/o/uri"); if (uri_el != null) { uri = uri_el.Value; } } // ============================== Вычисления частей вышестоящего документа ============================ if (type_id == "http://fogid.net/o/document" || type_id == "http://fogid.net/o/photo-doc" || type_id == "http://fogid.net/o/video-doc" || type_id == "http://fogid.net/o/audio-doc") { string mpDocId = xtree.Elements("inverse").FirstOrDefault(i => i.Attribute("prop").Value == "http://fogid.net/o/partItem")? .Element("record")? .Elements("direct").FirstOrDefault(i => i.Attribute("prop").Value == "http://fogid.net/o/inDocument")? .Element("record")? .Attribute("id")?.Value; XElement formatfordoc = new XElement("record", new XAttribute("type", "http://fogid.net/o/document"), // Части документа new XElement("inverse", new XAttribute("prop", "http://fogid.net/o/inDocument"), new XElement("record", new XElement("field", new XAttribute("prop", "http://fogid.net/o/pageNumbers")), new XElement("direct", new XAttribute("prop", "http://fogid.net/o/partItem"), new XElement("record", new XElement("field", new XAttribute("prop", "http://fogid.net/o/name"))))))); if (mpDocId != null) { string[] doclist = // Части документа SObjects.GetItemById(mpDocId, formatfordoc).Elements("inverse") .Where(inv => inv.Attribute("prop").Value == "http://fogid.net/o/inDocument") .Select(inv => inv.Element("record")) .Select(rec => new { docpart = rec.Element("direct")?.Element("record"), page = rec.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/pageNumbers")?.Value }) .OrderBy(pair => pair.page) .ThenBy(pair => pair.docpart.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/name")?.Value) .Select(pair => pair.docpart.Attribute("id").Value) .ToArray(); int ind = Array.IndexOf(doclist, id); if (ind > 0) { prev = doclist[ind - 1]; } if (ind < doclist.Length - 1) { next = doclist[ind + 1]; } } } this.xresult = ConvertToResultStructure(rec_format, xtree); //this.look = xtree; this.message = "duration=" + ((DateTime.Now - tt0).Ticks / 10000L); //this.look = xresult; }
public void LoadFromDb() { CalculateFormat(); _xtree = SObjects.GetItemById(eid, _format); }