Beispiel #1
0
        private XmlElement AsXmlFeedElement(XmlDocument doc, NodeFeed fd)
        {
            XmlElement feed = doc.CreateElement(string.Empty, "Feed", string.Empty);

            XmlAttribute attrf = doc.CreateAttribute("Name");

            attrf.Value = fd.Name;
            feed.SetAttributeNode(attrf);

            attrf       = doc.CreateAttribute("Expanded");
            attrf.Value = fd.IsExpanded ? "true" : "false";
            feed.SetAttributeNode(attrf);

            attrf       = doc.CreateAttribute("Selected");
            attrf.Value = fd.IsSelected ? "true" : "false";
            feed.SetAttributeNode(attrf);

            attrf       = doc.CreateAttribute("EndPoint");
            attrf.Value = fd.EndPoint.AbsoluteUri;
            feed.SetAttributeNode(attrf);

            attrf       = doc.CreateAttribute("Type");
            attrf.Value = "Feed";
            feed.SetAttributeNode(attrf);

            attrf = doc.CreateAttribute("Api");
            switch (fd.Api)
            {
            case ApiTypes.atFeed:
                attrf.Value = "Feed";
                feed.SetAttributeNode(attrf);
                break;

            case ApiTypes.atUnknown:
                attrf.Value = "Unknown";
                feed.SetAttributeNode(attrf);
                break;
            }

            attrf = doc.CreateAttribute("ViewType");
            switch (fd.ViewType)
            {
            case ViewTypes.vtCards:
                attrf.Value = "Cards";
                feed.SetAttributeNode(attrf);
                break;

            case ViewTypes.vtMagazine:
                attrf.Value = "Magazine";
                feed.SetAttributeNode(attrf);
                break;

            case ViewTypes.vtThreePanes:
                attrf.Value = "ThreePanes";
                feed.SetAttributeNode(attrf);
                break;
            }

            attrf       = doc.CreateAttribute("SiteTitle");
            attrf.Value = fd.SiteTitle;
            feed.SetAttributeNode(attrf);

            attrf = doc.CreateAttribute("SiteUri");
            if (fd.SiteUri != null)
            {
                attrf.Value = fd.SiteUri.AbsoluteUri;
            }
            feed.SetAttributeNode(attrf);

            attrf       = doc.CreateAttribute("UnreadCount");
            attrf.Value = fd.EntryCount.ToString();
            feed.SetAttributeNode(attrf);

            attrf       = doc.CreateAttribute("LastUpdate");
            attrf.Value = fd.LastUpdate.ToString("yyyy-MM-dd HH:mm:ss");
            feed.SetAttributeNode(attrf);

            return(feed);
        }
Beispiel #2
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;
            }
        }
Beispiel #3
0
        private NodeFeed LoadXmlChildFeed(XmlNode node)
        {
            var feedName = node.Attributes["Name"].Value;

            var  selecteds   = string.IsNullOrEmpty(node.Attributes["Selected"].Value) ? "" : node.Attributes["Selected"].Value;
            var  expandeds   = string.IsNullOrEmpty(node.Attributes["Expanded"].Value) ? "" : node.Attributes["Expanded"].Value;
            bool isSelectedf = (selecteds == "true") ? true : false;
            bool isExpandedf = (expandeds == "true") ? true : false;

            var    endpoint = node.Attributes["EndPoint"].Value;
            string api      = (node.Attributes["Api"] != null) ? node.Attributes["Api"].Value : "Unknown";

            ApiTypes at;

            switch (api)
            {
            case "Feed":
                at = ApiTypes.atFeed;
                break;

            default:
                at = ApiTypes.atUnknown;
                break;
            }

            string    viewType = (node.Attributes["ViewType"] != null) ? node.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;
            }

            string siteTitle = "";
            var    attr      = node.Attributes["SiteTitle"];

            if (attr != null)
            {
                siteTitle = string.IsNullOrEmpty(node.Attributes["SiteTitle"].Value) ? "" : node.Attributes["SiteTitle"].Value;
            }

            Uri siteUri = null;

            attr = node.Attributes["SiteUri"];
            if (attr != null)
            {
                var siteLink = string.IsNullOrEmpty(node.Attributes["SiteUri"].Value) ? "" : node.Attributes["SiteUri"].Value;

                if (!string.IsNullOrEmpty(siteLink))
                {
                    try
                    {
                        siteUri = new Uri(siteLink);
                    }
                    catch { }
                }
            }

            int unreadCount = 0;

            attr = node.Attributes["UnreadCount"];
            if (attr != null)
            {
                if (!string.IsNullOrEmpty(node.Attributes["UnreadCount"].Value))
                {
                    unreadCount = int.Parse(node.Attributes["UnreadCount"].Value);
                }
            }

            DateTime lastUpdate = default;

            attr = node.Attributes["LastUpdate"];
            if (attr != null)
            {
                if (!string.IsNullOrEmpty(node.Attributes["LastUpdate"].Value))
                {
                    lastUpdate = DateTime.Parse(node.Attributes["LastUpdate"].Value);
                }
            }


            if (!string.IsNullOrEmpty(endpoint))
            {
                NodeFeed feed = new NodeFeed(feedName, new Uri(endpoint));
                feed.IsSelected = isSelectedf;
                feed.IsExpanded = isExpandedf;
                feed.Parent     = this;

                feed.SiteTitle = siteTitle;
                feed.SiteUri   = siteUri;

                feed.EntryCount = unreadCount;
                feed.ViewType   = vt;
                feed.LastUpdate = lastUpdate;

                feed.Api = at;

                return(feed);
            }

            return(null);
        }
