Earlier this year, Microsoft announced Universal Apps – an enhancement in VS2013 that took advantage of improved API compatibility between Windows 8.1 and Windows Phone 8.1 to allow a much greater amount of code sharing between an app for both platforms.

This article is not going to look at that side of things in any detail. Instead, whilst working on a Universal App version of Relative History, it occurred to me that there might be … challlenges … when it comes to dealing with how a user has been using an existing Windows Phone app. The primary reason why there could be challenges is because a Windows Phone Universal App doesn’t use the Silverlight infrastructure so access to things like application settings get handled in a different way.

Upgrading a published Windows Phone app

There is some guidance published by Microsoft on how to upgrade an app. It mostly focusses on upgrading to Silverlight 8.1, which is not of much help to me, but there is some key information about the upgrade process, namely:

If testing, it is necessary to copy the ProductID and PublisherID attributes from the published app into the PhoneProductID and PhonePublisherID attributes in the Package.appxmanifest file. This is for the scenario where the earlier version of the app is already deployed onto a device or emulator but not installed from the Store. It is not possible to upgrade an app installed form the Store by deploying a new version of the app from your development computer.

If publishing, you simply submit the app to the Store. Microsoft takes care of replacing the product ID and publisher ID with the values from the app you are updating.

I’ll go into some of the above in more detail in a moment, but the key point here is that you cannot upgrade a Store-installed app in testing. If you want to test the process through the Store, here are the steps (thanks to Romasz for his answer on StackOverflow):

Publish a Beta version of the existing app – WP7.0/7.1/8.0 Silverlight.

Install that from the Store onto your phone.

Submit an update to the Beta version in the Store. Add a new package. Do not replace the old package.

Your phone will eventually spot the new version and update it. When you run the updated app, it should then execute any code you’ve written to deal with the upgrade process.

Can settings and files be “upgraded”?

My first thought was: when a user upgrades from a Silverlight-based WP app to a XAML-based WP app, what happens to the settings and what happens to any locally-stored files? Let’s see what the community says …:

If a WP Silverlight app gets updated to a WP 8.1 XAML app, what happens to settings & storage? Kept or lost? #WPdev

So, the answer is a qualified yes … so the next question is how do we go about it?

Upgrading an app

If you haven’t already done so, you need to install Windows Phone Power Tools (WPPT). This will help because it allows you to browse and access the contents of the app’s private storage. This is useful, for example, if you want to see what you need to be accessing, updating or (in my case) deleting when you migrate from Silverlight to XAML.

As was touched upon earlier and, as Ginny pointed out, you need to make sure that the App ID remains the same. This is the ID string that the operating system uses to identify your app and can be found in WMAppManifest.xml.

Copy that string into the clipboard then open the file Package.appxmanifest in VS2013 using the XML(Text) Editor. You need to paste the ID you’ve just copied into the PhoneProductId string in that file and save it.

The PublisherID can be found towards the end of the same XML section in WMAppManifest.xml and this then gets copied into the PhonePublisherId section of Package.appxmanifest.

Now build your app. If it was building successfully previously, it should still build successfully. You can even deploy it to a device or emulator if you want to double-check :-).

Next step is to install the WP Silverlight version of your app to a device or emulator. Use WPPT to install the XAP file. Once installed, run the app and do whatever you need to do in order to get it set up, or get some data installed … whatever is necessary to properly test the upgrade process.

Updating the settings

Once you’ve installed the Silverlight version and used it a bit, you can use WPPT to look at the Isolated Storage for your app:

Notice how I’ve expanded the Local directory. The main file we’re interested in now is __ApplicationSettings. Everything else will continue to exist after the app is updated by the WP XAML version of the app, and it then becomes up to you whether or not your new version can use those files, update them or delete them. In the case of my app, for example, the Silverlight version of the app uses the local SQL implementation and the data is stored in .sdf files. With the XAML version, I’ve moved to using SQLite so the .sdf files are essentially useless to me. My app will need to delete them in order to free up the storage space, but I’ll also use the contents of __ApplicationSettings in order to ascertain more information about those databases so that I can re-import the data, this time into a SQLite file.

So … onto __ApplicationSettings. If you use WPPT to get the file onto your computer, you can open it in WordPad and see something like this:

