Showing posts with label NetMonitor. Show all posts
Showing posts with label NetMonitor. Show all posts

Monday, November 5, 2012

Adding reactivity to NetMonitor

It was long time ago when I last time wrote about updates in the NetMonitor project. I was just using it from time to time to diagnose my network connection and it worked pretty well. However, I wasn't happy with its internals, especially with PingService implementation as it was rather complex for such simple job - it had to deal with entities from System.Threading namespace (e.g. Timer) to get called from time to time in background thread and this only added complexity without adding any business value.

Some time ago I tried playing with Task Parallel Library, but eventually it appeared that TPL is not applicable in this scenario.

This time I've found Rx Extensions and I really liked the approach. My task with sequential background execution is solved with the help of the extensions quite gracefully (here is simplified version):

var service = new PingService("google.com");

// Every second the ping service will be called from background thread, producing a sequence of metrics
var metrics = Observable.Interval(TimeSpan.FromSeconds(1))
    .Select(i => service.Execute());

// Consuming the sequence of metrics and updating UI
subscription = metrics.Subscribe(
    metric => Console.WriteLine(metric.RoundtripTime),
    exception => Console.WriteLine(exception.Message));

Applying Rx Extensions drastically simplified the service itself and program environment as additionally I got rid of events and handlers, I am satisfied with the changes it brought. In my scenario it looks like a simple messaging bus between services and their consumers.

I'm pretty confident that Reactive Extensions can change your attitude to composing asynchronous and event-based programs (as it once happened with invention of LINQ for data querying). More on Rx can be found on MSDN, 101 Samples, IntroToRx.

Friday, May 27, 2011

Thoughts on NetMonitor interface

Just to remind, here is the look of the current version of NetMonitor. There is no UI for managing the list of hosts, adding a new one or configuring the existing ones. The list of hosts are set in the application configuration file.

NetMonitor

I keep thinking on NetMonitor’s user interface, especially on editing screens. Moreover, I’m trying to imagine good system tray icon, that won’t be annoying but informative. During my life as a computer user I tried thousands of software programs, lot’s of them had really crappy UI while only several were more or less usable.

For now I have selected the following patterns:

List management

ListManagement

This is Alarms page from Clock application from iOS. The window shows a list of alarms, activation checkbox for each of them and 2 buttons on top that switch the screen: Edit mode and Add mode. No main menu, no toolbar are required. The UI is slick and simple to use.
The only question left is whether to keep those checkboxes on this screen or to move them to the host edit screen. As for alarms, the placement is right, so people could switch alarms on and off with ease, but what about hosts? How often users will enable and disable monitoring a host? The monitoring won’t wake you up early in the morning just because you forgot to switch it off. So, I tend to decide that the checkboxes should be put on the host configuration screen.

List edit mode

ListEdit

This window shows the same list of alarms but with different controls for each of them. Left red circle deletes an alarm, right arrow switches the window to the alarm configuration mode. Left top button is replaced with Done button that saves the result of list editing. However, the Delete control doesn’t deletes an item immediately, it displays sort of confirmation, like this:

ListDeleteItem

Note that the Delete button appear instead of right arrow. This proves that Apple software developers and interface engineers took into account every little detail so a customer feel comfortable with the UI.

Item edit mode

The screen that provides configuration details for an alarm. Here you can’t switch it on or off, just set up the alarm time, repeat mode, alarm name and snooze mode. Top buttons are: Save & Cancel.

ItemEdit

One more observation that might be interesting: if you noticed, the left top button from the main screen named Edit opens list management screen and the button Done there is located exactly on the same place as the button Edit. The same is true for alarm addition screen: button Add opens the Add alarm screen and the button Save is located right there, where button Add was. I think that this was done intentionally, after hundreds options and thorough UI testing.

Windows taskbar & system tray integration

