private Opml DownloadOpmlFeed(Uri uri)
        {
            // look for disk cache first
            Opml opmlFeed = TryLoadFromDisk(uri);

            if (opmlFeed != null)
            {
                return(opmlFeed);
            }

            // May fail under partial trust
            try
            {
                byte[] feed = new WebClient().DownloadData(uri.AbsoluteUri);

                var opmlDoc = new XmlDocument();
                opmlDoc.Load(new MemoryStream(feed));
                opmlFeed = Opml.LoadFromXml(opmlDoc);

                opmlFeed.UtcExpiry = DateTime.UtcNow.AddMinutes(_defaultTtlMinutes);

                // save to disk
                TrySaveToDisk(opmlDoc, uri, opmlFeed.UtcExpiry);
            }
            catch
            {
                return(new Opml());
            }

            return(opmlFeed);
        }
        internal Opml GetFeed(Uri uri)
        {
            Opml opmlFeed = null;

            lock (_cache)
            {
                if (_cache.TryGetValue(uri.AbsoluteUri, out opmlFeed))
                {
                    if (DateTime.UtcNow > opmlFeed.UtcExpiry)
                    {
                        _cache.Remove(uri.AbsoluteUri);
                        opmlFeed = null;
                    }
                }
            }

            if (opmlFeed == null)
            {
                opmlFeed = DownloadOpmlFeed(uri);

                lock (_cache)
                {
                    _cache[uri.AbsoluteUri] = opmlFeed;
                }
            }

            return(opmlFeed);
        }
示例#3
0
        public static Opml LoadFromXml(XmlDocument doc)
        {
            var _out = new Opml();

            try
            {
                // Parse head
                XmlNode head            = doc.GetElementsByTagName("head")[0];
                XmlNode title           = head.SelectSingleNode("./title");
                XmlNode dateCreated     = head.SelectSingleNode("./dateCreated");
                XmlNode dateModified    = head.SelectSingleNode("./dateModified");
                XmlNode ownerName       = head.SelectSingleNode("./ownerName");
                XmlNode ownerEmail      = head.SelectSingleNode("./ownerEmail");
                XmlNode ownerId         = head.SelectSingleNode("./ownerId");
                XmlNode docs            = head.SelectSingleNode("./docs");
                XmlNode expansionState  = head.SelectSingleNode("./expansionState");
                XmlNode vertScrollState = head.SelectSingleNode("./vertScrollState");
                XmlNode windowTop       = head.SelectSingleNode("./windowTop");
                XmlNode windowLeft      = head.SelectSingleNode("./windowLeft");
                XmlNode windowBottom    = head.SelectSingleNode("./windowBottom");
                XmlNode windowRight     = head.SelectSingleNode("./windowRight");

                if (title != null)
                {
                    _out.Title = title.InnerText;
                }

                if (dateCreated != null)
                {
                    _out.DateCreated = DateTime.Parse(dateCreated.InnerText);
                }

                if (dateModified != null)
                {
                    _out.DateModified = DateTime.Parse(dateModified.InnerText);
                }

                if (ownerName != null)
                {
                    _out.OwnerName = ownerName.InnerText;
                }

                if (ownerEmail != null)
                {
                    _out.OwnerEmail = ownerEmail.InnerText;
                }

                if (ownerId != null)
                {
                    _out.OwnerId = ownerId.InnerText;
                }

                if (docs != null)
                {
                    _out.Docs = docs.InnerText;
                }

                if (expansionState != null)
                {
                    _out.ExpansionState = expansionState.InnerText;
                }

                if (vertScrollState != null)
                {
                    _out.VertScrollState = vertScrollState.InnerText;
                }

                if (windowTop != null)
                {
                    _out.WindowTop = windowTop.InnerText;
                }

                if (windowLeft != null)
                {
                    _out.WindowLeft = windowLeft.InnerText;
                }

                if (windowBottom != null)
                {
                    _out.WindowBottom = windowBottom.InnerText;
                }

                if (windowLeft != null)
                {
                    _out.WindowLeft = windowLeft.InnerText;
                }

                // Parse body
                XmlNode     body        = doc.GetElementsByTagName("body")[0];
                XmlNodeList outlineList = body.SelectNodes("./outline");
                foreach (XmlElement outline in outlineList)
                {
                    _out.Outlines.Add(ParseXml(outline));
                }

                return(_out);
            }
            catch
            {
                return(new Opml());
            }
        }
        private Opml TryLoadFromDisk(Uri uri)
        {
            if (_directoryOnDisk == null)
            {
                return(null);  // no place to cache
            }

            // look for all files matching the prefix
            // looking for the one matching url that is not expired
            // removing expired (or invalid) ones
            string pattern = GetTempFileNamePrefixFromUrl(uri) + "_*.opml.resources";

            string[] files = Directory.GetFiles(_directoryOnDisk, pattern, SearchOption.TopDirectoryOnly);

            foreach (string opmlFilename in files)
            {
                XmlDocument opmlDoc               = null;
                bool        isOpmlFileValid       = false;
                DateTime    utcExpiryFromOpmlFile = DateTime.MinValue;
                string      urlFromOpmlFile       = null;

                try
                {
                    opmlDoc = new XmlDocument();
                    opmlDoc.Load(opmlFilename);

                    // look for special XML comment (before the root tag)'
                    // containing expiration and url
                    var comment = opmlDoc.DocumentElement.PreviousSibling as XmlComment;

                    if (comment != null)
                    {
                        string c = comment.Value;
                        int    i = c.IndexOf('@');
                        long   expiry;

                        if (long.TryParse(c.Substring(0, i), out expiry))
                        {
                            utcExpiryFromOpmlFile = DateTime.FromBinary(expiry);
                            urlFromOpmlFile       = c.Substring(i + 1);
                            isOpmlFileValid       = true;
                        }
                    }
                }
                catch
                {
                    // error processing one file shouldn't stop processing other files
                }

                // remove invalid or expired file
                if (!isOpmlFileValid || utcExpiryFromOpmlFile < DateTime.UtcNow)
                {
                    try
                    {
                        File.Delete(opmlFilename);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex);
                    }

                    // try next file
                    continue;
                }

                // match url
                if (urlFromOpmlFile.ToLower() == uri.AbsoluteUri.ToLower())
                {
                    // found a good one - create DOM and set expiry (as found on disk)
                    Opml opmlFeed = Opml.LoadFromXml(opmlDoc);
                    opmlFeed.UtcExpiry = utcExpiryFromOpmlFile;
                    return(opmlFeed);
                }
            }

            // not found
            return(null);
        }
示例#5
0
 private Opml GetDefaultOpmlFeed()
 {
     var opmlFeed = new Opml();
     string filePath = Config.GetPathToFile(Config.ConfigFileType.SolutionsExplorer);
     if (File.Exists(filePath))
     {
         opmlFeed = Opml.LoadFromFile(filePath);
     }
     return opmlFeed;
 }
示例#6
0
        protected override void OnLoad(EventArgs e)
        {
            var opmlFeed = new Opml();
            string elementIdPrefix = ClientID;
            string instanceVarName = elementIdPrefix + "_feedBrowser";
            if (((String.IsNullOrEmpty(OpmlUrl)) && (String.IsNullOrEmpty(OpmlFile)) && (String.IsNullOrEmpty(OpmlText))))
            {
                opmlFeed = GetDefaultOpmlFeed();
            }
            else
            {
                if ((!String.IsNullOrEmpty(OpmlText)))
                {
                    var opmlDoc = new XmlDocument();
                    opmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><opml version=\"2.0\"><head /><body>" + OpmlText + "</body></opml>");
                    opmlFeed = Opml.LoadFromXml(opmlDoc);
                }
                else if ((!String.IsNullOrEmpty(OpmlUrl)))
                {
                    opmlFeed = Opml.LoadFromUrl(new Uri(OpmlUrl));
                }
                else
                {
                    opmlFeed = Opml.LoadFromFile(OpmlFile);
                }
            }
            var script = new StringBuilder();

            string tabInstanceVarName = instanceVarName + "_tabs";
            script.Append("var " + tabInstanceVarName + " = new DotNetNuke.UI.WebControls.TabStrip.Strip(\"" + tabInstanceVarName + "\");");
            script.Append("var " + instanceVarName + " = new DotNetNuke.UI.WebControls.FeedBrowser.Browser(\"" + instanceVarName + "\"," + tabInstanceVarName + ");");
            script.Append(tabInstanceVarName + ".setResourcesFolderUrl(\"" + ResourcesFolderUrl + "\");");
            script.Append(instanceVarName + ".setResourcesFolderUrl(\"" + ResourcesFolderUrl + "\");");

            script.Append(instanceVarName + ".setElementIdPrefix(\"" + elementIdPrefix + "\");");
            if ((!String.IsNullOrEmpty(Theme)))
            {
                script.Append(instanceVarName + ".setTheme(\"" + Theme + "\");");
            }
            if ((!String.IsNullOrEmpty(RssProxyUrl)))
            {
                script.Append(instanceVarName + ".setRssProxyUrl(\"" + RssProxyUrl + "\");");
            }
            if ((!String.IsNullOrEmpty(DefaultTemplate)))
            {
                script.Append(instanceVarName + ".setDefaultTemplate(\"" + DefaultTemplate + "\");");
            }
            script.Append(instanceVarName + ".setAllowHtmlDescription(");
            if ((AllowHtmlDescription))
            {
                script.Append("true");
            }
            else
            {
                script.Append("false");
            }
            script.Append(");");

            string renderScript = GetRenderingScript(instanceVarName, opmlFeed.Outlines);
            bool includeFallbackScript = false;
            
			//Is there any OPML structure to render?
			if ((String.IsNullOrEmpty(renderScript)))
            {
                includeFallbackScript = true;
                script.Append(instanceVarName + ".setTabs(defaultFeedBrowser());");
            }
            else
            {
				//Javascript function that renders the OPML structure
                script.Append("function " + instanceVarName + "customFeedBrowser() ");
                script.Append("{");
                script.Append("     var " + instanceVarName + "tabs = [];");
                script.Append("     with (DotNetNuke.UI.WebControls.FeedBrowser) ");
                script.Append("     {");
                script.Append(renderScript);
                script.Append("     }");
                script.Append("     return(" + instanceVarName + "tabs);");
                script.Append("} ");
                script.Append(instanceVarName + ".setTabs(" + instanceVarName + "customFeedBrowser());");
            }
            		
            //NK 11/25/08
            //This code has a jQuery dependency so it can't be loaded using standard client script registration
            //It must come later in the page which is why it is inline; also ClientScript buggy when used in webcontrols
			if (!Page.ClientScript.IsClientScriptBlockRegistered("FBHostUrl"))
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(),
                                                            "FBHostUrl",
                                                            "<script type=\"text/javascript\">var $dnn = new Object(); $dnn.hostUrl = '" + Globals.ResolveUrl("~/") + "';</script>");
                output.Append("<script type=\"text/javascript\" src=\"" + Globals.ResolveUrl("~/Resources/Shared/scripts/init.js") + "\"></script>");
                output.Append("<script type=\"text/javascript\" src=\"" + Globals.ResolveUrl("~/Resources/Shared/scripts/DotNetNukeAjaxShared.js") + "\"></script>");
                output.Append("<script type=\"text/javascript\" src=\"" + Globals.ResolveUrl("~/Resources/TabStrip/scripts/tabstrip.js") + "\"></script>");
                output.Append("<script type=\"text/javascript\" src=\"" + Globals.ResolveUrl("~/Resources/FeedBrowser/scripts/feedbrowser.js") + "\"></script>");
                output.Append("<script type=\"text/javascript\" src=\"" + Globals.ResolveUrl("~/Resources/FeedBrowser/scripts/templates.js") + "\"></script>");
                if ((includeFallbackScript))
                {
                    output.Append("<script type=\"text/javascript\" src=\"" + Globals.ResolveUrl("~/Resources/FeedBrowser/scripts/fallback.js") + "\"></script>");
                }
                if ((!String.IsNullOrEmpty(StyleSheetUrl)))
                {
                    script.Append(tabInstanceVarName + ".setStyleSheetUrl(\"" + StyleSheetUrl + "\");");
                    script.Append(instanceVarName + ".setStyleSheetUrl(\"" + StyleSheetUrl + "\");");
                }
            }
            script.Append(instanceVarName + ".render();");
            output.Append("<script type=\"text/javascript\">" + script + "</script>");

            base.OnLoad(e);
        }
