Introducing Hull CS Blogs for Windows 8

This week I’ve been working on porting my Hull CS Blogs app for Windows Phone 7 to Windows 8 (The PC &  Tablet Operating System).

I’ve been able to use a lot of my code from the WP7 app, but making some changes. For example saving and writing files is now done through Local Storage using StorageFolder, StorageFile and Stream objects rather than through Isolated Storage on Windows Phone. It took me a while to get used to the new API’s but now I understand them I actually prefer them and think they make more sense. For example my code to load an XML file on Windows Phone 7 Looked like this:

public static void LoadXML(string Location, out XDocument XMLFile)
        {
            // Get the local storage directory for this application
            using (IsolatedStorageFile IsoFile = IsolatedStorageFile.GetUserStoreForApplication())
            {
                //Open the file and make it into a stream
                using (IsolatedStorageFileStream IsoSteam = new IsolatedStorageFileStream(Location, FileMode.Open, IsoFile))
                {
                    XMLFile = XDocument.Load(IsoSteam);
                }
            }
        }

And in Windows 8 it now looks like this:

        public async static Task LoadXMLAsync(string Location)
        {
            // Get the local storage directory for this application
            StorageFolder storageArea = Windows.Storage.ApplicationData.Current.LocalFolder;

            // Get the file itself
            StorageFile storageFile = await storageArea.GetFileAsync(Location);

            // Read the file in as a stream
            IRandomAccessStream randomAccessFileStream = await storageFile.OpenReadAsync();
            Stream fileStream = randomAccessFileStream.AsStreamForRead((int)randomAccessFileStream.Size);

            return XDocument.Load(fileStream);
        }

Whilst the Windows 8 code appears to be longer, to me it makes more sense, and that can be more important in projects such as ours in which the code is going to be handed over to other software developers. First you find the directory, then you find the file, then you use it. It’s the exact same way of accessing data as people do in real life, or through windows explorer.

At the moment I’m still working on the user interface. An interesting challenge of Windows 8 development, which I haven’t had to deal with before in Windows Phone development, is the large amount of different screen sizes and resolutions that devices can have. In Windows Phone 7 there was one size,  800 x 480px.

The Windows 8 version of Hull CS Blogs should be available on the Windows Store before Windows 8 is available to the general public on the 26th October.

Danny

Advertisements

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s