It is important to note that the application settings stored by a WP Silverlight app cannot be accessed through ApplicationData.LocalSettings. The latter is for Windows Store apps.

To retrieve the settings stored by a WP Silverlight app, we basically have to read and parse the __ApplicationSettings file. A simplistic way to do this would be something like this:

That succeeds in reading in the XML. You’ve then got to iterate through the list, looking for Keys that you are interested in and extracting the Values from the corresponding XML node. For example, here is one node retrieved from my settings file:

Things get a bit more challenging if you used a class or other complex type to save away. Thankfully, Pedro Lamas has written a great bit of code that essentially mimics what the Silverlight code does when it reads in the application settings file. So, now, all you need to do is call GetValuesAsync() and you’ll end up with a set of key pairs including any non-standard classes. In my case, that is an ObservableCollection<DatabaseList>.

Now, I did encounter some struggle points while trying to get Pedro’s code to work in my app. The main challenge was around the handling of the first line in the settings file. That line of text (which I was ignoring in my simplistic approach) actually lists out any “non standard” types so that the DataContractSerializer knows how to parse the XML appropriately and rebuild the objects.

So why was I having problems? Here is the first line from my settings file:

The problem I was having was that the call to Type.GetType (in Pedro’s code) was returning null because the system couldn’t match the object. There were a couple of reasons why, in my case:

The WP Silverlight app had an assembly name of “Relative History”. In my Universal App project, I had the Win8.1 project set to an assembly name of “RelHist2.Windows” and the WP8.1 project set to an assembly name of “RelHist2.WindowsPhone”.

The version number expected was 1.4.8.0 but my Universal App has a version number of 1.0.0.0.

One work-around I came up with was to replace the section of Pedro’s code where knownTypes is declared with this:

This worked but did mean that the code wasn’t then as flexible as it should be. I finally solved the problem by changing the assembly names in my Universal App to match that of the Silverlight app, and increased the version number to be higher than that of the Silverlight app.

One final tweak to Pedro’s code if you are copying/pasting his code rather than using Cimbalino is to change:

For a while, I’ve been using my Surface Pro 2 with an external monitor, with the Surface beneath the monitor. In Windows, I’ve had the Surface’s screen to the left of the monitor and I’ve “trained” myself that if I want to move something from the monitor “down” to the Surface, I have to move it to the left.

Today, I added a 2nd external monitor, daisy-chained with Display Pro, and then moved the SP2 so that it sits underneath both of them, like this:

I then opened the Screen resolution dialog and started dragging the SP’s screen across so that it would sit between the two external monitors. As I did, I realised you could alter the vertical position of the screen relative to the two monitors. In doing so, I discovered that you can literally match how the monitors are laid out:

I’ve now got to retrain my muscle memory so that it moves content in the physical direction of the screens rather than how I remembered the logical layout, but I am really impressed that this is possible!

(Probably obvious to most, but sometimes it is the little things that can make a big difference!)

One of the things I love about the look of Windows 8 is the little touches of feedback as you navigate around. For example, here is the Messaging icon on the Start screen:

If you hover over it on a mouse-based system, you get a little extra border to hint that you can click on it:

and if you select the icon, you get a different border with an earmarked tick:

Sweet! So what happens if you try to use this in your own app? Here are the screenshots of a button using the Standard500x130Template in a GridView:

Now, I don’t consider myself to be a designer but these look pretty ugly to me! If you look at the Standard500x130Template, though, it doesn’t really hint at how it can be made prettier to get it to look more like the Messaging button.

The solution lies with ItemContainerStyle. This is a block of XAML that you can reference from, say, a GridView and it defines what an item is going to look like when it goes through different visual states. The first thing you have to do is use Blend to capture a copy of the default definition by using these steps:

In the window that appears (below), accept the defaults and click on OK:

Switch Blend to code view and you should find a style has been added called GridViewItemStyle1. You can copy & paste this either into a central style XAML file for your project or, if only needed on a single page, directly into the Resources section of that page’s XAML.

(If you are struggling with the above steps, you can find the original XAML at the end of this post)

I’ve already mentioned that I’m not a designer, so I don’t pretend to fully understand VisualState or StoryBoard but I’ll work through some of the key elements as I understand them and explain how the rendering of the items works.

Let’s start with what happens when you position the pointer over an item. We’ve seen from the screenshots that a big grey rectangle appears. This happens because the VisualState PointerOver contains the following line:

If you look further down the XAML, you will see that this is a rectangle with a fill colour of ListViewItemPointerOverBackgroundThemeBrush. What the above animation does is switch the opacity so that it becomes visible.

So why is it a big grey rectangle and not a nice border like with the Messaging icon? The answer lies with another rectangle which, by default, is only shown when the item is selected! This is the SelectionBackground rectangle and it is filled with ListViewItemSelectedBackgroundThemeBrush. I’ll come back to this in a minute.

Now, let’s look in more detail at what happens when the item is selected. This is another VisualState called, sensibly enough, Selected. This changes the opacity of SelectionBackground, SelectedBorder and SelectedCheckMark so that they become visible. We’ve already looked at SelectionBackground, so what about SelectedBorder and SelectedCheckMark?

SelectedBorder is another rectangle that gets drawn around the item with a stroke colour of ListViewItemSelectedBackgroundThemeBrush so that you get a thin, unfilled rectangle.

SelectedCheckMark is a grid consisting of two paths – one drawn with a fill colour of ListViewItemSelectedBackgroundThemeBrush and the other drawn with a fill colour of ListViewItemCheckThemeBrush. The latter is the tick and the former is the corner triangle that is drawn around the tick.

So, all of the pieces of the puzzle are there. Why, then, doesn’t the item get drawn even remotely like the Messaging icon? Let’s look at the Selected visual state again. It causes three items to be displayed but there is a problem with this – the SelectionBackground, as defined in the style, is filled with the same colour as the SelectedBorder and the corner triangle in SelectedCheckMark. That is why the border and triangle don’t show up.

After a bit of thinking about this, I made a couple of changes that actually ended up fixing all of the above problems, so I’ll just share my changes:

Change the fill colour of SelectionBackground so that it uses a different colour from ListViewItemSelectedBackgroundThemeBrush. In my case, because my items are being drawn on a white background, I fixed the colour at white … you’ll see why in a minute.

Change the opacity of SelectionBackground from 0 to 1 so that it is always visible.

Why make the last change? It turns out that the reason you get a big grey rectangle instead of a nice border hint is because the selection background isn’t visible – remember that I mentioned it only gets switched on when the item is selected? So by forcing it to be visible all of the time, that changes the appearance of that big grey rectangle to a nice border hint.

Here are the screenshots after revising the style:

Much better!

I don’t know or understand why the default style is defined the way it is, and it may be that the changes I’ve made aren’t the optimal ones but they do seem to get my app to be closer to those released by Microsoft. Once you’ve defined the style, all you need to do is reference it in the GridView or ListView with ItemContainerStyle=”{StaticResource <whatever you called it>}”.

Windows tries to protect you from yourself, and it tries to do it without nannying you, but sometimes it can be a real nuisance. A good example is blocked files. If you download something from the Internet, it is considered to be “untrusted” and therefore blocked from being used until you go and unblock it.

Which is all well and good if it is just one file, but if you’ve downloaded a Zip file of source and you extract everything from the Zip file, you’ve then got to unblock each and every file.

Which is a nuisance if you are using Explorer, because you can only do one at a time.

So it was really nice to find that PowerShell can unblock files and you can provide it with a recursive listing of files to unblock, e.g.:

Get-ChildItem -Recurse | Unblock-File

USE WITH CAUTION! This will literally unblock every file from the current directory downwards, so be sure that you do trust everything you are unblocking, but it should save you some time.

After working with Active Directory since 2000, I’ve clearly become a bit spoiled with the ability to create a group in AD that serves the purpose of both a security group and a distribution group with just one checkbox. Why do I say that? Because in LDAP, there isn’t a commonly used way of achieving that same goal.

LDAP, or Lightweight Directory Access Protocol, is an Internet protocol that services can use to look up information from a server. Active Directory makes use of LDAP which is why you’ll come across terms common to both such as schema.

