public override bool Match(FeedInfo feed) { //compare as defined ... return(false); }
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> /// Method to implement for a feed compare. Should return true, /// if the criteria match that feed. /// </summary> /// <param name="feed">FeedInfo to compare (work on)</param> /// <returns>true, if the feed match</returns> public abstract bool Match(FeedInfo feed);
/// <summary> /// [Not yet implemented] /// </summary> /// <param name="feed"></param> /// <returns></returns> public override bool Match(FeedInfo feed) { return(false); }
/// <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; }
private void BuildGoogleFeed() { // // the majority of the code to follow is based upon the excellent blog below: // http://blog.codenamed.nl/2015/05/14/creating-a-google-shopping-feed-with-c/ // // get an instance of the store application var HccApp = HotcakesApplication.Current; var totalProducts = 0; var feed = new FeedInfo(); // get the store URL based upon SSL var storeUrl = Request.IsSecureConnection ? HccApp.CurrentStore.RootUrlSecure() : HccApp.CurrentStore.RootUrl(); // used to get currency code var regionInfo = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID); feed.Link = storeUrl; feed.Title = HccApp.CurrentStore.StoreName; feed.Updated = DateTime.Now; feed.Entries = new List <EntryInfo>(); // find all products in the store that are active var searchCriteria = new ProductSearchCriteria { DisplayInactiveProducts = false }; // using the search instead of querying the Products directly to use cache var products = HccApp.CatalogServices.Products.FindByCriteria(searchCriteria, 1, int.MaxValue, ref totalProducts); // non-shipping var shippingInfo = new ShippingInfo { Price = Constants.HARDCODED_PRICE_ZERO }; // not taxable (e.g., software) var taxInfo = new TaxInfo { Rate = Constants.HARDCODED_PRICE_ZERO }; // iterate through each product and add it to the feed foreach (var product in products) { var productUrl = UrlRewriter.BuildUrlForProduct(product); var productEntry = new EntryInfo { Availablity = GetStockMessage(product), // OPTIONS: preorder, in stock, out of stock Condition = Constants.CONDITION_NEW, // OPTIONS: new, refurbished, used Description = product.LongDescription, GoogleProductCategory = Constants.HARDCODED_GOOGLE_CATEGORY, // hard-coded for this example project (see property attributes) Id = product.Sku, ImageLink = DiskStorage.ProductImageUrlMedium(HccApp, product.Bvin, product.ImageFileMedium, Request.IsSecureConnection), Link = productUrl, MobileLink = productUrl, Price = string.Format(Constants.CURRENCY_TEXT_FORMAT, product.SitePrice.ToString(Constants.CURRENCY_FORMAT), regionInfo.ISOCurrencySymbol), ProductType = GetFirstAvailableCategory(HccApp, product.Bvin), // put your preferred site category here Title = product.ProductName, MPN = product.Sku, // this should be replaced with real data Brand = product.VendorId, // this should be replaced with real data Color = string.Empty, Gender = Constants.GENDER_UNISEX, // OPTIONS: male, female, unisex AgeGroup = Constants.AGE_GROUP_ADULT, // OPTIONS: newborn, infant, toddler, kids, adult GTIN = GenerateGTIN() // this should be replaced with real data }; // this could and should be iterated on to show shipping options for up to 100 locations productEntry.Shipping = new List <ShippingInfo>(); productEntry.Shipping.Add(shippingInfo); // this could and should be iterated on to show taxes for up to 100 locations productEntry.Tax = new List <TaxInfo>(); productEntry.Tax.Add(taxInfo); feed.Entries.Add(productEntry); } // simply done to display the feed in the textbox // alternatives could be to send this through a web service or other means txtGoogleFeed.Text = feed.SerializeObject(); }
public FeedConfigViewModel(FeedInfo info) { Data = info; _feeds = new ObservableCollection <FeedItemInfo>(info.Feeds); }
private static bool Filter(FeedInfo f, IEnumerable <string> subscribedAnimes) { var unpackedTitle = OptionUtils.UnpackOption(f.AnimeTitle.Value, string.Empty); return(subscribedAnimes.Contains(unpackedTitle)); }
public List<FeedInfo> GetRss() { List<FeedInfo> listrss = new List<FeedInfo>(); try { string rssurl = "http://www.jqpress.com/feed/post.aspx"; XmlTextReader reader = new XmlTextReader(rssurl); DataSet ds = new DataSet(); ds.ReadXml(reader); if (ds != null && ds.Tables.Count > 0) { DataTable dt = ds.Tables[2]; foreach (DataRow dr in dt.Rows) { FeedInfo post = new FeedInfo(); post.title = dr["title"].ToString(); post.description = dr["description"].ToString(); post.link = dr["link"].ToString(); post.pubDate = dr["pubDate"].ToString(); listrss.Add(post); } } } catch (Exception e) { } return listrss; }
public FeedInfoEqualityTest() { _sut1 = new FeedInfo(); _sut2 = new FeedInfo(); }
public static Tuple <DateTime, DateTime> GetFeedDateRange(GTFSFeed feed) { FeedInfo info = feed.GetFeedInfo(); if (info.StartDate != null && info.EndDate != null) { return(new Tuple <DateTime, DateTime>( DateTime.ParseExact(info.StartDate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture), DateTime.ParseExact(info.EndDate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture))); } DateTime?minStartLeft = null; DateTime?minStartRight = null; DateTime?maxEndLeft = null; DateTime?maxEndRight = null; DateTime minStart; DateTime maxEnd; if (feed.Calendars.Any()) { minStartLeft = feed.Calendars.Min(x => x.StartDate); maxEndLeft = feed.Calendars.Max(x => x.EndDate); } if (feed.CalendarDates.Any()) { minStartRight = feed.CalendarDates.Where(x => x.ExceptionType == ExceptionType.Added).Min(x => x.Date); maxEndRight = feed.CalendarDates.Where(x => x.ExceptionType == ExceptionType.Added).Max(x => x.Date); } if (minStartLeft.HasValue && minStartRight.HasValue) { if (minStartLeft > minStartRight) { minStart = minStartRight.Value; } else { minStart = minStartLeft.Value; } } else { if (minStartLeft.HasValue) { minStart = minStartLeft.Value; } else { minStart = minStartRight.Value; } } if (maxEndLeft.HasValue && maxEndRight.HasValue) { if (maxEndLeft > maxEndRight) { maxEnd = maxEndLeft.Value; } else { maxEnd = maxEndLeft.Value; } } else { if (maxEndLeft.HasValue) { maxEnd = maxEndLeft.Value; } else { maxEnd = maxEndRight.Value; } } return(new Tuple <DateTime, DateTime>(minStart, maxEnd)); }
/// <summary> /// Reads the list of articles from the stream and returns the feed item. /// </summary> /// <param name="f">Information about the feed. This information is updated based /// on the results of processing the feed.</param> /// <param name="newsgroupListStream">A stream containing an nntp news group list.</param> /// <param name="response">The response.</param> /// <param name="cacheDataService">The cache data service to store embedded binary content.</param> /// <param name="cachedStream">Flag states update last retrieved date on feed only /// if the item was not cached. Indicates whether the lastretrieved date is updated /// on the NewsFeed object passed in.</param> /// <returns> /// A FeedInfo containing the NewsItem objects /// </returns> internal static FeedInfo GetItemsForNewsGroup(INewsFeed f, Stream newsgroupListStream, WebResponse response, IUserCacheDataService cacheDataService, bool cachedStream) { int readItems = 0; List <INewsItem> items = new List <INewsItem>(); NewsItem item; StringBuilder content = new StringBuilder(); #if DEBUG // just to have the source for the item to build to track down issues: StringBuilder itemSource = new StringBuilder(); #endif NntpWebResponse nntpResponse = (NntpWebResponse)response; FeedInfo fi = new FeedInfo(f.id, f.cacheurl, items, f.title, f.link, String.Empty); try { foreach (MimeMessage msg in nntpResponse.Articles) { string parentId; string id; string author = parentId = id = null; DateTime pubDate = DateTime.UtcNow; content.Length = 0; string title; if (msg.Subject != null) { title = EscapeXML(msg.Subject.Value); } else { title = ""; } UnstructuredField fld = msg.Header.GetField(MimeField.MessageID) as UnstructuredField; if (fld != null) { id = fld.Value; } MailboxListField mfld = msg.Header.GetField(MimeField.From) as MailboxListField; if (mfld != null && mfld.MailboxList.Count > 0) { author = mfld.MailboxList[0].AddressString; } fld = msg.Header.GetField(MimeField.References) as UnstructuredField; if (fld != null) { // returns the hierarchy path: the last one is our real parent: string[] singleRefs = fld.Value.Split(' '); if (singleRefs.Length > 0) { parentId = CreateGoogleUrlFromID(singleRefs[singleRefs.Length - 1]); } } DateTimeField dfld = msg.Header.GetField(MimeField.Date) as DateTimeField; if (dfld != null) { pubDate = dfld.DateValue; } ITextBody txtBody = msg.Body as ITextBody; if (txtBody != null) { content.Append(txtBody.Reader.ReadToEnd()); content = NntpClient.DecodeBody(content, (fileName, bytes) => { string name = PrepareEmbeddedFileUrl(fileName, id, nntpResponse.ResponseUri); // we replace the uuencoded/yencoded binary content with a clickable link: if (IsImage(fileName)) { return(String.Format("<img src='{1}' alt='{0}'></img>", fileName, cacheDataService.SaveBinaryContent(name, bytes).AbsoluteUri)); } return(String.Format("<a href='{1}'>{0}</a>", fileName, cacheDataService.SaveBinaryContent(name, bytes).AbsoluteUri)); }, line => { // escape HTML/XML special chars: return(line.Replace("<", "<").Replace("]]>", "]]>")); }); content = content.Replace(Environment.NewLine, "<br>"); } if (id != null) { item = new NewsItem(f, title, CreateGoogleUrlFromID(id), content.ToString(), author, pubDate, id, parentId); item.FeedDetails = fi; item.CommentStyle = SupportedCommentStyle.NNTP; item.Enclosures = Collections.GetList <IEnclosure> .Empty; items.Add(item); FeedSource.ReceivingNewsChannelServices.ProcessItem(item); } else { #if DEBUG _log.Warn("No message-id header found for item:\r\n" + itemSource.ToString()); #else _log.Warn("No message-id header found for item."); #endif } } //update last retrieved date on feed only if the item was not cached.) if (!cachedStream) { f.lastretrieved = new DateTime(DateTime.Now.Ticks); f.lastretrievedSpecified = true; } //any new items in feed? if ((items.Count == 0) || (readItems == items.Count)) { f.containsNewMessages = false; } else { f.containsNewMessages = true; } FeedSource.ReceivingNewsChannelServices.ProcessItem(fi); FeedSource.RelationCosmosAddRange(items); fi.itemsList.AddRange(items); } catch (Exception e) { _log.Error("Retriving NNTP articles from " + nntpResponse.ResponseUri + " caused an exception", e); } return(fi); }
public static async Task UpdateFeedInfoAsync(FeedInfo f) { await _db.UpdateAsync(f); }
/// <summary> /// 如果f存在,则返回它的id;如果f不存在,则插入并返回它的插入后的id /// </summary> public static async Task <int> InsertOrReplaceFeedAsync(FeedInfo f) { await _db.InsertOrReplaceAsync(f); return((int)f.Id); }
public async static Task RemoveAFeedAsync(FeedInfo feed) { await _db.DeleteAsync(feed); }