About admin

I have a Software Engineering degree from UW-Platteville. I worked for 2 1/2 years testing avionics software and doing minor Ada development. In 2005 I moved to Green Bay, WI and been working with Microsoft Technology including Windows Forms, ASP.Net, Windows Services, Web Services, LINQ, WPF, Silverlight, SQL Server, SSRS, etc. I am proficient in C#.Net, VB.Net, Javascript, XAML, and XML.

Adding HID Device to UWP Application

In this post I wanted to go through adding a HID device to a UWP Application. I will go into detail about determining the correct usage, setting up capabilities and connecting to the device.

To begin, we need to determine Usage ID and Usage Page of the HID device. We also need to determine the Vendor ID and Product ID for the device. Let’s start by opening the Device Manager, expanding Human Interface Devices and locating your HID device. Right click the device and select Properties.

Select Detail tab and under Property select Hardware Ids from the dropdown. From here we can get all the information we need to connect our device. Make note of the VID, PID, and HD_DEVICE_UP.

At this point we can determine if our device is supported by UWP. You can check MSDN documentation for HID limitations. Basically the device can be accessed if the Usage Page is vendor defined (0xFF00-0xFFFF). In our example, usage page is 0xFF00 and usage id is 0x0004.

Now we are ready to set up our capabilities for the UWP app. To define HID capabilities, we need to edit the package manifest XML. Select Package.appxmanifest file in Visual Studio and select View Code. Scroll down to Capabilities and add a new DeviceCapability.

<DeviceCapability Name="humaninterfacedevice">
   <Device Id="vidpid:[VID] [PID]">
      <Function Type="usage:[UsagePage] [UsageId]"/>
   </Device>
</DeviceCapability>

Here are the Capabilities from my UWP app.

<Capabilities>
   <Capability Name="internetClient" />
   <DeviceCapability Name="webcam" />
   <DeviceCapability Name="microphone" />
   <DeviceCapability Name="humaninterfacedevice">
      <Device Id="vidpid:046D C52B">
         <Function Type="usage:FF00 0001"/>
      </Device>
   </DeviceCapability>
</Capabilities>

Replace the VID, PID, and Usage with the values for your device. The order for the usage is imporatant here. Usage page should be first, followed by usage id. In the example above, FF00 is the usage page and 0001 is the usage id.

Final step is to add the code to connect to the HID device. Once connected we can read input reports to get data sent by the HID device. We will use Windows.Devices.HumanInterfaceDevice namespace to interface with our HID device.

ushort vid = 1133;      // 0x046D
ushort pid = 50475;     // 0xC52B

ushort usageId = 1;         // 0x0001
ushort usagePage = 65280;   // 0xFF00

// get selector string for the device (connection string)
string selector = HidDevice.GetDeviceSelector(usagePage, usageId, vid, pid);
// find the device
var myDevices = await DeviceInformation.FindAllAsync(selector);

HidDevice myHidDevice = null;

if (myDevices.Any())
{
    myHidDevice = await HidDevice.FromIdAsync(myDevices[1].Id, FileAccessMode.Read);
}

if (myHidDevice != null)
{
    myHidDevice.InputReportReceived += (sender, args) =>
                {
                    // read report
                };
}

Introduction to Work Item Charting

How would you like to visualize your work item progress on your project home page? One of the features in Visual Studio Online and TFS 2013 is Work Item Charting. These charts can be created from flat list work item queries (tree and direct links queries are not supported) and pinned to your project home page. In this post I will walk through creating a work item query, adding a chart, and pinning it to your project home page.

Let’s get started by creating a work item query that we would like to visualize. I will create a “Sprint Work” Shared Query that will bring back all Task Work Items in my current Sprint.

clip_image002

At this point I can pin the results to the project home page, which will show the Count of items returned. That is useful in some cases, but I would like to display further detail about the work items returned by my query. To show that detail, I will create a Chart by selecting the ‘Charts’ option.

clip_image004

Once on the ‘Charts’ view, I will create a ‘New Chart’.

clip_image006

On the ‘Configure Chart’ view I have several options. First, I can pick the type of Chart to display. In this case I will select the ‘Pie’ chart. I will then select ‘State’ to ‘Group By’. As you can see, I can also group by Work Item Type (which will not be helpful for me since my query only returns ‘Task’ work item types) and by Assigned To. I also have options on how the chart should be sorted. In this case I will select ‘Label’ so that my chart will continue to display consistently when the values change.