For the UNIX world, the commonly used schemas are defined in RFCs. For example, the most common objectClass used to define a person – inetOrgPerson – is defined in RFC 2798. This is a really great class to use for storing personal information in an LDAP directory because it has attributes for all of the important stuff you might want to know about someone.

When it comes to groups, though, things get a bit tougher. There is posixGroup which is a good class to use for security needs because it stores a group ID, a description and the members of the group. Rather surprisingly, there isn’t an accepted standard for defining a distribution or email group. There are classes for defining groups of users, such as groupOfNames, groupOfUniqueNames and groupOfMembers. They each have their slight differences and which one(s) you use typically comes down to either personal preference or the tools you are going to be using to manage those groups.

Another curious aspect about groups in LDAP is that there are differences in how the members are represented. For example, posixGroup uses an attribute called memberUid and the value is just that – the uid of the member of the group. groupOfUniqueNames, by comparison, uses an attribute called uniqueMember and the value is the distinguishedName of the member. One of the benefits of using the distinguishedName is that it allows groupOfUniqueNames to contain other groups as members, which posixGroup does not.

So when it comes to trying to maximise the value of a group’s membership by using the group for dual-purposes, i.e. security and email, what can you do? One option is to define your own objectClass and add it to the schema on the LDAP server. That is essentially what Microsoft did but the problem then is that your tools probably won’t know how to work with that class unless you can modify the tools.

Given that the objectClasses do represent members in different ways makes any attempt to “merge” or “overlay” multiple objectClasses to get the desired result is also likely to fail.

For myself, in the end, I decided that I would use posixGroup as the definitive representation of a group and then have a script that reads the various posixGroup groups and creates groupOfUniqueNames groups to match those groups. I wrote the script in Perl and it is at the end of this blog.

Here is a bit more detail about how the script works and how I’ve got my LDAP server set up …

I have an organizationalUnit (OU) called groups, below which I have an OU called mailing and an OU called security. The idea should be clear but all of my posixGroup groups go into ou=security and the script creates the mailing groups in ou=mailing. The script can be used in two ways:

Full scan of the security OU. It looks at each of the groups in turn and processes it.

Processing of one security group by specifying the cn value on the command line. This functionality is primarily there for use with LDAP Account Manager Pro. This great web-based product allows the administrator to define custom scripts that get run at specified trigger points. In my case, I get it to run the script, passing the cn value, when a group is created or modified, thus ensuring the email group is kept up-to-date.

The logic behind processing a security group is as follows:

Get the attributes we need from the security group: modifyTimestamp, description, displayName, mail, owner and memberUid.

If there aren’t any members, we delete the corresponding email group. This is because groupOfUniqueNames has to have at least one member. If you want to use groupOfMembers instead, that restriction goes away and the script could be modified accordingly.

If the email group already exists and its modifyTimestamp is newer than that of the security group, we don’t do anything else because the implication is that it was created by the script after the security group was created/modified.

The next step is to delete the email group. This is done rather than trying to figure out the differences in group membership. If you want to get fancy with the code, go ahead but this works for me .

The final step is to create a new email group, specifying the attributes and members retrieved from the security group.

A few notes about the attributes: the posixGroup class doesn’t allow you to specify a display name (displayName), email address (mail) or group owner (owner). To permit that, I use the objectClass extensibleObject which allows you to add any attribute defined in the schema. LDAP purists tend to frown on this because it could lead to errant attributes being added. If you are concerned, you could define your own objectClass as an auxiliary class in order to allow just those three attributes to be used. Alternatively, the script will work without them since displayName and owner aren’t strictly necessary and the script can auto-create an email address by adding the email domain to the end of the existing cn value.

For the email groups, I again use extensibleObject because groupOfUniqueNames doesn’t allow a display name or email address. The email address is clearly required if you want this to work as an email group and the display name may be required if you are, for example, syncing with Google (which was my requirement) and you want the group to have a “nicer” name than just the cn value. Again, if you don’t like the idea of allowing all attributes to be added, you could define your own objectClass and amend the script accordingly.

Final comments:

this is my first Perl script and I have been quite lazy in that I have hard-coded the various domain bits into the script. Feel free to improve and, if you want, share back!

I’ve not used SSL in the connection because the script runs directly on the LDAP server. It is quite straightforward to amend the script to use LDAPS and there are examples on the web on how to do that.

