Exemplo n.º 1
0
        private void ScheduleForUpdate(IResource root)
        {
            RSSPlugin plug = RSSPlugin.GetInstance();

            if (plug == null)
            {
                return;
            }
            foreach (IResource res in root.GetLinksTo(null, Core.Props.Parent).ValidResources)
            {
                if (res.Type == "RSSFeedGroup")
                {
                    ScheduleForUpdate(res);
                }
                else if (res.Type == "RSSFeed" && _oldRSSFeedList.IndexOf(res) == -1)
                {
                    if (!res.HasProp(Props.UpdateFrequency) || !res.HasProp(Props.UpdatePeriod))
                    {
                        res.SetProp(Props.UpdateFrequency, 4);
                        res.SetProp(Props.UpdatePeriod, UpdatePeriods.Hourly);
                    }
                    plug.ScheduleFeedUpdate(res);
                }
            }
        }
Exemplo n.º 2
0
        private static int ConfirmImportRecursive(IResource res)
        {
            int count = 0;

            foreach (IResource child in res.GetLinksTo(null, Core.Props.Parent))
            {
                if (child.Type == "RSSFeedGroup")
                {
                    int childCount = ConfirmImportRecursive(child);
                    if (childCount == 0)
                    {
                        child.Delete();
                    }
                    count += childCount;
                }
                else if (child.GetIntProp(Props.Transient) == 1)
                {
                    IResourceList items = child.GetLinksOfType("RSSItem", Props.RSSItem);
                    items.DeleteAll();
                    child.Delete();
                }
                else
                {
                    if (RSSPlugin.GetInstance() != null)
                    {
                        RSSPlugin.GetInstance().QueueFeedUpdate(child);
                    }
                    count++;
                }
            }
            return(count);
        }
Exemplo n.º 3
0
        private void ProcessUrlDrop(IResource targetResource, IDataObject data, string format, Encoding encoding)
        {
            Stream dataStream = (Stream)data.GetData(format);

            if (dataStream != null)
            {
                string url = Utils.StreamToString(dataStream, encoding);
                RSSPlugin.GetInstance().ShowAddFeedWizard(url, targetResource);
            }
        }
Exemplo n.º 4
0
        internal void ExecuteOperation()
        {
            IResource rootGroup = _importRoot;

            if (_importPreview)
            {
                _previewRoot = Core.ResourceStore.NewResource("RSSFeedGroup");
                rootGroup    = _previewRoot;
            }

            bool hasOPML = true;

            try
            {
                hasOPML = OPMLProcessor.Import(new StreamReader(_importStream), rootGroup, !_importPreview);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Core.MainWindow,
                                "Error importing OPML file " + _importFileName + ":\n" + ex.Message,
                                "Import OPML", MessageBoxButtons.OK);
                // the import may have been partially successful, and we still want to
                // update the feeds that were imported successfully
            }

            if (!hasOPML)
            {
                MessageBox.Show(Core.MainWindow,
                                _importFileName + " is not an OPML file", "Import OPML", MessageBoxButtons.OK);
                return;
            }

            if (_importPreview)
            {
                if (_previewRoot.GetLinksOfType(null, "Parent").Count > 0)
                {
                    Core.UIManager.QueueUIJob(new MethodInvoker(ShowImportPreviewDialog));
                }
                else
                {
                    _previewRoot.Delete();
                }
            }
            else
            {
                foreach (IResource feed in Core.ResourceStore.GetAllResources("RSSFeed"))
                {
                    if (!feed.HasProp(Props.LastUpdateTime) && !feed.HasProp(Props.ItemCommentFeed))
                    {
                        RSSPlugin.GetInstance().QueueFeedUpdate(feed);
                    }
                }
            }
        }
Exemplo n.º 5
0
 internal OPMLImporter(ImportManager manager, IResource importRoot)
 {
     if (manager == null)
     {
         RSSPlugin.GetInstance().RegisterFeedImporter("OPML Files", this);
     }
     else
     {
         _manager    = manager;
         _importRoot = importRoot;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Import subscription
        /// </summary>
        public void DoImport(IResource importRoot, bool addToWorkspace)
        {
            if (_login.Length == 0 || _password.Length == 0)
            {
                return;
            }
            RSSPlugin plugin   = RSSPlugin.GetInstance();
            string    authInfo = Convert.ToBase64String(Encoding.ASCII.GetBytes(_login + ":" + _password));

            ImportUtils.UpdateProgress(0, _progressMessage);

            importRoot = plugin.FindOrCreateGroup("Bloglines Subscriptions", importRoot);

            ImportUtils.UpdateProgress(10, _progressMessage);

            WebClient client = new WebClient();

            client.Headers.Add("Authorization", "basic " + authInfo);

            ImportUtils.UpdateProgress(20, _progressMessage);

            try
            {
                Stream stream = client.OpenRead(_ImportURL);
                ImportUtils.UpdateProgress(30, _progressMessage);
                OPMLProcessor.Import(new StreamReader(stream), importRoot, addToWorkspace);
                ImportUtils.UpdateProgress(90, _progressMessage);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("BlogLines subscrption load failed: '" + ex.Message + "'");
                RemoveFeedsAndGroupsAction.DeleteFeedGroup(importRoot);

                string message = "Import of BlogLines subscription failed:\n" + ex.Message;
                if (ex is WebException)
                {
                    WebException e = (WebException)ex;
                    if (e.Status == WebExceptionStatus.ProtocolError &&
                        ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.Unauthorized)
                    {
                        message = "Import of BlogLines subscription failed:\nInvalid login or password.";
                    }
                }
                ImportUtils.ReportError("BlogLines Subscription Import", message);
            }
            ImportUtils.UpdateProgress(100, _progressMessage);
            return;
        }
Exemplo n.º 7
0
        private void OnSaveFeedImpl()
        {
            foreach (IResource feed in _feeds)
            {
                feed.BeginUpdate();
            }
            if (!_chkAuthentication.Checked)
            {
                _edtUserName.Text = string.Empty;
                _edtPassword.Text = string.Empty;
            }

            _needUpdate = _needUpdate || _udUpdateFrequency.Changed || _cmbUpdatePeriod.Changed;

            if (!_chkUpdate.Checked)
            {
                _cmbUpdatePeriod.SetValue("daily");
                _cmbUpdatePeriod.Changed   = true;
                _udUpdateFrequency.Minimum = -1;
                _udUpdateFrequency.SetValue(-1);
                _udUpdateFrequency.Changed = true;
            }

            SettingSaver.Save(Controls);
            if (_feeds.Count == 1)
            {
                _feed.SetProp(Props.URL, _edtAddress.Text);
                _feed.SetProp(Core.Props.Name, _edtTitle.Text);
                _feed.SetProp(Core.Props.Annotation, _edtAnnotation.Text);
            }

            foreach (IResource feed in _feeds)
            {
                feed.EndUpdate();
            }

            if (_needUpdate)
            {
                foreach (IResource feed in _feeds)
                {
                    RSSPlugin.GetInstance().QueueFeedUpdate(feed);
                }
            }
        }
Exemplo n.º 8
0
        internal static void DoConfirmImport(IResource previewRoot, IResource importRoot)
        {
            foreach (IResource res in previewRoot.GetLinksTo(null, Core.Props.Parent))
            {
                if (res.Type == "RSSFeedGroup")
                {
                    int count = ConfirmImportRecursive(res);
                    if (count == 0)
                    {
                        res.Delete();
                        continue;
                    }
                    if (RelinkExistingGroup(res, importRoot))
                    {
                        continue;
                    }
                    Core.WorkspaceManager.AddToActiveWorkspaceRecursive(res);
                }

                if (res.Type == "RSSFeed" && res.GetIntProp(Props.Transient) == 1)
                {
                    // Delete all items
                    IResourceList items = res.GetLinksOfType("RSSItem", Props.RSSItem);
                    items.DeleteAll();
                    res.Delete();
                }
                else
                {
                    res.DeleteProp(Props.Transient);
                    res.SetProp(Core.Props.Parent, importRoot);
                    if (res.Type == "RSSFeed")
                    {
                        Core.WorkspaceManager.AddToActiveWorkspace(res);
                        if (RSSPlugin.GetInstance() != null)
                        {
                            RSSPlugin.GetInstance().QueueFeedUpdate(res);
                        }
                    }
                }
            }
            previewRoot.Delete();
        }
Exemplo n.º 9
0
        public FeedDemonImporter()
        {
            bool   FeedDemonFound = true;
            string basePath       = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string daemonPath     = Path.Combine(basePath, @"Bradsoft.com\FeedDemon\1.0");

            _channelsPath = Path.Combine(daemonPath, "Channels");
            _groupsPath   = Path.Combine(daemonPath, "Groups");

            FeedDemonFound = Directory.Exists(_channelsPath) && Directory.Exists(_groupsPath);

            if (!FeedDemonFound)
            {
                // don't build additional data structures
                return;
            }

            RSSPlugin.GetInstance().RegisterFeedImporter("FeedDemon", this);
            _flag = Core.ResourceStore.FindUniqueResource("Flag", "FlagId", "RedFlag");
        }
Exemplo n.º 10
0
 internal BloglinesImporter()
 {
     RSSPlugin.GetInstance().RegisterFeedImporter("Bloglines", this);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Import subscription
        /// </summary>
        public void DoImport(IResource importRoot, bool addToWorkspace)
        {
            if (null == FileNames)
            {
                return;
            }

            int totalFeeds     = Math.Max(FileNames.Length, 1);
            int processedFeeds = 0;

            ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessage);
            IResource currentRoot = null;

            foreach (string fileName in FileNames)
            {
                string defaultName = null;
                Stream opml        = null;

                if (!File.Exists(fileName))
                {
                    defaultName = fileName;
                    // Try to load as URL
                    try
                    {
                        opml = new JetMemoryStream(new WebClient().DownloadData(fileName), true);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine("OPML file '" + fileName + "' can not be load: '" + ex.Message + "'");
                        opml = null;
                    }
                }
                else
                {
                    defaultName = Path.GetFileName(fileName);
                    // Try to load title from this file
                    try
                    {
                        opml = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine("OPML file '" + fileName + "' can not be load: '" + ex.Message + "'");
                        opml = null;
                    }
                }

                if (null == opml)
                {
                    continue;
                }

                // Try to get name
                string name = null;
                try
                {
                    XmlDocument xml = new XmlDocument();
                    xml.Load(opml);
                    XmlElement title = xml.SelectSingleNode("/opml/head/title") as XmlElement;
                    name = title.InnerText;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("OPML file '" + fileName + "' doesn't have title: '" + ex.Message + "'");
                }
                if (name == null || name.Length == 0)
                {
                    name = defaultName;
                }

                try
                {
                    opml.Seek(0, SeekOrigin.Begin);
                    if (_manager == null || FileNames.Length > 1)
                    {
                        currentRoot = RSSPlugin.GetInstance().FindOrCreateGroup("Subscription from " + name, importRoot);
                    }
                    else
                    {
                        currentRoot = importRoot;
                    }
                    OPMLProcessor.Import(new StreamReader(opml), currentRoot, addToWorkspace);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("OPML file '" + fileName + "' can not be load: '" + ex.Message + "'");
                    RemoveFeedsAndGroupsAction.DeleteFeedGroup(currentRoot);
                    ImportUtils.ReportError("OPML File Import", "Import of OPML file '" + fileName + "' failed:\n" + ex.Message);
                }

                processedFeeds += 100;
                ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessage);
            }
            return;
        }
Exemplo n.º 12
0
        public override void DisplayResource(IResource rssItem, WordPtr[] wordsToHighlight)
        {
            string subject = rssItem.GetPropText(Core.Props.Subject);

            ShowSubject(subject, wordsToHighlight);

            IResource feed = rssItem.GetLinkProp(-Props.RSSItem);

            if (feed != null && feed.HasProp(Props.AutoFollowLink) && rssItem.GetPropText(Props.Link).Length > 0)
            {
                AttachWebBrowser();
                Core.WebBrowser.NavigateInPlace(rssItem.GetPropText(Props.Link));
            }
            else
            {
                StringBuilderDecor decor = new StringBuilderDecor("<html>");
                decor.AppendText(GetItemStyle());
                decor.AppendText(Core.MessageFormatter.StandardStyledHeader(subject));

                string body = rssItem.GetPropText(Core.Props.LongBody);
                if (_showSummary)
                {
                    RssBodyConstructor.ConstructSummary(rssItem, SummaryStyle, body, decor);
                }

                //-------------------------------------------------------------
                // Update the search results offsets
                //-------------------------------------------------------------
                if (wordsToHighlight != null)
                {
                    int inc = decor.ToString().Length;  // Prepended length

                    for (int a = 0; a < wordsToHighlight.Length; a++)
                    {
                        wordsToHighlight[a].StartOffset += inc;
                    }
                }

                ProcessBody(decor, body, rssItem);

                //-------------------------------------------------------------
                if (!_useDetailedURLs)
                {
                    RssBodyConstructor.AppendLink(rssItem, decor, cLinkAlias);
                }
                else
                {
                    RssBodyConstructor.AppendLink(rssItem, decor);
                }

                RssBodyConstructor.AppendRelatedPosts(rssItem, decor, _useDetailedURLs);
                RssBodyConstructor.AppendEnclosure(rssItem, decor);
                RssBodyConstructor.AppendSourceTag(rssItem, decor);
                RssBodyConstructor.AppendCommentsTag(rssItem, decor);
                decor.AppendText("</body></html>");
                ShowHtml(decor.ToString(), _ctxRestricted, wordsToHighlight);
            }

            IResourceList feeds = rssItem.GetLinksOfType(Props.RSSFeedResource, Props.RSSItem);
            IResource     owner = Core.ResourceBrowser.OwnerResource;

            if ((owner != null && owner.Type == Props.RSSFeedGroupResource) ||
                (feeds.Count > 0 && owner == feeds [0]))
            {
                RSSPlugin.GetInstance().RememberSelection(owner, rssItem);
            }
        }
Exemplo n.º 13
0
        private void OnFinishClick()
        {
            Trace.WriteLine("SubscribeToSearchFeeds -- OnFinishClick.");
            _nextButton.Enabled = false;
            if (_feedsToSubscribe == null)
            {
                throw new InvalidOperationException("Trying to finish wizard with unknown feeds to subscribe");
            }
            if (_feedsToSubscribe.Length == 0)
            {
                DoCancel();
                Close();
                return;
            }
            if (_feedsToSubscribe.Length == 1 &&
                RSSPlugin.GetExistingFeed(_feedsToSubscribe [0].Resource.GetStringProp(Props.URL)) != null)
            {
                MessageBox.Show(this, "You have already subscribed to this feed.",
                                "Subscribe to Feed");
                DoCancel();
                return;
            }

            IResource parentGroup = _titleGroupPane.SelectedGroup;

            if (parentGroup == null)
            {
                parentGroup = RSSPlugin.RootFeedGroup;
            }

            Trace.WriteLine("SubscribeToSearchFeeds -- Starting to link feeds to parent.");
            foreach (ResourceProxy proxy in _feedsToSubscribe)
            {
                if (proxy == _newFeedProxy)
                {
                    _newFeedProxy = null;
                }
                proxy.BeginUpdate();
                try
                {
                    if (_feedsToSubscribe.Length == 1)
                    {
                        proxy.SetProp(Core.Props.Name, _titleGroupPane.FeedTitle);
                    }
                    proxy.DeleteProp(Props.Transient);
                    proxy.SetProp(Core.Props.Parent, parentGroup);
                    Trace.WriteLine("SubscribeToSearchFeeds -- Link feed to parent [" + parentGroup.DisplayName + "]");
                }
                finally
                {
                    proxy.EndUpdate();
                    Trace.WriteLine("SubscribeToSearchFeeds -- EndUpdate called for a feed");
                }
                Core.WorkspaceManager.AddToActiveWorkspace(proxy.Resource);
                Trace.WriteLine("SubscribeToSearchFeeds -- AddToActiveWorkspace called for a feed.");
                RSSPlugin.GetInstance().QueueFeedUpdate(proxy.Resource);
                Trace.WriteLine("SubscribeToSearchFeeds -- QueueFeedUpdate called for a feed.");
            }

            Core.UIManager.BeginUpdateSidebar();
            if (Core.TabManager.ActivateTab("Feeds"))
            {
                Core.LeftSidebar.ActivateViewPane("Feeds");
            }
            Core.UIManager.EndUpdateSidebar();
            RSSPlugin.RSSTreePane.SelectResource(_feedsToSubscribe [0].Resource);
            RSSPlugin.SaveSubscription();

            _newFeedProxy     = null;
            _feedsToSubscribe = null;
            Close();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Import subscription
        /// </summary>
        public void DoImport(IResource importRoot, bool addToWorkspace)
        {
            RSSPlugin plugin = RSSPlugin.GetInstance();

            importRoot = plugin.FindOrCreateGroup("FeedDemon subscriptions", importRoot);

            // Count full count of resources
            string[] allFiles = Directory.GetFiles(_groupsPath, "*.opml");

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

            ImportUtils.UpdateProgress(processedFiles / totalFiles, _progressMessage);
            foreach (string file in allFiles)
            {
                IResource group = null;
                string    name  = Path.GetFileNameWithoutExtension(file);
                group = plugin.FindOrCreateGroup(name, importRoot);

                try
                {
                    Hashtable ns     = new Hashtable();
                    Stream    stream = new FileStream(file, FileMode.Open, FileAccess.Read);

                    // Fix bugs in OPML
                    ns["fd"] = _fdNS;
                    OPMLProcessor.Import(new StreamReader(stream), group, addToWorkspace, ns);
                }
                catch (Exception ex)
                {
                    RemoveFeedsAndGroupsAction.DeleteFeedGroup(group);
                    ImportUtils.ReportError("FeedDemon Subscription Import", "Import of FeedDemon group '" + name + "' failed:\n" + ex.Message);
                }

                processedFiles += 100;
                ImportUtils.UpdateProgress(processedFiles / totalFiles, _progressMessage);
            }

            // Read summary.xml
            string summary = Path.Combine(_channelsPath, "summary.xml");

            if (File.Exists(summary))
            {
                try
                {
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.Load(summary);
                    foreach (XmlElement channel in xdoc.GetElementsByTagName("channel"))
                    {
                        string      title = null;
                        string      url   = null;
                        XmlNodeList l     = null;

                        l = channel.GetElementsByTagName("title");
                        if (l.Count < 1)
                        {
                            continue;
                        }
                        title = l[0].InnerText;

                        l = channel.GetElementsByTagName("newsFeed");
                        if (l.Count < 1)
                        {
                            continue;
                        }
                        url = l[0].InnerText;
                        _name2url.Add(title, url);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("FeedDemon subscrption load failed: '" + ex.Message + "'");
                }
            }
            return;
        }
Exemplo n.º 15
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);
        }