Friday, August 31, 2012

Windows 8 AppBar style not found.

The Windows 8 AppBar comes with a set of default icons embedded in a set of AppBarButtonStyles.

AppBarButtonStyles

These styles are available inside the StandardStyles xaml file inside the Common folder of your Windows 8 XAML project.

The strange this was that when I tried to apply these styles to my AppBar buttons, Visual Studio complained that it couldn’t find the related resource:

<Button Style="{StaticResource AddAppBarButtonStyle}" />

I spent way too much time before I discovered that for one reason or another the AppBarButtonStyles were commented out inside the StandardStyles.xaml. Doh!



After uncommenting the styles I wanted to use, it worked perfectly.

Thursday, August 30, 2012

Caliburn.Micro: Design time support

WPF and Caliburn.Micro are a powerful combination. You create a viewmodel and related view, name your controls appropriately  and all magic happens automatically. Controls are bound to the View Model’s properties and methods for you. The problem is that it is all happing at run time not at design time. So when you are developing inside Visual Studio or Expression Blend you aren’t able to see how the form will look like with bound data.
Caliburn.Micro supports design-time binding out-of-the-box. How can we configure this?
In the constructor of my ViewModel, I check if we are executing in design time:
public class SampleViewModel : Screen
{
 public SampleViewModel()
 {
  if (Execute.InDesignMode)
         LoadDesignData();
 }
}
In this sample I populate my ViewModel with some sample data at design time.

private void LoadDesignData()
{
 this.Sessions.Add(new ProfilerSessionViewModel() { Id = Guid.NewGuid(), Duration = "30ms", Name = "Session 1", Started = DateTime.Now.AddMilliseconds(-30) });
 this.Sessions.Add(new ProfilerSessionViewModel() { Id = Guid.NewGuid(), Duration = "30ms", Name = "Session 1", Started = DateTime.Now.AddMilliseconds(-30) });
 this.Timings.Add(new TimingViewModel() { Duration = "30ms" });
 /*Removed some lines*/
    this.Queries.Add(new QueryViewModel() { CallStack = "", Duration = "10", NrOfRecordsAffected = 92, Query = "SELECT * FROM Products", QueryType = "ExecuteDataReader", Step = "Executing query", TimeFromStart = "3" });
}

In my view I added the following code:

<Window x:Class="VLM.SOFA.Profiling.Win.UI.ProfilerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" 
xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
xmlns:vm="clr-namespace:VLM.SOFA.Profiling.Win.UI"
d:DataContext="{d:DesignInstance Type=vm:SampleViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True">
</Window>


I set the Bind.AtDesignTime property of Caliburn.Micro to true, create an ignorable alias “d” and assign an instance of my viewmodel to my design time datacontext.

And now we have nice design time support:

image

Wednesday, August 29, 2012

Some random Azure news…

Windows Azure Training Kit

Last week Microsoft released the August 2012 version of the Windows Azure Training Kit. The update of the Windows Azure Training Kit includes 41 hands-on labs and 35 presentations.

Some of the updates in this version include:

  • Added 7 presentations specifically designed for the Windows Azure DevCamps
  • Added 4 presentations for Windows Azure SQL Database, SQL Federation, Reporting, and Data Sync
  • Added presentation on Security & Identity
  • Added presentation on Building Scalable, Global, and Highly Available Web Apps
  • Several hands-on lab bug fixes
  • Added the Windows Azure DevCamp 1-day event agenda
  • Updated Windows Azure Foundation Training Workshop 3-day event agenda

Azure Storage Explorer 5 Preview 1

I also noticed that a new version of the Azure Storage Explorer is available. Azure Storage Explorer is a useful GUI tool for inspecting and altering the data in your Windows Azure Storage storage projects including the logs of your cloud-hosted applications. A must have for every Azure developer!

ase5_blobsview.png

Tuesday, August 28, 2012

Visual Studio 2012 RTM: Async tests are not found when using .NET Framework 4.0

For a project I created some async unit tests inside Visual Studio 2012 RC.
[TestMethod]  
public async Task AsyncTest()   
{   
 var result = await MyOperationAsync();   
 Assert.IsTrue(result);   
} 

Last week I took the opportunity to upgrade to the VS 2012 RTM version. But when I tried to run my async tests again, no tests were executed and the MsTest engine reported that no tests were found?! When I removed the async and await keywords, MsTest found my tests again… What has changed in Visual Studio that this no longer works?

