示例#1
0
        public List<StreamItem> Execute(Subscription subscription)
        {
            _Subscription = subscription;

            var rss = new RssPlugin();
            return rss.Execute(_Subscription);
        }
示例#2
0
        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;
        }
示例#3
0
 public IPlugin GetPluginFromSubscription(Subscription s)
 {
     return Plugins.AsParallel().SingleOrDefault<IPlugin>(p => p.GetTypeName() == s.Type);
 }
示例#4
0
        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;
        }
示例#5
0
        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;
        }
示例#6
0
 partial void DeleteSubscription(Subscription instance);
示例#7
0
 partial void UpdateSubscription(Subscription instance);
示例#8
0
 partial void InsertSubscription(Subscription instance);
示例#9
0
 public Subscription Insert(Subscription s)
 {
     return Insert<Subscription>(s);
 }