public static XObject DmDataField(SGraph.SNode item, SGraph.ROntologyDatatypePropertyDefinition prop)
        {
            string str        = null;
            var    range_name = prop.DirectObjectLinks("range")
                                .Select(p => p.TargetId).FirstOrDefault();

            if (range_name == "string")
            {
                str = item.DataField(prop.Id);
            }
            else if (range_name == "date")
            {
                str = item.DataField(prop.Id);
                str = SSNodeExt.DatePrinted(str);
            }
            else if (range_name == "text")
            {
                str = item.TextField(prop.Id, "ru");
            }
            else if (range_name == "Email")
            {
                str = item.TextField(prop.Id, "ru");
            }
            else if (range_name == "URI")
            {
                string uri_text = item.DataField(prop.Id);
                return(uri_text != null
                           ? new XElement("a",
                                          new XAttribute("href", uri_text),
                                          new XAttribute("target", "external"),
                                          uri_text)
                           : null);
            }
            else if (range_name != null)
            {
                var range_def = StaticModels.sDataModel.OntologyModel.GetItemById(range_name);
                if (range_def != null && range_def.Definition.Id == "EnumerationType")
                {
                    string enum_value = item.DataField(prop.Id);
                    if (enum_value != null)
                    {
                        str = range_def.DirectProperties().Where(p => p.Definition.Id == "state").Cast <SGraph.SDataLink>()
                              .Select(p => p.XOriginal).Where(px =>
                                                              px.Attribute("value").Value == enum_value &&
                                                              px.Attribute(SGraph.SNames.xmllang).Value == "ru")
                              .Select(px => px.Value).FirstOrDefault();
                    }
                }
            }
            return(str == null ? null : new XText(str));
        }
Exemple #2
0
        public static int PhotoTransform(this SNode sNode)
        {
            var iisstore = sNode.DirectProperties <SDataLink>("iisstore").FirstOrDefault();

            if (iisstore == null)
            {
                return(0);
            }
            var transform = iisstore.XOriginal.Attribute("transform");

            if (transform == null)
            {
                return(0);
            }
            return(transform.Value.ToCharArray().Where(c => c == 'r').Count() % 4);
        }
Exemple #3
0
        public static string Documenttype(this SNode sNode)
        {
            var iisstore = sNode.DirectProperties <SDataLink>("iisstore").FirstOrDefault();

            if (iisstore == null)
            {
                return(null);
            }
            var owner = iisstore.XOriginal.Attribute("documenttype");

            if (owner == null)
            {
                return(null);
            }
            return(owner.Value);
        }
