Example #1
0
 internal void DoCancel()
 {
     if (_importRoot != null)
     {
         RemoveFeedsAndGroupsAction.DeleteFeedGroup(_importRoot);
         _importRoot = null;
     }
 }
Example #2
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;
        }
Example #3
0
        /// <summary>
        /// Import subscription
        /// </summary>
        public void DoImport(IResource importRoot, bool addToWorkspace)
        {
            importRoot = _plugin.FindOrCreateGroup("SharpReader subscriptions", importRoot);
            // We will add info about imported feeds here
            _importedFeeds = new ArrayList();

            ImportUtils.UpdateProgress(0, _progressMessage);
            // Start to import feeds structure
            XmlDocument feedlist = new XmlDocument();

            try
            {
                feedlist.Load(_subscriptionPath);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("SharpReader subscrption load failed: '" + ex.Message + "'");
                RemoveFeedsAndGroupsAction.DeleteFeedGroup(importRoot);
                ImportUtils.ReportError("SharpReader Subscription Import", "Import of SharpReader subscription failed:\n" + ex.Message);
                return;
            }

            ImportUtils.FeedUpdateData defaultUpdatePeriod;
            XmlAttribute period = feedlist.SelectSingleNode("/feeds/@refreshMinutes") as XmlAttribute;

            if (period != null)
            {
                defaultUpdatePeriod = ImportUtils.ConvertUpdatePeriod(period.Value, 1);
            }
            else
            {
                defaultUpdatePeriod = ImportUtils.ConvertUpdatePeriod("", 1);
            }

            ImportUtils.UpdateProgress(10, _progressMessage);
            XmlElement root = (XmlElement)feedlist.SelectSingleNode("/feeds");

            ImportGroup(root, importRoot, defaultUpdatePeriod, addToWorkspace);
            ImportUtils.UpdateProgress(100, _progressMessage);
            return;
        }
Example #4
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;
        }
Example #5
0
        /// <summary>
        /// Import subscription
        /// </summary>
        public void DoImport(IResource importRoot, bool addToWorkspace)
        {
            IResource feedRes = null;

            importRoot = _plugin.FindOrCreateGroup("RssBandit subscriptions", importRoot);

            // We will add info about imported feeds here
            _importedFeeds = new ArrayList();

            ImportUtils.UpdateProgress(0, _progressMessage);
            // Start to import feeds structure
            XmlDocument feedlist = new XmlDocument();

            try
            {
                feedlist.Load(_subscriptionPath);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("RssBandit subscrption load failed: '" + ex.Message + "'");
                RemoveFeedsAndGroupsAction.DeleteFeedGroup(importRoot);
                ImportUtils.ReportError("RSS Bandit Subscription Import", "Import of RSS Bandit subscription failed:\n" + ex.Message);
                return;
            }

            ImportUtils.FeedUpdateData defaultUpdatePeriod;
            XmlAttribute period = feedlist.SelectSingleNode("/feeds/@refresh-rate") as XmlAttribute;

            if (period != null)
            {
                defaultUpdatePeriod = ImportUtils.ConvertUpdatePeriod(period.Value, 60000);
            }
            else
            {
                defaultUpdatePeriod = ImportUtils.ConvertUpdatePeriod("", 60000);
            }

            XmlNodeList feeds = feedlist.GetElementsByTagName("feed");

            int totalFeeds     = Math.Max(feeds.Count, 1);
            int processedFeeds = 0;

            ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessage);
            foreach (XmlElement feed in feeds)
            {
                string s = ImportUtils.GetUniqueChildText(feed, "link");

                if (s == null)
                {
                    continue;
                }
                // May be, we are already subscribed?
                if (Core.ResourceStore.FindUniqueResource("RSSFeed", "URL", s) != null)
                {
                    continue;
                }

                FeedInfo info = new FeedInfo();
                info.url = s;

                IResource group = AddCategory(importRoot, feed.GetAttribute("category"));
                // Ok, now we should create feed
                feedRes = Core.ResourceStore.NewResource("RSSFeed");
                feedRes.BeginUpdate();
                feedRes.SetProp("URL", s);

                s = ImportUtils.GetUniqueChildText(feed, "title");
                ImportUtils.Child2Prop(feed, "title", feedRes, Core.Props.Name, Props.OriginalName);

                ImportUtils.Child2Prop(feed, "etag", feedRes, Props.ETag);

                s = ImportUtils.GetUniqueChildText(feed, "last-retrieved");
                if (s != null)
                {
                    DateTime dt = DateTime.Parse(s);
                    feedRes.SetProp("LastUpdateTime", dt);
                }

                // Peridoically
                ImportUtils.FeedUpdateData upd;
                s = ImportUtils.GetUniqueChildText(feed, "refresh-rate");
                if (s != null)
                {
                    upd = ImportUtils.ConvertUpdatePeriod(s, 60000);
                }
                else
                {
                    upd = defaultUpdatePeriod;
                }
                feedRes.SetProp("UpdatePeriod", upd.period);
                feedRes.SetProp("UpdateFrequency", upd.freq);

                // Cached?
                s = ImportUtils.GetUniqueChildText(feed, "cacheurl");
                if (s != null)
                {
                    info.cacheFile = s;
                }
                else
                {
                    info.cacheFile = null;
                }

                // Login & Password
                ImportUtils.Child2Prop(feed, "auth-user", feedRes, Props.HttpUserName);
                s = ImportUtils.GetUniqueChildText(feed, "auth-password");
                if (s != null)
                {
                    feedRes.SetProp(Props.HttpPassword, DecryptPassword(s));
                }

                // Enclosures
                ImportUtils.Child2Prop(feed, "enclosure-folder", feedRes, Props.EnclosurePath);

                // Try to load "read" list
                XmlElement read = ImportUtils.GetUniqueChild(feed, "stories-recently-viewed");
                if (read != null)
                {
                    ArrayList list = new ArrayList();
                    foreach (XmlElement story in read.GetElementsByTagName("story"))
                    {
                        list.Add(story.InnerText);
                    }
                    if (list.Count > 0)
                    {
                        info.readItems = list;
                    }
                    else
                    {
                        info.readItems = null;
                    }
                }
                // Feed is ready
                feedRes.AddLink(Core.Props.Parent, group);
                feedRes.EndUpdate();
                info.feed = feedRes;
                _importedFeeds.Add(info);
                if (addToWorkspace)
                {
                    Core.WorkspaceManager.AddToActiveWorkspace(feedRes);
                }

                processedFeeds += 100;
                ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessage);
            }
            return;
        }
Example #6
0
 private void CancelImport()
 {
     RemoveFeedsAndGroupsAction.DeleteFeedGroup(_previewRoot);
 }
Example #7
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;
        }