Category Archives: Uncategorized

Windows Identity Framework – Externalising Authentication

Standard

image

As an architect that works for an ISV, I’m interested in making our application functionality to as useful as possible to as many people as possible in an organisation.

A “barrier to entry” for applications can be when a customer only needs a small part of the application functionality.    Many applications have their own authentication and login sequence, which make them unsuitable for this kind of functionality.

Typically customers have some kind of corporate application, intranet or portal that is designed to incorporate little bits of applications.  Over the last few years a number of authentication standards have become accepted by many organisations, including Microsoft.

Microsoft have released the RTM version of WIF (Windows Identity Framework) which provides a layer of abstraction over authentication, allowing a pluggable approach to establishing trust between web applications.

Vittorio Bertocci provides an excellent overview of WIF in his PDC09 Talk.

In this demo, Vittorio demonstrates adding an “STS Reference” to his project.  An STS is a “Secure Tokens Service”.    He also shows how “Claims” (properties against a credentials token) can be bound to fields in a webforms user interface.

It’s heartening to see Microsoft attempting to take a traditionally complex area and create tools to make it usable.

Advertisements

Catching Application Level Mouse Events in Winforms

Standard

image

As part of my work on flick scrolling I’ve created an example of a class that can create mouse events for an entire Winforms application.

To use it, just declare it, like so:

Private WithEvents moAppMouseEvents As New ApplicationLevelMouseEvent

 

I’ve only implemented the MouseUp and MouseDown events, but these are consistent with the Form ones:

 

Private Sub moAppMouseEvents_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles moAppMouseEvents.MouseUp

 
End Sub
Private Sub moAppMouseEvents_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles moAppMouseEvents.MouseDown
 
End Sub

 

The code uses an IMessageFilter in the tradtional fashion:

 

Public Class ApplicationLevelMouseEvents
    Implements IDisposable
    Implements IMessageFilter

    Public Event MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Public Event MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

    Private Const WM_LBUTTONUP As Integer = &H202
    Private Const WM_LBUTTONDOWN As Integer = &H201
    'Private Const WM_RBUTTONDOWN As Integer = &H204
    'Private Const WM_MBUTTONDOWN As Integer = &H207
    'Private Const WM_NCLBUTTONDOWN As Integer = &HA1
    'Private Const WM_NCRBUTTONDOWN As Integer = &HA4
    'Private Const WM_NCMBUTTONDOWN As Integer = &HA7
    Public Sub New()
        Application.AddMessageFilter(Me)
    End Sub

    Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
        If (m.Msg = WM_LBUTTONDOWN) Then

            Dim loArgs As New MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y, 0)

            RaiseEvent MouseDown(Me, loArgs)

        ElseIf (m.Msg = WM_LBUTTONUP) Then
            Dim loArgs As New MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y, 0)
            RaiseEvent MouseUp(Me, loArgs)
        End If
        Debug.WriteLine(m.Msg.ToString)
        Return False

    End Function

    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                Application.RemoveMessageFilter(Me)
            End If
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class

 

The sample could be enhanced to support the full range of events such as mouse move, so feel free to take the sample and change it.  If you post your code, please link back to this post.

 

Links

A Simple Scroll Controller for Winforms

3D in Silverlight 2.0

Standard

image

So what’s the difference between WPF and Silverlight again?  Oh yes, well WPF has more advanced features.

You know, 3D graphics!

Isn’t it strange that many Silverlight demos invariably incorporate 3D style effects? 

Take a look at this article for a very rich solution:

Silverlight: Building Advanced 3D Animations with Silverlight 2.0

I wonder how long it will be before Silverlight supports 3D natively?

Walking Through Passive View

Standard

walk.png 

DevX have published an interesting romp through the refactoring of a traditional forms app into a shiny new  n-tier architecture utilises MVP.

It compares the difference in coding style between traditional gui programming and MVP, then moves into unit testing, services and dependency injection.  

Take a look:  

Layered Architecture, Dependency Injection, and Dependency Inversion

For a less formal and more extensive overview, this series of articles by Jeremy Miller is great:

Build your own CAB   (No, not a taxi or a Pocket PC install, but Microsoft Patterns and Practice’s “Composite Application Block”) 

Dave Cheong’s Blog – Lots of Nuggets to Share

Standard

Although my original intent was simply to share technical information on this blog, I come across something really useful and special every now and then.

If you’re interested in personal improvement, take a look at Dave Cheong’s Blog.

There’s many useful little articles that act as a pithy reminder of what you should be doing.  Examples include:

Creating Commands in XAML only

Standard

Previously I posted an article about defining “Commands” in WPF applications and responding in code.

A way of doing this in XAML only is setting up a binding to a property on another control.

In this example, a toggle button is used to toggle the blod state on a rich text box.

For example:

<Toolbar>

<ToggleButton MinWidth="40" Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=XAMLRichBox}" TextBlock.FontWeight="Bold">B</ToggleButton>

</Toolbar>

 

I got this idea from this article: Mastering the WPF RichTextBox