23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tip The tile and badge updaters are very sensitive to properly formed XML. In the PHP code above,<br />

leaving off the closing / for the badge element will make the update fail to appear. Avoiding such trivial<br />

errors is again why the Notifications Extensions Library was created, at least for ASP.NET. I’m hoping<br />

that some enterprising reader might consider a similar project for PHP and other server-side languages!<br />

Going back to the Windows Developer Blog post mentioned earlier, I want to point out that the<br />

ASP.NET example given there—the one that begins with @{—is using the ASP.NET Razor syntax<br />

(typically in a .cshtml file), introduced with Microsoft WebMatrix. Razor/WebMatrix, along with tools<br />

such as Visual Studio Express 2012 for Web and a whole lot else, can be installed through the Web<br />

platform installer. To familiarize yourself with Razor, which works much in the same way as PHP, start<br />

with Walkthrough: Creating a Web Site using Razor Syntax in Visual Studio.<br />

To make that long story short, here are the steps in Visual Studio Express 2012 for Web to create a<br />

simple tile update service based on the Razor code in the blog post:<br />

• Select File > New Web Site from the menu.<br />

• In the New Web Site dialog, select ASP.NET Web Site (Razor v1), give it a project name and<br />

folder, and press OK. Call this site HelloTiles.<br />

• Once the project is created, you should see the Default.cshtml file opened.<br />

• Copy and paste the following Razor code into that file, replacing the default contents. The little<br />

piece of C# code at the top for the weekDay variable is something we’ll use in the next section to<br />

demonstrate debugging; it’s not used in generating the XML. Here, note that I tested and<br />

generated the XML contents by using the tile designer in Scenario 5 of the App tiles and badges<br />

sample (see Figure 13-15); this saved me lots of time wondering whether my XML was correct.<br />

@{<br />

//<br />

// This is where any other code would be placed to acquire the dynamic content<br />

// needed for the tile update. In this case we'll just return static XML to show<br />

// the structure of the service itself.<br />

//<br />

var weekDay = DateTime.Now.DayOfWeek;<br />

}<br />

<br />

<br />

<br />

<br />

<br />

Liam--<br />

593

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!