NetMonitor is extremely lightweight, it is more like a tiny utility than a ordinary windows application, that’s why I suppose that it should sit in the system tray rather than in Windows taskbar. If so, then there is one utility which behavior I like -- network information popup window that shows currently available networks. It looks like this:

Networks

It is displayed after clicking on its tray icon and disappears after loosing the focus or after the second click on the icon. The elements I like here are: support of groups of items (collapsing and expanding groups, see up arrows), and network signal strength icon. The icon is displayed only for Wireless connections, so you might not be able to see it on your connected to a LAN computer. The only problem is that usage of similar icon is not a good idea, not only because the icon is the property of Microsoft, but mostly because users might get confused for 2 identical icons in their system trays. Another option to use a traffic light icon in the system tray, but I doubt whether this will be that informative.

Having described the future UI changes, I could proceed with the implementation. As soon as I have something to show, I’ll share the results.

Thursday, March 3, 2011

NetMonitor. Discovering network configuration

It’s time to add some value to the project. For a long time I’ve been thinking about the UI for adding/editing/removing hosts and I’m still not sure which one will be good enough. As a  result, I’ve delayed this interface for further steps, today I’ll show how to discover network configuration of a computer and find out IP addresses of gateway, DNS servers, etc. to fill in the list of hosts.

The Base Class Library (BCL) doesn’t contain any network configuration-related classes mostly because it must be platform independent. So we have to interoperate somehow with machine-dependent components such as Windows Management Instrumentation (WMI). Luckily, BCL provides the System.Management.ManagementClass type which will help. In order to read network adapter’s configuration we will use “Win32_NetworkAdapterConfiguration” WMI class.

        // Creating the desired WMI class
        var mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
        // Getting all instances of the specified WMI class
        var items = mc.GetInstances();

Having fetched all instances of WMI class we read the required properties and form the list of hosts. The properties that are interesting for us are:

  • DefaultIPGateway
  • DHCPServer
  • DNSServerSearchOrder
  • WINSPrimaryServer
  • WINSSecondaryServer

Here is the code:

        var gateList = new HashSet();
        var dnsList = new HashSet();
        var dhcpList = new HashSet();
        var winsList = new HashSet();

        foreach (var item in items) {
          // Skipping devices that are not IP-enabled
          if (!((bool)item["ipEnabled"]))
            continue;

          var addresses = (string[])item["DefaultIPGateway"];
          if (addresses != null && addresses.Length > 0)
            foreach (var gw in addresses)
              gateList.Add(gw);

          addresses = (string[])item["DNSServerSearchOrder"];
          if (addresses != null && addresses.Length > 0)
            foreach (var dns in addresses)
              dnsList.Add(dns);

          string dhcp = (string)item["DHCPServer"];
          if (!string.IsNullOrEmpty(dhcp))
            dhcpList.Add(dhcp);

          string wins1 = (string)item["WINSPrimaryServer"];
          if (!string.IsNullOrEmpty(wins1))
            winsList.Add(wins1);

          string wins2 = (string)item["WINSSecondaryServer"];
          if (!string.IsNullOrEmpty(wins2))
            winsList.Add(wins2);
        }

        foreach (var address in gateList)
          Hosts.Add(new HostViewModel(address, "Gateway"));
        foreach (var address in dnsList)
          Hosts.Add(new HostViewModel(address, "DNS"));
        foreach (var address in dhcpList)
          Hosts.Add(new HostViewModel(address, "DHCP"));
        foreach (var address in winsList)
          Hosts.Add(new HostViewModel(address, "WINS"));

Depending on the number and configuration of your network interfaces, the NetMonitor will automatically discover and fill in the list of hosts to monitor.

Here are my automatically discovered hosts. As you see, my Wi-Fi router also acts like a DNS server & a DHCP server, the other two DNS servers (10.0.0.x) are provided by additional VPN connection. BTW, it might be a good idea to remove duplicate entries from the list.

NetMonitor

Download latest binaries or play with the code.

