One of the cool features of the DemoDashboard is the integration with Twitter. You can use that in your own widgets by importing the TwitterService. The interface for the service looks like this:

    /// <summary>
    /// Provides integration with Twitter
    /// </summary>
    public class TwitterService
    {
        /// <summary>
        /// Raised when the number of user tweeting the session hashcode changes
        /// </summary>
        public event EventHandler<UsersCountEventArgs> UsersCountChanged;

        /// <summary>
        /// Login a user in Twitter. Should not be used by new widgets.
        /// </summary>
        public void Login(string username, string password)
        {
		//...
        }

        /// <summary>
        /// Login a user in Twitter. Should not be used by new widgets.
        /// </summary>
        public void Login(ICredentials credentials)
        {
		//...
        }

        /// <summary>
        /// Gets and sets the session hashcode. Changing the session hashcode in a widget is not recommended
        /// </summary>
        public string HashCode
        {
            get; set;
        }

        /// <summary>
        /// Resets the session hashcode. User count is reset to 0.
        /// </summary>
        public void Reset()
        {
		//...
        }

        /// <summary>
        /// Gets the number of distinct Twitter users tweeting the session hashcode. 
        /// </summary>
        public int GetUsersCount()
        {
		//...
        }

        /// <summary>
        /// Registers a callback. When a Twitter user tweets "#sessionid command" the callback method is executed.
        /// </summary>
        public void RegisterCommand(string command, Action<IEnumerable<FeedItem>> handler)
        {
		//...
        }

        /// <summary>
        /// Returns your message formatted with the session hashcode. Useful for tweeting from a widget.
        /// </summary>
        public string GetMessageWithHashcode(string message)
        {
		//...
        }

        /// <summary>
        /// Returns your message formatted with the session hashcode. Useful for tweeting from a widget. Use this method for long messages.
        /// </summary>
        public List<string> GetMessagesWithHashcode(string message)
        {
		//...
        }

        /// <summary>
        /// Updates the logged in Twitter user's status. Messages longer than 140 chars will be truncated.
        /// </summary>
        public void UpdateStatus(string message)
        {
		//...
        }

        /// <summary>
        /// Updates the logged in Twitter user's status. Use this with GetMessagesWithHashCode for long messages. 
        /// </summary>
        public void UpdateStatus(List<string> messages)
        {
		//...
        }
}

The most useful methods are UpdateStatus and RegisterCommand. Here's how the Coolness Widget uses the RegisterCommand to change the face icon based on user's tweets:

            // register the two feedback messages this widget understands
            twitterService.RegisterCommand("is cool", ProcessCoolMessages);
            twitterService.RegisterCommand("is not cool", ProcessNotCoolMessages);

And here's how the TweetThis widget uses the service to update the logged in user's status:

        void UpdateStatus(string newStatus)
        {
            // This uses the Twitter service to update the speaker Twitter status publishing the selected code
            this.uiService.ExecuteOperation(() => twitterService.UpdateStatus(twitterService.GetMessagesWithHashcode(newStatus)));
        }

Last edited Dec 2, 2009 at 2:57 PM by joj, version 2

Comments

No comments yet.