image To get the taste of Windows8 and WinRT, Let us develop a quick C# + Xaml application that sends notifications to the Metro UI Tiles. Before jumping in, make sure you read about

So, let us create a quick app. Here we go.

About Tiles

As you might have already seen in the Demos, Windows 8 start screen features Tiles, as start points of the application. Your applications can send notifications to tiles, so that they are displayed in the start screen, above the tile. The types for Tile manipulations are in the namespace Windows.UI.Notifications

Basically, we are interested in three classes.

  • TileNotification
    • Defines an update to a tile, including its visuals, identification tag, and expiration time.
  • TileUpdateManager
    • Creates TileUpdater objects used to change and update Start menu tiles. This class also provides access to the XML content of the system-provided tile templates so that you can customize that content for use in updating your tiles.
  • TileUpdater
    • Changes the appearance or content of the specific tile that the updater is bound to.

 

About Our HelloTiles Application

The Samples pack that comes with Windows 8 SDK has a Javascript/HTML sample for basic and advanced tile manipulation, so I thought about putting together a quick C#/XAML application along the same lines. So, you can see our tile, just under the “Weather” tile, with notification “tiles are cool”.

tilesarecool

So, to start with, we’ll create a simple C#/XAML application for Windows RT, with a very simple Textbox and Button, and when the user enter some notification and click Send, the tile will be updated in the Start screen. This is just a demo scenario, and you know how to do better in an actual application –i.e, you can send a notification when something interesting happens in your application. Tiles are just one way to notify the user, but for now, let us keep things simple and create a quick notifier application, some what like this.

ui

Creating The Project and Punching in some code

Time for some action. Let us fire up Visual Studio 2011, and create a new C#/XAML Metro application. Name it HelloTiles.

image

The project will get created, and you’ll find the App.xaml and MainPage.xaml files in the Project explorer. This should not surprise you if you have worked with Silverlight/WPF projects earlier. How ever, as I mentioned in my earlier article remember that the Xaml libraries are now directly part of WinRT and no longer run on top of the CLR, so most of the Xaml controls and types are now moved under Windows.UI* namespaces.

Along with the Xaml files, you’ll also find  a Package.appxmanifest file. Open that and change the “Initial Rotation” to Landscape. Also, specify a suitable image for the wide logo so that the notification display will work correctly (by default it is not there, add a new image of the specified dimension to the images, and pick it against the wide logo field).

image

Now, let us write some code.

1 – The UI Code

The UI code is very minimal, let us open MainPage.xaml and replace the Xaml code there with this. Basically, we have a very simple stack panel, and a text box and a button.

  <UserControl x:Class="HelloTiles.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="768" d:DesignWidth="1366">
    
    <StackPanel HorizontalAlignment="Center"  VerticalAlignment="Center" x:Name="LayoutRoot" >
        <TextBlock Text="Tile Notifier" FontSize="100" VerticalAlignment="Center"/>
        <StackPanel Orientation="Vertical" Margin="20" >
            <TextBox Text="Message to send" Name="txtMain" Width="500" VerticalAlignment="Center" Margin="2"/>
        <Button Content="Send Notification" Click="Button_Click" HorizontalAlignment="Center"/>
        </StackPanel>
    </StackPanel>
        
</UserControl>

2 – Code behind for sending notifications

Now, let us send the notification to the tile when ever the user clicks the button. See that we already have a Button_Click event handler as part of the XAML, so now let us add some meat behind. Open Manpage.xaml.cs, and add the button handler, and the ClearTileNotification and SendTileNotification methods there. I had a look at the Javascript example, and almost did a quick line by line translation. Remember, we are accessing WinRT types and methods from here as well as from Javascript, so it was very easy.
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;

