Beispiel #1
0
        /*  función GetDocumentTimestamp(bool) => string
         *      Devuelve el timestamp del documento o de una entrada específica
         *  @param document : True si se quiere recuperar el timestamp del documento, False si se quiere el de la entrada
         *  @return : timestamp (o campo "updated") del documento de licitaciones o de la entrada
         */
        public string GetDocumentTimestamp(bool document)
        {
            IEnumerable <XElement> query;

            if (document)
            {
                // Realiza una consulta Linq desde la raíz del documento
                query =
                    from node in DocumentRoot.Elements()
                    where node.Name.LocalName.Equals("updated")
                    select node;
            }
            else
            {
                // Realiza una consulta Linq desde la raíz de la entrada
                query =
                    from node in EntryRoot.Parent.Elements()
                    where node.Name.LocalName.Equals("updated")
                    select node;
            }

            // Si no lo encuentra, devuelve null
            if (!query.Any())
            {
                _Log(this, "Updated element couldn't be found", ELogLevel.WARN);
                return(null);
            }
            // Si existe, devuelve el timestamp del documento
            else
            {
                return(query.First().Value);
            }
        }
        private bool SortAndAdd(StringComparison stringComparison, XElement?newNode)
        {
            var comparer = new DelegateComparer <string>((left, right) => string.Compare(left, right, stringComparison));

            string GetName(XElement node) => node.Attribute(_nameAttributeName)?.Value.TrimStart('>') ?? string.Empty;

            var nodes = DocumentRoot
                        .Elements(_dataNodeName)
                        .ToArray();

            var sortedNodes = nodes
                              .OrderBy(GetName, comparer)
                              .ToArray();

            var hasContentChanged = SortNodes(nodes, sortedNodes);

            if (newNode == null)
            {
                return(hasContentChanged);
            }

            var newNodeName = GetName(newNode);
            var nextNode    = sortedNodes.FirstOrDefault(node => comparer.Compare(GetName(node), newNodeName) > 0);

            if (nextNode != null)
            {
                nextNode.AddBeforeSelf(newNode);
            }
            else
            {
                DocumentRoot.Add(newNode);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Returns a unique (unused) Id. The returned ids are guaranteed not to repeat unless New or Load is called.
        /// </summary>
        public String GetUniqueId()
        {
            const string prefix = "auto_";

            foreach (XElement element in DocumentRoot.Elements())
            {
                String elementIdString = element.GetStringAttribute("Id");
                if (!elementIdString.StartsWith(prefix))
                {
                    continue;
                }

                Int64 elementId;
                if (!Int64.TryParse(elementIdString.Substring(prefix.Length), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out elementId))
                {
                    continue;
                }

                if (_maxId <= elementId)
                {
                    _maxId = elementId + 1;
                }
            }

            return(prefix + _maxId.ToString("X", CultureInfo.InvariantCulture));
        }
Beispiel #4
0
        /*  función GetEntrySet(IDictionary<string, XNamespace>) => IEnumerable<XElement>
         *      Devuelve el conjunto de entradas en el fichero atom
         *      Las entradas vienen definidas por el elemento entry
         *  @param namespaces : Diccionario de espacios de nombres
         *  @return : Conjunto de elementos XML
         *      @ej : [ XElement(<entry xmlns="..."> <id>...</id> ... </entry>), ... ]
         */
        public IEnumerable <XElement> GetEntrySet(IDictionary <string, XNamespace> namespaces)
        {
            // Realiza una consulta Linq para extraer el conjunto de entradas
            IEnumerable <XElement> entrySet =
                from entry in DocumentRoot.Elements(namespaces["xmlns"] + "entry")
                select entry;

            _Log(this, $"Loaded entry set with {entrySet.Count()} elements", ELogLevel.INFO);
            return(entrySet);
        }
Beispiel #5
0
        public XElement GetShapeById(String id)
        {
            IEnumerable <XElement> shapes = from c in DocumentRoot.Elements() where c.GetStringAttribute("Id") == id select c;

            foreach (XElement result in shapes)
            {
                return(result);
            }
            return(null);
        }
Beispiel #6
0
        /*  función GetNextFile() => Uri
         *      Devuelve la URI correspondiente al siguiente fichero, descrito por el
         *      elemento "link" y el atributo "rel=next"
         *  @return : La URI que describe el fichero enlazado al siendo parseado en esta instancia
         */
        public Uri GetNextFile()
        {
            // Realiza una consulta Linq desde la raíz del documento para encontrar el enlace
            IEnumerable <XElement> query =
                from node in DocumentRoot.Elements()
                where node.Name.LocalName.Equals("link") && node.LastAttribute.Value.Equals("next")
                select node;

            // Si no lo encuentra, devuelve null
            if (!query.Any())
            {
                _Log(this, "Link to next file couldn't be found", ELogLevel.WARN);
                return(null);
            }
            // Si existe, devuelve la URI correspondiente al siguiente fichero
            else
            {
                _Log(this, $"Linked next file: {query.First().FirstAttribute.Value}", ELogLevel.DEBUG);
                return(new Uri(query.First().FirstAttribute.Value));
            }
        }