/// <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; }
private void ImportGroup(XmlElement root, IResource rootGroup, ImportUtils.FeedUpdateData defaultUpdatePeriod, bool addToWorkspace) { // Import all groups XmlNodeList l = root.SelectNodes("RssFeedsCategory"); if (l != null) { foreach (XmlElement group in l) { string name = group.GetAttribute("name"); if (name == null) { name = "Unknown group"; } IResource iGroup = _plugin.FindOrCreateGroup(name, rootGroup); ImportGroup(group, iGroup, defaultUpdatePeriod, addToWorkspace); } } // Import all elements IResource feedRes = null; l = root.SelectNodes("RssFeed"); if (l != null) { foreach (XmlElement feed in l) { string s = feed.GetAttribute("url"); 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; // Ok, now we should create feed feedRes = Core.ResourceStore.NewResource("RSSFeed"); feedRes.BeginUpdate(); feedRes.SetProp("URL", s); ImportUtils.Attrib2Prop(feed, "name", feedRes, Core.Props.Name, Props.OriginalName); ImportUtils.Attrib2Prop(feed, "etag", feedRes, Props.ETag); ImportUtils.Attrib2Prop(feed, "authUserName", feedRes, Props.HttpUserName); s = feed.GetAttribute("authPassword"); if (s != null) { string sharpReaderPassword = "******"; MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider(); TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider(); DES.Key = MD5.ComputeHash(Encoding.ASCII.GetBytes(sharpReaderPassword)); DES.Mode = CipherMode.ECB; byte[] DESed = Convert.FromBase64String(s); byte[] DeDESed = DES.CreateDecryptor().TransformFinalBlock(DESed, 0, DESed.Length); // Huuray! feedRes.SetProp(Props.HttpPassword, Encoding.Unicode.GetString(DeDESed)); } s = feed.GetAttribute("lastRefresh"); if (s != null) { DateTime dt = DateTime.Parse(s); feedRes.SetProp(Props.LastUpdateTime, dt); } // Peridoically ImportUtils.FeedUpdateData upd; s = feed.GetAttribute("refreshMinutes"); if (s != null) { upd = ImportUtils.ConvertUpdatePeriod(s, 1); } else { upd = defaultUpdatePeriod; } feedRes.SetProp(Props.UpdatePeriod, upd.period); feedRes.SetProp(Props.UpdateFrequency, upd.freq); // Cached? info.cacheFile = GetCacheNameByURL(info.url); // Feed is ready feedRes.AddLink(Core.Props.Parent, rootGroup); feedRes.EndUpdate(); info.feed = feedRes; _importedFeeds.Add(info); if (addToWorkspace) { Core.WorkspaceManager.AddToActiveWorkspace(feedRes); } } } }
/// <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; }