protected override void MarkItemUnread(INewsItem item) { if (item == null) { return; } int idx = itemsFeed.Items.IndexOf(item); if (idx < 0) { itemsFeed.Items.Add(item); } else { // should not happen, just if we get called this way: (itemsFeed.Items[idx]).BeenRead = false; } if (HasNodes) { // child handle this: FeedSourceEntry entry = app.FeedSources.SourceOf(item.Feed); UnreadItemsNodePerSource child; if (childrenBySourceID.TryGetValue(entry.ID, out child)) { child.UpdateReadStatus(child, 1); } } else { // handle by myself: UpdateReadStatus(this, 1); } }
internal int IndexNewsItems(IList <INewsItem> newsItems) { if (newsItems != null) { for (int i = 0; i < newsItems.Count; i++) { INewsItem item = newsItems[i]; if (item != null) { try { // we do not always have the content loaded: if (item.ContentType == ContentType.None && item.Feed != null && item.Feed.owner != null) { if (item.Feed.owner != null) { FeedSource handler = (FeedSource)item.Feed.owner; handler.GetCachedContentForItem(item); } } indexModifier.Add(LuceneNewsItemSearch.Document(item), item.Language); } catch (Exception ex) { Log.Error("IndexNewsItems() error", ex); } } } return(newsItems.Count); } return(0); }
protected override void MarkItemRead(INewsItem item) { if (item == null) { return; } int idx = itemsFeed.Items.IndexOf(item); if (idx >= 0) { itemsFeed.Items.RemoveAt(idx); if (HasNodes) { // child handle this: FeedSourceEntry entry = app.FeedSources.SourceOf(item.Feed); UnreadItemsNodePerSource child; if (childrenBySourceID.TryGetValue(entry.ID, out child)) { child.UpdateReadStatus(child, -1); } } else { // handle by myself: UpdateReadStatus(this, -1); } } }
/// <summary> /// Adds the or replace the optional feed reference element. /// </summary> /// <param name="newsItem">The news item.</param> /// <param name="feedUrl">The feed URL.</param> /// <param name="sourceID">The source ID.</param> /// <returns></returns> public static XmlElement AddOrReplaceOriginalFeedReference(INewsItem newsItem, string feedUrl, int sourceID) { if (newsItem == null) { throw new ArgumentNullException("newsItem"); } XmlQualifiedName key = AdditionalElements.GetQualifiedName(OriginalFeedRef); XmlQualifiedName attrKey = AdditionalElements.GetQualifiedName(OriginalSourceID); if (newsItem.OptionalElements == null) { newsItem.OptionalElements = new Dictionary <XmlQualifiedName, string>(2); } if (newsItem.OptionalElements.ContainsKey(key)) { newsItem.OptionalElements.Remove(key); } XmlElement element = RssHelper.CreateXmlElement(Prefix, key, feedUrl); element.Attributes.Append(RssHelper.CreateXmlAttribute(String.Empty, attrKey, sourceID.ToString())); newsItem.OptionalElements.Add(key, element.OuterXml); return(element); }
/// <summary> /// Posts a comment to a newsgroup using NNTP /// </summary> /// <param name="item2post">An NNTP item that will be posted to the website</param> /// <param name="postTarget">An feed that is the post target</param> /// <param name="credentials">Credentials to use</param> /// <returns>The NNTP Status code returned</returns> /// <exception cref="WebException">If an error occurs when the POSTing the /// comment</exception> public static void PostCommentViaNntp(INewsItem item2post, INewsFeed postTarget, ICredentials credentials) { string comment = item2post.ToString(NewsItemSerializationFormat.NntpMessage); Encoding enc = Encoding.UTF8, unicode = Encoding.Unicode; byte[] encBytes = Encoding.Convert(unicode, enc, unicode.GetBytes(comment)); //enc.GetBytes(comment); enough ??? NntpWebRequest request = (NntpWebRequest)WebRequest.Create(postTarget.link); request.Method = "POST"; if (credentials != null) { request.Credentials = credentials; } Stream myWriter = null; try{ myWriter = request.GetRequestStream(); myWriter.Write(encBytes, 0, encBytes.Length); request.GetResponse(); } catch (Exception e) { throw new WebException(e.Message, e); }finally{ if (myWriter != null) { myWriter.Close(); } } }
/// <summary> /// interface impl. ISearchCriteria /// </summary> /// <param name="item"></param> /// <returns></returns> public override bool Match(INewsItem item) { // compare dates only int itemDate = item.Date.DateToInteger(); return(itemDate > lowDateOnly && itemDate < highDateOnly); }
/// <summary> /// Removes the entries for the specified feed URL. /// </summary> /// <param name="entry">The entry.</param> /// <param name="feedUrl">The feed URL.</param> public void RemoveFeed(FeedSourceEntry entry, string feedUrl) { if (string.IsNullOrEmpty(feedUrl) || feedInfo.ItemsList.Count == 0) { return; } Stack removeAtIndex = new Stack(); for (int i = 0; i < feedInfo.ItemsList.Count; i++) { INewsItem n = feedInfo.ItemsList[i]; if (n != null) { int sourceId; string feedUrlRef = OptionalItemElement.GetOriginalFeedReference(n, out sourceId); if (!String.IsNullOrEmpty(feedUrlRef) && sourceId == entry.ID && String.Equals(feedUrlRef, feedUrl, StringComparison.OrdinalIgnoreCase)) { removeAtIndex.Push(i); } } } while (removeAtIndex.Count > 0) { feedInfo.ItemsList.RemoveAt((int)removeAtIndex.Pop()); } }
/// <summary> /// Processes the item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public INewsItem ProcessItem(INewsItem item) { try { _newsItemChannelsLock.AcquireReaderLock(0); try { if (_newsItemChannels.Count == 0) { return(item); } // process in prio order: foreach (NewsItemChannelBase sink in _newsItemChannels.Values) { try { item = sink.Process(item); } catch (Exception ex) { _log.Error("NewsChannelServices.ProcessItem() sink '" + (sink != null ? sink.ChannelName : "[ChannelName]?") + "' failed to process INewsItem", ex); } } } finally { _newsItemChannelsLock.ReleaseReaderLock(); } } catch (ApplicationException) { // lock timeout } catch (Exception ex) { _log.Error("Failed to process INewsItem.", ex); } return(item); }
public override INewsItem Process(INewsItem item) { /* if (item.HasContent) { * item.SetContent(NewsComponents.Utils.HtmlHelper.StripBadTags(item.Content), item.ContentType); * } */ return(base.Process(item)); }
/// <summary> /// Returns the feed URL and source ID of the optional feed reference element for this <paramref name="newsItem"/>. /// </summary> /// <param name="newsItem">The news item.</param> /// <param name="sourceID">out: The source ID. -1 in case no source ID is available</param> /// <returns> /// The feed URL of the source feed if a pointer to it exists and NULL otherwise. /// </returns> public static string GetOriginalFeedReference(INewsItem newsItem, out int sourceID) { if (newsItem == null) { throw new ArgumentNullException("newsItem"); } sourceID = -1; string feedUrl = null; XmlQualifiedName key = AdditionalElements.GetQualifiedName(OriginalFeedRef); if (key != null && newsItem.OptionalElements.ContainsKey(key)) { string str = newsItem.OptionalElements[key]; int startIndex = str.IndexOf(">") + 1; int endIndex = str.LastIndexOf("<"); feedUrl = str.Substring(startIndex, endIndex - startIndex); endIndex = startIndex; startIndex = str.IndexOf(OriginalSourceID + "=", 0, endIndex); if (startIndex > 0) { startIndex = startIndex + (OriginalSourceID + "=").Length + 1; endIndex = str.IndexOf("\"", startIndex); string fs = str.Substring(startIndex, endIndex - startIndex); if (!String.IsNullOrEmpty(fs)) { Int32.TryParse(fs, out sourceID); } } } return(feedUrl); }
/// <summary> /// TODO /// </summary> /// <param name="item"></param> /// <returns></returns> static public string GetHashCode(INewsItem item) { if (item == null) { return(null); } System.Text.StringBuilder newHash = new System.Text.StringBuilder(); if (item.Feed != null && !string.IsNullOrEmpty(item.Feed.link)) { newHash.Append(item.Feed.link.GetHashCode().ToString()); } if (!string.IsNullOrEmpty(item.Link)) { newHash.Append(item.Link.GetHashCode().ToString()); } if (!string.IsNullOrEmpty(item.Title)) { newHash.Append(item.Title.GetHashCode().ToString()); } if (item.HasContent) { newHash.Append(item.Content.GetHashCode().ToString()); } return(newHash.ToString()); }
/// <summary> /// Apply all filters to the specified INewsItem. /// </summary> public bool Apply(ThreadedListViewItem lvItem) { INewsItem item = lvItem.Key as INewsItem; if (item == null) { return(false); } bool anyApplied = false; foreach (string key in filters.Keys) { INewsItemFilter filter = filters[key]; if (filter != null && filter.Match(item)) { if (!CancelFilterAction(key)) { filter.ApplyAction(item, lvItem); anyApplied = true; } } } return(anyApplied); }
/// <summary> /// Removes the optional element for the specified <paramref name="newsItem"/> from the optional elements. /// </summary> /// <param name="key">The key.</param> /// <param name="newsItem">The news item.</param> public static void RemoveElement(XmlQualifiedName key, INewsItem newsItem) { if (key != null && newsItem.OptionalElements != null && newsItem.OptionalElements.ContainsKey(key)) { newsItem.OptionalElements.Remove(key); } }
public void ConfigureArticle(UltraTreeNodeExtended n, INewsItem ni) { n.Cells[0].Value = /*ni.Date.ToString()+" "+ */ ni.Title; n.Cells[0].Appearance.Cursor = Cursors.Hand; n.Override.NodeAppearance.Cursor = Cursors.Hand; n.Override.HotTrackingNodeAppearance.Cursor = Cursors.Hand; }
internal void MarkAllItemsRead(FeedSourceEntry entry) { if (entry == null) { return; } UnreadItemsNodePerSource child; childrenBySourceID.TryGetValue(entry.ID, out child); for (int i = itemsFeed.Items.Count - 1; i >= 0; i--) { INewsItem item = itemsFeed.Items[i]; FeedSourceEntry owner = app.FeedSources.SourceOf(item.Feed); if (owner != null && owner.ID.Equals(entry.ID)) { itemsFeed.Items.RemoveAt(i); if (child != null) { // child handle this: child.UpdateReadStatus(child, -1); } else { // handle by myself: UpdateReadStatus(this, -1); } } } }
/// <summary> /// Initializes a new instance of the <see cref="PostReplyThreadHandler"/> class. /// </summary> /// <param name="feedHandler">The feed handler.</param> /// <param name="commentApiUri">The comment API URI.</param> /// <param name="item2post">The item2post.</param> /// <param name="inReply2item">The in reply2item.</param> public PostReplyThreadHandler(FeedSource feedHandler, string commentApiUri, INewsItem item2post, INewsItem inReply2item) { this.feedHandler = feedHandler; this.commentApiUri = commentApiUri; this.item2post = item2post; this.inReply2item = inReply2item; }
private static void ConfigureComment(UltraTreeNodeExtended n, INewsItem ni) { n.Override.ItemHeight = COMMENT_HEIGHT; n.Cells[0].Value = ni.Title; n.Cells[0].Appearance.Cursor = Cursors.Hand; n.Override.NodeAppearance.Cursor = Cursors.Hand; n.Override.HotTrackingNodeAppearance.Cursor = Cursors.Hand; }
/// <summary> /// Returns true if the INewsItem has a flag /// </summary> /// <param name="item"></param> /// <returns></returns> public bool Match(INewsItem item) { if (item != null && item.FlagStatus != Flagged.None) { return(true); } return(false); }
/// <summary> /// Gets the source of a <paramref name="newsItem"/>. /// </summary> /// <param name="newsItem">The news item.</param> /// <returns></returns> public FeedSourceEntry SourceOf(INewsItem newsItem) { if (newsItem == null) { return(null); } return(SourceOf(newsItem.Feed)); }
/// <summary> /// Returns the optional XmlElement if found within the NewsItem.OptionalElements list, /// else null. /// </summary> /// <param name="item">NewsItem</param> /// <param name="elementName">String</param> /// <param name="elementNamespace">String</param> /// <returns></returns> static public XmlElement GetOptionalElement(INewsItem item, string elementName, string elementNamespace) { if (item == null || item.OptionalElements == null) { return(null); } return(GetOptionalElement(item.OptionalElements, elementName, elementNamespace)); }
/// <summary> /// Remove the list of NewsItems from the lucene search index. /// </summary> /// <param name="newsItem">The news items list.</param> public void IndexRemove(INewsItem newsItem) { if (!UseIndex || newsItem == null) { return; } this.IndexRemove(new[] { newsItem }); }
/// <summary> /// Add the NewsItem to the lucene search index. /// </summary> /// <param name="item">The news item.</param> public void IndexAdd(INewsItem item) { if (!UseIndex || item == null) { return; } this.IndexAdd(new[] { item }); }
/// <summary> /// Returns the optional XmlElement if found within the NewsItem.OptionalElements list, /// else null. /// </summary> /// <param name="item">NewsItem</param> /// <param name="qName">XmlQualifiedName</param> /// <returns>XmlElement</returns> static public XmlElement GetOptionalElement(INewsItem item, XmlQualifiedName qName) { if (item == null || item.OptionalElements == null || qName == null) { return(null); } return(GetOptionalElement(item.OptionalElements, qName.Name, qName.Namespace)); }
/// <summary> /// Sets the font of the list view item to the color used to denote /// an item that links to the user's URL. Currently this color is /// Blue. /// </summary> /// <param name="item"></param> /// <param name="lvItem"></param> public void ApplyAction(INewsItem item, ThreadedListViewItem lvItem) { if (lvItem != null && item != null) { lvItem.Font = FontColorHelper.MergeFontStyles(lvItem.Font, FontColorHelper.HighlightStyle); lvItem.ForeColor = FontColorHelper.HighlightColor; } }
private static bool WasItemAdded( IEnumerable<INewsItem> currentNews, INewsItem item) { var itemInfo = new NewsItemInfo(item); return currentNews.Any(containedItem => itemInfo == new NewsItemInfo(containedItem)); }
public void ProcessAction(string parameter) { INewsItem item = FindItemByID(parameter); if (item != null) { //RaiseItemClick(item); } }
private static INewsItem TestItemParsing(string fileName) { HtmlNode newsItemNode = ReadHtml(fileName); INewsItem item = NewsItemFactory.Create(newsItemNode); AssertNewsItem(item); return(item); }
/// <summary> /// Designated initializer /// </summary> /// <param name="replyToItem"></param> /// <param name="title"></param> /// <param name="name"></param> /// <param name="url"></param> /// <param name="email"></param> /// <param name="comment"></param> /// <param name="beautify"></param> public PostReplyEventArgs(INewsItem replyToItem, string title, string name, string url, string email, string comment, bool beautify) { this.ReplyToItem = replyToItem; this.FromName = name; this.FromUrl = url; this.FromEMail = email; this.Comment = comment; this.Title = title; this.Beautify = beautify; }
private static void AssertNewsItem(INewsItem item) { // Some of these properties can never be null, // they are accessed in order to throw a NullReferenceException, // if they were not initialized Assert.NotNull(item); Assert.NotNull(item.Title); Assert.NotEqual(DateTime.MinValue, item.Date); }
/// <summary> /// Adds the specified item. /// </summary> /// <param name="item">The item.</param> public void Add(INewsItem item) { if (item == null) { return; } item.FeedDetails = this.feedInfo; this.feedInfo.ItemsList.Add(item); this.modified = true; }