It took me some time to figure out the root cause. What happened?

As the projects I wanted to test were .NET 4.0 projects, I decided to set the Unit Test project also to .NET 4.0. Of course in .NET 4.0, you don’t have async support out-of-the-box. So I installed the “Async targeting pack for Visual Studio 2012”.

The "Async Targeting Pack for Visual Studio 2012" enables projects targeting .NET Framework 4.0 or Silverlight 5 to use the Async language feature in C# 5 and Visual Basic 11. This pack requires Visual Studio 2012 and will not work with Visual Studio 2010.

The pack contains the API support necessary to use the 'async' and 'await' keywords in C# 5.0 and Visual Basic 11, as well as a set of Task-based adapter APIs that allow using some of the existing asynchronous APIs with the new language keywords.

 
This worked fine in Visual Studio 2012 RC. MsTest was able to discover and run my tests without a problem. The moment I upgraded to the RTM version, it no longer worked.
How did I fix it?
After changing the target framework for my Test project to .NET 4.5, my tests were discovered again. Anyone with a better solution?

Monday, August 27, 2012

WinRT: The notification platform does not have the proper privileges to complete the request.

While trying to register my Windows 8 app for push notifications using PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(), it always failed with the following error message:

The notification platform does not have the proper privileges to complete the request. (Exception from HRESULT: 0x803E0208)

Reading the exception information made me think that my app was missing some declarations in the app manifest, but the only one I needed was the internetClient capability and I couldn’t find another related declaration.

In the end the MSDN forum brought the rescue. I was running in the simulator and it that case you don’t have the required privileges. Running from Local Machine solved the issue.

Friday, August 24, 2012

Caliburn Micro: configuring the Window dialog

Caliburn Micro offers you the WindowManager to display a dialog. You only have to specify the viewmodel and Caliburn will do the rest, it finds the corresponding usercontrol, embeds this usercontrol into a window, binds view and viewmodel together and shows the result to the user.var loginViewModel = new LoginViewModel(); 


WindowManager windowManager = new WindowManager(); 
SettingsViewModel vm=new SettingsViewModel();
windowManager.ShowDialog(vm); 

But what if you want to change the behavior or the look of this window? As Caliburn.Micro creates this window for you, you don’t have direct control over it.

Therefore the WindowManager.ShowDialog method has an extra overload which allows you to specify a settings object (as a Dictionary<string,object>).

How can we use this? An example…

dynamic settings = new ExpandoObject(); 
settings.WindowStyle = WindowStyle.ToolWindow; 
settings.ShowInTaskbar = true; 
settings.Title = "This is a custom title"; 
 
windowManager.ShowDialog(loginViewModel, null, settings); 

Thursday, August 23, 2012

Caliburn.Micro: Using a local resource as a proxy to your viewmodel

For a project we are doing we are using the ArcGis WPF components. As we want to use a MVVM architecture we try to use databind wherever possible(by using Caliburn.Micro). The problem is that one of the WPF components (the GpsLayer) inherits from DependencyObject, but the DependencyObject is not linked to a DataContext. Microsoft states that the DO should inherit the DataContext from the containing FrameworkElement, but that in fact doesn't happen.
The only samples we found that worked were using the StaticResource approach:
<Window.Resources>
     <local:MainViewModel x:Key="MainViewModel" />
</Window.Resources>

<Grid DataContext="{StaticResource MainViewModel}">

    <esri:Map Extent="-14268281.1311858,2195120.17402859,-7232639.54776086,7467160.93387503">
    <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" />
      <esri:GraphicsLayer ID="MyGraphicsLayer" 
                          GraphicsSource="{Binding SearchResults, Source={StaticResource MainViewModel}}"/>
    </esri:Map>
</Grid>

But in this case, the MainViewModel was instantiated when the View is constructed, resulting in a View-First approach. We wanted a ViewModel first approach and let Caliburn.Micro do the hard work for us.

After trying lots of possible solutions, the ArcGis forums finally brought some help. There they suggested to create a DataContextProxy object to proxy access to the ViewModel.

public class DataContextProxy : Freezable
    {
        #region Overrides of Freezable

        protected override Freezable CreateInstanceCore()
        {
            return new DataContextProxy();
        }

        #endregion

        public object Data
        {
            get { return (object)GetValue(DataProperty); }
            set { SetValue(DataProperty, value); }
        }

        public static readonly DependencyProperty DataProperty =
            DependencyProperty.Register("Data", typeof(object), typeof(DataContextProxy), new UIPropertyMetadata(null));
    }

And in the XAML you can use it like this:

<esri:Map>
    <esri:Map.Resources>
            <local:DataContextProxy x:Key="proxy" Data="{Binding}" />
    </esri:Map.Resources>
    <esri:ArcGISTiledMapServiceLayer ID="PhysicalTiledLayer"
              Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>

    <esri:GraphicsLayer ID="MyGraphicsLayer"
            GraphicsSource="{Binding Path=Data.SearchResults, Source={StaticResource proxy}}" Renderer="{StaticResource MySimpleRenderer}" />
</esri:Map>

Wednesday, August 22, 2012

Remove Source Control Bindings

One of the annoying side effects of TFS (compared to Git) is that it adds a lot of extra files to manage the source control integration. This is not a problem as long as you don’t want to share your solution with someone else.  But the moment you zip your code and let them open up your solution, they get weird warnings from Visual Studio when they load the solution and projects.

