示例#1
0
        /// <summary>
        /// Import cached items, flags, etc.
        /// </summary>
        public void DoImportCache()
        {
            Stream    stream = null;
            RSSParser parser = null;

            // Register our item processor
            _plugin.RegisterItemElementParser(FeedType.Rss, _rbNS, "flag-status", this);
            _plugin.RegisterItemElementParser(FeedType.Atom, _rbNS, "flag-status", this);

            ImportUtils.UpdateProgress(0, _progressMessageCache);
            int totalFeeds     = Math.Max(_importedFeeds.Count, 1);
            int processedFeeds = 0;

            // Ok, all feeds are created. Try to import all caches and mark read items
            _parseCache = true;
            foreach (FeedInfo fi in _importedFeeds)
            {
                ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessageCache);
                processedFeeds += 100;
                if (fi.feed.IsDeleted)
                {
                    continue;
                }
                if (null == fi.cacheFile)
                {
                    continue;
                }

                string path = Path.Combine(_cachePath, fi.cacheFile);
                if (!File.Exists(path))
                {
                    continue;
                }
                try
                {
                    // Load feed!
                    parser = new RSSParser(fi.feed);
                    using (stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                    {
                        parser.Parse(stream, Encoding.UTF8, true);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("RSS Bandit cache '" + path + "' load failed: '" + ex.Message + "'");
                }

                if (fi.readItems != null)
                {
                    // And mark as read
                    IResourceList allItems = fi.feed.GetLinksTo("RSSItem", "From");
                    foreach (string readOne in fi.readItems)
                    {
                        IResourceList markAsRead = Core.ResourceStore.FindResources("RSSItem", "GUID", readOne).Intersect(allItems, true);
                        foreach (IResource item in markAsRead)
                        {
                            item.DeleteProp(Core.Props.IsUnread);
                        }
                    }
                }
            }
            ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessageCache);

            // And here we should import flags from flags stream
            if (_flaggedPath == null)
            {
                return;
            }

            // Register two additional elements
            _plugin.RegisterItemElementParser(FeedType.Rss, _rbNS, "feed-url", this);
            _plugin.RegisterItemElementParser(FeedType.Atom, _rbNS, "feed-url", this);
            _parseCache = false;

            IResource pseudoFeed = Core.ResourceStore.NewResourceTransient("RSSFeed");

            try
            {
                parser             = new RSSParser(pseudoFeed);
                parser.ItemParsed += this.FlaggedItemParsed;
                using (stream = new FileStream(_flaggedPath, FileMode.Open, FileAccess.Read))
                {
                    parser.Parse(stream, Encoding.UTF8, true);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("RssBandit flags load failed: '" + ex.Message + "'");
            }
            pseudoFeed.Delete();
        }
示例#2
0
        /// <summary>
        /// Import cached items, flags, etc.
        /// </summary>
        public void DoImportCache()
        {
            RSSPlugin plugin = RSSPlugin.GetInstance();

            _readItems = new ArrayList();
            // Register us for special tags
            plugin.RegisterItemElementParser(FeedType.Rss, _fdNS, "state", this);
            plugin.RegisterItemElementParser(FeedType.Atom, _fdNS, "state", this);

            string[] allFiles = Directory.GetFiles(_channelsPath, "*.rss");

            int totalFiles     = Math.Max(allFiles.Length, 1);
            int processedFiles = 0;

            foreach (string file in allFiles)
            {
                ImportUtils.UpdateProgress(processedFiles / totalFiles, _progressMessageCache);
                processedFiles += 100;

                IResource feed = null;
                string    name = HtmlTools.SafeHtmlDecode(Path.GetFileNameWithoutExtension(file));
                if (_name2url.ContainsKey(name))
                {
                    IResourceList feeds = Core.ResourceStore.FindResources("RSSFeed", Props.URL, _name2url[name]);
                    if (feeds.Count > 0)
                    {
                        feed = feeds[0];
                    }
                }
                if (feed == null)
                {
                    IResourceList feeds = Core.ResourceStore.FindResources("RSSFeed", Core.Props.Name, name);
                    if (feeds.Count > 0)
                    {
                        feed = feeds[0];
                    }
                }
                // Not found (import of this feed was canceled?)
                if (feed == null)
                {
                    continue;
                }
                _readItems.Clear();
                using (Stream rss = new FileStream(file, FileMode.Open))
                {
                    try
                    {
                        RSSParser parser = new RSSParser(feed);
                        parser.Parse(rss, Encoding.UTF8, true);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine("FeedDemon cache '" + file + "' load failed: '" + ex.Message + "'");
                    }
                }
                foreach (IResource r in _readItems)
                {
                    if (!r.IsDeleted)
                    {
                        r.DeleteProp(Core.Props.IsUnread);
                    }
                }
            }
            ImportUtils.UpdateProgress(processedFiles / totalFiles, _progressMessageCache);
        }