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); } } } }
/// <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; }
/// <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; }
/// <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; }