Imagine Cup Student DevCamps Followup

imagineCamp2Over the weekend I was at University of Ottawa presenting to the students in the Electrical Engineering and Computer Science program talking about building for Windows and Windows Phone and the best way to leverage and re-use code across the different platforms.  It’s always exciting to meeting and share with students my experience in software development and helping them along in their endeavours/careers.  You can read more about the event on the RedBit blog 

As a follow up here are bunch of resources and links to things I mentioned during the two days

If you attended (or if you didn’t, heard it was mid terms) feel free to connect with me here or via twitter to ask questions on developing for both Windows and Windows Phone or any other questions in general.

Next up will be Queens University register here and another one end of March in the Kitchener Waterloo Region (will post details on that soon).

Quick Tip: Getting Device ID on Windows & Windows Phone

When building out apps, there are some situations where you are required to get a unique ID of the device whether it be for analytic data or to potentially limit devices from accessing some private services.

This quick tip will show you how to get the device ID on different platforms such as Windows Phone 7, Windows Phone 8 and Windows 8.

Windows Phone 7

To get device ID on Windows Phone 7 you can use the following

private string m_DeviceUniqueId;
public string DeviceId
{
    get
    {
        if (m_DeviceUniqueId == null)
        {
            object val;
            if (Microsoft.Phone.Info.DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out val))
                m_DeviceUniqueId = Convert.ToBase64String((val as byte[]));
        }
        return m_DeviceUniqueId;
    }
}

Windows Phone 8

Getting device ID on Windows Phone 8 is slightly different the the previous version and can be accomplished with the following

private string m_DeviceUniqueId;
public string DeviceId
{
    get
    {
        if (m_DeviceUniqueId == null)
        {
            m_DeviceUniqueId = Windows.Phone.System.Analytics.HostInformation.PublisherHostId;
        }
        return m_DeviceUniqueId;
    }
}

Windows 8

On Windows 8, it’s yet another API to get the device ID and can be accomplished with the following

private string m_DeviceUniqueId;
public string DeviceId
{
    get
    {
        if (m_DeviceUniqueId == null)
        {
            var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
            var hardwareId = token.Id;
            var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);

            byte[] bytes = new byte[hardwareId.Length];
            dataReader.ReadBytes(bytes);

            m_DeviceUniqueId = BitConverter.ToString(bytes).Replace("-","");
        }
        return m_DeviceUniqueId;
    }
}

Gotchas

If you are using this code to get ID with your apps, be aware that the ID returned will be different in every app.  For example, if you have APP1 and APP2, APP1 may return 12345 as the device ID and APP2 may return 09876 as the device ID even though they are running on the same device.

Enjoy!

Sharing Code Part IV: Portable Class Libraries

In the last three posts, I have gone through various ways to share common code across the various Windows based platforms. So far in this series of articles in sharing code we have looked at

  1. Sharing Code Part I: Common Source File (source code download)
  2. Sharing Code Part II: Partial Classes (source code download)
  3. Sharing Code Part III: Conditional Compile (source code download)

In this final part, we’ll look at using a Portable Class Library to share the Math2 class across the different platforms instead of the C# source code file. Personally, I prefer sharing the source code file across the platforms and not sharing an assembly as it gives a little more control. Of course, if I’m building out an API or SDK for external developers to use, a Portable Class Library is the way to go. Continue reading Sharing Code Part IV: Portable Class Libraries

Sharing Code Part III: Conditional Compile

In the first part of Sharing Code series we looked at sharing a common class source file across three different platforms, and in the second part we continued with using partial classes to separate the code out. In this third part of the series, we’ll look at using conditional compiles in our code and continue working on the sample code from the previous articles. Continue reading Sharing Code Part III: Conditional Compile

Sharing Code Part II: Partial Classes

In the first part of Sharing Code series we looked at sharing a common class source file across three different platforms. Continuing the series on Sharing Code across various platforms, we’ll look at leveraging partial classes to help share code across our many apps on Windows 8, Windows Phone 7 & Windows Phone 8 using the same source code from Part I.

What is a Partial Classes?

Essentially a partial class allows you to separate a class or structure into two or more separate files. Personally, I use this technique to hide any specific platform code from other platforms.

Continue reading Sharing Code Part II: Partial Classes

Sharing Code Part I: Common Source Files

In this article, I’ll go through how to share source code files between Windows Phone 8, Windows Phone 7.1 and Windows 8.  In this sample we’ll go through how to share a Math class between two separate Windows Phone projects.

Creating the Projects

First thing is to create two Visual Studio 2012 Projects one for Windows Phone 7.1, 8 and Windows 8.

Windows Phone 7.1 Project

Create a Windows Phone Project and call it WP7_App and uncheck ‘Create Directory for solution’.

Continue reading Sharing Code Part I: Common Source Files

