tisdag, mars 24, 2009

 

A simple bandwidth test based on HTTP, AJAX and jQuery

Recently I had the opportunity to work with my friend Micael on a HTTP broadband testing application. This test will be used as a zero-touch diagnose tool to identify network related issues between users and a video conference system server.

The test was produced for the non-profit organization Infinite Family which involves users located both in the USA and South Africa. The video conference system is located in South Africa and the internet connection to South Africa is provided by a satellite link. Only the hop over the satellite link adds a few hundred milliseconds in response time (ICMP Ping), so it can be really poor conditions for a video link!

The test has equal capabilities as many of the other tests out there. What it does is that it tries to calculate a response time, which of course is not ICMP Ping as one might think, the test only does HTTP and AJAX. Instead, the test uses a HTTP HEAD request to get somewhat a measurement of how long it takes to establish a TCP session and send some data over port 80.
The test does not only measure the response time, it also measure upload and download speeds. For these kind of tests a lot more data is sent back and forth to the HTTP server using (AJAX) HTTP requests.

The whole test consists of one HTML page with references to jQuery and jQuery UI.
This test was the first project in which I could try out jQuery for real. I had some hard time get it working properly on my PCs and the kids' Mac, but now it works in IE, Opera, Firefox and Safari on both Mac OS and Windows.
I must say I really like working with jQuery. To me it's somewhat aligned with the way I use LINQ and extension methods when coding in C#, so it was a piece of cake start coding with this neat Javascript library.
The progress bar used in the test is a pretty simple thing to do with a few DIV elements and a bit of CSS. That was the approach I used in an early version, but I decided to try out jQuery UI as soon as I jumped on the jQuery track.

You can find the test right here.

Etiketter: , , ,


lördag, mars 21, 2009

 

Bacchi Orden Open

Tomorrow is the Bacchi Orden Open taking place in Hornstull, Stockholm.
RemoteX Technologies is sponsoring and I and my collegue Erik will play in the tournament (thanks Pal!).

The Pal asked me quite a while ago for ideas on how we (RemoteX Technologies) could help them out in digitalizing the scorekeeping process during the event. First I thought about putting together a customized version of RemoteX Applications which would help entering scores etc using PDAs. However, the scorekeeping process and the service process (which is what RemoteX Applications primarily supports) did not align very well, so we skipped that idea.
The solution ended up in using their already existing web application (based on the LAMP stack), with some minor adjustments to support Pocket Internet Explorer, Opera for Mobile and such.

QR Code with Face design
Each player plays two so called entries and each entry consists of 4 random games.
Each game on each entry is registered a score and the best score is used in a player ranking algorithm to produce the tournament standings page.
To ease the pain of writing down the score on a piece of paper and THEN enter them into the web application, the solution also involves a free software called i-Nigma which is used to scan QR-codes.
All players get their two entries printed on papers. Each printed entry has four QR-codes, each representing a link to a page on which the score is to be entered by the scorekeeper.
So basically, the scorekeeping process is:

  1. The player plays a game
  2. Calls for the scorekeeper to register the score of the game
  3. The scorekeeper uses a mobile phone equipped with i-Nigma to scan the QR-code of the game
  4. The scorekeeper enters the score in a text field in the web browser on the mobile phone
  5. The player can continue play the remaining games in the entry


AFTER EVENT UPDATE:
Everything worked out eventually, but we came up with a few issues we need to address before the upcoming (bigger) event, Stockholm Open:


We had some really nasty problems during the event, but as my former CEO Ulf Engerby at Qbranch would put it: Success is planned, shit happens!

If you want more information about the event, please visit the website.

Etiketter: , , , ,


måndag, mars 16, 2009

 

How I succeeded to configure Pidgin to work with our Office Communications Server

Since it was a real hassle to figure out these settings I decided to note them here for future references. Since I didn't find this variant of the Pidgin+SIPE+LCS configuration anywhere else, it may be useful for others too.

While talking to others using Pidgin + LCS I noticed the configuration may differ depending on your setup, i.e. internal only or external LCS / SIP server.
At work we use an internal only LCS server which is only listening on its default TCP port (5060).
Below you can see that I need to enter domain + username in the auth* fields. I know others that don't use these fields in their setup, but they do have an externally accessible (over TLS/SSL, port 443) LCS / SIP server.
So be prepared, your result may vary :).


  1. Download Pidgin (v2.5.5 in my case)
  2. Download SIPE (v1.3.3, libsipe.dll, precompiled dist for Windows)
  3. Put libsipe.dll in the plugins directory of Pidgin
  4. Go to Accounts -> Manage Accounts
  5. Choose Add..
  6. Enter the following settings.

    Tab: Basic
    Protocol = Microsoft LCS/OCS
    Username = <your SIP address in Active Directory is your primary e-mail address>
    Password = <your Active Directory password>


    Tab: Advanced
    Use Proxy = Checked
    Proxy Server = <the FQDN of your LCS server, i.e. mylcs.corp.local>
    Use non-standard port = Checked
    Port = 5060
    Connection Type = TCP
    Auth User = <your Active Directory username>
    Auth Domain = <your Active Directory domain name in dotted form, i.e. corp.local>

  7. Click Save and you should see your LCS contacts appearing in the Buddy List of Pidgin


