/// <summary>Makes all RssWatchers start watching each URL.</summary> public void Start() { if (_status.Equals(Status.Activated)) { return; } #if ZEPTAIR Zeptair.Lib.Common.ConfParam zeptConf = TaskMain.Instance.ZeptConf(false); bool hasValidZeptLicKey = TaskMain.Instance.HasValidZeptLicKey; #endif _mutex.WaitOne(); foreach (RssWatcher watcher in _watchers) { #if ZEPTAIR if (watcher.TargetInfo.IsZeptDist && (!hasValidZeptLicKey || !zeptConf.AcceptCmd)) { continue; } #endif watcher.Start(); } _mutex.ReleaseMutex(); _status = Status.Activated; }
/// <summary>Restarts Zeptair Dist. watchers.</summary> public void RestartZeptDist() { Zeptair.Lib.Common.ConfParam zeptConf = TaskMain.Instance.ZeptConf(false); _mutex.WaitOne(); foreach (RssWatcher watcher in _watchers) { if (!watcher.TargetInfo.IsZeptDist) { continue; } watcher.Stop(); if (zeptConf.AcceptCmd) { watcher.Start(); } } _mutex.ReleaseMutex(); }
/// <summary>Does read the target URL.</summary> /// <param name="state"></param> public void DoRead(Object state) { _mutex.WaitOne(); if (!_activated) { _mutex.ReleaseMutex(); return; } Log.AddInfo(@"RssWatcher.DoRead() : " + this._targetInfo.Title); string url = _targetInfo.Url; #if ZEPTAIR if (_targetInfo.IsZeptDist) { Zeptair.Lib.Common.ConfParam zeptConf = TaskMain.Instance.ZeptConf(false); if (zeptConf.SpecifyAdminNames && zeptConf.AdminNames != null && zeptConf.AdminNames.Length > 0) { if (url.IndexOf('?') >= 0) { url += @"&"; } else { url += @"?"; } url += @"admins=" + zeptConf.AdminNames; } } #endif RssFeed feed = null; try { ServicePointManager.ServerCertificateValidationCallback = ThetisCore.Lib.EasyTrustPolicy.CheckValidationResult; HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url); if (_targetInfo.UserName != null && _targetInfo.UserName.Length > 0) { webReq.Credentials = new NetworkCredential(_targetInfo.UserName, _targetInfo.Password); } if (_lastFeed == null) { feed = RssFeed.Read(webReq); } else { feed = RssFeed.Read(webReq, _lastFeed); } _lastFeed = feed; } catch (WebException we) { Log.AddError(" " + we.Message + "\n" + we.StackTrace); } if (feed != null && !feed.Cached) { bool modified = false; ArrayList postArray = new ArrayList(); if (_feedHistory == null) { _feedHistory = feed; foreach (RssChannel channel in feed.Channels) { foreach (RssItem item in channel.Items) { postArray.Add(InfoItem.Create(item, channel.Title, _targetInfo)); } } modified = true; } else { foreach (RssChannel channel in feed.Channels) { int historyIdx = RssHelper.IndexOf(_feedHistory.Channels, channel); if (historyIdx < 0) { _feedHistory.Channels.Add(channel); foreach (RssItem item in channel.Items) { postArray.Add(InfoItem.Create(item, channel.Title, _targetInfo)); } modified = true; } else { RssItemCollection historyItems = _feedHistory.Channels[historyIdx].Items; foreach (RssItem item in channel.Items) { if (!RssHelper.Contains(historyItems, item)) { historyItems.Add(item); postArray.Add(InfoItem.Create(item, channel.Title, _targetInfo)); modified = true; } } } } } if (modified) { _feedHistory.LastModified = feed.LastModified; _targetInfo.SaveFeedHistory(_feedHistory); _manager.PostItems(postArray, _targetInfo); postArray.Clear(); } postArray = null; } _mutex.ReleaseMutex(); }