The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








Latest Diggs - Programming

Internet Blogs - Blog Top Sites

Site Hits

Total: 2,551,710
since: 19 Jan 2005

CLINQ v1 Demo - Network Message Filtering

posted Wed 09 Jan 08

Since I put up the source code to CLINQ yesterday on CodePlex, I've already had multiple requests for demo code. I have a couple of tweaks left to make on the source code, but the demo will be available shortly. Here is the lowdown on the demo:

To illustrate the power of using CLINQ to do dynamic filtering (it does sorting and grouping as well, but I'll do those in another demo), I created a sample WPF application that is listening for network messages on a peer mesh. These messages are, hypothetically, coming from an order system broadcasting that employee X has created an order for Y quantity of Z product in warehouse W. The WPF listening application has two visible "bins" or "baskets" into which network-transmitted orders will be placed. The contents of these bins are determined at runtime by a configuration file. If you remember that I say peer mesh, you might gather that you could run multiple instances of this app in multiple locations on your network, monitoring any number of bins/order destinations for fulfillment. Again, this is just a cheesy sample, but it does illustrate Continuous queries on Continuous Collections that are being filled in the background from network messages.

Here's what the queries look like in the constructor of the main window of the WPF client application:

// this is a facade/model object to facilitate easy binding. 
// It has 2 properies representing the bins
_binSplit = new BinSplit();
_binSplit.LeftBin = from tx in ModelRoot.Current.AllTransactions
      where tx.WarehouseName == ConfigurationManager.AppSettings["leftBin"]
      select tx;
_binSplit.RightBin = from tx in ModelRoot.Current.AllTransactions
      where tx.WarehouseName == ConfigurationManager.AppSettings["rightBin"]
      select tx;
this.DataContext = _binSplit; // bind the WPF GUI to the model object

This is really the crucial core of what it looks like to be consuming the CLINQ library. First off, you're writing queries against data that is known to be empty. When was the last time you wrote a query against an empty list and found that useful? Because these queries are continuous, it makes no difference whether any rows match your query at definition time - they could auto-populate at a later time when the app is running.

To show you that I'm not doing any manual filtering, here is the code that responds to network messages:

void _txService_OnTransactionArrived(Transaction t)
{
    ModelRoot.Current.AllTransactions.Add(t);
}

Because WPF responds to INotifyPropertyChanged and the INotifyCollectionChanged events, it will respond to changes to the output of a CLINQ query. In short, when you bind your WPF GUI to a ContinuousCollection that was created through a Continuous Query - you're basically done. As changes occur in the source collection (in our case ModelRoot.Current.AllTransactions). those changes are processed by the chain of view adapters and eventually (if applicable), make their way directly to the GUI.

Here's a look at the WPF application that is receiving network messages. In the demo, I've got it listening for messages for WAREHOUSE1 and WAREHOUSE2, which are the left and right bins respectively.

The application is actually receiving network messages for three different warehouses, but because of the nature of the CLINQ queries, it is only binding to two of those. You can see how this can be used to dramatically reduce the UI-thread traffic by filtering messages to only those that are applicable to the GUI at that moment.

There are a couple of things you will need in order to run this demo:

  • The demo code - I will be posting this up on the CodePlex CLINQ site very soon.
  • Visual Studio 2008 / .NET Framework 3.5
  • PNRP (Peer Name Resolution Protocol). For Windows XP you need to download this separately and enable it, which requires a reboot. For Windows Vista, you may need to change the PNRP service from "Manual" to "Automatic". This is required for the peer mesh networking portion of the demo.

I will be publishing more demos of CLINQ illustrating different queries and hopefully, different practical situations in which you might want to use it. If you have ideas for different kinds of demos that you want to see, also please let me know by commenting here or posting a discussion thread up on the CodePlex site.

Note: When you're running the demo, it is possible that the network sender console application will send as many as 10 batches of messages before the WPF client receives them... That's just due to the fact that the console application starts a crapload faster than the WPF application... Give it at least 15-20 seconds before the WPF app catches up and starts getting the network messages.

tags:        

links: digg this    del.icio.us    technorati    reddit




1. Aldo left...
Wed 16 Jan 08 2:42 pm

Hey, On the Clinq sample - I had an side comment related to your use of DuplexChannels...

Add a second duplex channel in TransactionSender.Program.Main:

ITransactionServiceChannel _txChannel2 =

  • CommunicationCenter<ITransactionServiceChannel, LocalTransactionService>.OpenPeerChannel(

  • "urn://topic/netfilterdemo");

and also uncomment out this line in LocalTransactionServer.cs...

  • Console.WriteLine("Published Transaction.");

Then run TransactionSender console app. You notice only 3 txns writelines output per timer call to the console not the 6 I expected (2 callback channels each called 3 times per timer). It's like the second duplex channel callaback NEVER is lost or hidden by the first????? Very very strange...

Does this work for anyone?


Tag Related Posts

CLINQ v1.1.0.0 Released!

Fri 02 May 08 5:38 P GMT-05
tags:          

CLINQ v1 Demo - Network Message Filtering

Wed 09 Jan 08 7:47 P GMT-05
tags:        

Continuous LINQ v1.0.0.0 Released

Tue 08 Jan 08 4:53 P GMT-05

Building a Ledger Style for WPF Grids

Tue 21 Aug 07 3:30 P GMT-05
tags:    

Continuous LINQ - Can I write games with it?

Mon 13 Aug 07 3:09 P GMT-05
tags:        

Continuous LINQ

Mon 06 Aug 07 1:21 P GMT-05
tags:    

My first "Acropolis" Application

Mon 04 Jun 07 1:40 P GMT-05
tags:      

Exploring the Delegate Design Pattern

Mon 14 May 07 6:30 P GMT-05

Orcas' Hidden Gem - The managed PNRP stack

Fri 11 May 07 6:45 P GMT-05
tags:        

Will Silverlight be DOA?

Mon 16 Apr 07 8:02 P GMT-05

Exploring the MVC Pattern in WPF

Tue 10 Apr 07 12:51 P GMT-05
tags:                      

WPF Bindings == WTF Bindings?

Mon 12 Mar 07 6:31 P GMT-05

On MUDs

Thu 08 Mar 07 5:00 A GMT-05
tags:                    

Cocoa Programming vs. WPF : NIB vs XAML

Tue 20 Feb 07 2:09 P GMT-05

Cocoa Bindings vs. WPF Binding

Thu 15 Feb 07 5:41 P GMT-05
tags:                

What I think is a bug in WCF POX messaging

Thu 04 Jan 07 4:58 P GMT-05
tags:      

Ulysses Agenda Makes Redmond Developer News

Wed 29 Nov 06 7:10 P GMT-05
tags:                

Ulysses Agenda - Network Engine Test 1

Mon 09 Oct 06 2:26 A GMT-05
tags:              

Ulysses Agenda : First Cut Networking Design

Thu 14 Sep 06 12:46 A GMT-05
tags:                  

First Impressions of Windows Vista RC1

Thu 07 Sep 06 1:30 P GMT-05
tags:                      

Localizing a WPF Application

Tue 22 Aug 06 11:39 A GMT-05
tags:            

WPF Slide Show and Photo Album

Fri 18 Aug 06 6:48 P GMT-05

.NET Framework 3.0 June CTP is out!

Fri 23 Jun 06 6:23 P GMT-05
tags:                

Tech-Ed 2006 - Session Reviews

Tue 13 Jun 06 6:22 P GMT-05
tags:                    

Tech-Ed 2006 Day 1 - Registration Day

Sun 11 Jun 06 7:17 P GMT-05

WPF/XAML and LINQ - A match made in heaven

Tue 06 Jun 06 11:32 A GMT-05
tags: