Click here to Skip to main content
Click here to Skip to main content

7MC Gofer

By , 23 Jun 2010
 

A gofer or go-fer (pronounced /'go?f?r/ "Topo") is an employee who is often sent on errands.

Introducing 7MC Gofer

7MC Gofer is a Windows Phone 7 based remote control for my Windows Media Center.

Installing Vista Media Center TCP/IP Controller

Download the Windows 7 version here.

Before we can start, we need a way of controlling our 7MC. Vista Media Center TCP/IP Controller is a small addin for 7MC which hosts an HTTP-like server that accepts simple commands (like button-up, volume, etc.).

Once installed, test the service by navigating to the following URL using your browser (http://localhost:40510/help).

I also created an EXTREMELY simple wrapper for executing commands:

public</span /> class</span /> MceService
{
    const</span /> string</span /> endPointServer = "</span />localhost"</span />;

    private</span /> void</span /> ExecuteCommand(string</span /> command, params</span /> object</span />[] args)
    {
        string</span /> requestUriString = string</span />.Format
		("</span />http://{0}:40510/{1}"</span />, endPointServer, command);
        foreach</span /> (var</span /> arg in</span /> args)
        {
            requestUriString += "</span />%20"</span />;
            requestUriString += arg;
        }

        Console.WriteLine(requestUriString);

        var</span /> request = (HttpWebRequest)WebRequest.Create(requestUriString);
        request.Method = "</span />GET"</span />;
        request.BeginGetResponse(ExecuteCommandCallback, null</span />);
    }

    static</span /> void</span /> ExecuteCommandCallback(IAsyncResult result) { }

    public</span /> void</span /> Goto(string</span /> parameter)
    {
        ExecuteCommand("</span />goto"</span />, parameter);
    }

    //</span /> The reset is removed for brevity
</span />}

This is based on the code demoed by Dan & Clint @ Tech-ed (you have to watch their video).

MVVM Light Toolkit

Download the toolkit here (also read the Get Started).

The last thing we need to cover before we can start is the MVVM Light Toolkit. It’s a GREAT MVVM toolkit created by Laurent Bugnion. I am using this framework for 2 main reasons, locating the ViewModel...

DataContext="</span />{Binding Main, Source={StaticResource Locator}}"</span />

...and hooking up the commands… Here is the command (In my ViewModel):

private</span /> RelayCommand backCommand;
public</span /> RelayCommand BackCommand
{
    get</span />
    {
        if</span /> (backCommand == null</span />)
            backCommand = new</span /> RelayCommand(() => 
                {
                    //</span /> Do your work here...
</span />                });

        return</span /> backCommand;
    }
}

And in the View?

<</span />Button</span /> Content</span />="</span />Back"</span />></span />
    <</span />i:Interaction.Triggers</span />></span />
        <</span />i:EventTrigger</span /> EventName</span />="</span />Click"</span />></span />
            <</span />cmd:EventToCommand</span /> Command</span />="</span />{Binding BackCommand}"</span /> /</span />></span />
        <</span />/</span />i:EventTrigger</span />></span />
    <</span />/</span />i:Interaction.Triggers</span />></span />
<</span />/</span />Button</span />></span />

MVVM Light Toolkit makes this extremely easy!

Creating a Windows Phone 7 Client

Windows Phone

Download the tools here.

Now that we have the basics covered, we can start with the actual application! This is what I have in mind… The main view (which I called the Dashboard offers shortcuts to some of the main capabilities of 7MC, like videos, pictures, music and TV). I also allow you to change the volume (up, down, mute and un-mute). Here is the dashboard:

Once you have actually clicked on option, you will be taken to another view.

This is the direction pad. Navigation is done using simple gestures (Flick up/down/left/right and double-tap).

Here is the code to check for gestures:

private</span /> void</span /> PhoneApplicationPage_ManipulationStarted
	(object</span /> sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
    e.Handled = true</span />;
}

private</span /> void</span /> PhoneApplicationPage_ManipulationDelta
	(object</span /> sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
}

private</span /> void</span /> PhoneApplicationPage_ManipulationCompleted
	(object</span /> sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
    double</span /> x = e.TotalManipulation.Translation.X;
    double</span /> y = e.TotalManipulation.Translation.Y;

    //</span /> Ugly hack I know...
</span />    var</span /> vm = DataContext as</span /> MainViewModel;

    if</span /> (Math.Abs(y) > Math.Abs(x))
    {
        if</span /> (y < -20)
        {
            vm.MceService.Button("</span />up"</span />);
        }
        if</span /> (y > 20</span />)
        {
            vm.MceService.Button("</span />down"</span />);
        }
    }
    else</span />
    {
        if</span /> (x < -20)
        {
            vm.MceService.Button("</span />left"</span />);
        }
        if</span /> (y > 20</span />)
        {
            vm.MceService.Button("</span />right"</span />);
        }
    }
}

Very basic, I know… but it works. :)

And as always, here is the code.

Before you start, check out this video:

Also read:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

rudigrobler
South Africa South Africa
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generali need a ebook windows phone 7 developmentmemberminhhung1987200231 Oct '10 - 7:10 
GeneralRe: i need a ebook windows phone 7 developmentmembermaciekgrabek19 Dec '10 - 22:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 23 Jun 2010
Article Copyright 2010 by rudigrobler
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid