Пример #1
0
        public int Compare(XElement x, XElement y)
        {
            int cmp1 = x.Attribute("type").Value.CompareTo(y.Attribute("type").Value);

            if (cmp1 != 0)
            {
                return(-cmp1);
            }
            string s1 = StaticObjects.GetField(x, "http://fogid.net/o/from-date");
            string s2 = StaticObjects.GetField(y, "http://fogid.net/o/from-date");

            if (string.IsNullOrEmpty(s1))
            {
                s1 = "_";                          // + x.Attribute("id").Value;
            }
            if (string.IsNullOrEmpty(s2))
            {
                s2 = "_";                // + y.Attribute("id").Value;
            }
            int cmp2 = s1.CompareTo(s2); //string.Compare(s1, s2);

            if (cmp2 != 0)
            {
                return(cmp2);
            }
            return(x.Attribute("id").Value.CompareTo(y.Attribute("id").Value));
        }
Пример #2
0
        /// <summary>
        /// Преобразование "стандартного" портрета в более удобную форму. Сейчас будем "ваять" html типа комбинации полей и правой колонки
        /// в раскрытии персоны
        /// </summary>
        /// <param name="xtree"></param>
        /// <returns></returns>
        private XElement ToPortrait(XElement xtree)
        {
            var ph = xtree.Elements("inverse")
                     .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/reflected")
                     .Select(i => i.Element("record"))
                     .Where(r => r.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/ground")?.Value == "portrait")
                     .Select(r => r.Element("direct")?.Element("record"))
                     .Where(r1 => r1 != null && r1.Attribute("type").Value == "http://fogid.net/o/photo-doc")
                     .OrderByDescending(r1 => r1.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/from-date")?.Value)
                     .ToArray()
                     .FirstOrDefault()
            ;
            string ph_uri = null;

            if (ph != null)
            {
                ph_uri = ph.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/uri").Value;
            }

            string lang    = null;
            int    nameind = -1;

            XElement[] namefields = xtree.Elements("field")
                                    .Where(f => f.Attribute("prop").Value == "http://fogid.net/o/name")
                                    .Where((f, i) =>
            {
                string la = f.Attribute("{http://www.w3.org/XML/1998/namespace}lang")?.Value;
                if (nameind == -1 || la == "ru")
                {
                    nameind = i;
                    lang    = la;
                }
                return(true);
            })
                                    .ToArray();
            if (nameind == -1)
            {
                nameind = 0;
            }

            string fd   = xtree.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/from-date")?.Value;
            string td   = xtree.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/to-date")?.Value;
            string desc = xtree.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/description")?.Value;

            XElement[] titles = xtree.Elements("inverse").Where(i => i.Attribute("prop").Value == "http://fogid.net/o/has-title")
                                .Select(i => i.Element("record"))
                                .OrderBy(r => r.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/from-date")?.Value)
                                .ToArray();
            XElement[] works = xtree.Elements("inverse").Where(i => i.Attribute("prop").Value == "http://fogid.net/o/participant")
                               .Select(i => i.Element("record"))
                               .Where(r => r.Element("direct")?.Element("record")?
                                      .Elements("field")
                                      .FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/org-classification")?.Value == "organization")
                               .OrderBy(r => r.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/from-date")?.Value)
                               .ToArray();

            XElement result = new XElement("html",
                                           new XElement("head"),
                                           new XElement("body",
                                                        new XElement("div",
                                                                     (ph_uri == null? null : new XElement("img", new XAttribute("src", Url.Content("~/Docs/GetPhoto?s=small&u=" + ph_uri)), new XAttribute("align", "right"))),
                                                                     new XElement("div", namefields[nameind].Value),
                                                                     namefields.Where((f, i) => i != nameind).Select(f => new XElement("div", f.Value)),
                                                                     (fd == null && td == null) ?null: new XElement("div",
                                                                                                                    (fd == null ? "" : StaticObjects.DatePrinted(fd)) + (td == null ? "" : " - " + StaticObjects.DatePrinted(td))),
                                                                     desc == null ? null : new XElement("div", desc),
                                                                     new XElement("div", new XAttribute("style", "background-color:aquamarine;"),
                                                                                  titles.Select(r => new XElement("div", StaticObjects.DatePrinted(StaticObjects.GetField(r, "http://fogid.net/o/from-date")),
                                                                                                                  new XElement("span", StaticObjects.GetField(r, "http://fogid.net/o/degree"))))),
                                                                     works.Select(parti =>
            {
                XElement xorg = parti.Element("direct")?.Element("record");
                return(new XElement("div",
                                    StaticObjects.GetField(parti, "http://fogid.net/o/from-date"),
                                    StaticObjects.GetField(parti, "http://fogid.net/o/role"),
                                    xorg == null ? null : StaticObjects.GetField(xorg, "http://fogid.net/o/name"),
                                    null));
            }),
                                                                     null)),
                                           null);

            return(result);
        }
Пример #3
0
        public IActionResult Index()
        {
            var model = new IndexModel();

            string sdir = HttpContext.Request.Query["sdirection"].FirstOrDefault();

            // Поработаем с сессией
            if (sdir == null)
            {
                sdir = HttpContext.Session.GetString("sdirection");
                if (sdir == null)
                {
                    sdir = "person";
                }
            }
            if (sdir != null)
            {
                model.TabDirection = sdir;
            }
            HttpContext.Session.SetString("sdirection", sdir);

            string p      = HttpContext.Request.Query["p"].FirstOrDefault();
            string id     = HttpContext.Request.Query["id"].FirstOrDefault();
            string pg_str = HttpContext.Request.Query["pg"].FirstOrDefault();

            if (pg_str != null)
            {
                model.Pg = Int32.Parse(pg_str);
            }

            if (p == null && id == null)
            {
                id = "w20070417_7_1744";
            }
            XElement xrec = null;

            if (p == "search")
            {
                string searchstring          = HttpContext.Request.Query["searchstring"].FirstOrDefault();
                IEnumerable <XElement> query = OAData.OADB.SearchByName(searchstring)
                                               .Distinct(new RecordIdComparer())
                                               .ToArray();
                var list = new List <object[]>();
                foreach (XElement el in query)
                {
                    string t     = el.Attribute("type").Value;
                    string name  = el.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/name")?.Value;
                    string name1 = StaticObjects.GetField(el, "http://fogid.net/o/name");
                    if (t == "http://fogid.net/o/person")
                    {
                        list.Add(new object[] { el.Attribute("id").Value, name });
                    }
                }
                model.SearchResults = list;
            }
            else if (id != null && (xrec = OAData.OADB.GetItemByIdBasic(id, false)) != null) // Построение портрета
            {
                // Сначала надо выяснить тип сущности, для этого запрашиваем ее без формата
                model.Id   = xrec.Attribute("id").Value;
                model.Type = xrec.Attribute("type").Value;
                // Заодно вычислим важные поля
                //foreach (XElement el in xrec.Elements("field"))
                //{
                //    string prop = el.Attribute("prop").Value;
                //    if (prop == "http://fogid.net/o/name") model.Name = el.Value;
                //    else if (prop == "http://fogid.net/o/from-date") model.StartDate = el.Value;
                //    else if (prop == "http://fogid.net/o/to-date") model.EndDate = el.Value;
                //    else if (prop == "http://fogid.net/o/description") model.Description = el.Value;
                //    else if (prop == "http://fogid.net/o/uri") model.Uri = el.Value;
                //}
                model.Name        = StaticObjects.GetField(xrec, "http://fogid.net/o/name");
                model.StartDate   = StaticObjects.GetField(xrec, "http://fogid.net/o/from-date");
                model.EndDate     = StaticObjects.GetField(xrec, "http://fogid.net/o/to-date");
                model.Description = StaticObjects.GetField(xrec, "http://fogid.net/o/description");
                model.Uri         = StaticObjects.GetField(xrec, "http://fogid.net/o/uri");
                model.Docmetainfo = StaticObjects.GetField(xrec, "http://fogid.net/o/docmetainfo");

                // Теперь определим формат для этого типа
                if (model.Type == "http://fogid.net/o/photo-doc")
                {
                    model.XRecord = OAData.OADB.GetItemById(id, model.Formats["http://fogid.net/o/document"]);
                    model.BuildPortrait();
                }
                else if (model.Formats.ContainsKey(model.Type))
                {
                    XElement format = model.Formats[model.Type];

                    model.XRecord = OAData.OADB.GetItemById(id, format);
                    model.BuildPortrait();
                }
                else if (new string[] { "http://fogid.net/o/geosys", "http://fogid.net/o/country", "http://fogid.net/o/region",
                                        "http://fogid.net/o/city", "http://fogid.net/o/geosys-special" }.Contains(model.Type))
                {
                    XElement format = new XElement("record", //new XAttribute("type", "http://fogid.net/o/person"),
                                                   new XElement("field", new XAttribute("prop", "http://fogid.net/o/name")),
                                                   new XElement("field", new XAttribute("prop", "http://fogid.net/o/from-date")),
                                                   new XElement("field", new XAttribute("prop", "http://fogid.net/o/to-date")),
                                                   new XElement("field", new XAttribute("prop", "http://fogid.net/o/description")),
                                                   new XElement("inverse", new XAttribute("prop", "http://fogid.net/o/reflected"),
                                                                new XElement("record",
                                                                             //new XElement("field", new XAttribute("prop", "http://fogid.net/o/ground")),
                                                                             new XElement("direct", new XAttribute("prop", "http://fogid.net/o/in-doc"),
                                                                                          new XElement("record",
                                                                                                       new XElement("field", new XAttribute("prop", "http://fogid.net/o/name")),
                                                                                                       new XElement("field", new XAttribute("prop", "http://fogid.net/o/uri")),
                                                                                                       new XElement("field", new XAttribute("prop", "http://fogid.net/o/docmetainfo")),
                                                                                                       new XElement("field", new XAttribute("prop", "http://fogid.net/o/description")),
                                                                                                       new XElement("field", new XAttribute("prop", "http://fogid.net/o/from-date")),
                                                                                                       null)))));
                    model.XRecord = OAData.OADB.GetItemById(id, format);
                    model.BuildPortrait();
                }
                else
                {
                    model.XRecord = xrec;
                }
                // Вычисление docidarr. Это имеет смысл, когда задано значение ir или ic, тогда мы сделаем выборку, дойдя до документов и превратив выборку в массив.
                string ir = HttpContext.Request.Query["ir"].FirstOrDefault();
                string ic = HttpContext.Request.Query["ic"].FirstOrDefault();
                if (!string.IsNullOrEmpty(ir))
                {
                    model.ir = ir;
                    XElement doctree = OAData.OADB.GetItemById(ir, new XElement("record",
                                                                                new XElement("inverse", new XAttribute("prop", "http://fogid.net/o/reflected"),
                                                                                             new XElement("record",
                                                                                                          new XElement("direct", new XAttribute("prop", "http://fogid.net/o/in-doc"),
                                                                                                                       new XElement("record",
                                                                                                                                    new XElement("field", new XAttribute("prop", "http://fogid.net/o/name")),
                                                                                                                                    new XElement("field", new XAttribute("prop", "http://fogid.net/o/from-date")),
                                                                                                                                    null))))));
                    model.docidarr = doctree.Elements("inverse")
                                     .Select(inv => inv.Element("record"))
                                     .Distinct(new IdEqual())
                                     .OrderBy(r => r.Element("direct")?.Element("record"), new PhotosFirst())
                                     .Select(r => r?.Element("direct")?.Element("record")?.Attribute("id")?.Value)
                                     .Where(d => d != null)
                                     .ToArray();
                    model.Check_docidarr(ir, model.docidarr);
                }
                else if (!string.IsNullOrEmpty(ic))
                {
                    model.ic = ic;
                    XElement doctree = OAData.OADB.GetItemById(ic, new XElement("record",
                                                                                new XElement("inverse", new XAttribute("prop", "http://fogid.net/o/in-collection"),
                                                                                             new XElement("record",
                                                                                                          new XElement("direct", new XAttribute("prop", "http://fogid.net/o/collection-item"),
                                                                                                                       new XElement("record", new XElement("field", new XAttribute("prop", "http://fogid.net/o/name"))))))));
                    model.docidarr = doctree.Elements("inverse")
                                     .Select(inv => inv.Element("record")?.Element("direct")?.Element("record"))
                                     //.Attribute("id")?.Value)
                                     .Where(r => r != null)
                                     .OrderBy(r => StaticObjects.GetField(r, "http://fogid.net/o/name"))
                                     .Select(r => r.Attribute("id").Value)
                                     .ToArray();
                }
            }

            return(View(model));
        }
Пример #4
0
        public void BuildPortrait()
        {
            adocauthority = this.XRecord.Elements("inverse")
                            .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/adoc")
                            .Select(i => i.Element("record"))
                            .ToArray();

            reflected_reflections = this.XRecord.Elements("inverse")
                                    .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/reflected")
                                    .Select(i => i.Element("record"))
                                    .Distinct(new IdEqual())
                                    .OrderBy(r => r.Element("direct")?.Element("record"), PhotosFirst.PhF())
                                    .ToArray();

            portraitphotouri = reflected_reflections
                               .Where(re => re.Elements("field").FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/ground")?.Value == "portrait")
                               .Select(re => re.Element("direct")?.Element("record"))
                               .Where(r => r?.Attribute("type").Value == "http://fogid.net/o/photo-doc")
                               .FirstOrDefault()
                               ?.Elements("field")
                               .FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/uri")?.Value;

            titles = this.XRecord.Elements("inverse")
                     .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/has-title")
                     .Select(i => i.Element("record"))
                     .Select <XElement, Tuple <string, string> >(r => Tuple.Create <string, string>(
                                                                     r.Elements("field").FirstOrDefault(f => f.Attribute("prop")?.Value == "http://fogid.net/o/degree")?.Value,
                                                                     r.Elements("field").FirstOrDefault(f => f.Attribute("prop")?.Value == "http://fogid.net/o/from-date")?.Value
                                                                     ))
                     .OrderBy(t => t.Item2)
                     .ToArray();

            XElement[] participant_participation = this.XRecord.Elements("inverse")
                                                   .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/participant")
                                                   .Select(i => i.Element("record"))
                                                   .ToArray();
            work = participant_participation
                   .Where(r => r.Element("direct")?.Element("record")?.Elements("field")
                          .FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/org-classification")?.Value == "organization")
                   .ToArray();
            parties = participant_participation
                      .Where(r => r.Element("direct")?.Element("record")?.Elements("field")
                             .FirstOrDefault(f => f.Attribute("prop").Value == "http://fogid.net/o/org-classification")?.Value != "organization")
                      .ToArray();


            naming = this.XRecord.Elements("inverse")
                     .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/referred-sys")
                     .Select(i => i.Element("record"))
                     .Select <XElement, Tuple <string, string, string> >(r => Tuple.Create <string, string, string>(
                                                                             r.Elements("field").FirstOrDefault(f => f.Attribute("prop")?.Value == "http://fogid.net/o/alias")?.Value,
                                                                             r.Elements("field").FirstOrDefault(f => f.Attribute("prop")?.Value == "http://fogid.net/o/from-date")?.Value,
                                                                             r.Elements("field").FirstOrDefault(f => f.Attribute("prop")?.Value == "http://fogid.net/o/to-date")?.Value
                                                                             ))
                     .OrderBy(t => t.Item2)
                     .ToArray();
            var inorg_participation = this.XRecord.Elements("inverse")
                                      .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/in-org")
                                      .Select(i => i.Element("record"))
                                      .ToArray();

            firstfaces = inorg_participation
                         .Where(r => StaticObjects.GetField(r, "http://fogid.net/o/role-classification") == "director")
                         .ToArray();
            allparticipants = inorg_participation
                              .Where(r => StaticObjects.GetField(r, "http://fogid.net/o/role-classification") != "director")
                              .ToArray();
            //inorg_participation = this.XRecord.Elements("inverse")
            //    .Select(i => i.Element("record"))
            //    .OrderBy(r => StaticObjects.GetField(r.Element("direct").Element("record"), "http://fogid.net/o/from-date"))
            //    .ToArray();
            indocreflected = this.XRecord.Elements("inverse")
                             .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/in-doc")
                             .Select(i => i.Element("record"))
                             .ToArray();
            incollectionmember = this.XRecord.Elements("inverse")
                                 .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/in-collection")
                                 .Select(i => i.Element("record")?.Element("direct")?.Element("record"))
                                 .Where(r => r != null)
                                 .OrderBy(r => StaticObjects.GetField(r, "http://fogid.net/o/name"))
                                 .ToArray();
            orgparentorgrelatives = this.XRecord.Elements("inverse")
                                    .Where(i => i.Attribute("prop").Value == "http://fogid.net/o/org-parent")
                                    .Select(i => i.Element("record")?.Element("direct")?.Element("record"))
                                    .Where(r => r != null)
                                    .ToArray();
        }