Posts

ICacheItemExpiration implementation for a set of Rows

Image
Here is a little code that will create a class that you can use with Enterprise Library caching.  Basically it allows you to define a WHERE clause where any object in that WHERE clause changes (across a single table) then the cache will expire the object in the cache.  Think of it as a way to store a List<> of object that represent rows in a table in the cache and be able to detect if any row changes so that you can drop the cached list.  LastUpdate is a timestamp column that needs to be on every row.  This works since timestamp column type is always incremented by one, which means that SELECT MAX(LastUpdate) will tell you the maximum change across all rows. using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; using System.Data; using System.Configuration; using Microsoft.Practices.EnterpriseLibrary.Caching; using Microsoft.Practices.EnterpriseLibrary.Caching.Properties; namespace ERS.Base { //...

Movin' along with .net 2.0 web project in c#

Image
I'm getting farther along in my new pet project. I had many issues with converting to a web application project. Then I balked at which style of data access/data layer to use. Then I fidgetted with notation and styles. After wasting bunches of time, I'm finally moving along. Data is going in, data is going out. It looks aweful and the backend is a SQL client. But the user functionality is moving along. The rest can be fixed after I feel some momentum. So I'm using asp.net 2.0 c# with sql backend. Enterprise Framework from MS patterns and practices. MS Membership provider with a SQL provider. Data layer is business objects with provider model. I have nunit plugged in but haven't written in unit tests yet. Argh! Since I'm not a graphic designer, it looks BAD. A bad ripoff of www.xcache.com .   Programming to www.pandora.com .  

My Lastest Tech Article on 15Seconds

Image
http://www.15seconds.com/issue/080214.htm  - Create a Slide Show Using the AJAX SlideShow and TreeView Controls

Skining Custom Controls

Image
For the longest time I couldn't skin my custom control, background: a custom control looks like this: public class MyGridView : GridView { ... } This custom controls was in a separate class library.  Bill researched the problem and it appears that you can't skin a custom control that is in a nested namespace.  I.e. the custom control can't have this: namespace MyNamespace.SubNameSpace {    public class MyGridView : GridView    {       ...    } } It has to be in a single namespace to work: namespace MyNamespace {    public class MyGridView : GridView    {      ...    } } Visual Studio 2005 - .NET 2.0 - ASP.NET 2.0 {6230289B-5BEE-409e-932A-2F01FA407A92}  

Compare Byte Arrays

Image
Slightly more efficient by starting off with a reference compare. If the same two arrays are passed in, no need to compare the elements. I don't think there is a better way unless you use unsafe code / pointers. The use of generics makes this more general purpose. bool Compare<T>(T[] left, T[] right) {     // handles the same array     // handles both null     if (left == right)         return true ;       // fails when either are null     if (left == null || right == null )         return false ;       if (left.Length != right.Length)         return false ;       for ( int i = 0; i < left.Length; i++)     {         if (!left[i].Equals(right[i]))      ...

Compare IEnumerable (a still better option)

Image
My office mate Chad came up with yet an even better option. You need to be using 3.5 and include the System.Linq extension method namespace. It didn't perform quite as well but pretty close. Even more general purpose. Note that the default SequenceEqual method throws an exception when either operator is null so I handled those cases first. bool Compare<T>( IEnumerable <T> left, IEnumerable <T> right) {     // handles the same array     // handles both null     if (left == right)         return true ;       // fails when either are null     if (left == null || right == null )         return false ;       return left.SequenceEqual(right); }  

When a Codebase Sucks There's Always JavaScript

Image
In working on some inherited code in a very large and complex website I was a little bit skeptical of touching the code.  Let's just say the codebase was dubious at best.  This presented a problem as I had 3 days to make a lot of changes in the admin section of the site.  When inheriting code there is always a learning curve.  Unfortunately I didn't have this luxury as I spent 1.5 days getting the code running locally (still haven't COMPLETELY finished this).  This left me with about another half-day to learn the handful of tables I was to be using.  One day to actually write the code.  No problem.  So the client relayed to the PM what needed to be done which was ultimately relayed to me.  "When a manager selects a value from the whatever dropdownlist the values for the FileUpload control disappears and the user has to re-enter this value (which is by design as this would be a huuuuge security risk. Think if you could programmatically ...