public List<StreamItem> Execute(Subscription subscription) { _Subscription = subscription; var rss = new RssPlugin(); return rss.Execute(_Subscription); }
public List<StreamItem> Execute(Subscription subscription) { _Subscription = subscription; var list = new List<StreamItem>(); // http://twitter.com/users/show/TanzimSaqib.xml ///var request = "http://twitter.com/statuses/user_timeline/5704372.atom"; /* "http://search.twitter.com/search.atom?q=from:" + _Subscription.UserName; */ try { var feed = XElement.Load(subscription.Url); if (feed != null) { // RSS if (feed.Element("channel") != null) { list = (from item in feed.Element("channel").Elements("item").AsParallel() select new StreamItem { //Description = item.Elements(ns + "link").Single(e => (e.Attribute("rel").Value == "image")).Attribute("href").Value Title = XmlHelper.StripTags(item.Element("title").Value, 160).ToTweet("embedded-anchor"), Url = item.Element("link").Value, Icon = _Subscription.Icon, Timestamp = Utilities.Rfc822DateTime.FromString((item.Element("pubDate").Value)) }).ToList(); } // Invalid else list = null; } } catch (Exception e) { // We got upset by the Twitter API at the moment, show from Db } finally { } return list; }
public IPlugin GetPluginFromSubscription(Subscription s) { return Plugins.AsParallel().SingleOrDefault<IPlugin>(p => p.GetTypeName() == s.Type); }
public List<StreamItem> Execute(Subscription subscription) { _Subscription = subscription; var bag = new System.Collections.Concurrent.ConcurrentBag<StreamItem>(); try { if (Feed != null) { XNamespace ns = "http://www.w3.org/2005/Atom"; // RSS if (Feed.Element("channel") != null) { var items = (from item in Feed.Element("channel").Elements("item").AsParallel() select item).ToList(); Parallel.ForEach(items, i => { var streamItem = new StreamItem(); streamItem.Timestamp = Utilities.Rfc822DateTime.FromString(i.Element("pubDate").Value); streamItem.Url = i.Element("link").Value; streamItem.Title = i.Element("title").Value; streamItem.Icon = _Subscription.Icon; if (i.Element("description") != null) streamItem.Description = i.Element("description").Value; bag.Add(streamItem); }); } // Atom else if (Feed.Element(ns + "entry") != null) { var items = (from item in Feed.Elements(ns + "entry").AsParallel() select item).ToList(); Parallel.ForEach(items, i => { var streamItem = new StreamItem(); streamItem.Timestamp = Utilities.Rfc822DateTime.FromString(i.Element(ns + "published").Value); streamItem.Url = i.Elements(ns + "link").Single(e => (e.Attribute("rel").Value == "alternate")).Attribute("href").Value; streamItem.Title = i.Element(ns + "title").Value; streamItem.Icon = _Subscription.Icon; if (i.Element(ns + "content") != null) streamItem.Description = i.Element(ns + "content").Value; bag.Add(streamItem); }); } // Invalid else bag = null; } } catch (Exception e) { // We got upset by the RSS/Atom, load previous items. // TODO: list = bla bla. } finally { if (bag != null && bag.Count > 0) { Parallel.ForEach(bag, i => { if (i != null && !string.IsNullOrEmpty(i.Description)) { var img = Regex.Match(i.Description, "src=[\"]?([^\" >]+)", RegexOptions.Compiled); if (img.Success) i.Description = "<img " + img.Value + "\" class=\"embedded-image\">"; else i.Description = string.Empty; } }); } } return bag != null && bag.Count > 0 ? bag.ToList() : null; }
public Subscription Subscribe(Dictionary<string, string> parameters) { var subscription = new Subscription { ID = Guid.NewGuid(), Type = GetTypeName(), Icon = ICON_PATH, UserName = string.Empty, Password = string.Empty, Url = parameters["url"], LastUpdated = DateTime.Now }; _Subscription = subscription; var title = GetSubscriptionFriendlyName(); subscription.Title = title.Substring(0, title.Length < 64 ? title.Length : 64); subscription.FriendlyUrl = GetSubscriptionFriendlyUrl(); return Feed != null ? subscription : null; }
partial void DeleteSubscription(Subscription instance);
partial void UpdateSubscription(Subscription instance);
partial void InsertSubscription(Subscription instance);
public Subscription Insert(Subscription s) { return Insert<Subscription>(s); }