Exemple #4
0
        /// <summary>
        /// Освобождение ресурса. Предполагается, что контент ресурса - нормальный
        /// </summary>
        /// <param name="resource">
        /// The resource.
        /// </param>
        protected void FreeContent(SResource resource)
        {
            SNode node = resource._content;

            // Если нет контента
            if (node == null)
            {
                return;
            }
            foreach (SObjectLink olink in node.DirectObjectLinks().Where(p => p._target_resource != null)) //TODO: возможно, проверка Where излишняя
            {
                SResource target_resource = olink._target_resource;
                target_resource._inverseProperties.Remove(olink);
                //olink.Target = null;
            }
            resource._content = null;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SObjectLink"/> class.
 /// </summary>
 /// <param name="x">
 /// The x.
 /// </param>
 /// <param name="source">
 /// The source.
 /// </param>
 public SObjectLink(XElement x, SNode source)
 {
     // _Definition.Id = x.Name;
     Source    = source;
     _targetId = SNode.Coding(x.Attribute(SNames.rdfresource).Value);
     System.DateTime tt1 = System.DateTime.Now;
     if (source._rDataModel is SOntologyModel)
     {
         Definition = ROntologyPropertyDefinition.Abstract(x.Name);
     }
     else
     {
         var def = source._rDataModel.OntologyModel.GetOntologyNode(x.Name.ToString()) as SGraph.ROntologyObjectPropertyDefinition;
         if (def != null)
         {
             Definition = def;
         }
         else
         {
             Definition = source.Definition.DirectPropertyDefinitions <ROntologyObjectPropertyDefinition>()
                          .FirstOrDefault(propDef => propDef.Id == x.Name.ToString())
                          ?? source._rDataModel
                          .OntologyModel
                          .InsertNew <ROntologyObjectPropertyDefinition>(x.Name,
                                                                         source.Definition.Id,
                                                                         Target != null
                                                                 ? Target.Definition.Id
                                                                 : XName.Get("entity"),
                                                                         false);
         }
     }
     //Definition = source._rDataModel is SOntologyModel
     //                 ? ROntologyPropertyDefinition.Abstract(x.Name)
     //                 : source.Definition.DirectPropertyDefinitions<ROntologyObjectPropertyDefinition>()
     //                       .FirstOrDefault(propDef => propDef.Id == x.Name.ToString())
     //                       ?? source._rDataModel
     //                       .OntologyModel
     //                       .InsertNew<ROntologyObjectPropertyDefinition>(x.Name,
     //                                                                     source.Definition.Id,
     //                                                                     Target != null
     //                                                                     ? Target.Definition.Id
     //                                                                     : "entity",
     //                                                                     false);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SDataLink"/> class.
        /// вместо статической "пустышки" делаю конструктор с параметрами null, вдруг пригодиться ещё где-то
        /// </summary>
        /// <param name="x">
        /// </param>
        /// <param name="source">
        /// </param>
        public SDataLink(XElement x, SNode source)
        {
            // _Definition.Id = x.Name; // что делать с именем по умолчанию? XName.Get("") не работает
            Source     = source;
            _innerText = x.Value;
            XAttribute langatt = x.Attribute(SNames.xmllang);

            if (langatt != null)
            {
                _lang = langatt.Value;
            }
            //TODO:  Следующий оператор должен был что-то означать, но за ним следовал XOriginal = x;
            //if (x.Attributes().Where(a => a.Name != SNames.xmllang).FirstOrDefault() != null) XOriginal = x;
            if (x.Attributes().Any(att => att.Name != SNames.xmllang))
            {
                XOriginal = XElement.Parse(x.ToString());
            }
            System.DateTime tt1 = System.DateTime.Now;
            if (source._rDataModel is SOntologyModel)
            {
                Definition = ROntologyPropertyDefinition.AbstractDataProp(x.Name);
            }
            else
            {
                var def = source._rDataModel.OntologyModel.GetOntologyNode(x.Name.ToString()) as SGraph.ROntologyDatatypePropertyDefinition;
                if (def != null)
                {
                    Definition = def;
                }
                else
                {
                    Definition = source.Definition.DirectPropertyDefinitions <ROntologyDatatypePropertyDefinition>()
                                 .FirstOrDefault(propDef => propDef.Id == x.Name.ToString())
                                 ?? source._rDataModel.OntologyModel
                                 .InsertNew <ROntologyDatatypePropertyDefinition>(x.Name, source.Definition.Id, "text", false);
                }
            }
            //Definition = source._rDataModel is SOntologyModel
            //                 ? ROntologyPropertyDefinition.AbstractDataProp(x.Name)
            //                 : source.Definition.DirectPropertyDefinitions<ROntologyDatatypePropertyDefinition>()
            //                       .FirstOrDefault(propDef => propDef.Id == x.Name.ToString())
            //                       ?? source._rDataModel.OntologyModel
            //                       .InsertNew<ROntologyDatatypePropertyDefinition>(x.Name, source.Definition.Id, "text", false);
        }
Exemple #7
0
        /// <summary>
        /// Подготовка ресурса для того, чтобы образовать запись. Если ресурс занят, то он освобождается
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <returns>
        /// </returns>
        protected SResource PrepareResource(XElement x)
        {
            XName     item_id = SNode.Coding(x.Attribute(SNames.rdfabout).Value);
            SResource resource;

            if (this.resources.ContainsKey(item_id))
            {
                resource = this.resources[item_id];
                // Если уничтоженный, то возвращается null
                //if (resource.Deleted) return null;
                // Если есть контент, то он освобождается
                if (resource._content != null)
                {
                    FreeContent(resource);
                }
            }
            else
            {
                resource = new SResource(item_id);
                resources.Add(item_id, resource);
            }
            return(resource);
        }
Exemple #8
0
        /// <summary>
        /// Добавление записи формата rdf или оператора удаления или замены в модель.
        /// </summary>
        /// <param name="xOperator">
        /// xml представление записи.
        /// </param>
        public void Include(XElement xOperator)
        {
            XName      rname          = xOperator.Name;
            XAttribute userDocumentId = xOperator.Attribute(SNames.AttUsersWorkRDFDocumentId);

            if (userDocumentId != null)
            {
                // var docUri = GetItemById(userDocumentId.Value).Uri();
                userDocumentId.Remove();
                AddToUserWorkDoc(xOperator, userDocumentId.Value);
                // LOG.WriteLine("\n\n" + DateTime.Now.ToString() + " " + userDocumentId.Value + "\n" + xOperator.ToString());
            }
            if (rname == SNames.TagDelete)
            {
                if (!string.IsNullOrEmpty(xOperator.Attribute(SNames.AttItem_id).Value))
                {
                    XName id = SNode.Coding(xOperator.Attribute(SNames.AttItem_id).Value);
                    this.DeleteItem(id);
                }
            }
            else if (rname == SNames.TagSubstitute)
            {
                if (!string.IsNullOrEmpty(xOperator.Attribute(SNames.AttOld_id).Value) &&
                    !string.IsNullOrEmpty(xOperator.Attribute(SNames.AttNew_id).Value))
                {
                    XName old_id = SNode.Coding(xOperator.Attribute(SNames.AttOld_id).Value);
                    XName new_id = SNode.Coding(xOperator.Attribute(SNames.AttNew_id).Value);
                    this.SubstituteItem(old_id, new_id);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(xOperator.Attribute(SNames.rdfabout.ToString()).Value))
                {
                    return;
                }
                XName element_id = SNode.Coding(xOperator.Attribute(SNames.rdfabout.ToString()).Value);
                // Если этот идентификатор неопределен, то ничего не делаем
                // если нет ресурса, то вставляем айтем
                if (!this.resources.ContainsKey(element_id))
                {
                    this.IncludeItem(xOperator); return;
                }
                SResource resource = this.resources[element_id];
                // если ресурс уничтожен, то элемент не вставляем
                if (resource.Deleted)
                {
                    return;
                }
                // смотрим контент ресурса
                SNode node = resource._content;
                // если контента нет, то вставляем элемент
                if (node == null)
                {
                    this.IncludeItem(xOperator); return;
                }
                // если (контент есть)&
                // определяемый ид не совпадает с идентификатором узла,
                // НО определяемый совпадает с последним, ТО меняем контент на новый
                if (element_id != node.Id)
                { // Здесь должно осуществиться и другое условие
                    if (element_id == resource._lastId)
                    {
                        this.IncludeItem(xOperator);
                    }
                    // иначе данные устаревшие и не фиксируются
                }
                else
                { // Здесь замена осуществится только если временная отметка нового определения позже старой
                    // выявляем временную отметку у элемента
                    DateTime   modificationTime = DateTime.MinValue;
                    XAttribute mt = xOperator.Attribute(SNames.AttModificationTime);
                    if (mt != null && DateTime.TryParse(mt.Value, out modificationTime) && modificationTime > node.modificationTime)
                    {
                        this.IncludeItem(xOperator);
                    }
                }
            }
        }
Exemple #9
0
 public static string Name(this SNode sNode)
 {
     return(sNode == null ? "no item" : sNode.TextField("name", "ru") ?? "no name");
 }
Exemple #10
0
        public static string Published(this SNode sNode, string regime)
        {
            var property = sNode.DataProperty("published-" + regime);

            return(property == null ? "" : property.InnerText);
        }
Exemple #11
0
 public static string DateLast(this SNode sNode)
 {
     return(sNode.DataProperty("to-date") != null?sNode.DataProperty("to-date").InnerText : null);
 }
Exemple #12
0
        //public static string Owner(this SNode sNode)
        //{
        //    var iisstore = sNode.DirectProperties<SDataLink>("iisstore").FirstOrDefault();
        //    if (iisstore == null) return null;
        //    var dtype = iisstore.XOriginal.Attribute("owner");
        //    if (dtype == null) return null;
        //    return dtype.Value;
        //}

        public static string CurrentUri(this SNode sNode, string size)
        {
            return(sNode.Uri() == "" ? null : "?r=" + size + "&u=" + sNode.Uri());
        }