Sharing Code Across Platforms: Introduction

In 2006 I did a presentation on that focused on .NET Compact Framework for Desktop Developers where the core focus was on how to leverage existing code from the full desktop .NET Framework and .NET Compact Framework.

Well seven years later (yes I’ve been doing this a long time!), some of those techniques are still usable with all the different mobile platforms available and as a developer you definitely want to leverage as much code as possible.

In the next series of articles, I will go through some techniques on sharing code across different platforms including Windows Phone 7, Windows Phone 8 and Windows 8. You can use some of the techniques also on iOS and Android using Xamarin.

The following topics will be covered:

  1. Sharing Code Part I: Common Source File (source code download)
  2. Sharing Code Part II: Partial Classes (source code download)
  3. Sharing Code Part III: Conditional Compile (source code download)
  4. Sharing Code Part IV: Portable Class Libraries (source code download)

I have personally used these techniques with various products we have built plus customer work.  By the end of the series, hopefully you will have a good understanding on how to leverage your code across different platforms using C#.

Note that the samples being used are not using anything like MVVM or other frameworks as it’s something I was using my 11yr old son on using programming to solve some math homework he had and I wanted to keep it as simple as possible.

Windows 8 HTML/JavaScript Sessions at DevTeach

DevTeach is coming to Toronto May 27-31st and I’ll be doing a couple of session on developing Windows 8 apps using HTML5 and JavaScript

Designing Windows Store HTML5/JavaScript Apps Using Blend and Visual Studio

Embrace the Windows 8 design principles by taking full advantage of the rich feature sets offered by both Blend and Visual Studio. Learn how to start from scratch and have a fully functioning (and visually appealing!) application that highlights how to work with styles, controls, data sources, layout, CSS3 transitions, web services, and many other features that help you create a better user experience with greater productivity.

JavaScript, HTML, and Windows Store Apps

In this talk we’ll cover the basics of creating a Windows Store app experience using HTML and JavaScript, including the Windows Library for JavaScript (WinJS). Topics will include how to leverage your existing HTML and JavaScript skills, how to integrate Windows 8 personality and contracts into your app, and how Microsoft Visual Studio 2012 provides tools to make this easy and fast.

There are also a bunch of other sessions on Agile, Architecture, Mobile, Cloud Computing, SQL and other topics by some great speakers so be sure to register for DevTeach and attend!

Building Windows 8 Apps with HTML5 & JavaScript

Recently I was asked to do a webcast on Building Windows 8 Apps with HTML5 & JavaScript as part of the Developer Movement Web Camp.

WEBC1_Custom

Here is a list of some of the content covered:

Throughout some of the demos, I showed the Contoso Cookbook.  The original download for Contoso Cookbook which goes through a lot of concepts is available in the Windows 8 Camp in a Box.

Here is a list of the links used for some of the demos and links to source code

  1. Demo 1
    1. Windows 8 HTML5 Platform
    2. 3D Transforms
    3. CSS3 Grid Layouts
  2. Demo 2
    1. Touch Effects
    2. Touch Effects in Windows 8 Source Code
  3. Demo 3 – Contoso Cookbook
  4. Demo 4 – Windows 8 Twitter Search App
  5. Demo 5 – Animation Library Sample

Here is the video which is hosted on the Channel 9 site and be sure to check out all the other Developer Movement Web Camp presentations including my other one A Lap Around Windows 8 Development for HTML Developers.

A Lap Around Windows 8 Development for HTML Developers

labWin8

During the  Developer Movement Web Camp I presented on Building Windows 8 Apps with HTML5 & JavaScript and as a deeper dive, I also presented Lap Around HTML Development for Windows 8 where I covered the features of WinJS and some of the WinJS Controls in more details. Here is a list of some of the topics covered:

  1.  WinJS Promises
  2. WinJS Animation Library
  3. Camera Capture in Windows 8
  4. Windows.Devices.Sensors
  5. MSPointer in WinJS
  6. WinJS Tiles & Notifications
  7. Windows Push Notification Service
  8. WinJS Contracts

A lot of the demos where off the MSDN sample site and listed here for easy download

  1. Demo 1,6,8,9 – Contoso Cookbook
  2. Demo 2 – Controls
    1. HTML Essential Controls
    2. ListView Essential Samples
  3. Demo 3 – Animation Library Sample
  4. Demo 4
    1. Camera Capture UI Sample
    2. Media Capture Sample
  5. Demo 5 – Canvas Paint Sample
  6. Demo 7 – App Tiles & Badges Sample

Throughout some of the demos, I showed the Contoso Cookbook.  The original download for Contoso Cookbook which goes through a lot of concepts is available in the Windows 8 Camp in a Box.

Here is the video which is hosted on the Channel 9 site and be sure to check out all the other Developer Movement Web Camp presentations.