Esempio n. 1
0
        private void ProcessNodeFolderChild(NodeFolder nf, XmlDocument xdoc, XmlElement parent)
        {
            foreach (NodeTree nt in nf.Children)
            {
                if (nt is NodeFeed)
                {
                    XmlElement eleOutline = xdoc.CreateElement(string.Empty, "outline", string.Empty);
                    parent.AppendChild(eleOutline);

                    XmlAttribute typeAttr = xdoc.CreateAttribute("type");
                    typeAttr.Value = "rss";
                    eleOutline.SetAttributeNode(typeAttr);

                    XmlAttribute textAttr = xdoc.CreateAttribute("text");
                    textAttr.Value = nt.Name;
                    eleOutline.SetAttributeNode(textAttr);

                    XmlAttribute titleAttr = xdoc.CreateAttribute("title");
                    titleAttr.Value = nt.Name;
                    eleOutline.SetAttributeNode(titleAttr);

                    XmlAttribute xmlUriAttr = xdoc.CreateAttribute("xmlUrl");
                    xmlUriAttr.Value = (nt as NodeFeed).EndPoint.AbsoluteUri;
                    eleOutline.SetAttributeNode(xmlUriAttr);

                    if ((nt as NodeFeed).SiteUri is not null)
                    {
                        XmlAttribute htmlUriAttr = xdoc.CreateAttribute("htmlUrl");
                        htmlUriAttr.Value = (nt as NodeFeed).SiteUri.AbsoluteUri;
                        eleOutline.SetAttributeNode(htmlUriAttr);
                    }
                }
            }
        }