Friday, February 4, 2011

NetMonitor. Implementing IDisposable pattern

The `IDisposable` pattern and its correct usage often are the subject of flaming discussions. At least among those developers, who are aware of its existence. Oh, sorry. Truth be told, the pattern had been the subject of discussions, but after the exciting and extremely detailed article on the topic was published by fathers of .NET, CLR, etc., the only thing left for us was to follow their wise recommendations.

And so did I, because `NetMonitor.PingService` uses `Threading.Timer` & `NetworkInformation.Ping` types which implement `IDisposable` by themselves. Here is how the canonic `IDisposable` implementation looks like, applying for `PingService` class:

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    private void Dispose(bool disposing)
    {
      if (isDisposed)
        return;

      if (!disposing)
        return;

      if (IsRunning)
        Stop();

      if (timer != null)
        timer.Dispose();
      if (ping != null)
        ping.Dispose();

      isDisposed = true;
    }

    ~PingService()
    {
      Dispose(false);
    }

Note the presence of a finalizer, 2 working modes of Dispose method, etc. All this stuff is explained with uncompromising details in the above-mentioned article. Great reading, don’t miss it.

Thursday, January 27, 2011

NetMonitor. Making UI more efficient

After releasing the first more-or-less useful version of NetMonitor, I’ve been playing with it in different environments and situations, trying to realize whether the current UI is efficient enough for providing useful information about the network health in a form that can be grasped quickly, without spending noticeable amount of time on data parsing and understanding. Also, I’ve been observing the usage of controls that are located at the main window.

Here is how it looked originally:

 NetMonitor UI zones

After a week or two, I’ve made the following observations:

1. Buttons “Start” & “Stop” in this tiny application are useless at all. I’ve noticed that while I had to push “Start” button in order to begin the monitoring process, I never pushed “Stop” button when I wanted to stop the monitoring, because closing the application seemed more natural to me as a regular user. Also, I’ve realized that pushing “Start” button is the excess step, I’d prefer an application, at least this simple one, would start functioning immediately, without additional clicks. So, I’m removing the toolbar with the buttons and launching the monitoring right from the start.

2. Information that is presented in Data panel was also a subject for the investigation. I realized that some columns are more important and other are less. For example, columns “Host” and “Response time” were those I paid much attention to, while “Address” and “Health” were less convenient for me. As for “Host” vs. “Address”: I think that a human-being prefers to operate with more natural textual names for hosts instead of IPs or internet addresses with those “www”, “com”, etc. Moreover, internet address is required for application only, a user wants to know how much is response time for “my router”, “my vpn server”, “my website”, etc., and not for “192.168.0.1”, “10.0.0.66” or other stuff constructed from weird combination of digits and dots.

NetMonitor important columns

So, first of all I’ve removed the toolbar. That was rather easy and didn’t take much time. The most difficult task was how to reorganize the data presentation to provide better visualization. I’ve been experimenting with various patterns and understood that there couldn’t be a good solution unless I refuse using DataGrid as a presentation pattern. So I began probing with direct item templates for `ListView` control. After a while a fresh new look for NetMonitor was born:

Fresh new look for NetMonitor

This information layout focuses on the important data: human readable host names and response time, while other potentially useful information such as IP address, is less expressed. Moreover, the important pieces of data are located closer to each other and it is more convenient for eyes and brain to grasp the connected pieces of information.

The solution was simple. I removed `ListView.View` and nested `GridView` nodes and add a DataTemplate for a ListView. Nothing special:

<ListView.ItemTemplate>
  <DataTemplate>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
      </Grid.RowDefinitions>
      <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Name}"
         FontSize="18.667" Margin="5,0,0,0" />
      <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding ResponseTime}"
         FontSize="18.667" HorizontalAlignment="Right" Margin="0,0,5,0" />
      <TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Address}"
         FontSize="10.667" Margin="5,0,0,5" />
      <TextBlock Grid.Row="1" Grid.Column="1" Text="ping"
         FontSize="10.667" HorizontalAlignment="Right" Margin="0,0,5,5" />
    </Grid>
  </DataTemplate>
