/// <summary>Creates a RSS Watcher for the specified RSS target.</summary> /// <param name="info">Target Information.</param> /// <returns>true if succeeded, false otherwise.</returns> public bool AddWatcher(RssTargetInfo info) { foreach (RssWatcher watcher in _watchers) { if (watcher.TargetInfo.Url.Equals(info.Url)) { return(false); } } _mutex.WaitOne(); RssWatcher newWatcher = new RssWatcher(this, info); _watchers.Add(newWatcher); if (_status.Equals(Status.Activated)) { newWatcher.Start(); } _mutex.ReleaseMutex(); info.Save(); return(true); }
/// <summary>Deletes completely specified Information Items.</summary> /// <param name="generatorId">Generator ID to find RssTargetInfo.</param> /// <param name="itemIds">Array of IDs of the Information Items.</param> public void RestoreTrash(string generatorId, int[] itemIds) { RssTargetInfo[] targetInfos = TaskMain.Instance.RssManager.TargetInfos; RssTargetInfo targetInfo = RssTargetInfo.FindGenerator(targetInfos, generatorId); if (targetInfo != null) { targetInfo.TrashBox.Restore(itemIds); } }
/// <summary>Restore specified Information Items.</summary> /// <param name="itemIds">Array of IDs of the Information Items.</param> public void Restore(IEnumerable itemIds) { if (itemIds == null) { return; } this.Load(); ArrayList items = new ArrayList(); foreach (int itemId in itemIds) { foreach (InfoItem refItem in _infoItems) { if (itemId == refItem.Id) { items.Add(refItem); _infoItems.Remove(refItem); break; } } } if (items.Count <= 0) { return; } XmlSerializer writer = new XmlSerializer(typeof(InfoItem[])); using (StreamWriter file = new StreamWriter(_path)) { InfoItem[] array = new InfoItem[_infoItems.Count]; _infoItems.CopyTo(array); writer.Serialize(file, array); } RssTargetInfo[] targetInfos = TaskMain.Instance.RssManager.TargetInfos; RssTargetInfo targetInfo = RssTargetInfo.FindGenerator(targetInfos, ((InfoItem)items[0]).GeneratorId); #if ZEPTAIR if (targetInfo.IsZeptDist) { TaskMain.Instance.ZeptDistManager.PostItems(items, true); } else #endif TaskMain.Instance.InfoManager.PostItems(items, true); }
/// <summary>Posts new items to the Information Manager.</summary> /// <param name="items">Array of the Information Items to post.</param> /// <param name="targetInfo">Target Information.</param> public void PostItems(ArrayList items, RssTargetInfo targetInfo) { if (items == null || items.Count <= 0) { return; } #if ZEPTAIR if (targetInfo.IsZeptDist) { TaskMain.Instance.ZeptDistManager.PostItems(items, true); } else #endif TaskMain.Instance.InfoManager.PostItems(items, true); }
/// <summary>Removes the specified Information Items.</summary> /// <param name="itemIds">Array of IDs of the Information Items.</param> /// <param name="bLoadSave">Flag to Load and Save the file.</param> public void RemoveItems(int[] itemIds, bool bLoadSave) { if (bLoadSave) { _Load(); } if (itemIds == null || itemIds.Length <= 0) { return; } RssTargetInfo[] targetInfos = TaskMain.Instance.RssManager.TargetInfos; foreach (int id in itemIds) { InfoItem item = null; foreach (InfoItem elem in _infoItems) { if (elem.Id == id) { item = elem; break; } } if (item == null) { continue; } _infoItems.Remove(item); RssTargetInfo targetInfo = RssTargetInfo.FindGenerator(targetInfos, item.GeneratorId); if (targetInfo != null) { targetInfo.TrashBox.Push(new InfoItem[1] { item }); } } if (bLoadSave) { _Save(); } }
/// <summary>Loads RssWatchers.</summary> /// <returns>true if succeeded, false otherwise.</returns> public bool LoadWatchers() { _watchers.Clear(); ArrayList targetInfos = RssTargetInfo.Load(); if (targetInfos == null || targetInfos.Count <= 0) { return(false); } _mutex.WaitOne(); foreach (RssTargetInfo targetInfo in targetInfos) { RssWatcher watcher = new RssWatcher(this, targetInfo); _watchers.Add(watcher); } _mutex.ReleaseMutex(); return(true); }
/// <summary>Constructor.</summary> /// <param name="info">Target Information.</param> public RssWatcher(RssManager manager, RssTargetInfo targetInfo) { _manager = manager; _targetInfo = targetInfo; _feedHistory = _targetInfo.LoadFeedHistory(); }