Sunday, September 16, 2012

Windows 8 Hard Drive Problem

I have taken a break from my Windows 8 posts because I am having a problem with my Windows 8 environment.

I have a Dell Studio 540 that has worked for a couple years without any problems. To try out Windows 8 I purchased a new Seagate Barracuda 500 GB SATA drive, switched the SATA cable from my old drive to the new one and installed the Windows 8 x64 RTM from MSDN. Initially it worked ok but after about a week of off and on use I started getting corrupt files on the drive and it eventually got to the point where none of the restore tools in Windows 8 could fix the problem. At this point I ran the Seagate diagnostics on the drive but it didn’t find any problems.

I re-formatted the drive and re-installed Windows 8, and again after a couple days I got corrupt files. I also checked the event log this time and noticed NTFS errors in the log. As a final test I re-formatted the drive but installed Windows 7 this time. I have been running Win 7 on the drive for over a week now with no problems, so it appears to be an issue with Windows 8.

If anyone has seen any issues like this with Windows 8 please let me know. I’ll also post here if I find a resolution to the problem.

Saturday, September 15, 2012

Recently I have been trying out a new online development environment called  This site combines and online IDE,  a hosting environment, as well as social networking elements that  allow you to easily develop web based applications in PHP, Perl, Python and Ruby. The site is currently in a closed Beta, but you can request an invite from the login screen. It is free to try out the Beta, but the site will eventually move to a pay model. Their FAQ says that there will be an option for a small, free development environment.

Once your account is created and you click on the Develop tab you will be taken to this screen.


On the far left are buttons that take to various parts of the site and just to the right of that is the file structure for you hosting site. You will be assigned a sub-domain at to access your applications, in my case it is The directory structure is automatically populated with some sample files to start with. In the main pane of the screen you will see the development tools, but the only one that is currently available is Ace Editor which is a basic text editor. You can double click on a file in the directory to open it for editing, or right click on a folder to get to a context menu that will allow you to create a new file.


Besides the text editor, there is also a terminal window that gives you access to the bash shell for you hosting server.


The site currently has support for both the MySQL and Mongo databases. Setting up a database is very easy. From your account settings you select Database settings, then click the plus sign on the Database Settings line to add a new database.


Once you select the type the database will immediately be setup and you will be provided with the host name, userid and password to access it. There is currently no graphical MySQL management tool built into the site, but I did find instructions on their wiki that explains how to install PhpMyAdmin in your site, although I haven’t tried it yet.

What I have seen so far is a very nice start at an online development environment. There are still a lot of features missing, but what has been implemented works nicely. I look forward to seeing how this site evolves over time.

Sunday, September 9, 2012

Scheduled Toast Notification

In my last post I introduced Toast Notifications for WinRT apps. In that example I had the notification show immediately, but you can also schedule a toast to appear sometime in the future. The NotificaitonsExtensions library doesn’t have direct support for scheduled toast but this is pretty easy to work around.
Here is the code for a scheduled toast:

var toast = ToastContentFactory.CreateToastText01();
toast.TextBodyWrap.Text = "You have a new message";

var schedToast = new ScheduledToastNotification(toast.GetXml(), DateTime.Now.AddSeconds(30), new TimeSpan(0, 0, 60), 5);

The first two lines setup a toast notification using the NotificationsExtensions library just like we did in the last example. In the next line we create the scheduled toast object, by passing four parameters to the constructor. For the first parameter we use the GetXml() function to get the XML template from our toast object. The second parameter sets the time when we want the toast to appear, in this case 30 seconds in the future. The third and fourth parameters are optional and allow you to enable the snooze capability of the notification. When the user closes the toast it will reappear after the time interval set in the third parameter  (this must be from 60 seconds to 60 minutes), and will reappear the number of time in the fourth parameter (this must be from 1 to 5).

The final line calls the AddToSchedule function to schedule the notification.

Once the notification has been created it will pop up at the scheduled time even if the program is no longer in memory. There is a function called RemoveFromSchedule that can be used to remove the notification if you have still have a reference to the ScheduledToastNotification object. In most cases we won’t still have a reference to this object so we need a way to find it. To do this we will first have to add a unique identifier to the ScheduledToastNotification object:

schedToast.Id = "ToastID1";

Here I am just using a fixed string, but for a real application you will have to come up with some method of uniquely identifying notifications. After the notification has been created you can use the Id to find and remove it:

