,

Sample Twitter Timeline Viewer

The principle example for this chapter is a Twitter timeline viewer that downloads the tweets of a specified Twitter user, caches them in a local database, and displays them on a page. The code for this example is located in the DataDrivenApps/TwitterExample directory of the WPUnleashed.Examples project.

The Twitter timeline viewer has a simple data model consisting of two entities representing a Twitter user and a tweet or TimelineItem (see Figure 29.3), and it demonstrates using a local database to cache cloud data.

Image

FIGURE 29.3 A TwitterUser has many TimelineItems.

TimelineItem represents a status update (tweet) that contains information including the tweet text, the time the tweet occurred, and the user’s id (see Listing 29.1). The TwitterUser class holds a collection, specifically an EntitySet of TimelineItem objects.

LISTING 29.1. TimelineItem Class (excerpt)


[Table]
public class TimelineItem : NotifyPropertyChangeBase
{
    string id;

    [Column(IsPrimaryKey = true)]
    public string Id
    {
        get
        {
            return id;
        }
        set
        {
            Assign(ref id, value);
        }
    }

    string text;

    [Column(DbType = "NVarChar(140)")]
    public string Text
    {
        get
        {
            return text;
        }
        set
        {
            Assign(ref text, value);
        }
    }
    DateTime? receivedTime;

    [Column]
    public DateTime? ReceivedTime
    {
        get
        {
            return receivedTime;
        }
        set
        {
            Assign(ref receivedTime, value);
        }
    }

    string twitterUserId;

    [Column(CanBeNull = false)]
    public string TwitterUserId
    {
        get
        {
            return twitterUserId;
        }
        set
        {
            Assign(ref twitterUserId, value);
        }
    }

    EntityRef<TwitterUser> user;

    [Association(Storage = "user",
                 ThisKey = "TwitterUserId",
                 IsForeignKey = true)]
    public TwitterUser TwitterUser
    {
        get
        {
            return user.Entity;
        }
        set
        {
            user.Entity = value;
        }
    }
}


To declare the TimelineItem class as representing a table in the database, it is decorated with a Table attribute. The TableAttribute class includes a Name property, which allows you to explicitly define the name of the database table. If it is not provided, the name of the class is used as the table name. For example, to override the TimelineItem table name to something else, the following could be used:

[Table(Name = "SomethingElse")]
public class TimelineItem : NotifyPropertyChangeBase
{ ... }

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.26.152