Esempio n. 2
0
        private void ProcessOutlineChild(XmlNodeList childs, NodeFolder parent)
        {
            foreach (XmlNode outline in childs)
            {
                if (!outline.LocalName.Equals("outline"))
                {
                    continue;
                }

                string title = "empty";
                if (outline.Attributes["text"] is not null)
                {
                    title = outline.Attributes["text"].InnerText;
                }

                var xmlUrl = "";
                if (outline.Attributes["xmlUrl"] is not null)
                {
                    xmlUrl = outline.Attributes["xmlUrl"].Value;

                    if (!string.IsNullOrEmpty(xmlUrl))
                    {
                        try
                        {
                            Uri xu = new Uri(xmlUrl);

                            NodeFeed feed = new(title, xu);

                            if (outline.Attributes["htmlUrl"] is not null)
                            {
                                var htmlUrl = "";
                                htmlUrl = outline.Attributes["htmlUrl"].Value;

                                Uri hu = new Uri(htmlUrl);
                                feed.SiteUri = hu;
                            }

                            feed.Parent = parent;

                            parent.Children.Add(feed);

                            //Debug.WriteLine(feed.Name + " feed added");

                            continue;
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }

                if (outline.ChildNodes.Count > 0)
                {
                    ProcessOutlineChild(outline.ChildNodes, parent);
                }
            }
        }
Esempio n. 3
0
        // Import OPML
        public NodeFolder LoadOpml(XmlDocument xdoc)
        {
            string opmlTitle = "OPML imported feeds";

            // Dummy Root Folder
            NodeFolder dummyFolder = new NodeFolder(opmlTitle);

            dummyFolder.IsSelected = true;
            dummyFolder.IsExpanded = true;
            dummyFolder.Parent     = null; // for now

            if (xdoc is null)
            {
                return(dummyFolder);
            }

            XmlNode opmlTitleNode = xdoc.SelectSingleNode("//opml/head/title");

            if (opmlTitleNode is not null)
            {
                dummyFolder.Name = opmlTitleNode.InnerText;
            }

            XmlNode bodyNode = xdoc.SelectSingleNode("//opml/body");

            if (bodyNode is null)
            {
                return(dummyFolder);
            }

            if (bodyNode.ChildNodes.Count > 0)
            {
                foreach (XmlNode outline in bodyNode.ChildNodes)
                {
                    if (!outline.LocalName.Equals("outline"))
                    {
                        continue;
                    }

                    string title = "empty";
                    if (outline.Attributes["text"] is not null)
                    {
                        title = outline.Attributes["text"].InnerText;
                    }

                    var xmlUrl = "";
                    if (outline.Attributes["xmlUrl"] is not null)
                    {
                        xmlUrl = outline.Attributes["xmlUrl"].Value;

                        if (!string.IsNullOrEmpty(xmlUrl))
                        {
                            try
                            {
                                Uri xu = new Uri(xmlUrl);

                                NodeFeed feed = new(title, xu);

                                if (outline.Attributes["htmlUrl"] is not null)
                                {
                                    var htmlUrl = "";
                                    htmlUrl = outline.Attributes["htmlUrl"].Value;

                                    Uri hu = new Uri(htmlUrl);
                                    feed.SiteUri = hu;
                                }

                                feed.Parent = dummyFolder;

                                dummyFolder.Children.Add(feed);

                                //Debug.WriteLine(feed.Name + " feed added");

                                continue;
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }

                    if (outline.ChildNodes.Count > 0)
                    {
                        NodeFolder folder = new NodeFolder(title);
                        folder.IsSelected = true;
                        folder.IsExpanded = true;

                        folder.Parent = dummyFolder;

                        dummyFolder.Children.Add(folder);

                        //Debug.WriteLine(folder.Name + " folder added");

                        ProcessOutlineChild(outline.ChildNodes, folder);
                    }
                }
            }

            return(dummyFolder);
        }
Esempio n. 4
0
        // Loads service tree.
        public void LoadXmlDoc(XmlDocument doc)
        {
            if (doc == null)
            {
                return;
            }
            if (doc.DocumentElement == null)
            {
                return;
            }

            XmlNodeList accountList;

            accountList = doc.SelectNodes("//Accounts");
            if (accountList == null)
            {
                return;
            }

            foreach (XmlNode a in accountList)
            {
                // Loop through the top level childs.
                XmlNodeList serviceList = a.ChildNodes;
                if (serviceList == null)
                {
                    continue;
                }

                foreach (XmlNode s in serviceList)
                {
                    if (s.LocalName.Equals("Service"))
                    {
                        var accountName = s.Attributes["Name"].Value;

                        var    userName     = s.Attributes["UserName"].Value;
                        var    userPassword = s.Attributes["UserPassword"].Value;
                        var    endpoint     = s.Attributes["EndPoint"].Value;
                        string api          = (s.Attributes["Api"] != null) ? s.Attributes["Api"].Value : "Unknown"; //
                        string tp           = (s.Attributes["Type"] != null) ? s.Attributes["Type"].Value : "Unknown";

                        var  selecteds   = string.IsNullOrEmpty(s.Attributes["Selected"].Value) ? "" : s.Attributes["Selected"].Value;
                        var  expandeds   = string.IsNullOrEmpty(s.Attributes["Expanded"].Value) ? "" : s.Attributes["Expanded"].Value;
                        bool isSelecteds = (selecteds == "true") ? true : false;
                        bool isExpandeds = (expandeds == "true") ? true : false;

                        ServiceTypes stp;
                        switch (tp)
                        {
                        case "AtomPub":
                            stp = ServiceTypes.AtomPub;
                            break;

                        case "Feed":
                            stp = ServiceTypes.Feed;
                            break;

                        case "XML-RPC":
                            stp = ServiceTypes.XmlRpc;
                            break;

                        case "AtomAPI":
                            stp = ServiceTypes.AtomApi;
                            break;

                        default:
                            stp = ServiceTypes.Unknown;
                            break;
                        }

                        ApiTypes at;
                        switch (api)
                        {
                        case "AtomPub":
                            at = ApiTypes.atAtomPub;
                            break;

                        case "AtomFeed":
                            at = ApiTypes.atFeed;
                            break;

                        case "RssFeed":
                            at = ApiTypes.atFeed;
                            break;

                        case "Feed":
                            at = ApiTypes.atFeed;
                            break;

                        case "XML-RPC_MovableType":
                            at = ApiTypes.atXMLRPC_MovableType;
                            break;

                        case "XML-RPC_WordPress":
                            at = ApiTypes.atXMLRPC_WordPress;
                            break;

                        case "AtomAPI":
                            at = ApiTypes.atAtomApi;
                            break;

                        default:
                            at = ApiTypes.atUnknown;
                            break;
                        }

                        string    viewType = (s.Attributes["ViewType"] != null) ? s.Attributes["ViewType"].Value : "Cards";
                        ViewTypes vt;
                        switch (viewType)
                        {
                        case "Cards":
                            vt = ViewTypes.vtCards;
                            break;

                        case "Magazine":
                            vt = ViewTypes.vtMagazine;
                            break;

                        case "ThreePanes":
                            vt = ViewTypes.vtThreePanes;
                            break;

                        default:
                            vt = ViewTypes.vtCards;
                            break;
                        }

                        if (stp == ServiceTypes.Feed)
                        {
                            continue;
                        }

                        if ((!string.IsNullOrEmpty(accountName)) && (!string.IsNullOrEmpty(userName)) && (!string.IsNullOrEmpty(userPassword)) && (!string.IsNullOrEmpty(endpoint)))
                        {
                            NodeService account = new NodeService(accountName, userName, userPassword, new Uri(endpoint), at, stp);
                            account.IsSelected = isSelecteds;
                            account.IsExpanded = isExpandeds;
                            account.Parent     = this;

                            account.ServiceType = stp;
                            account.Api         = at;

                            account.ViewType = vt;


                            XmlNodeList collectionList = s.SelectNodes("Collection");
                            foreach (XmlNode c in collectionList)
                            {
                                var  collectionName = c.Attributes["Name"].Value;
                                var  selectedc      = string.IsNullOrEmpty(c.Attributes["Selected"].Value) ? "" : c.Attributes["Selected"].Value;
                                var  expandedc      = string.IsNullOrEmpty(c.Attributes["Expanded"].Value) ? "" : c.Attributes["Expanded"].Value;
                                bool isSelectedc    = (selectedc == "true") ? true : false;
                                bool isExpandedc    = (expandedc == "true") ? true : false;

                                string collectionHref = (c.Attributes["Href"] != null) ? c.Attributes["Href"].Value : "";

                                string collectionId = (c.Attributes["Id"] != null) ? c.Attributes["Id"].Value : "";

                                if ((!string.IsNullOrEmpty(collectionName)) && (!string.IsNullOrEmpty(collectionHref)))
                                {
                                    NodeEntryCollection entries = null;

                                    // TODO:
                                    switch (account.Api)
                                    {
                                    case ApiTypes.atAtomPub:
                                        entries = new NodeAtomPubEntryCollection(collectionName, new Uri(collectionHref), collectionId);
                                        break;

                                    case ApiTypes.atXMLRPC_MovableType:
                                        entries = new NodeXmlRpcEntryCollection(collectionName, new Uri(collectionHref), collectionId);
                                        break;

                                    case ApiTypes.atXMLRPC_WordPress:
                                        entries = new NodeXmlRpcEntryCollection(collectionName, new Uri(collectionHref), collectionId);
                                        break;
                                        //case ApiTypes.atAtomAPI:
                                        //    break;
                                    }

                                    if (entries == null)
                                    {
                                        continue;
                                    }

                                    if (entries is NodeAtomPubEntryCollection)
                                    {
                                        if (c.Attributes["CategoriesUri"] != null)
                                        {
                                            var catsUrl = c.Attributes["CategoriesUri"].Value;
                                            if (!string.IsNullOrEmpty(catsUrl))
                                            {
                                                try
                                                {
                                                    Uri catsUri = new(catsUrl);
                                                    (entries as NodeAtomPubEntryCollection).CategoriesUri = catsUri;
                                                }
                                                catch { }
                                            }
                                        }

                                        var catFixed = c.Attributes["IsCategoryFixed"].Value;
                                        if (!string.IsNullOrEmpty(catFixed))
                                        {
                                            if (catFixed == "true")
                                            {
                                                (entries as NodeAtomPubEntryCollection).IsCategoryFixed = true;
                                            }
                                        }

                                        XmlNodeList acceptList = c.SelectNodes("Accept");
                                        foreach (XmlNode act in acceptList)
                                        {
                                            (entries as NodeAtomPubEntryCollection).AcceptTypes.Add(act.InnerText);
                                        }
                                    }

                                    XmlNodeList categoryList = c.SelectNodes("Category");
                                    foreach (XmlNode t in categoryList)
                                    {
                                        var  categoryName = t.Attributes["Name"].Value;
                                        var  selectedt    = string.IsNullOrEmpty(t.Attributes["Selected"].Value) ? "" : t.Attributes["Selected"].Value;
                                        var  expandedt    = string.IsNullOrEmpty(t.Attributes["Expanded"].Value) ? "" : t.Attributes["Expanded"].Value;
                                        bool isSelectedt  = (selectedc == "true") ? true : false;
                                        bool isExpandedt  = (expandedc == "true") ? true : false;

                                        if (!string.IsNullOrEmpty(categoryName))
                                        {
                                            NodeCategory category = null;

                                            switch (account.Api)
                                            {
                                            case ApiTypes.atAtomPub:
                                                category = new NodeAtomPubCategory(categoryName);
                                                break;

                                            case ApiTypes.atXMLRPC_MovableType:
                                                category = new NodeXmlRpcMTCategory(categoryName);
                                                break;

                                            case ApiTypes.atXMLRPC_WordPress:
                                                category = new NodeXmlRpcWPCategory(categoryName);
                                                break;
                                                //case ApiTypes.atAtomAPI:
                                                //    break;
                                            }

                                            if (category == null)
                                            {
                                                return;
                                            }

                                            if (category is NodeAtomPubCategory)
                                            {
                                                (category as NodeAtomPubCategory).Term = categoryName;

                                                var categoryScheme = t.Attributes["Scheme"].Value;
                                                (category as NodeAtomPubCategory).Scheme = categoryScheme;
                                            }


                                            category.IsSelected = isSelectedc;
                                            category.IsExpanded = isExpandedc;
                                            category.Parent     = entries;

                                            entries.Children.Add(category);
                                        }
                                    }

                                    entries.IsSelected = isSelectedc;
                                    entries.IsExpanded = isExpandedc;
                                    entries.Parent     = account;

                                    account.Children.Add(entries);
                                }
                            }

                            this.Children.Add(account);
                        }
                    }
                    else if (s.LocalName.Equals("Feed"))
                    {
                        NodeFeed feed = LoadXmlChildFeed(s);
                        if (feed == null)
                        {
                            continue;
                        }

                        feed.Parent = this;

                        if (feed != null)
                        {
                            this.Children.Add(feed);
                        }
                    }
                    else if (s.LocalName.Equals("Folder"))
                    {
                        var folderName = s.Attributes["Name"].Value;

                        if (!string.IsNullOrEmpty(folderName))
                        {
                            var  selecteds   = string.IsNullOrEmpty(s.Attributes["Selected"].Value) ? "" : s.Attributes["Selected"].Value;
                            var  expandeds   = string.IsNullOrEmpty(s.Attributes["Expanded"].Value) ? "" : s.Attributes["Expanded"].Value;
                            bool isSelecteds = (selecteds == "true") ? true : false;
                            bool isExpandeds = (expandeds == "true") ? true : false;

                            NodeFolder folder = new NodeFolder(folderName);
                            folder.IsSelected = isSelecteds;
                            folder.IsExpanded = isExpandeds;
                            folder.Parent     = this;

                            int unreadCount = 0;
                            var attr        = s.Attributes["UnreadCount"];
                            if (attr != null)
                            {
                                if (!string.IsNullOrEmpty(s.Attributes["UnreadCount"].Value))
                                {
                                    unreadCount = int.Parse(s.Attributes["UnreadCount"].Value);
                                }
                            }
                            folder.EntryCount = unreadCount;

                            string    viewType = (s.Attributes["ViewType"] != null) ? s.Attributes["ViewType"].Value : "Cards";
                            ViewTypes vt;
                            switch (viewType)
                            {
                            case "Cards":
                                vt = ViewTypes.vtCards;
                                break;

                            case "Magazine":
                                vt = ViewTypes.vtMagazine;
                                break;

                            case "ThreePanes":
                                vt = ViewTypes.vtThreePanes;
                                break;

                            default:
                                vt = ViewTypes.vtCards;
                                break;
                            }
                            folder.ViewType = vt;



                            XmlNodeList feedList = s.SelectNodes("Feed");
                            foreach (XmlNode f in feedList)
                            {
                                NodeFeed feed = LoadXmlChildFeed(f);
                                if (feed == null)
                                {
                                    continue;
                                }

                                feed.Parent = folder;

                                if (feed != null)
                                {
                                    folder.Children.Add(feed);
                                }
                            }

                            this.Children.Add(folder);
                        }
                    }
                }

                break;
            }
        }