namespace HelloTiles
{
    partial class MainPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ClearTileNotification();
            SendTileTextNotification(this.txtMain.Text,30);
        }

        void ClearTileNotification()
        {
            // the same TileUpdateManager can be used to clear the tile since 
            // tile notifications are being sent to the application's default tile
            TileUpdateManager.CreateTileUpdaterForApplication().Clear();            
        }

        void SendTileTextNotification(string text, int secondsExpire)
        {
            // Get a filled in version of the template by using getTemplateContent
            var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText03);

            // You will need to look at the template documentation to know how many text fields a particular template has       

            // get the text attributes for this template and fill them in
            var tileAttributes = tileXml.GetElementsByTagName(&quot;text&quot;);
            tileAttributes[0].AppendChild(tileXml.CreateTextNode(text));

            // create the notification from the XML
            var tileNotification = new TileNotification(tileXml);

            // send the notification to the app's default tile
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
        }
    }
}

The app is pretty simple, what we are doing is,

  • Getting the Tile Template type by calling GetTemplateContent as an Xml document
  • Modify the text in the Xml
  • Create a tile notification using that Xml
  • Sending that to the Tile.

As I mentioned in the above step, make sure you are setting a valid logo for the Wide logo, and changing the initial rotation to Landscape. For available tile formats, you can refer the Tile schema if you are interested to see the available tile templates and how they look like.

Run the application, enter something in the textbox, and click the button. Now, hit your Win key and go to the Start screen, you should see the notification there. Ensure that your tile is in landscape mode, you can right click a tile to modify it’s properties or to un-install the application. Happy Coding!!

Read more >>

image I gave a bullet point overview about Build conference here in my last past. If you havn’t yet got Windows 8 Dev Preview up and running, go grab it here. There are several ways to get up and running with Windows 8.

In my case, I downloaded the ISO image of Developer preview with tools (the 4+ GB One), Extracted it to a USB drive and made the USB drive bootable, Booted from that and then installed Windows 8 on a Local HD Partition in my home machine. Now, it is dual bootable, Windows 8 and Windows 7, and all is well.

Let us get in to the business. Windows 8 comes with WinRT, a new object oriented native/unmanaged API for developing ‘Metro’ applications for Windows. WinRT APIs are expected to replace the Win32 APIs. WinRT projects types using meta data, and is fully object oriented, so you can access WinRT directly from managed languages like C#. Here are a couple of interesting reads about WinRT.

WinRT is going to the ‘the runtime’ for Windows, across multiple devices like PCs, Tablets etc. You can develop Windows Metro style applications on top of WinRT in

image 

1 - C#/VB.NET and Xaml

    • Xaml libraries with WinRT are now re-written in C++, and don’t have any .NET dependencies
    • WinRT XAML is a subset of the earlier XAML libraries that was available with .NET, and doesn’t support some features like DataTriggers etc as of now
    • Presently, you can access only a subset of the .NET BCL/Runtime from your C#/VB.NET + XAML WinRT application.
      • This doesn’t even support .NET Client Profile, it is just .NET core profile with access to a minimum set of .NET namespaces, combined with XAML namespaces now in Windows.UI.
      • The entire CLR will be loaded at the time of execution, but you’ll be able to access only a subset of that. As simple as that. This is to ensure that you are running in a sandboxed environment, and CLR comes into play as a thin layer only for binding your calls to WinRT at run time. As WinRT is object oriented and has managed data, you are any way developing directly against WinRT

2 - C++ and XAML

    • If you are developing in C++ and XAML, your code will be compiled directly to an unmanaged library.
    • I assume this provides the maximum performance advantage, as your code is directly compiled to native code.

3 - Javascript + HTML5

    • From Javascript, you can call WinRT methods directly and in that sense it is native. The UI is rendered in HTML5. If your application is a Javascript + HTML5 application, it will be run in a ‘shell’ which uses the same rendering engine in IE10.

You may continue to develop .NET/C#/Silverlight applications for classic desktop scenarios, but if you need to develop Metro applications, then you have to develop against WinRT.

Other than the XAML UI services, Win RT also Provides APIs for

  • Communication – Sockets, Streams and all
  • Devices – Geolocation, Sensors, Near Field Communication etc
  • Media – Playback, Capture, Effects
  • Other OS Services – Application services, Threading, Memory Management, Authentication etc.
Read more >>

//Build/–Windows 8 Thoughts