clip_image008

As you can see above, the chart is updated as we modify the parameters. Once I am done making the changes, I will select ‘OK’ to save the chart and return to the ‘Charts’ view. Several charts can be created for a single work item query.

Next, I will pin the chart I just created to my project home page. To do that, I will hover over the chart so that ellipses display in the top right corner. I will then click on the ellipses to display options that are available to configure the chart.

clip_image010

From here I will select ‘Pin to homepage’ to pin this chart to my project home page. To view the chart, navigate to the project home page.

On the project home page, I have the flexibility to move my pinned items around so that they display in a way that work for you. To customize the display, just click on the pinned item and move it to a new location using drag and drop.

Configure TFS connection for Visual Studio Release Management (InRelease)

Open Release Management Client and select Administration tab. Select Manage TFS.

clip_image002

Select New to add a new TFS Connection and specify the TFS Server.

clip_image004

Once all information is filled out, select ‘Verify’. A common error that occurs is the Access Denied error.

Access Denied: ReleaseUser needs the following permission(s) to perform this action: Make requests on behalf of others.

This error occurs if the user being used does not have the right permissions in TFS. To configure the permissions, a user or a windows group must be added to the Project Collection Administrators group and granted Make requests on behalf of others permission.

Add User or Windows Group to Project Collection Administrators.

clip_image006

Grant Make requests on behalf of others permission to the user or windows group.

clip_image008

Once above steps are completed, the connection can be verified and saved.

Sign Silverlight XAP with TFS Build

I have a Silverlight application that is set up for Continuous Integration with Team Foundation Server. As part of the build, I needed to sign the XAP with a certificate. To accomplish this I will be using a command line tool SignTool.exe. The tool is automatically installed with Visual Studio and it has to exist on the TFS Server.

Steps below walk through the setup process.

1) Check-in the certificate into TFS. This must be done so that the build server downloads it into the workspace.

2) Update the Post-build event on the Silverlight project

In Project Properties, select ‘Compile’ option, then select the ‘Build Events…’ button.

image

We will be modifying Post-build event command line.  Select the ‘Edit Post-build …’ button.

clip_image004

Enter the SignTool command to execute:

"C:\Program Files (x86)\Windows Kits\8.0\bin\x86\SignTool.exe" sign /v /f
$(SolutionDir)\..\MyCert.pfx /p CertPassword $(TargetName).xap

Specify the path to the certificate relative to the solution directory so that it can be found during the Build.

3) Verify that your build definition is set up to download the certificate into its workspace.

TFS Check-in Policy

When using TFS as part of your ALM solution, you may want certain conditions to occur with every check-in. For example, you may want to force developers to associate work item(s) with every changeset check-in. You are able to accomplish this through the use of the TFS Check-in Policy.

TFS 2012 Check-in Policies are as follows:

  • Builds Policy
  • Changeset Comment Policy
  • Code Analysis Policy
  • Work Items Policy

If you download and install TFS 2012 Power Tools, you will also get the following Check-in Policies:

  • Custom Path Policy
  • Forbidden Patterns Policy
  • Work Item Query Policy

In order to use the policies from the Power Tools, each client machine must have TFS 2012 Power Tools installed.

Below are the steps to set up a Check-in policy in Visual Studio 2012:

1) From Team Explorer, select the project and click on the “Settings” option.

clip_image002

2) Select the “Source Control” option

clip_image004

3) Select the “Check-in Policy” tab and click on the “Add” button. You will be presented with available check-in policies.

clip_image006

4) Choose a policy and click the “OK” button.

To add more than one check-in policy to the project, simply repeat steps 3 and 4.

Silverlight WebAqua – Unlicensed Version

We have been using a WebAqua Silverlight Navigation control in our application for several years.  Recently, after implementing a few changes to the application and deploying to our test server, we started seeing an “Unlicensed Version” message in the middle of the application.  Our version was licensed and had no issues until the most recent set of changes.

Over last few weeks I’ve been emailing WebAqua Tech Support and spent several hours on their Live Chat trying to resolve the issue without any success.  After all licensing attempts have failed, I went down the path of backtracking through our code, which led me to my solution.