All Done!

torsdag, mars 12, 2009

 

How To Make the Firefox/YouTube Wait Symbol In WPF

Recently I thought about doing one of those trendy animated "hour glasses", the "wait" symbol which appears when that computer of yours is waiting or working on stuff in the background.

So what do I mean by "doing one".. In HTML? with jQuery UI perhaps? No and no.

About 3-4 months ago we started to get WPF into production in our product at work and now we're doing all our new features based on WPF and XAML.
So this animated "hour glass" (or "spinner" which is the word I will use from here) must of course be created in WPF.

I believe that you guys and girls out there who have worked with XAML, since the spec came out in 2006, probably just say "Say hi to XAML, my friend". For me however, I'm quite proud of how easy it was for me to create this animated little thing.

When I brought this up during lunch a couple of days ago I discussed what the least CPU consumtive design would be.
My first design thought I came up with was based on 8 circles with ColorAnimations which would make the circles look like the were rotating.
After a quick discussion with my fellow collegues Morten and Wilhelm I got interested about the idea of using a rotating (using RenderTransform) Canvas instead. This idea worked out very well and here is the result (you must have .Net installed to view it in your browser).

So the XAML required to achieve this is quite simple, here is a summary:

  1. A Canvas is used to distribute the 8 circles on
  2. Each circle has its fixed position and its own transparency (which makes the "tail" effect)
  3. We add a trigger to the FrameworkElement.Loaded event for the Canvas, in which we...
  4. ...add a DoubleAnimation targeting the Angle property of the RotateTransform we also added to the Canvas
  5. We use a ViewBox as the parent of the Canvas which lets us scale the animation to fit in i.e. a TabPage header control (like the tabs in Firefox)


And here is the XAML:

<Viewbox>
<Canvas Width="80" Height="80" Name="canvas">
<Canvas.RenderTransform>
<RotateTransform Angle="0" CenterX="40" CenterY="40" />
</Canvas.RenderTransform>
<Canvas.Triggers>

<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="canvas"
Storyboard.TargetProperty="(Canvas.RenderTransform).(RotateTransform.Angle)"
To="360"
Duration="0:0:0.7"
RepeatBehavior="Forever"/>
</Storyboard>

</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Canvas.Triggers>
<Ellipse Canvas.Top="0" Canvas.Left="30" Width="20" Height="20" Fill="#08000000"/>
<Ellipse Canvas.Top="10" Canvas.Left="50" Width="20" Height="20" Fill="#15000000"/>

<Ellipse Canvas.Top="30" Canvas.Left="60" Width="20" Height="20" Fill="#38000000"/>
<Ellipse Canvas.Top="50" Canvas.Left="50" Width="20" Height="20" Fill="#55000000"/>
<Ellipse Canvas.Top="60" Canvas.Left="30" Width="20" Height="20" Fill="#88000000"/>
<Ellipse Canvas.Top="50" Canvas.Left="10" Width="20" Height="20" Fill="#aa000000"/>
<Ellipse Canvas.Top="30" Canvas.Left="0" Width="20" Height="20" Fill="#cc000000"/>
<Ellipse Canvas.Top="10" Canvas.Left="10" Width="20" Height="20" Fill="#ff000000"/>

</Canvas>
</Viewbox>


Pretty easy, or what do you think?

Etiketter: , ,


 

A fluent interface and the Builder pattern

My former collegue Thomas Lundström blogged about fluent interfaces quite a while ago, which he followed up in a comment to Johan Lindfors' post "A small DSL to order coffee" (in Swedish).

The blog post and its comments discusses two different approaches to fluent interfaces. The first approach is based on getters which mutates the instance when they are called. Some people think this is a very bad design - getters should not mutate the instance!
I agree on that. I strongly believe that a get operation should be idempotent and not mutate the object instance. This for the same reason a HTTP GET request should not mutate a resource and a HTTP POST/PUT should mutate a collection/the resource.
(That's why I prefer RESTful web services more than SOAP over HTTP, but that's a totally different blog post. :)

The second approach is the one that Thomas points out. It's the classical Builder Pattern where you have a totally separate class which is used to build object instances. It differentiates itself among the creational OOD design patterns by targeting primarily mutable objects. It's like a bunch of Factory methods which is used like a Factory, but instead of having thousands of different methods in one Factory (overloads for example), the Builder is used in several calls to create/configure the final object instance.

An approach which was recently used at work is a mix of the two approaches mentioned above. Instead of having a separate builder we have builder methods on the object instance itself, either directly or via extension methods. Separate from the builder methods we got some Factory Methods. These are the starting point to create a basic instance. The builder methods are then used to further shape the object instance to our needs.

Approach #1 - getters which creates/mutate the object instace:

Coffee myLatte = Coffee.OrderLatte.Double.FatFree.Vanilla;


Approach #2 - a separate builder

Coffee myLatte = CoffeeBuilder.Latte().Double().FatFree().Vanilla().Build();


Our approach - a mix of factory methods and builder methods on the object instance itself

Coffee myLatte = Coffee.Latte().Double().FatFree().Vanilla();


So what's the pros and cons with the last two approaches?
I guess they are quite similar, but here is some pros:
- The separate builder seems a bit more aligned with the Separation Of Concerns principle
- The built-in builder methods via extension methods provides a lightweight class structure, even for classes in a third-party class library, such as the BCL.

(Please post a comment if you can think of more pros and cons or if you just totally disagree with me :)

So of course, the $10.000 question answer is... It depends on your context!
Anyhow, here is a sample how we tend to use this mix of Factory Methods and Builder methods at work.

The following code is used to build construct the collection of DataGridViewColumns used in a Windows Forms DataGridView control.
The CreateColumns() method is used to create an enumeration of the columns to use and TextColumn() is a sample Factory Method.


protected override IEnumerable CreateColumns()
{
yield return TextColumn()
.For( WorkOrderPresenter.Properties.Title )
.WeightedWidth( 100 );

yield return TextColumn()
.For( WorkOrderPresenter.Properties.Description )
.WeightedWidth( 200 );

yield return ComboBoxColumn( _activityBindingSource )
.For( WorkOrderPresenter.Properties.Activity )
.WeightedWidth( 100 )
.Width( 90, 130 );
....
}

///
/// Creates a textbox column with default behavior.
///

protected virtual DataGridViewTextBoxColumn TextColumn()
{
return new DataGridViewTextBoxColumn().WrapContents().WithDefaultBehavior();
}


The methods For(), WeightedWidth(), Width(), WrapContents() and WithDefaultBehavior() are Builder (extension) methods on DataGridViewColumn.

Etiketter: , , , , ,


måndag, mars 09, 2009

 

Bye bye Debug.WriteLine!

Recently I had the opportunity to deal with a couple nasty WM_PAINT handlers. Everyone who have been in a situation where you need to debug some broken paint operations knows that it can be really hard to debug using breakpoints, since you can't break into the debugger. When you break into the debugger, the WM_PAINT event will trigger once again when you switch back to the program you are debugging. Of course you can overcome this by placing the debugger and the debugee on different areas of your screen, but mostly I don't think it pays back to use breakpoints for these kind of scenarios.

So what do we do when we have a bug in a WM_PAINT handler? Write a unit test? Nope. At least I don't, even if that would be my preferred way to go.
As long as I remember I think I have inserted alot of those Debug.WriteLine() statements all around my code, so I can get some kind of trace log for the program.
However, this requires modification and recompilation of the code.

So let me introduce to you something I started using recently: Tracepoints!
I read about them years ago and have tried to use them in earlier versions of Visual Studio. A week ago they became my new little helper... in Visual Studio 2008.

Here is a quick how to from MSDN on how you can use them:
How to: Specify a Tracepoint/Breakpoint Action

So now I don't use Debug.WriteLine() anymore. Instead, I let a tracepoint print a message including the expression I need to evaluate and print.
However, even though this feature works great, you may run into trouble.
Today I discovered issues where the expression evaluation times out!
The timeout occurred when I had quite a number of tracepoint set in a piece of code I was debugging on my Windows Mobile device.

Every time I have to deal with UI components which implements a quite complex handler for WM_PAINT I always think "There must be some way to test this!". So far I haven't found a satisfactory design where UI components meets the requirements of my unit testing framework.
If you have ideas or links on how to succeed with automated testing and UI components, please let me know!

Update: Merrick Chaffer has a quite similar blog post with a nice screen shot on the dialog where you set up your tracepoint

Etiketter: , ,


tisdag, mars 03, 2009

 

Consider the environment before printing

About a year ago or so I received e-mails with the following message in its signature:
P Please consider the environment before printing this e-mail
(if you see the capital 'P' character in the beginning of the message, please read on...)

Now, one year after, I see this message more often.
Normally I try to avoid long e-mail signatures (which easily can get longer than the e-mail body), but due to the number of printed e-mails in the recycle bin in our printer room at work I believe this is a keeper.

When receiving an e-mail with this message it has also a small graphic besides it showing a small green tree and a road. This is actually not an image attached to the e-mail (which I really try to avoid in my e-mail signature, like the corporate logo etc.), as it's the capital 'P' character in the WebDings font.

With that said, it won't show up if you aren't using Outlook or Internet Explorer or any other e-mail viewer with capabilities to display rich formatted text. For example, it won't show up in Firefox.

Side-track:
It's exactly the same with smileys. Ever read an e-mail on your mobile phone (using Pocket Outlook for instance) and you wondered about all the capital 'J' characters? The smiley is the symbol displayed when you type capital 'J' and use the Wingdings font.

I tried to find some info about this green message so I could copy it into my e-mail signature. Please see this blog post for more info! (and add the message to your e-mail signature today)

Etiketter:


Prenumerera på Inlägg [Atom]