Only get the data that is needs to be displayed

May 12, 2009 09:58 by bryan

I have been on the look out for the ability to display and search a customers database, but having the ability to display millions of records if that what the end users wants.  But the trouble is that it can take a long time to return a million records from a data source.

I've talked about paging before in my article LINQ-to-SQL-and-Paging, which works fine for internet based paging, but what about WPF and WinForm Grids, well I came across Vitrual Mode for the Microsoft Data Grid, which can provide an answer.  What this allow you to do is, load the data you can see on the screen very quickly and as you scroll through the data is fetched when required.

By setting the VirtualMode = true for a data grid, it allows you to add a handler for deail with CellValueNeeded 

Here is the main body of the code

Each time the Data grid needs some values it will call the following:

And of course the NameListCache class

 

I have attached the source, you will also find a PopulateData project to populate the database with data.

 

DataGridViewVirtualModePaging.zip (19.43 kb)

PopulateData.zip (11.43 kb)

Here are a few of the database scripts that yu will need for the sample

Names.sql (581.00 bytes)

GetNames.sql (786.00 bytes)


How to get an EULA displayed for your clickonce application

May 7, 2009 13:17 by bryan

Stuck with this issue, if needing a ClickOnce installation to display an EULA, I final found a solution, on MSDN

Here's a round about way to get your clickonce applications to install with an End user license agreement. Basically you build a redistributable component that can be seen in your prerequsites dialog box under the publish window. This allows a nice way to have all your apps reuse the same agreement, if you want. It's very easy, you need only to create three files ("eula.txt", "product.xml", and "package.xml") and two folders in this case ("EULApackage", and "en"). I documented everything below on how I set mine up. it works great. the only thing you'll have to change is the Name of the component and of course you'll need your own end user licence agreement saved as eula.txt. The component needs to be put in the following path:

Visual Studio 2005

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages

Visual Studio 2008

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

in this folder you should see some sub folders for other redistributable components. First make a new sub directory for your component. I called mine EULApackage. in this new folder you need the following. -A file called product.xml and a sub folder called "en" (for english) you can do various things with the product.xml file, but here's the way mine looks

<?xml version="1.0" encoding="utf-8" ?>

<Product
 
xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
 
ProductCode="EULA.Bootstrap.Component"
>
 
<!-- Defines list of files to be copied on build -->
 
<PackageFiles>
   
<PackageFile Name="en/eula.txt"/>
 
</PackageFiles>

 
<Commands>
   
<Command PackageFile="en/eula.txt"
     
Arguments='' >
       
<ExitCodes>
<ExitCode Value="0" Result="Success"/>          
<DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
       
</ExitCodes>
   
</Command>
 
</Commands>
</Product>

*in this case the file eula.txt was the text file that was my license agreement. Note that it's not an rtf file. Rtf won't display propertly using this method.

Now inside my "en" subfolder i put the eula.txt file and another xml file called package.xml, again this xml file can be used to do all kinds of stuff

heres the contents of my version*

 

 <?xml version="1.0" encoding="utf-8" ?>

<Package
 
xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
 
Name="DisplayName"
 
Culture="Culture"
 
LicenseAgreement="eula.txt">

   
<PackageFiles>
       
<PackageFile Name="eula.txt"/>
   
</PackageFiles>

 
<!-- Defines a localizable string table for error messages and url's  -->
 
<Strings>
   
<String Name="DisplayName">Companies End User License Agreement</String>
   
<String Name="Culture">en</String>

   
<String Name="CancelFailure">User Failed to Accept Companies End User License Agreement.</String>
   
<String Name="GeneralFailure">A fatal error occurred during the installation of ELUA Component Execution</String>
   
<String Name="AdminRequired">You do not have the permissions required to install this application.  Please contact your administrator.</String>
 
</Strings>    
</Package>

Note: whatever you put in the DisplayName field is what your user will see when he's confronted with the eula text If you have all this put together correctly and in the right folders, the next time you start up VS2005 and go to your publish tab -> prerequisites you should see the DisplayName field. Just check this as a prerequisite for you app. when the user clicks install on the publish.htm file it'll present the user with the conents of your eula.txt file inside of a standard license acceptance dialog box. if the choose accept your stuff installs, if they decline then it exits rather nicely and nothing is installed on their systems. If you mess up the formatting for either of the two files or if you leave out the "en" sub folder then the component won't show up in the prerequisites dialog (when publishing)

Additional notes: although this works great it is a round about method and their are ways around the eula, such as if your publish.htm file allows them to run the application directly (I guess without the bootstrapper starting)but if they click the install button it will run. This also has the benifits of not running every time you publish an update to your clickonce application. They have to run the boot strapper to get the eula to show up (by clicking the install button on publish.htm) I figured out this method by looking at some of the other redistributable components that were already in the path

Visual Studio 2005

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages

Visual Studio 2008

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

You can look in those other components product.xml and package.xml files to see what cool things they've done with them.

 

If you are using Visual Studio 2008, you can also set up your project file to include the Package, here is an example below

<BootstrapperPackage Include="EULA.Bootstrap.Component">
  <Visible>False</Visible>
  <ProductName>RPS End User License Agreement</ProductName>
  <Install>true</Install>
</BootstrapperPackage>

Caching from a non Web applications

February 6, 2009 08:30 by bryan

Okay you are developing a WinForm application and you are looking at performance, one area is Caching of information, but wait a minute I've been using caching in my web applications for sometime, but how do you do it from a WinForm application as you don't have a host to store your cache.

Would you know it you can use the web cache too, just you have to take a few extra steps to retain your cache, either in memory or in temporary files.

You can use the HttpRequest to store the System.Web.Cache objects in your application, and this works well.

I also came across any Blog, providing another method to Caching, however I have a little concern over this method of caching in files as you are likely to get file locking.

Using System.Web.Caching From The Console Or Windows Forms

I've written my own simple VB.NET application to show it working and just holding the Cache in memory for the life of the application.

WinFormCache.zip (17.73 kb)

Of course you could run a Windows Service which holds all the Cache information, this way it will be available to all your WinForm applications should you require it.