</ListView.ItemTemplate>

After that small achievement I got closer to the point of feeling the dark power of WPF =)

P.S.
The repository is updated, binaries are available here, as usual.

Friday, January 14, 2011

NetMonitor. Making application configurable

After we made the application working, the next step is to make it configurable, so a user won’t need to recompile the program when he wants to add or modify a host.

This step is rather easy to implement, although personally I don’t like .NET configuration and prefer INI-files based one, in this particular scenario I’m choosing the standard one. So, in order to map a collection of HostViewModel items, I’ve added HostConfigurationElement, HostConfigurationElementCollection & MainSection types. While working on this task, I’ve found absolutely fabulous and useful .NET configuration guide, which I recommend to everyone. The guide consists of 3 big parts: Unraveling, Decoding & Cracking the Mysteries of .NET 2.0 Configuration, don’t miss it.

So, having configuration-related types done, I got the ability to move host-related data to application configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="NetMonitor.Main" type="NetMonitor.Configuration.MainSection, NetMonitor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </configSections>
  <NetMonitor.Main>
    <hosts>
      <host name="Wi-Fi Router" address="192.168.1.1"/>
      <host name="Gate" address="10.1.8.2"/>
      <host name="VPN Server" address="10.0.0.66"/>
      <host name="DNS Server" address="10.0.0.1"/>
      <host name="Google" address="google.com"/>
      <host name="Yahoo" address="yahoo.com"/>
    </hosts>
  </NetMonitor.Main>
</configuration>

After the application has been made configurable, it might become useful not only for me, but for somebody else. Therefore, I’ve built it and uploaded here for those who might be interested in using it. In this public version I removed personal hosts such as wi-fi router, gate, etc., because they don’t make any sense to anyone, except me.

Next time I’m going to make some changes to the UI, as there are tons of tasks to be done to get really useful piece of software, even to this tiny one.

Thursday, January 6, 2011

NetMonitor. Bringing together UI and services

In the previous part I introduced a Ping service which purpose was to execute Ping command asynchronously, grab results and notify its listeners. Today I’m going to bring together the UI that had been constructed earlier with this service.