var scheduled = ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications();
foreach( ScheduledToastNotification notify in scheduled) {
    if (notify.Id == "ToastID1")   ToastNotificationManager.CreateToastNotifier().RemoveFromSchedule(notify);

In this code the first line gets a list of all scheduled toast notifications that our app has created. The next two lines will iterate through this collection looking for the Id of the notification we want to remove, then calling RemoveFromSchedule to remove it.

Monday, September 3, 2012

Toast Notifications

There is one other type of notification that I didn’t cover in my original articles on WinRT application notification, that is the toast notification. In this article I will explain how to use these with the NotficationsExtensions that I introduced in my last post.
Unlike tile notifications and badges, toast notifications show up in the application UI instead of on the start screen tile, and will even show up if they user is in a different app. The notification tile appears on the upper right corner of the screen and will stay visible for a short period of time or until the user closes it.
Before we can show toast notifications there are  a couple things we need to do. First, open the Package.appmanifest in your application and be sure Toast capable is set to Yes.
Next, on the start screen select Settings from the Charm menu, click Change PC Setting, then select Notifications and be sure Show app notification is turned on
Now we can look at the code. First be sure you have the NotificationsExtensions library included in your application as I described in my last post. You will also want to add these two namespaces:

using NotificationsExtensions.ToastContent;
using Windows.UI.Notifications;

Here is the code to display a simple notification.

var toast = ToastContentFactory.CreateToastText01();
toast.TextBodyWrap.Text = "You have a new message";
var notify = toast.CreateNotification();

The first line uses the NotificationsExtensions library to create an object for the notification template we want to use. Just like notification tiles on the Start menu there are a number of different notification styles, some with text and some with text and an image. Once we have the template object we can set the text we want to display, this is done in the second line. Finally the third and fourth lines display the notification which will stay on the screen for about seven seconds then fade out.


If you want it to stay on the screen longer you can do this to have it displayed for 25 seconds:

toast.Duration = ToastDuration.Long;

This is a simple example of a notification, but there are other things we can do with it. When the notification popped up you will notice that there was a sound along with it. You can change this sound to one of a couple different built in sounds like this:

toast.Audio.Content = ToastAudioContent.Reminder;

or you can turn it off completely like this:

toast.Audio.Content = ToastAudioContent.Silent;

Instead of a single short sound, you can also specify one of a series of looping sounds that will play until the toast disappears or is dismissed.

toast.Duration = ToastDuration.Long;
toast.Audio.Loop = true;
toast.Audio.Content = ToastAudioContent.LoopingCall;

For the looping sounds to work you also have to have the Duration set to Long and the Loop property set to true.

Saturday, September 1, 2012

Notifications Extensions

When I wrote my first article on tile notifications in WinRT apps back when the developer preview was released I commented that the method for setting up the content for the tiles was a little cumbersome and I hoped that a better way would come along in the release version. There was no changes to the actual framework, but the WinRT samples do come with  a helper library called NotificationsExtensions that does make things easier.
You can get the source code for the library from the App tile and badge sample. You can find the source there in both C# and VB.NET. In this article I will be showing how to use it in C#. Once you have downloaded the sample you will want to pull out the NotificationsExtensions project folder and add it to your own project. If you want, once you have compiled the project, you can just add the NotficationsExtensions.winmd file found in the bin directory into other projects and included it as a reference instead of using the source project.
To use the library the first thing you will want to do is include a couple namespaces:

using NotificationsExtensions.TileContent;
using Windows.UI.Notifications;

The first is the namespace for the tile notification helper classes and the second is the WinRT namespace for notifications. Also remember that if you want to see the wide tile on the start screen you will need to create a 150x310 pixel jpg or png and point the Wide Logo property in the application manifest to it.

Now we are ready to setup the tile content.

ITileWideText03 tileContent = TileContentFactory.CreateTileWideText03();
tileContent.TextHeadingWrap.Text = "Wide tile notification";

ITileSquareText04 squareContent = TileContentFactory.CreateTileSquareText04();
squareContent.TextBodyWrap.Text = "Square tile notification";
tileContent.SquareContent = squareContent;

The first line uses the TileContentFactory class from the NotificationsExtensions library to create a helper class to build the wide tile content template. In TileContentFactory there is a function to create a class for each tile template. You can see all the available templates on the Tile Template Catalog page on MSDN. Once the template class is created you can use its properties to set the content of the template instead of having to deal directly with the XML template.  The second line sets the text to appear on this tile.

The next three lines use a similar process to setup a square tile template. If your application supports both tile sizes then you should always create a notification template for each size so it will display no matter which size the user has set the tile to. The third line of that section attaches the square content to the content we created for the wide tile.

Once we have the templates setup it’s a simple matter to display them using the notification functions:


If you compare this to how the notification was done in my original post, you can see that this does make thing a little easier.

Badge Notifications

Besides tile notifications the library also has helpers for doing badge notifications. As described in my earlier post, badges are either small numbers or symbols that can be shown in the lower right corner of a tile. To do badges you will want to include one more namespace:

using NotificationsExtensions.BadgeContent;

The code to show a numeric badge looks like this:

BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(10);

The first line creates the content for the numeric badge using the new library. You can see that the number to be displayed is passed to the constructor. The second line uses the framework functions to display the badge.

The code to display glyph badges is similar:

BadgeGlyphNotificationContent badgeContent = new BadgeGlyphNotificationContent(GlyphValue.Busy);

In this case we pass one of the GlyphValue enumerations to the constructor to specify which shape we want to display.