示例#7
0
文件: Opml.cs 项目: biganth/Curt
        public static Opml LoadFromXml(XmlDocument doc)
        {
            var _out = new Opml();
            try
            {
                // Parse head
                XmlNode head = doc.GetElementsByTagName("head")[0];
                XmlNode title = head.SelectSingleNode("./title");
                XmlNode dateCreated = head.SelectSingleNode("./dateCreated");
                XmlNode dateModified = head.SelectSingleNode("./dateModified");
                XmlNode ownerName = head.SelectSingleNode("./ownerName");
                XmlNode ownerEmail = head.SelectSingleNode("./ownerEmail");
                XmlNode ownerId = head.SelectSingleNode("./ownerId");
                XmlNode docs = head.SelectSingleNode("./docs");
                XmlNode expansionState = head.SelectSingleNode("./expansionState");
                XmlNode vertScrollState = head.SelectSingleNode("./vertScrollState");
                XmlNode windowTop = head.SelectSingleNode("./windowTop");
                XmlNode windowLeft = head.SelectSingleNode("./windowLeft");
                XmlNode windowBottom = head.SelectSingleNode("./windowBottom");
                XmlNode windowRight = head.SelectSingleNode("./windowRight");

                if (title != null)
                {
                    _out.Title = title.InnerText;
                }

                if (dateCreated != null)
                {
                    _out.DateCreated = DateTime.Parse(dateCreated.InnerText);
                }

                if (dateModified != null)
                {
                    _out.DateModified = DateTime.Parse(dateModified.InnerText);
                }

                if (ownerName != null)
                {
                    _out.OwnerName = ownerName.InnerText;
                }

                if (ownerEmail != null)
                {
                    _out.OwnerEmail = ownerEmail.InnerText;
                }

                if (ownerId != null)
                {
                    _out.OwnerId = ownerId.InnerText;
                }

                if (docs != null)
                {
                    _out.Docs = docs.InnerText;
                }

                if (expansionState != null)
                {
                    _out.ExpansionState = expansionState.InnerText;
                }

                if (vertScrollState != null)
                {
                    _out.VertScrollState = vertScrollState.InnerText;
                }

                if (windowTop != null)
                {
                    _out.WindowTop = windowTop.InnerText;
                }

                if (windowLeft != null)
                {
                    _out.WindowLeft = windowLeft.InnerText;
                }

                if (windowBottom != null)
                {
                    _out.WindowBottom = windowBottom.InnerText;
                }

                if (windowLeft != null)
                {
                    _out.WindowLeft = windowLeft.InnerText;
                }

                // Parse body
                XmlNode body = doc.GetElementsByTagName("body")[0];
                XmlNodeList outlineList = body.SelectNodes("./outline");
                foreach (XmlElement outline in outlineList)
                {
                    _out.Outlines.Add(ParseXml(outline));
                }

                return _out;
            }
            catch
            {
                return (new Opml());
            }
        }