Game on. After going through the Day 1 keynote for the Build event, I should say I’m pretty much convinced that Microsoft has got the equation correct. They corrected the Tablet part of the equation, and got the entire Cloud <-> Tablet stack in place, with proper platforms and a nice set of developer tools. And with out doubt, Windows 8 devices are going to be a definite competitor for iPad/iOS, and Microsoft has officially entered the post PC era.

image

Here are few quick observations, mainly on the developer side.

About Metro UI

    • Metro applications are now officially the first class applications that  can fully leverages the touch features of Windows 8.
    • The new start screen looks very refreshing, with dynamic tiles.

For Developers

    • Develop application in HTML5<->JS<->WinRT or XAML<->.NET<->WinRT
      • You can develop native Windows applications either using Javascript and HTML or using .NET and XAML. This also means, ability to access native WinRT APIs straight from Java script.
      • This is particularly interesting because Javascript development model suits a lot of cloud based applications, and now JS developers can develop first class Windows 8 applications.
    • Visual Studio vNext, .NET 4.5
    • IE10 Engine powers the JS/HTML5 Apps
    • A lot of asynchronous programming everywhere
  • Expression Blend 5 now supports editing HTML5, much like you use it for editing XAML.
  • To a great extent, your XAML assets can be reused across multiple devices – desktops, slates and phone.
  • Windows 8 Store
    • Transparent approval proces
    • Developers can publish applications right from Visual Studio.

New APIs and Extension Points

    • Charms
      • Apps can share charms, to inter-operate. For example, an “Insert Picture” dialog box can show you results from other applications that can handle the image/picture data type.
    • Direct Compute API
      • Enables you to leverage the power of GPU in your applications
    • Sensor Fusion API
      • A Single API for all your sensors like Accelerometer, magnetometer and gyroscope

Windows Live integration

    • The whole suite of Windows Live services are neatly integrated to Windows 8.
    • All these Windows Live applications (Mail, Calendar, Photos) are now developed in Javascript/HTML5 and is native.
    • You can connect multiple devices via Windows Live

Support for Wide Variety of Hardware

    • The hardware support for Windows 8 seems really awesome. The demos features Windows 8 running on a variety of hardware devices
    • New and improved features include
      • Multi monitor support with start button on all screens
      • Hyper V Support for client
      • USB 3 Support
      • Hardware acceleration for all applications
      • Malware detection in boot strapper
      • A boot mode called “Cold Boot“ which is super fast

You can download Windows 8 Developer Release and related development tools from http://msdn.microsoft.com/en-us/windows/home/ by 8 PM PST. Enjoy, happy coding!!

Read more >>

As I mentioned in my last post, more and more organizations are leaning towards Web Oriented Architecture (WOA) which are highly scalable. If you were exploring cool, scalable options to build highly performing web applications, you know what Node.js is for.

After following the recent post from Scott Hanselman, I was up and running quickly with Node.js. In this post, I’ll explain step by step how I’ve setup Node.js and Mongodb to create a simple Todo listing application.

Setting up Node.js

This is what I’ve done.

1 – Goto http://nodejs.org/, scroll down and download node.exe for Windows, and place it in your c:\node folder

image

2 – Goto IIS Node project in Git at https://github.com/tjanczuk/iisnode, download the correct ‘retail’ link of IIS Node zip file (I downloaded the already built retail package, otherwise you can download and build from the source).

image

3 – Extract the zip file some where, and run the install.bat or install_iisexpress.bat depending on your IIS Version. If you don’t have IIS installed, try installing IIS 7.5 express here from MS download center.

image

4 – Make sure you have IIS URL rewrite module installed, so that some node.js samples with URL rewriting will work correctly. Install URL Rewrite module if you don’t have it, and restart IIS.

Verifying that all is well

Once Step 3 is over, this will configure the required modules and virtual directories, and you should be able to access the node virtual directory at http://localhost/node – which points to the www folder where you extracted the iisnode zip file.

image