Solution

The issue was caused by the levels of nesting.   To begin with, the FishEye control was nested 11 layers deep inside Border controls and Grids.  We have 10 Border controls with a Grid inside used for layout.  The issue came up when I added another layer of nesting by wrapping everything in a Grid to add a “Loading…” message that overlays the whole User Control.  This seems very odd, but the message went away after I removed the outer Grid.

I hope that this solution will come in handy for someone with a similar issue.

Silverlight Telerik Transitions with User Controls

 

I was looking to implement Silverlight Telerik Transitions in my Silverlight 5 application with User Controls to walk a user through a wizard.  My initial approach was to use a Visual State Manager, which would allow me to keep all the UI logic in the XAML.  This did not work well with Telerik Transitions.  I decided to use DataTriggers that modified the state of the UI  based on a WizardState enumeration on my View Model.

View Model

 
Namespace ViewModels.Employee
 
    Public Class EmployeeViewModel
        Inherits BaseViewModel
 
 
#Region "Properties"
 
        Private _employeeSetupState As EmployeeSetupStateEnum
 
        Public Property EmployeeSetupState As EmployeeSetupStateEnum
            Get
                Return _employeeSetupState
            End Get
            Set(ByVal value As EmployeeSetupStateEnum)
                If _employeeSetupState <> value Then
                    _employeeSetupState = value
                    NotifyPropertyChanged("CanMoveForward")
                    NotifyPropertyChanged("CanMoveBack")
                    NotifyPropertyChanged("EmployeeSetupState")
                End If
            End Set
        End Property
 
        Public ReadOnly Property CanMoveForward() As Boolean
            Get
                Dim newState As Integer = EmployeeSetupState + 1
                If [Enum].IsDefined(GetType(EmployeeSetupStateEnum), newState) Then
                    Return True
                End If
 
                Return False
            End Get
        End Property
 
        Public ReadOnly Property CanMoveBack() As Boolean
            Get
                Dim newState As Integer = EmployeeSetupState - 1
                If [Enum].IsDefined(GetType(EmployeeSetupStateEnum), newState) Then
                    Return True
                End If
 
                Return False
            End Get
        End Property
 
        ' The Properties for the View Models are defined here.
 
#End Region
 
#Region "Base Overrides/Overloads"
 
        Public Overrides Sub Initialize()
            MyBase.Initialize()
 
            EmployeeSetupState = 0
            InitializeStep()
        End Sub
 
#End Region
 
#Region "Public Methods"
 
        Public Sub NextStep()
 
            If CanMoveForward Then
                EmployeeSetupState = CType(EmployeeSetupState + 1, EmployeeSetupStateEnum)
                InitializeStep()
            End If
 
        End Sub
 
        Public Sub PreviousStep()
 
            If CanMoveBack Then
                EmployeeSetupState = CType(EmployeeSetupState - 1, EmployeeSetupStateEnum)
                InitializeStep()
            End If
 
        End Sub
 
#End Region
 
#Region "Private Methods"
 
        Private Sub InitializeStep()
 
            Select Case EmployeeSetupState
                Case EmployeeSetupStateEnum.EmployeeGeneralInformationState
                    EmployeeGeneralInformationViewModel.Initialize()
                Case EmployeeSetupStateEnum.EmployeeAddressInformationState
                    EmployeeAddressInformationViewModel.Initialize()
                Case EmployeeSetupStateEnum.EmployeeContactInformationState
                    EmployeeContactInformationViewModel.Initialize()
                Case EmployeeSetupStateEnum.EmployeeCommentsState
                    EmployeeCommentsViewModel.Initialize()
            End Select
 
        End Sub
 