The script assumes, when converting from memberUid to uniqueMember that all of the UIDs exist in the same OU, namely ou=staff,ou=accounts,dc=example,dc=com. It should be fairly straightforward to extend the script so that it searches for the UID and finds the DN that way.

Those of you who have followed my occasional blog postings will know that I have a home theatre setup with a Hush PC running Windows 7 with Media Center and a Synology NAS to store full rips of DVDs and Blu-Rays. I use Media Browser as the front-end to all of my stored videos.

Recently, however, two factors have led me to become increasingly frustrated with this configuration:

ArcSoft’s Total Media Theatre does not play well in conjunction with Media Browser. The more recent versions of MB have improved the situation but TMT 5 just doesn’t play well. I don’t know if it is the fact that my hardware is now getting a bit old or because TMT 5 just isn’t a good bit of software.

Some of the Blu-Rays recently purchased are protected by Cinavia. If you haven’t come across this before, it is an audio watermark designed in such a way that if you play a copy of the content rather than an original source, playback is supposed to stop after a period of time with an error. Now, the version of TMT 5 I was using had not had Cinavia support added but the Blu-Rays wouldn’t play properly, if at all, so I was left wondering if there was a change in the way the discs were being created that my version of TMT 5 was choking on. Upgrading TMT to the most recent version would introduce Cinavia support, which would then totally prevent me from using ripped copies.

So I’ve been researching the various options available to me, focussing mostly on HandBrake. This is a great, free piece of software that does a fantastic job of taking various source material (DVD, Blu-Ray and others) and converting to MP4. It does one job and it does it really well. It does not include any capability for defeating copy protection but I use AnyDVD HD for that.

Now I know that converting Blu-Rays to a different compressed format – both audio and video – is going to lose me some fidelity, and I know that I’ll lose functionality as well, such as the ability to dynamically turn subtitles on and off, or select different audio streams, etc. There are ways to solve this, such as using different containers such as MKV, but Windows 7 doesn’t support MKV natively and I didn’t want to install any more software onto the media PC. According to reports I’ve read, it is possible that the Cinavia watermark survives the transcoding but Windows 7 doesn’t provide any support for Cinavia :-).

Here are the settings I ultimately ended up with:

Normal preset

Video tab: select Fast Decode. I found this necessary to stop the media PC occasionally choking on the playback.

Audio tab: add an audio track of your choice with the codec set to AAC (faac) and mixdown set to 5.1 Channels.

Subtitles tab: if your Blu-Ray has any foreign language in it (e.g. Avatar, Star Wars I, Salt, etc), you can choose to have the English subtitles for those sections burned into the video image. This requires a copy of the nightly build of HandBrake and not the stable build at this time (0.9.8 doesn’t support this feature). Just add Foreign Audio Scan, select Forced Only and Burn In. It should be noted that enabling this feature will result in longer processing time as HB then has to scan through the video to see where the subtitles get turned on and off in order to determine if there are any foreign language subtitles to select.

That’s it. I found the resulting video and audio to be of very high quality.

Having installed Windows 8 Pro, Visual Studio 2012 Premium and the new Windows Phone 8 SDK, I was keen to make sure that my Windows Phone 7.1 project still built & worked. That meant getting all of the references to work again.

Most of the references were for packages that I could install through Nuget. However, one was for a Zip file that I had to download and unpack. Upon browsing to the appropriate DLL and selecting it as the reference, Visual Studio promptly reported:

A reference to a higher version or incompatible assembly cannot be added to the project

The ultimate solution was to right-click on each of the files that had been contained in the Zip file, choosing Properties and then clicking on the Unblock button. Once that was all done, Visual Studio then allowed me to add the reference, although it did warn me that it might be unstable! Not a lot I can do about that J.

The Multilingual App Toolkit (or MAT for short!) integrates into Visual Studio 2012 and is intended to make it easy to manage the translation of strings through features such as import & export of translations and the use of Microsoft Translator to automate some of the processes.

Here is the answer: you must mark each and every string as Signed off in the Multilingual Editor (so that the blob on the left hand side of the window goes green) before those strings are used. Once you’ve done that, you should then see the strings being used so long as you’ve set your display language appropriate in Windows.