Up Silverlight

Code sample: Secura Mail

Last modified on October 28, 2011 11:25

DevForce Silverlight Powers SecuraMail.net, the award winning high-security Silverlight email client.

"After working with Ria Services for almost a year, DevForce become the obvious answer."

Most people think email clients are old school and boring. The truth is that email was one of the first killer apps. And even today, everyone needs an email client. But little has changed since Gmail and Hotmail hit the scene. People flocked to those services because they were feature-rich, cost nothing, and easy to use. But today, there are security concerns: What happens when that email goes out across the net through many different networks? It’s not secure and you have no control over it.


secura.png

Choosing DevForce

The major challenge in building a secure email client is the data access. There is a lot of chatter going on back and forth between the client and server, and a lot of data to move across the wire—and speed is essential. After working with Ria Services for almost a year, I threw in the towel and picked up DevForce. 

I really wish now that I had started with DevForce for several reasons:

  1. It's easier to learn. There are many resources for getting off the ground, including videos, templates, sample code and documentation. The forums are answered by the DevForce team with accurate answers to your questions.
  2. It’s very fast. DevForce zips your data for you automatically when it goes across the wire. This is a huge benefit when you have a lot of text to deal with as in HTML emails. I was doing this manually in Ria Services.
  3. DevForce has been around for 10 years now. It is mature, well tested, and of course works very well. I found it very easy to implement advanced concepts such as paging. For example, the main email grid pages 250 emails much faster than other clients, even Gmail and Hotmail. 
  4. Every feature I have found a need for has already been thought of by the DevForce team. This means I don’t have to write it myself. For example, off-line reading of email is supported through Silverlight’s Isolated Storage, but getting the data there and back is done by DevForce. So I did not have to write bunch of code to save entities to xml and then store it as a text file.
  5. Security is built right in to DevForce. Just configure the site to run on HTTPS and your data across the wire is encrypted automatically. How easy is that!
    And it has all worked out great. Secura Mail (aka Jet-Email) won Ineta's Component Code Challenge this year … and it is still in beta! It will fill the need for HIPPA/SAS 70 email services that are currently very expensive but required by law in many corporate environments. The end goal was not just security, but also a highly usable user interface—better than current industry standards, and I think we were able to achieve this.

DevForce integration

One of my favorite features in DevForce is how it makes it really easy to do paging. By combining a DevForce component, a standard paging control and a data grid, you have everything you need to enable real time paging. For example, if you click on the header of the grid, the grid doesn’t merely sort the existing data in the grid; it actually triggers a sort order change event which triggers DevForce into calling a new query of the entities in the new sort order. So the first page is the first page of ALL the data, not just a simple resort of the existing data.
 
Further, once data has been brought down to the client, it is cached there. So if the user goes from Page 1 to page 2 and then back to page 1, the cached data is used instead of making another call to the server. No custom code is required to get this functionality; it’s baked right into DevForce.
  
The component that orchestrates the paging is called the EntityQueryPagedCollectionView.

To put it to use, you instantiate it like this:

C#
//A simple query which gets all email messages.
var query = EmailEntityManager.vEmailMessageEntities;  

// The constructor takes the query, the page size and the load size.
EntityQueryPagedCollectionView EmailMessages = new EntityQueryPagedCollectionView(
query,
250,
250 );

//We now add a sort description which will determine the initial sort order.  
EmailMessages.SortDescriptions.Add(new SortDescription("SentOn", ListSortDirection.Descending));
 

I also want to know when the current email changes, so I add this event handler:

C#
EmailMessages.CurrentChanged += new EventHandler(EmailMessages_CurrentChanged);


The next thing to do is wire up the DataPager to the EntityQueryPagedCollectionView.  This is done in the xaml:
C#
<DataPager Source="{Binding EmailMessages}" />


Now we need to wire up the Grid to the EntityQueryPagedCollectionView. This also is done in the xaml:
C#
<DataGrid ItemsSource="{Binding vEmailMessages, Mode=TwoWay}" />


The grid is just a standard DataGrid (I actually use the ComponentOne FlexGrid for the greatest speed, but the above works with the standard Silverlight datagrid as well). I create the columns in code, and one of the properties of the column is the sort order property. It is this property which allows the grid to tell the EQPCV to refresh with a new sort order.
 
And that’s it. In just a few lines of code, you have put together a sophisticated grid with data caching.  As you can see, there is really no coding – just wiring up the three elements to work together.

In practice, I don’t bring down the full entity to populate a grid. Instead, I create view in the database that contains just the columns that I want to display in the grid. I then create an entity based on the view. So I will have one entity called EmailMessageEntity and then another one based on the view called vEmailMessageEntity. The grid is then bound to the “slim” version. When the current email changes, I make a call up to the database and get the one full entity that I need and then display that. By having a slim entity, data access time is greatly sped up and the grid is very responsive to sort changes and paging.

There are many more DevForce features that I use, but this is one of my favorites.

Tags:
Created by DevForce on April 12, 2011 10:58

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade