Ejemplo n.º 1
0
        public override void DeleteFeedItems(ISession session)
        {
            XmlNodeList FeedXmlItems = XmlFeed.SelectNodes("/atom:feed/atom:entry", AtomNamespaceManager);

            foreach (XmlNode XmlNodeItem in FeedXmlItems)
            {
                XmlNode xmlLink = XmlNodeItem.SelectSingleNode("atom:link[@rel='service.edit']", AtomNamespaceManager);

                if (xmlLink == null)
                {
                    throw new Exception("Missing /feed/entry/link[@rel='service.edit' in '" + AtomNamespace + "'.");
                }

                XmlAttribute xmlHref = xmlLink.Attributes["href"];

                if (xmlHref == null)
                {
                    throw new Exception("Element /feed/entry/link[@rel='service.edit'] is missing an href attribute.");
                }

                HttpWebRequest DeleteRequest = (HttpWebRequest)WebRequest.Create(xmlHref.InnerText);
                if (!string.IsNullOrEmpty(mFeed.Username))
                {
                    DeleteRequest.Credentials = new NetworkCredential(mFeed.Username, mFeed.Password, null);
                }

                DeleteRequest.Method    = "DELETE";
                DeleteRequest.UserAgent = "DBlog.NET/1.0";

                string rx = new StreamReader(DeleteRequest.GetResponse().GetResponseStream()).ReadToEnd();
            }
        }
Ejemplo n.º 2
0
    private void UnserializeMap(BinaryReader br)
    {
        int count = br.ReadInt32();

        for (int i = 0; i < count; ++i)
        {
            ushort      key  = (ushort)br.ReadInt16();
            XmlNodeItem item = new XmlNodeItem();
            item.Xpath    = br.ReadString();
            item.Text     = br.ReadString();
            item.ItemType = (ItemType)br.ReadInt32();
            _map[key]     = item;
        }
    }
Ejemplo n.º 3
0
    public void Init(string xmlInput)
    {
        StringReader sr     = new StringReader(xmlInput);
        XmlReader    reader = XmlReader.Create(sr);
        MemoryStream ms     = new MemoryStream();
        ushort       i      = 1;

        while (reader.Read())
        {
            switch (reader.NodeType)
            {
            case XmlNodeType.Element:
                _path.AddElement(reader.Name);
                _map[i++] = new XmlNodeItem()
                {
                    Xpath    = _path.ToString(),
                    Text     = reader.Name,
                    ItemType = ItemType.Element
                };
                if (reader.HasAttributes)
                {
                    reader.MoveToFirstAttribute();
                    _path.AddAttribute(reader.Name);
                    _map[i++] = new XmlNodeItem()
                    {
                        Xpath    = _path.ToString(),
                        Text     = reader.Name,
                        ItemType = ItemType.Attritube
                    };
                    _path.RemoveLastElement();
                    while (reader.MoveToNextAttribute())
                    {
                        _path.AddAttribute(reader.Name);
                        _map[i++] = new XmlNodeItem()
                        {
                            Xpath    = _path.ToString(),
                            Text     = reader.Name,
                            ItemType = ItemType.Attritube
                        };
                        _path.RemoveLastElement();
                    }
                    reader.MoveToElement();
                }
                if (reader.IsEmptyElement)
                {
                    _path.RemoveLastElement();
                }
                break;

            case XmlNodeType.EndElement:
                _path.RemoveLastElement();
                break;

            default:
                break;
            }
        }
        foreach (KeyValuePair <ushort, XmlNodeItem> pair in _map)
        {
            _map2[pair.Value.Xpath] = pair.Key;
        }
    }
