Beispiel #1
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 #2
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);
                    }
                }
            }
        }