What we need is a simple way to strip out all the source control bindings before we distribute the code. And that’s exactly what Saveen Reddy did.  He created a tool called VSUnbindSourceControl(https://vsunbindscc.codeplex.com/)

Usage:

  • Copy your solution to a new directory (because the tool does modify files)
  • Run this command: VSUnbindSourceControl.exe d:\myfolder

Once the tool is finished, all the source control bindings have been removed from an SLN files and from any *proj files.

Thanks Saveen!

Tuesday, August 21, 2012

Translating localized error messages

I talked about translating localized error messages before, but this time a colleague (thank you Martin!) found a similar tool: http://finderr.net/

“FindErr.NET solves the problem of almost nonexistent resources on the web for most software problems when they are sought for in their localized form - this is due to the fact that most problems are described in English.

FindErr.NET helps software developers to diagnose problems sent by their international clients with less effort. After quickly finding the meaning of an error message, developers are able to quickly debug the problem or ask for help on internet forums.

FindErr.NET assists IT professionals (such as IT Support personnel, system administrators or computer power users) to find information on a problem they encounter on a localized version of Windows (or a Windows installation with a language pack installed). After finding English equivalent of an error message, it is much easier to locate a solution on support forums, Microsoft Knowledge Base or to find it using a web search engine.”

image

Monday, August 20, 2012

TFS gets one step closer to distributed source control…

Between all the news about the release of Visual Studio 2012 and Windows 8, you’ll almost forget that Microsoft has other products too. Last week Brian Harry announced Git-tf, a solution that enables you to work locally with a Git repo – edit, commit, revert, branch, merge, etc. and then “sync up” with a central TFS repository. In this way, you can have the best of both DVCS and TFS.

The integration takes the form of a new command line tool called “Git-tf”. Git-tf works with a standard Git install and getting started is super easy. Just visit the download page and checkout Git-TF_Getting_Started.html. At the moment Git-tf won’t work with Team Foundation Service – it will only work with an on premises TFS server – either 2008, 2010 or 2012(but support for Team Foundation Service will be added soon).

Friday, August 17, 2012

Configuring AppFabric caching

For a project we are planning to scale out to a web farm solution. Therefore we started by configuring the AppFabric cache using the information found here: http://www.cshandler.com/2011/07/using-window-server-appfabric-for.html.

However no success, when we tried to run the site we ended up with the following yellow screen of death:

image

After further investigating the issue, we noticed a little bit more useful error message

Could not load type "Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider”

We had added the correct reference so why couldn’t  the application find that class? In the end we found out that some lines were missing inside the assemblies section of our web.config:

<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<!-- other assemblies -->
<add assembly="Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
</system.web>

Thursday, August 16, 2012

Community TFS Build Extensions: NUnit activity

For a customer I was replacing the MSTest activity inside the Build Process template by the NUnit activity from the Community TFS Build Extensions(http://tfsbuildextensions.codeplex.com/).

After configuring the activity I saw inside the build log that the NUnit tests were running fine and that the results were published to Team Foundation Server.

image

According to the documentation I should also see the results inside my build report:

image

But when I opened my report no test information was available.

What went wrong?

When the the Build report is loaded, it tries to find the related test results from the TFS database. One of the filter criteria to find the correct tests are the build platform(e.g. Any CPU,x86,…) and flavor(e.g. Debug, Release,…).  This means that if you passed the wrong information to the NUnit activity, TFS will not be able to find the test results in the TFS database.

And this was exactly what happened to me. I hardcoded the flavor inside the activity to “Release” while my build configuration was using “Debug”. After updating the flavor to the correct value, TFS was able to load the test results as expected.

image

Wednesday, August 15, 2012

Building mobile applications: the big question.

Everyone who is planning to build a mobile application has to answer the same question: ‘What approach should I take?’

I posted about this question before but while trying the Icenium beta I found the following interesting posts about this topic:

Inside these posts they talk about 3 possible answers to build mobile applications:

  • Native apps are built for a specific platform with the platform SDK, tools and languages, typically provided by the platform vendor (e.g. xCode/Objective-C for iOS, Eclipse/Java for Android, Visual Studio/C# for Windows Phone).
  • Mobile Web apps are server-side apps, built with any server-side technology (PHP, Node.js, ASP.NET) that render HTML that has been styled so that it renders well on a device form factor.
  • Hybrid apps, like native apps, run on the device, and are written with web technologies (HTML5, CSS and JavaScript). Hybrid apps run inside a native container, and leverage the device’s browser engine (but not the browser) to render the HTML and process the JavaScript locally. A web-to-native abstraction layer enables access to device capabilities that are not accessible in Mobile Web applications, such as the accelerometer, camera and local storage.

By the way I can really recommend to have a look at Icenium, it is a cross-platform mobile development solution using HTML5 & JavaScript to build apps that run natively on iOS and Android. But what makes Icenium really nice is that it offers a full IDE in the cloud to do this(and also a local environment if you’re not into cloud Glimlach).

Tuesday, August 14, 2012

IIS Manager Error: A specified logon session does not exist. It may already have been terminated.

Last week I was configuring a TFS 2012 server to support https. I installed a wildcard SSL certificate on our Windows 2008 Server trying to install a wildcard SSL cert.  I launched the Certificate Snap-in inside MMC and placed the SSL certificate into the local computer repository without problems.

But when I opened the IIS manager to use this certificate, the problems started. I wanted to enable SSL for the TFS website, so I selected the web site and choose the Bindings option from the action menu.

image

The site bindings window was loaded. I clicked Add… to add a new binding and choose https from the Type dropdown.

image

But when I tried to select the certificate from the SSL certificate dropdown, I got the following error message:

A specified logon session does not exist. It may already have been terminated. (Exception from HRESULT: 0x80070520)

I could click OK but the binding didn’t work.

On the IIS forums I found the following post mentioning two possible solutions:

  • Deleting the certificate and reinstalling it via mmc certificate snap-in
  • Installing the certificate with ‘Mark exportable’ is true

I already used the first option, so I tried the second solution and it worked!

Remark: In the same post someone mentions that making your private key exportable is a security risk. So if someone has a better solution, feel free to let me know.

Monday, August 13, 2012

Disable NuGet Package Restore

Enabling the NuGet  package restore feature is easy. Just right click on your solution inside Visual Studio and choose the 'Enable NuGet Package Restore' option.

However what if you want to disable this again? I couldn’t find an option to do this, so let’s investigate all the changes that this option made.

First it added a .nuget folder containing a nuget.targets file and nuget.exe. So we’ll start by removing this folder and all its content from your solution.

Second it added an import to this target file to all your projects that are using NuGet packages. To remove this import right click on each project and choose unload project. Right click then on the csproj file and choose the Open with… option from the context menu. Choose the XML editor to edit the file. Browse the following line and remove it from the csproj file:

<Import Project="$(SolutionDir)\.nuget\nuget.targets" /> 


We are not there yet. There is one other change that is done to your projects: an extra property is added called ‘RestorePackages’. So we have to remove the following line from all csproj files:



<RestorePackages>true</RestorePackages> 


Remark: Do all these changes in one run. Otherwise Visual Studio will re-add all this information once you reload the project file.

Friday, August 10, 2012

WPF: Referring to a resource dictionary in another assembly

For a client I created a re-usable set of resource dictionary files. So I embedded them in a separate assembly that can be referenced in other WPF projects. But I always forget the correct syntax to refer to these resource files.

So just as a reminder to myself:

<ResourceDictionary Source="pack://application:,,,/YourSharedAssembly;component/Subfolder/YourSharedResourceFile.xaml"/>

Thursday, August 9, 2012

GitHub: view commits that include images

One of the cool features in GitHub is the way it allows you to compare images. Image your designer created a first version of your new company logo and later he does some small changes. How can you easily detect what’s changed? 

GitHub gives you four easy ways to view changes between image versions: 2-up, Swipe, Onion Skin, and Difference.

Let’s have a look at how this works:

  • Open your GitHub repository
  • Go to Commits

image

  • Click on the Commit that contains the image change.

image

  • Now you see the different images next to each other. This is the default 2-up view which lets you get a quick glimpse of both images. In addition, if the image has changed size between versions, the actual dimension change will be displayed. (Hmm, I’m wondering what the designer has changed… Knipogende emoticon)

image

  • Let’s click on Swipe to switch to another view. This lets you view portions of your image side by side. By dragging the swipe slider you can see the old version transform to the new version.

image

  • Next one is Onion Skin. It allows you to drag an opacity slider back to see how things have changed.

image

  • The last option is Difference. You have no clue what’s changed? Difference will highlight only pixels that are different between the two images, making it the go-to view mode for finding those single pixel changes in a file.

image

Wednesday, August 8, 2012

Web Deploy 3

Between all the announcements about the release of Visual Studio 2012, Windows 8, Windows Server 2012 and so on, I noticed one small announcement: the release of Web Deploy 3.

Web Deploy 3.0 can be installed using these links x86/x64. More details on installation can be found in Installing & Configuring Web Deploy tutorial.

Let’s have a look at some of the new features available in Web Deploy 3:

  • Deployment & Migration to IIS8: migrate to IIS8 from IIS 6, IIS7 and IIS7.5.
  • Publishing to Microsoft Azure Websites: deploy websites to Microsoft’s new Azure Websites offering.
  • Incremental Database Publishing using Data Tier Application (DAC) framework: incremental data sync and SQL Azure download using SQL DACPAC framework.
  • Automatic Backup:  allows server administrators to configure servers in such a way that each publish will automatically generate a backup and store it on server. If you need to roll back or go to a previous version, you will be able to do it without involving server administrator.
  • PowerShell Cmdlets: PowerShell Cmdlets for common Web Deploy tasks.
  • Improved Parameterization
  • Enabling Application Offline: automatically drops a blank App_Offline.htm file into the root of the application folder.
  • Changing authentication mode for a given website
  • Automatically disabling proxy settings
  • Support for IPv6-style bindings in certificate sync logic

Tuesday, August 7, 2012

NuGet: change build action value

For a client, I had to create a custom NuGet package. This packaged adds some custom content(images, scripts, icons,…) to an ASP.NET MVC project. Adding the content files was no problem, however I noticed that the BuildAction was incorrectly set.

To solve this we need some Powershell magic. Create an install.ps1 file and add it to your NuGet package(More info here).

Inside the powershell file I added the following code:

param($installPath, $toolsPath, $package, $project)

$item = $project.ProjectItems | where-object {$_.Name -eq "ReleaseNotes.txt"}

$item.Properties.Item("BuildAction").Value = [int]2

To find the correct enum value for BuildAction have a look here: http://msdn.microsoft.com/en-us/library/aa983962(VS.71).aspx

Remark: Note that the search through the ProjectItems is not recursive. Subfolders are not scanned.

Monday, August 6, 2012

TFS: Do a check-in without triggering a continuous integration build

One of the new features in TFS 2010 is Gated checkin. In this case when you check-in some code, a build is triggered that will build the existing code, plus your check-in. Only when the build is successful, your check-in is submitted to source control.  In that case it makes no sense to trigger another build, as this will keeps triggering builds until eternity.

To tell the build system to ignore the check-in operation, a check-in comment value “***NO_CI***” is specified to indicate "No Continuous Integration"meaning "please don't start a CI build because of this check in".

You can perfectly use it for your own builds too. Place the following into the comment field: ***NO_CI*** and when you check-in TFS will not kick off a build.