Ejemplo n.º 4
0
    public List <string> SplitXMLFile(string fileName, int startingLevel, int numEntriesPerFile)
    {
        List <string>     resultingFilesList = new List <string>();
        XmlReaderSettings readerSettings     = new XmlReaderSettings();

        readerSettings.DtdProcessing = DtdProcessing.Parse;
        XmlReader         reader       = XmlReader.Create(fileName, readerSettings);
        XmlWriter         writer       = null;
        int               fileNum      = 1;
        int               entryNum     = 0;
        bool              writerIsOpen = false;
        XmlWriterSettings settings     = new XmlWriterSettings();

        settings.Indent = true;
        settings.NewLineOnAttributes = true;
        Dictionary <int, XmlNodeItem> higherLevelNodes = new Dictionary <int, XmlNodeItem>();
        int    hlnCount            = 0;
        string fileIncrementedName = GetIncrementedFileName(fileName, fileNum);

        resultingFilesList.Add(fileIncrementedName);
        writer       = XmlWriter.Create(fileIncrementedName, settings);
        writerIsOpen = true;
        writer.WriteStartDocument();
        int treeDepth = 0;

        while (reader.Read())
        {
            switch (reader.NodeType)
            {
            case XmlNodeType.Element:
                treeDepth++;
                if (treeDepth == startingLevel)
                {
                    entryNum++;
                    if (entryNum == 1)
                    {
                        if (fileNum > 1)
                        {
                            fileIncrementedName = GetIncrementedFileName(fileName, fileNum);
                            resultingFilesList.Add(fileIncrementedName);
                            writer       = XmlWriter.Create(fileIncrementedName, settings);
                            writerIsOpen = true;
                            writer.WriteStartDocument();
                            for (int d = 1; d <= higherLevelNodes.Count; d++)
                            {
                                XmlNodeItem xni = higherLevelNodes[d];
                                switch (xni.XmlNodeType)
                                {
                                case XmlNodeType.Element:
                                    writer.WriteStartElement(xni.NodeValue);
                                    break;

                                case XmlNodeType.Text:
                                    writer.WriteString(xni.NodeValue);
                                    break;

                                case XmlNodeType.CDATA:
                                    writer.WriteCData(xni.NodeValue);
                                    break;

                                case XmlNodeType.Comment:
                                    writer.WriteComment(xni.NodeValue);
                                    break;

                                case XmlNodeType.EndElement:
                                    writer.WriteEndElement();
                                    break;
                                }
                            }
                        }
                    }
                }
                if (writerIsOpen)
                {
                    writer.WriteStartElement(reader.Name);
                }
                if (treeDepth < startingLevel)
                {
                    hlnCount++;
                    XmlNodeItem xni = new XmlNodeItem();
                    xni.XmlNodeType = XmlNodeType.Element;
                    xni.NodeValue   = reader.Name;
                    higherLevelNodes.Add(hlnCount, xni);
                }
                break;

            case XmlNodeType.Text:
                if (writerIsOpen)
                {
                    writer.WriteString(reader.Value);
                }
                if (treeDepth < startingLevel)
                {
                    hlnCount++;
                    XmlNodeItem xni = new XmlNodeItem();
                    xni.XmlNodeType = XmlNodeType.Text;
                    xni.NodeValue   = reader.Value;
                    higherLevelNodes.Add(hlnCount, xni);
                }
                break;

            case XmlNodeType.CDATA:
                if (writerIsOpen)
                {
                    writer.WriteCData(reader.Value);
                }
                if (treeDepth < startingLevel)
                {
                    hlnCount++;
                    XmlNodeItem xni = new XmlNodeItem();
                    xni.XmlNodeType = XmlNodeType.CDATA;
                    xni.NodeValue   = reader.Value;
                    higherLevelNodes.Add(hlnCount, xni);
                }
                break;

            case XmlNodeType.Comment:
                if (writerIsOpen)
                {
                    writer.WriteComment(reader.Value);
                }
                if (treeDepth < startingLevel)
                {
                    hlnCount++;
                    XmlNodeItem xni = new XmlNodeItem();
                    xni.XmlNodeType = XmlNodeType.Comment;
                    xni.NodeValue   = reader.Value;
                    higherLevelNodes.Add(hlnCount, xni);
                }
                break;

            case XmlNodeType.EndElement:
                if (entryNum == numEntriesPerFile && treeDepth == startingLevel || treeDepth == 1)
                {
                    if (writerIsOpen)
                    {
                        fileNum++;
                        writer.WriteEndDocument();
                        writer.Close();
                        writerIsOpen = false;
                        entryNum     = 0;
                    }
                }
                else
                {
                    if (writerIsOpen)
                    {
                        writer.WriteEndElement();
                    }
                    if (treeDepth < startingLevel)
                    {
                        hlnCount++;
                        XmlNodeItem xni = new XmlNodeItem();
                        xni.XmlNodeType = XmlNodeType.EndElement;
                        xni.NodeValue   = string.Empty;
                        higherLevelNodes.Add(hlnCount, xni);
                    }
                }
                treeDepth--;
                break;
            }
        }
        return(resultingFilesList);
    }
Ejemplo n.º 5
0
        protected override int UpdateFeedItems(ISession session)
        {
            int result = 0;

            if (!string.IsNullOrEmpty(mFeed.Xsl))
            {
                StringBuilder        TransformedString = new StringBuilder();
                XslCompiledTransform FeedXsl           = new XslCompiledTransform();
                FeedXsl.Load(new XmlTextReader(new StringReader(mFeed.Xsl)), null, null);
                StringWriter  StringWriter = new StringWriter(TransformedString);
                XmlTextWriter TextWriter   = new XmlTextWriter(StringWriter);
                FeedXsl.Transform(new XmlNodeReader(XmlFeed.DocumentElement), TextWriter);
                XmlFeed.LoadXml(TransformedString.ToString());
            }

            XmlNodeList FeedXmlItems = XmlFeed.SelectNodes("descendant::channel/item");

            List <FeedItem> updated = new List <FeedItem>();

            foreach (XmlNode XmlNodeItem in FeedXmlItems)
            {
                XmlNode xmlLink = XmlNodeItem.SelectSingleNode("link");
                string  link    = (xmlLink != null) ? xmlLink.InnerText : null;

                FeedItem current = null;

                if (!string.IsNullOrEmpty(link))
                {
                    for (int i = 0; i < mFeed.FeedItems.Count; i++)
                    {
                        FeedItem item = (FeedItem)mFeed.FeedItems[i];
                        if (item.Link == link)
                        {
                            current = item;
                            updated.Add(item);
                            mFeed.FeedItems.RemoveAt(i);
                            break;
                        }
                    }
                }

                if (current == null)
                {
                    result++;
                    current      = new FeedItem();
                    current.Feed = mFeed;
                    current.Link = link;
                }

                XmlNode xmlDescription = XmlNodeItem.SelectSingleNode("description");
                current.Description = (xmlDescription != null) ? xmlDescription.InnerText : null;

                XmlNode xmlTitle = XmlNodeItem.SelectSingleNode("title");
                current.Title = (xmlTitle != null) ? xmlTitle.InnerText : null;

                session.Save(current);
            }

            foreach (FeedItem item in mFeed.FeedItems)
            {
                session.Delete(item);
            }

            mFeed.FeedItems = updated;
            return(result);
        }