LightSwitch news RSS: bringing you news from around the world! (http://bit.ly/lightswitchnewsRSS)

So…. What’s up doc?

Not much.  Reading some blog posts by other LightSwitch community members…

Sweet! Google Reader?

Errr… Haven’t you heared? Google is dead.  (Google reader*)

The easiest way to keep up to date with the other LightSwitch community members is to wait until the end of the month, then read Beth Massi’s Community & Content Rollup.  Unfortunately, there’s two problems with that approach:

Don’t you have your own twitter bot to keep you up to date?

Well yes, to keep myself up to date on a daily bases (I like news as hot as it gets), I turned each interesting “source” into a tweet by my twitter bot using ifttt.com

Unfortunately, this bot had some weird hiccups lately so after an extremely exhausting week I decided to spend a Friday afternoon rethinking my news model…

Naice! Found something fancy?

Well, actually I did.  After signing up for over a dozen awesome, great or plain terrible services, I found a really fancy service and spent a couple of hours getting the result looking clean and crisp.  Unfortunately, after spending those hours I discovered that this particular service only refreshes once every 24 hours.  I ended up settling for Yahoo! pipes, some kind of workflowy editor that seems to have no other use than to combine RSS feeds.

Which in a way, is exactly what I need. :-)  And the pipes themselves look kind of fancy.

Image 031

So half a blog post to talk about how you wasted your Friday to end up with an RSS feed instead of a twitter bot?

No.

Half a blog post to talk about how I wasted my Friday to end up with an RSS feed in addition to a twitter bot.

That’s nice. Any downsides to this approach?

Well yes…. I got a bit lazy because Y!Pipes doesn’t have a copy&paste option, so now the bot that listens to the “LightSwitch news RSS feed”, doesn’t know the source of each item anymore.  Basically it  just tweets “#LightSwitch news: ….” now instead of tweeting “News by @AuthorTwitterHandle:  …”

Right… Well listen, thanks for blogging. We’ll give you a call…

Wait, there’s more!

  • RSS feeds are easy to plug into your favorite reader.  Or widget, like the new sidebar on my blog!
  • I can share the RSS feed now: http://bit.ly/lightswitchnewsRSS .  And if I find any good bloggers (feel free to make suggestions too!) I can simply update the Y!Pipes schema and you get all the new content too!

Smart!

And… Boring.  

Mostly boring.

So listen man, unless there’s some code goodies to be found in this post, I’ll be on my way.

Ok… Here you go :-)

namespace RssDomain
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel.DomainServices.Server;
    using System.ServiceModel.Syndication;
    using System.Xml;

    public class LightSwitchNewsItem
    {
        [Key]
        public string Id { get; set; }

        public string Subject { get; set; }

        public string Content { get; set; }

        public string FullArticle { get; set; }

        public DateTime PublishDate { get; set; }
    }

    public class RssDomainService : DomainService
    {

        private static IEnumerable<LightSwitchNewsItem> allItems;

        [Query(IsDefault = true)]
        public IEnumerable GetDefault()
        {
            if (allItems == null)
            {
                string url = @"http://bit.ly/lightswitchnewsRSS";
                XmlReader reader = XmlReader.Create(url);
                SyndicationFeed feed = SyndicationFeed.Load(reader);
                reader.Close();

                allItems = feed.Items.Select(
                               item => new LightSwitchNewsItem
                                   {
                                       Id = GetId(item),
                                       Subject = item.Title.Text,
                                       Content = item.Summary.Text,
                                       PublishDate = item.PublishDate.DateTime,
                                       FullArticle = GetLink(item)
                                   }
                               )
                               .OrderByDescending(x => x.PublishDate);

            }
            return allItems;

        }

        static int i;

        static string GetId(SyndicationItem item)
        {
            string id = null;
            if (!string.IsNullOrEmpty(item.Id))
            {
                id = item.Id;
            }
            else if ((id = GetLink(item)) == null)
            {
                id = "Unknown  " + (++i).ToString("000");
            }
            return id;

        }

        static string GetLink(SyndicationItem item)
        {
            var link = item.Links.FirstOrDefault();
            if (link != null)
                return link.Uri.ToString();
            return null;
        }
    }
}

My eyes! I’m not supposed to get ugly code in them!  What is that?

It’s the code you can copy&paste in a RIA domain service, then use it as an external data source in your LightSwitch projects.

Image 030

That is indeed pretty cool! 

Thanks!  But not as cool as Dissociative identity disorder.  But anyways, I’m off.  Cya man, and don’t forget:

Keep rocking LS!

You too!

About these ads

4 thoughts on “LightSwitch news RSS: bringing you news from around the world! (http://bit.ly/lightswitchnewsRSS)

  1. Pingback: Beth Massi - Sharing the goodness

  2. Pingback: Beth Massi的中文博客

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s