#End Region
 
    End Class
 
    ''' <summary>
    ''' States of the Employee setup process. These steps
    ''' are executed in the order specified.
    ''' </summary>
    ''' <remarks></remarks>
    Public Enum EmployeeSetupStateEnum
        EmployeeGeneralInformationState
        EmployeeAddressInformationState
        EmployeeContactInformationState
        EmployeeCommentsState
    End Enum
 
End Namespace

In the code above, I have an enumeration that specifies valid states for my employee setup process (specified in the order I want to show these states) and a property in my View Model that holds the current state of the employee setup process. I have a trigger that calls the Initialize() method on my View Model when the page loads.  During the initialization process, my EmployeeSetupState is set to the first step and the view model for that step is initialized by calling the InitializeStep() method.  I have a property that determines if the current EmployeeSetupState has a previous or next step.  My View Model also holds a reference to the View Models for each of the User Controls that make up my employee setup states (not shown in the code above).

View

<UserControl.Resources>
    <vm:EmployeeViewModel x:Name="ViewModel"/>
</UserControl.Resources>
 
<Grid xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Name="LayoutRoot">
 
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" MinHeight="250" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
 
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <ic:CallMethodAction MethodName="Initialize"
                                 TargetObject="{Binding Mode=OneWay}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
 
    <telerik:RadTransitionControl Content="{Binding EmployeeSetupState}">
        <telerik:RadTransitionControl.Transition>
            <telerik:FadeTransition />
        </telerik:RadTransitionControl.Transition>
        <telerik:RadTransitionControl.ContentTemplate>
            <DataTemplate>
                <Grid Margin="5,10,5,10">
 
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
 
 
                    <uc:EmployeeGeneralInformationView x:Name="EmployeeGeneralInformationView"
                        Visibility="Collapsed"
                        DataContext="{Binding Source=ViewModel, Path=EmployeeGeneralInformationViewModel, Mode=TwoWay}" />
                    <uc:EmployeeAddressInformationView x:Name="EmployeeAddressInformationView"
                        Visibility="Collapsed"
                        DataContext="{Binding Source=ViewModel, Path=EmployeeAddressInformationViewModel, Mode=TwoWay}" />
                    <uc:EmployeeContactInformationView x:Name="EmployeeContactInformationView"
                        Visibility="Collapsed"
                        DataContext="{Binding Source=ViewModel, Path=EmployeeContactInformationViewModel, Mode=TwoWay}" />
                    <uc:EmployeeCommentsView x:Name="EmployeeCommentsView"
                        Visibility="Collapsed"
                        DataContext="{Binding Source=ViewModel, Path=EmployeeCommentsViewModel, Mode=TwoWay}" />
 
                    <i:Interaction.Triggers>
                        <ei:DataTrigger Binding="{Binding Converter={StaticResource EnumToStringConverter}}"
                                        Value="EmployeeGeneralInformationState">
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Visible"
                                TargetName="EmployeeGeneralInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeAddressInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeContactInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeCommentsView" />
                        </ei:DataTrigger>
                        <ic:DataTrigger Binding="{Binding Converter={StaticResource EnumToStringConverter}}"
                                        Value="EmployeeAddressInformationState">
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeGeneralInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Visible"
                                TargetName="EmployeeAddressInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeContactInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeCommentsView" />
                        </ic:DataTrigger>
                        <ic:DataTrigger Binding="{Binding Converter={StaticResource EnumToStringConverter}}"
                                        Value="EmployeeContactInformationState">
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeGeneralInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeAddressInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Visible"
                                TargetName="EmployeeContactInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeCommentsView" />
                        </ic:DataTrigger>
                        <ic:DataTrigger Binding="{Binding Converter={StaticResource EnumToStringConverter}}"
                                        Value="EmployeeCommentsState">
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeGeneralInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeAddressInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Collapsed"
                                TargetName="EmployeeContactInformationView" />
                            <ic:ChangePropertyAction
                                PropertyName="Visibility" Value="Visible"
                                TargetName="EmployeeCommentsView" />
                        </ic:DataTrigger>
                    </i:Interaction.Triggers>
 
                </Grid>
            </DataTemplate>
        </telerik:RadTransitionControl.ContentTemplate>
    </telerik:RadTransitionControl>

    <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
        <Button x:Name="PreviousButton" Content="&lt; Previous"  HorizontalAlignment="Right"
                Visibility="{Binding CanMoveBack, Converter={StaticResource BoolToVisibilityConverter}}"
                Margin="5"  Style="{StaticResource ButtonPrimaryStyle}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <ic:CallMethodAction MethodName="PreviousStep"
                                         TargetObject="{Binding Mode=OneWay}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
        <Button x:Name="NextButton" Content="Next &gt;" Width="70" HorizontalAlignment="Right"
                Visibility="{Binding CanMoveForward, Converter={StaticResource BoolToVisibilityConverter}}"
                Margin="5" Style="{StaticResource ButtonPrimaryStyle}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <ic:CallMethodAction MethodName="NextStep"
                                         TargetObject="{Binding Mode=OneWay}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
 
    </StackPanel>
 
</Grid>

In my View, I bind the Content property of RadTransitionControl to the EmployeeSetupState from my View Model.  The transitions happen each time the state change occurs.  The data triggers control what view displays depending on the current employee setup state.  In the data triggers I use the ChangePropertyAction to set the Visibility of the User Controls.  This separates my View Model code to only determine and set the state of the setup process and my View handles the display.

Azure Limitations and Considerations

I thought that it would be a good blog post to outline some of the Azure limitations  and considerations that I have come across while working with Azure.  Keep in mind that this list is put together in March of 2011 and Azure is constantly changing.

1.  Long running queries or single transactions:  Currently Azure will kill any connections with queries that execute over 30 seconds.  Since you may share the server with others, Azure has to make sure that your query doesn’t eat up all the resources.  This same logic applies to single transactions.

2.  Support for SSRS:  Currently there is no support for SSRS in Azure, but there is word that it is coming soon.

3. Database backups:  Currently there is no support for database backups, but there are work arounds that allow you to backup to blob storage.

4.  Support for A/D (Active Directory):  There is now support for Windows Azure Connect (currently in beta) , which provides connectivity between on-premises and Azure resources.

5.  Support for FILESTREAM Data type:  This data type is currently not supported in SQL Azure.  A work around would be to store a path to the blob storage.

6.  Database encryption:  Database encryption is currently not supported.

7.  Database transaction log:  There is no way to view transaction logs.

8.  Database Size Limitation:  The current database size limit is set at 50 Gig.  There are other storage optionsAzure Blob Storage, Azure Table Storage, and Azure Queue Storage.

9.  SQL Jobs: There is no SQL Agent in SQL Azure.  An alternative would be to utilize a Worker Role.

Concatenate values in a List with LINQ

I had a stored procedure that accepted a comma delimited string of id’s as a parameter. My source was a generic list of "Employee" objects from which I had to get the id’s and create a comma delimited string.

image

To accomplish this I used a LINQ Aggregate Query:

  1. Dim employees As New List(Of Employee)
  2.  
  3. Dim e1 As New Employee() With { _
  4.     .EmployeeId = Guid.NewGuid, _
  5.     .FirstName = "John", _
  6.     .LastName = "Smith", _
  7.     .Position = "Engineer"}
  8.  
  9. Dim e2 As New Employee() With { _
  10.     .EmployeeId = Guid.NewGuid, _
  11.     .FirstName = "Bob", _
  12.     .LastName = "Johnson", _
  13.     .Position = "Business Analyst"}
  14.  
  15. employees.Add(New Employee() with
  16.  
  17. Dim employeeIds As String = _
  18.         employees.Select(Function(x) x.EmployeeId.ToString()) _
  19.                     .Aggregate(Function(y, z) y & "," & z)

In the example above, I used a comma as my separator.

ASP .NET Postback Performance – Part 2

In my previous post I described a performance issue I ran across due to a large amount of ViewState.  Now I will discuss some possible solutions.

To fix this issue I decided to store the ViewState in the Session, by overriding a PageStatePersister property to return SessionPageStatePersistor. The default page state persister is a HiddenFieldStatePersister, which stores ViewState as a hidden Base64-encoded string on the page.  To read more about the PageStatePersister, see the following MSDN documentation.

Code Snippet
  1. Protected Overrides ReadOnly Property PageStatePersister() As PageStatePersister
  2.     Get
  3.         Return New SessionPageStatePersister(Me)
  4.     End Get
  5. End Property

This functionality can be implemented as needed for each page.  I implemented above code only for the few pages that were performing poorly and got the following results:

    • From 143K per postback to 13k per postback
    • From 188K per postback to 2k per postback
    • From 700k per postback to 1k per postback
    • From 244K per postback to 1k per postback

To implement this functionality application wide, override PageStatePersister in the base class for all your pages.  This does place a larger load on the web server, so make sure that this is a right solution for you.

As a long term fix, I plan on going through the screens and disabling ViewState for controls that don’t need it. Since majority of controls do not need ViewState enabled, this should minimize the size of the ViewState.