Beispiel #4
0
        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)
            {
                XmlNodeList serviceList = a.SelectNodes("Service");
                if (serviceList == null)
                {
                    return;
                }

                foreach (XmlNode s in serviceList)
                {
                    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 : "Atom"; //

                    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;

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

                    case "AtomPub":
                        at = ApiTypes.atAtomPub;
                        break;

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

                    case "XML-RPC":
                        at = ApiTypes.atXMLRPC;
                        break;

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

                    default:
                        at = ApiTypes.atAtomPub;     // or?
                        break;
                    }

                    if (at == ApiTypes.atAtomFeed)
                    {
                        if ((!string.IsNullOrEmpty(accountName)) && (!string.IsNullOrEmpty(endpoint)))
                        {
                            NodeFeed account = new NodeFeed(accountName, new Uri(endpoint));
                            account.Selected = isSelecteds;
                            account.Expanded = isExpandeds;
                            account.Parent   = null;

                            this.Children.Add(account);
                        }
                        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);
                        account.Selected = isSelecteds;
                        account.Expanded = isExpandeds;
                        account.Parent   = null;

                        XmlNodeList workspaceList = s.SelectNodes("Workspaces");
                        foreach (XmlNode w in workspaceList)
                        {
                            var  workspaceName = w.Attributes["Name"].Value;
                            var  selectedw     = string.IsNullOrEmpty(w.Attributes["Selected"].Value) ? "" : w.Attributes["Selected"].Value;
                            var  expandedw     = string.IsNullOrEmpty(w.Attributes["Expanded"].Value) ? "" : w.Attributes["Expanded"].Value;
                            bool isSelectedw   = (selectedw == "true") ? true : false;
                            bool isExpandedw   = (expandedw == "true") ? true : false;
                            if (!string.IsNullOrEmpty(workspaceName))
                            {
                                NodeCollection blog = new NodeCollection(workspaceName);
                                blog.Selected = isSelectedw;
                                blog.Expanded = isExpandedw;
                                blog.Parent   = account;

                                XmlNodeList collectionList = w.SelectNodes("Collection");
                                foreach (XmlNode c in collectionList)
                                {
                                    var  collectionName = c.Attributes["Name"].Value;
                                    var  collectionHref = c.Attributes["Href"].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;
                                    if ((!string.IsNullOrEmpty(collectionName)) && (!string.IsNullOrEmpty(collectionHref)))
                                    {
                                        NodeEntryCollection entry = new NodeEntryCollection(collectionName, new Uri(collectionHref));
                                        entry.Selected = isSelectedc;
                                        entry.Expanded = isExpandedc;
                                        entry.Parent   = blog;

                                        blog.Children.Add(entry);
                                    }
                                }

                                account.Children.Add(blog);
                            }
                        }

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