First of all, let’s connect a class that represents a Host with an instance of Ping service. Here is how HostViewModel was initially designed:

  public class HostViewModel : ViewModelBase
  {
    private string name;
    private string health;
    private string responseTime;

    public string Name
    {
      get { return name; }
      set {
        name = value;
        RaisePropertyChanged("Name");
      }
    }

    public string Address { // The same logic }

    public string Health {  // The same logic }

    public string ResponseTime {  // The same logic }
  }

I’m adding a reference to an instance of Ping service in its constructor, an event listener and 2 methods to control host monitoring from outside:

  public class HostViewModel : ViewModelBase
  {
    // ...
    private readonly PingService ping;
    private readonly Queue messageLog;

    public void StartMonitor()
    {
      ping.Start();
    }

    public void StopMonitor()
    {
      ping.Stop();
      Invalidate();
    }

    private void PingCompleted(object sender, PingServiceMessage e)
    {
      if (e.Status != IPStatus.Success) {
        Health = e.ErrorMessage;
        Invalidate();
        return;
      }

      ResponseTime = GetAverageResponseTime(e).ToString("F1");
      Health = "OK";
    }

    private double GetAverageResponseTime(PingServiceMessage e)
    {
      messageLog.Enqueue(e);
      if (messageLog.Count > 5)
        messageLog.Dequeue();

      return messageLog.Select(m => m.RoundtripTime).Average();
    }

    private void Invalidate()
    {
      messageLog.Clear();
    }

    public HostViewModel(string address, string name)
    {
      Address = address;
      Name = name;
      messageLog = new Queue(8);
      ping = new PingService(Address);
      ping.PingCompleted += PingCompleted;
    }
  }
}

Note that I’ve also added a message queue to calculate average value of response time based on last 5 messages. This might help to avoid dramatic raises and falls of the variable.

The second step is to modify MainViewModel in order to initialize a collection of HostViewModels and bind commands to methods.

  public class MainViewModel : ViewModelBase
  {
    // ...
    private bool isMonitoring;

    public ICommand StartCommand
    {
      get {
        if (startCommand == null)
          startCommand = new RelayCommand(Start, () => !IsMonitoring);  // Binding command to methods
        return startCommand;
      }
    }

    public ICommand StopCommand
    {
      get {
        if (stopCommand == null)
          stopCommand = new RelayCommand(Stop, () => IsMonitoring);  // Binding command to methods
        return stopCommand;
      }
    }

    public bool IsMonitoring
    {
      get { return isMonitoring; }
      set {
        if (isMonitoring == value)
          return;

        isMonitoring = value;
        RaisePropertyChanged("IsMonitoring");
      }
    }

    // Starting all monitors
    private void Start()
    {
      IsMonitoring = true;
      foreach (var host in Hosts)
        host.StartMonitor();
    }

    // Stopping monitors
    private void Stop()
    {
      foreach (var host in Hosts)
        host.StopMonitor();
      IsMonitoring = false;
    }

    // Initializing a collection of hosts
    public MainViewModel()
    {
      Hosts = new ObservableCollection
        {
          new HostViewModel("192.168.1.1", "Wi-Fi Router"),
          new HostViewModel("10.1.8.2", "Gate"),
          new HostViewModel("10.0.0.66", "VPN Server"),
          new HostViewModel("10.0.0.1", "DNS Server"),
          new HostViewModel("google.com", "Google")
        };
    }

    public override void Cleanup()
    {
        // Clean up if needed
      if (IsMonitoring)
        Stop();

      base.Cleanup();
    }
  }

That’s it.
Note that in this step as well as in the previous one we don’t touch UI part at all. Nevertheless, the architecture of the application where WPF binding & commands are used, allows us to build an application where  ViewModels don’t know about UI, and Models don’t know about both ViewModels and UI. Good layered architecture, I’d say.

Here is the application. It works just fine, reacts on toolbar buttons’ clicks, refreshing the UI asynchronously without any freezing, using the resources of system ThreadPool:

NetMonitor

As usual, I’ve pushed the modifications to the public repository.

In the next post I’ll make the list of hosts configurable from outside the application code.

Monday, January 3, 2011

NetMonitor. Making Ping service

Earlier, I created a UI prototype for the NetMonitor application, which from my point of view is good enough to do what it is intended to, according to the requirements. Now it is time to add some brains to this piece of WPF.
So, I have to create a service that will execute Ping command to the specified host in a background thread and return a message with Ping command results. As I don’t really need to ping the desired host thousand times per second, the service should be taught to take a break for a while between requests.
What information will I need from the service? I guess, the following will be enough:
  public class PingServiceMessage : EventArgs
  {
    public string ErrorMessage { get; private set; }

    public long RoundtripTime { get; private set; }

    public IPStatus Status { get; private set; }
  }
The service will have the simplest API one've ever seen:
  public class PingService : IDisposable
  {
    public event EventHandler<PingServiceMessage> PingCompleted;

    public void Start() {}

    public void Stop() {}

    public void Dispose() {}
  }
What about the asynchronous implementation? The straightforward solution would be the usage of BackgroundWorker class per Ping service. It would take a delegate, execute it and return a result and then would sleep for a while without releasing its thread. Alex Ilyin & Alexander Nickolaev, my colleagues, would be indignant with such a solution. And you know, they would be definitely right. The solution is obviously resource consuming and is not robust.
A good alternative is System.Threading.Timer class that provides a developer with the possibility to run a given method in a thread, temporarily taken from the ThreadPool. In this case a thread is being taken only for operation execution time and is released immediately after the operation is finished. This strategy is less resource consuming and more stable, because whenever an operation fails, the service won’t suffer and another thread will be taken next time.
So, in order not to be beaten by my vigilant colleagues I’ve chosen the second option and implemented the service with the timer component. The entire implementation could be found in the public repository, I’ve only taken part of it:
  public class PingService : IDisposable
  {
    private readonly string target;
    private readonly Ping ping;
    private Timer timer;

    public event EventHandler<PingServiceMessage> PingCompleted;

    public void Start()
    {
      timer = new Timer(Run, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
    }

    public void Stop()
    {
      if (timer != null)
        timer.Dispose();
    }

    private void Run(object state)
    {
      PingServiceMessage message;
      try {
        var result = ping.Send(target, 1000);
        message = new PingServiceMessage(result);
      }
      catch (PingException e) {
        message = new PingServiceMessage(e.Message);
      }
      if (PingCompleted != null) {
        PingCompleted(this, message);
      }
    }

    public PingService(string target)
    {
      this.target = target;
      ping = new Ping();
    }
  }
What is interesting here? Timer is created only in Start method. It is given the ‘Run’ method and is told to execute it every 2 seconds and wait for 1 second before the first time. Instance of Ping class is created in PingService constructor. It can be easily reused with a sequence of ping commands providing that Ping command timeout will be less than timer value. In my case, the timeout is set to 1000 ms, while timer value is set to 2 seconds. Seems to be OK. As there is no legal way to stop the timer other than call ‘Dispose’ on it, the ‘Stop’ method does exactly that. ‘Run’ method tries to execute Ping command with timeout set to 1000 ms and catches PingExceptions, if any. Finally, it notifies PingService listeners by sending a new instance of PingServiceMessage that might contain information about Ping command result or an exception message.

Let’s check whether the service works. To do so, I’ve added a simple console application and used the service there:
  class Program
  {
    static void Main(string[] args)
    {
      var service = new PingService("192.168.1.1");
      service.PingCompleted += PingCompleted;
      service.Start();
      Console.ReadKey();
    }

    static void PingCompleted(object sender, PingServiceMessage e)
    {
      var service = sender as PingService;
      Console.WriteLine(string.Format("Reply from {0}: time={1} ms", service.Target, e.RoundtripTime));
    }
  }
Here is the result:
NetMonitorConsole
Wow, works like a charm! =)
In the next posts I will try connecting all these parts together.

Tuesday, December 21, 2010

NetMonitor. Choosing MVVM framework

In the previous post I created a sketch of my small application with the help of Microsoft Expression Blend 4. Among other great features of the development suite there is a one that makes Blend outstanding -- it produces working XAML files, so every single UI screen in your sketch is represented as a separate UI control and the corresponding XAML is more or less ready for copy-pasting to the real application. This makes Blend the most preferable suite for sketching of WPF applications.
Let’s go further. When we are speaking about WPF we mean MVVM pattern and vice versa. What is MVVM? It is a concept that is derived from Model-View-Presenter (Model-View-Controller) pattern. There are several great articles about it, for example, I’d recommend this one and this one. AFAIK, there are two featured MVVM frameworks: GalaSoft MVVMLight & Caliburn, both of them are targeting WPF & Silverlight. I chose the first one, MVVMLight, as a base for my application because it is said that the framework supports designing in Blend, and that’s what I want.
So, I installed MVVMLight and created a new project based on MVVMLight WPF Template, added HostViewModel class, which describes the required information about a host and its health, and MainViewModel class that contains a collection of HostViewModel instances and a pair of commands, Start & Stop, which are derived from RelayCommand. After that I adapted the above-mentioned “Screen_1.xaml” from the sketch project. Here it is:
NetMonitor 02
For now, commands do nothing and the hosts information is static rather than live. Nevertheless, after a short period of work I’ve got a prototype that is written on WPF & MVVM and even shows something.
So, the UI part of the requirements is almost done. In the next posts I’ll try creating a Ping service and make use of it with the help of Start and Stop commands.

Friday, December 17, 2010

NetMonitor. Prototyping with Expression Blend 4

In the previous part I listed the requirements to the application. According to the good practice of program development, I’ve decided to start with UI and make a sketch of main application window.
Earlier I used to play with 2 superior mockup tools, Balsamiq Mockups and Evolus Pencil, but today I’ve decided to try Microsoft Expression Blend 4 because it was specifically designed for WPF-based application development. After several tryouts I’ve managed to make a sketch of the application. Main window has 2 buttons and a list with hosts, each of them contains 4 pieces of information (Host name, IP address, Response time and Health). The sketch looks as follows:
NetMonitor Sketch
I know that there are some troubles with text alignment and may be many others but don’t forget that this is only a sketch and the only purpose of it is to show how the application might look like without extra details.
Here is the main window of Expression Blend 4, as it was in the middle of the sketching process:
Expression Blend Full.
As you may notice, in the left lower corner is the structure of the application. I’ve put a DockPanel inside the LayoutRoot and inserted there a ToolBar with Docking=Top & a ListView, which automatically took the rest of space. After that I’ve created a sample data source and bound it to the ListView. That’s it, my sample data immediately appeared in the ListView. During these operations I saw nor XAML neither C# code.
The sketch is ready, it even can be run in special Sketch Player (another great feature of Expression Blend 4) so customers can play with it, make comments and criticize. The next step will be transforming the sketch into a real application and start building network services.
In case anyone is interested in the source code, I’ve opened a public repository at the bitbucket.org, so anyone could get the sources, play with them and even add any valuable stuff.

Sunday, December 12, 2010

Comprehending WPF. NetMonitor

About a month ago I wrote a post about the overall complexity of WPF technology, steep learning curve and other things that might be perceived as roadblocks, especially for novices or old-school WinForms programmers.

After that I had several intensive discussions with my colleagues on the subject and they told me one important thing, the main idea was that the technology just seems to be overcomplicated, especially from the first look, when you don’t see the overall picture how it is built, how it works and how it should be used. Another thing that is worth mentioning is that the architecture is reasonable, because it gives a UI designer the required flexibility and power, which WinForms just can’t provide and this very fact can only be seen on complicated UI scenarios, not on simple ones.

As a result, they persuaded me to take a closer look on the platform and give it another try. And I did so. They say that abstract theoretical knowledge can’t compare with practical one, so I decided to make something small but more or less useful on WPF and therefore, get some practical knowledge of the technology.

I’ve set my choice on a little handy tool that will monitor and report the health of my network. For now the most quick and simple way to check the health is to open several Command Prompt windows and run a Ping command to various hosts in the network starting from my own router, then gate, VPN server, etc. and ending up with globally available hosts like google.com or similar. So you have to look at all those console windows, process and aggregate their logs and make a conclusion where the real problem is. As you might imagine, this way is neither convenient, nor informative, and finally, I’ve decided to create a better solution.

I’ve started with requirements. What are they?

The most important thing is to invent a codename. I’ve chosen a self-describing name — NetMonitor, why not?

UI

  • The main window shows a predefined read-only list of hosts and an average response time from Ping command.
  • Each host has a name and a valid internet address.
  • Two buttons start and stop the process of pinging.

Internals

  • In order the UI thread not to be frozen while waiting for Ping command response, each host pinging procedure must run in a separate thread.
  • Sending a Ping request once a second will be enough for monitoring tasks.
  • List of hosts for pinging should be configured from outside the application code, say, in app.config file or something. Personally, I don’t like xml configuration files, so i will try using ini file instead.

That will be enough, at least for the first version.

In the next posts I’ll write about the process of building the application.