Now, go to the end point http://localhost/node/helloworld/hello.js and see if everything works well. You can also open the hello.js file in the corresponding www\helloworld\ folder to have a look at the node hello world code.

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, world! [helloworld sample]');
}).listen(process.env.PORT);  

image

So as we’ve Node.js up and running, let us create a quick Todo listing application using Node.js and Mongodb by modifying this helloworld application.

Setting up Mongodb

Mongodb is a scalable, high performance, document database that goes well with node.js. See http://mongodb.org for more. In Mongodb, records are stored as JSON style documents, and documents are stored in collections. For now, consider that a collection is the NoSQL equivalent of a table, and a document is the NoSQL equivalent of a record.

1- First of all, you may need to install Mongodb. Goto http://www.mongodb.org/downloads, download the correct zip package, and extract it.

2- Create a folder ‘data’ in the path where you extracted Mongodb zip file. See the data folder.

image

3- Now, you should start mongod process. So, open command prompt, CD the folder where you extracted Mongodb, and start Mongod with data as the db folder using the command mongod –dbpath data

4- You should see the mongod process running, as shown below.

image

5- Now, let us insert few records to the todo collection of the database. For that, fire up mongo.exe client from the folder where you extracted the mongo db zip file, and insert few documents to the todo collection as shown below. Please note that

image

So, we have Mongodb running now, with a collection named todo with few documents in it.

Setting up Mongodb Module for Node.js

Normally, setting up packages/modules for Node.js is quite easy, it can be done using the Node package manager http://npmjs.org – How ever, I don’t think an NPM port is available for Windows right now. So, let us configure the Mongodb driver for Node.js manually.

1 – Goto https://github.com/christkv/node-mongodb-native and get the zip package. I downloaded v0.9.3 package, and extract it.

image

2 – Goto the  www\helloworld folder where you examined hello.js earlier. Now, create a folder node_modules under the helloworld folder and create the mongodb folder under this, and copy the contents of the package to the mongodb folder as shown below. It seems that the folder name under node_modules should match the package name defined in index.js.

image

 

Now let us write some code

Once you are through with installing Node.js, Mongodb and Mongodb module for Node.js, it is time to write some code. Fire up the hello.js file in the helloworld folder, and write some code to fetch the todo collection from Mongodb and return it as HTML.

GLOBAL.DEBUG = true;

//Load modules
var http = require('http');
var mongo = require('mongodb');
var sys = require("sys");
var test = require("assert");

var Db = require('mongodb').Db, Connection = require('mongodb').Connection,
  Server = require('mongodb').Server,
  BSON = require('mongodb').BSONNative;

//Default server and port
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? 
			process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? 
			process.env['MONGO_NODE_DRIVER_PORT'] : Connection.DEFAULT_PORT;

sys.puts("Connecting to " + host + ":" + port);


http.createServer(function (req, res) {

//Client connected
	res.writeHead(200, {'Content-Type': 'text/html'});    	
	res.write('<html><head><title>Todo List</title></head>');
	res.write('<body>');
	res.write('<h1>Todo list</h1>');
        var db = new Db('test', new Server(host, port, {}), {native_parser:false});
	db.open(function(err, db) {
	db.collection('todo', function(err, collection) {
	collection.find(function (err, cursor){
		res.write('<ul>');
		cursor.each( function (err, item) {                                   
				if (item == null) {
						res.write('</ul>');
						res.end('</body></html>');
						 db.close();
						}
				else 
				 res.write('<li>' + item.title + '</li>');
		});
	});
	});

	});	
}).listen(process.env.PORT);   

You may find that we are opening the database, and iterating through the collection and creating a list out of that and spitting out the html. This should work as long as you followed the steps I briefed above.

image

And yes, you just opened the Pandora’s box – start playing with various Node.js modules and samples on your Windows box. Follow some Node.js tutorials, and experiment further. It is important to note that the Node.js port for Windows is not yet perfect from a production point of view, but now Windows developers have a good way to start exploring options related to node.js and related modules.

And follow me in twitter @ http://twitter.com/amazedsaint for further updates, Keep in touch. Happy Coding!!

Read more >>

top