# Tuesday, August 15, 2006

A few years ago, for a short time, I worked at Neumont University (was "Northface University" until a certain company had issues with the name) with one Jonathan Ellis; a few months after he left NU, he told me about his new job at Berkeley Data Systems: they have a great product/service called Mozy which provides a really simple-to-use application that does backups of the data on your Windows machine. In the past I would back-up my data to DVDs and CDs, and while I still do that from time to time, the main problem is location – I store these discs in the same location as the computer that contains the data, so that if my house went up in flames or was broken into, I could still lose my data. Obviously, offsite storage is the answer, but what am I going to do? Run some discs over to my in-laws? It would work, but that is not the most convenient option, and what if the data changes on a fairly regular basis?

You may already know that offsite backup solutions have been around for a long time, and this is an established means for solving the “problem” of how to handle data backups, but Mozy is much cheaper than any other similar service available. In fact, if you don’t mind them emailing you once a month or so with some targeted advertising (i.e. ‘spam’ – but this is actually worthwhile spam), you can get 2GB of free backup storage space. Now, 2GB isn’t much if you are interested in backing up images, video, music, etc., but if you have a lot of source code or Word documents, etc. it may be adequate – and they will give you an extra 256MB for every user you refer, once that user has completed their first backup. If you don’t mind paying a little bit of money, you can upgrade to 30GB for $4.95 a month. Compare that to other services – you will be amazed at what a great deal Mozy represents; here is their (humorous) list of alternatives to using it:

  • Burn a new CD or DVD every Sunday night and store them at your brother-in-law's office.
  • Pay $200/year for an online backup service that uses old, mediocre software.
  • Buy a $200 external hard drive and hope your office doesn't burn down.
  • Do nothing and don't worry about backup. (We suggest closing your eyes, plugging your ears and repeating "I'm in my happy place, I'm in my happy place.")
  • Run a cron job of rsync, gzip and mcrypt piped over ssh to your friend's server over his DSL line.

Obviously, this is a slightly biased list, but there is truth to it nonetheless. A few things to note: their backup of your data is secure – SSL over the wire and then the data itself is encrypted using a key you provide or you can trust their use of the 448–bit power of the Blowfish algorithm; the backup is differential, so you don’t have to worry about large, time-consuming backups (except for the first time or any subsequent points in time where you decide to backup new, large files or sets thereof); Mozy does in-place upgrades to its software, automagically notifying you when they are needed; the application is small and uses a small amount of memory (usually around 12MB of my RAM).

I have been using Mozy for over a year now, if I remember correctly, and I have loved it. I have never needed (thankfully) to perform a restore on any files, so I can’t speak to how easy that is, but from all appearances, it doesn’t look like rocket science. The peace of mind I have from using it has been worth every piece of email I have ever received from Mozy. Give it a try and see if you don’t discover the same.

For some captioned screenshots of various aspects of the Mozy experience, expand this section:

Mozy runs in the system tray, and a tool tip tells you when the last backup occurred:

System Tray Tooltip

The context menu is fairly simple:

System Tray Menu

Choosing Status from said context menu gives you the following:

Status Dialog

If you choose Configure from either the context menu of the system tray item or the above status dialog:

LoadingConfig

If you know that you want to backup all files of a few certain types, the Backup Sets feature is nice:

BackupSetsTab

If the Backup Sets feature is too high-level for you, the File System tab lets you get as granular as you want:

FileSystemTab

There are three types of backups: manual (see the earlier Status dialog), automatic (checks CPU usage stats as well as idle time), and scheduled. You can specify that you want to be alerted if a backup has not occurred in n days.

ScheduleTab

The options are pretty self-explanatory:

OptionsTab

Want to know specific details about a given backup incident? This History is also available via a button on the Status dialog.

HistoryTab

Kick It on DotNetKicks.com

posted on Tuesday, August 15, 2006 8:51:47 AM (Mountain Daylight Time, UTC-06:00)  #    Comments [0]
# Friday, August 04, 2006

I have had my head buried in things at work so much that apparently I missed this Fjax thing; I came across it via this great post which derides it.

I couldn't agree more with Simon's assessment of the situation; just as he does, I plead with you to 'just say no' to this ridiculousness. What drives people to this? I wish I could have been there at the genesis of the idea so I could have tried my best quash it. Of course, some other idiot would have undoubtedly come up with it eventually.

While Simon (and many others) like the idea of using Flash for client-side storage, I don't know if I can agree with that either. Using Flash for much of anything other than animations like those found at HomestarRunner.com just seems wrong to me. :P

 

Kick It on DotNetKicks.com

posted on Friday, August 04, 2006 4:06:05 PM (Mountain Daylight Time, UTC-06:00)  #    Comments [0]

As much as it seems unwise to do so, I have started working on a JSON parser for .NET - why? Good question. Well, I have long used a certain library for doing "AJAX" with ASP.NET, and I don't much care for the way it handles some things with regards to dealing with client-side objects (i.e. JavaScript objects). Yes, there are other JSON-to-.NET libraries around, but what fun is that?

So, I am going to try to get something like this to work for myself. All I need to do is get a JSON string like "[1,2,3]" to convert to an integer array, right? Right! Not to mention getting any other JSON string to convert to an equivalent .NET type on the server, but that will be cake. ;) So, first thing I did was take the open-source and librerally-licensed JSON syntax checker implemented in C and convert it to C# (got the main file, JSON_checker.c done, haven't got to the UTF stuff yet). I ran it against all of the supplied tests (and a few of my own) and things are looking good (i.e. all the tests passed). This thing is implemented with a finite state machine - and it is hella-fast.

So, as it states on that site, the checker "could be adapted to produce a very fast JSON parser." Indeed. Using the state transition table and lots of stepping through the code and stepping through my brain, I have come up with a few ways (all of which need more work) of how I would create .NET objects from JSON using this tool. I am really having to reach back to my CS education to think about what data structures would be most appropriate for use in the process. Matching the json objects to their .NET counterparts is hopefully as simple as looking at the expected type and using reflection to instantiate it with the JSON data.

Well, anyway - who knows what will happen? My brain has been so fried lately that I don't know if I am heading down a dead-end or not. I want to create a simple, fairly bare-bones AJAX lib for use with ASP.NET that is built on top of MochiKit, since it is the best JavaScript library around. As much as I don't want to, I know someday I may need to learn Atlas, but I would rather not - it seems like it is going to be a pain in the rear. I am sure I will change my mind; after all, if Microsoft serves it to us on a platter, it must be good . . . right? :P Probably good like using DataSets as business objects...

Have you seen Script#, "a project for enabling script authoring via C#?!?!" Help me live, you have to be kidding me! I know it is hard to have code strewn across .js files, .aspx files, and .aspx.cs files, but I *really* don't like the idea of having all of my code in C# and have it magically converted to JavaScript. I mean, yeah, I suppose it is kind of cool in a weird, freaky geeky way, but I don't think I want to write code like that. Maybe I will sing a different tune a year or two from now, but something about it just seems . . . wrong. I am sure it is just me, I mean, Nikhil is a smart guy, much smarter than I, right? I'm pretty sure of it...99% at least.

Kick It on DotNetKicks.com

posted on Friday, August 04, 2006 12:50:33 AM (Mountain Daylight Time, UTC-06:00)  #    Comments [1]
# Sunday, April 30, 2006

In case you don't know about him, Stephen Colbert is the funniest guy around. He has a show (The Colbert Report (pronounced 'the coal-bear re-poor' - both t's are silent)) that parodies conservative talk shows such as The O'Reilly Factor, with Colbert playing an overt egomaniac who relies more on his gut feeling than rational thought. It is somewhat difficult for me to explain exactly why this show is so hilarious, which is why you had better sample it for yourself.

So, I just watched a re-broadcast of yesterday's annual White House Correspondents' Dinner event on C-Span, at which Stephen Colbert was the final guest speaker. Let's just say that he rocked. His sarcastic wit was in rare form as he skewered President Bush and various other people and institutions. Unfortunately, it has been reported that not everyone thought he was so funny; with Colbert's comments hitting so close to home, maybe Bush should find some the humility needed to examine his actions and those of his administration a little more closely (not that he would listen now).

Tonight the real Stephen Colbert (as opposed to the Stephen Colbert character he plays on The Colbert Report) will be featured on 60 Minutes. Also, if you find the samples of the show funny, and don't get Comedy Central on your TV, think about purchasing 16 episodes for the low price of $9.99 from iTunes (16 episodes, which is a full month's worth). That is how I get my Colbert fix, and I highly recommend it.

[UPDATE: Here is a full transcript of what was, essentially, a roast of Bush by Colbert.]

Kick It on DotNetKicks.com

posted on Sunday, April 30, 2006 2:35:18 PM (Mountain Daylight Time, UTC-06:00)  #    Comments [0]
# Saturday, January 14, 2006

I use SourceGear's Vault for source control (v2.0.6 - I do not have the money to upgrade nor feel I would get much by doing so) and don't care much for the diff/merge tool that came with it (nor is the newer version any better), so I use the free and open source KDiff3 instead.

In order to integrate the two, open the Vault client application, select the Options item in the Tools menu, change the program in both the diff and merge sections so that it points to the KDiff3.exe file, and use the following arguments strings:

For Diff:
 "%LEFT_PATH%" --fname "%LEFT_LABEL%" "%RIGHT_PATH%" --fname "%RIGHT_LABEL%"

For Merge:
 "%BASELINE_PATH%" "%OTHER_PATH%" --fname "%OTHER_LABEL%" "%WORKING_PATH%" --fname "%WORKING_LABEL%" -o "%DEST_PATH%" --fname "%DEST_LABEL%"

Note that you must include a space character at the beginning of each of these argument lists - maybe there is a good reason SourceGear designed things this way, but off of the top of my head I can't think of a good reason; it merely causes frustration if you forget.

I hope this is useful to someone, I have to have this information each time I run Vault somewhere new, and I get tired of losing it (not that it is all that hard to figure out, I simply want to save some time and reduce the tedium of the task).

[UPDATE: Added label information in the argument lists]

Kick It on DotNetKicks.com

posted on Saturday, January 14, 2006 11:11:30 PM (Mountain Standard Time, UTC-07:00)  #    Comments [1]
# Friday, January 06, 2006


I was recently working on a project where we needed to queue ajax calls on the client, and when I went looking for a JavaScript queue, was only able to find one that used certain JavaScript Array object functionality (shift() and unshift()) that does not work in IE 5.0, which we needed to support (argh). I only needed minimal functionality for that project, but I figured I might use this on my own so I came home and wrote this:


///////////////////////////////////////////////////////////////////////
/////////////////////////////// Queue /////////////////////////////////
///////////////////////////////////////////////////////////////////////
// This Queue works in older browsers where the shift() and unshift()
// methods of the later versions of the Array object, which are often
// used in other queue implementations, don't work.
function Queue()
{
    this.dequeue = Queue_Dequeue;
    this.enqueue = Queue_Enqueue;
    this.clear = Queue_Clear;
    this.count = Queue_Count;
    this.contains = Queue_Contains;
    this.peek = Queue_Peek;
    this.toArray = Queue_ToArray;
    this.m_Queue = new Array();
}
function Queue_Enqueue(value)
{
    if (value != null)
    {
        this.m_Queue[this.count()] = value;
    }
    else
    {

        throw new Error("Cannot place null value into Queue");
    }
}
function Queue_Dequeue()
{
    var objectAtFront = this.m_Queue[0];
    var temporaryQueueArray = new Array();
    for(var index = 0; index < this.count() - 1; index++)
    {
        temporaryQueueArray[index] = this.m_Queue[index + 1];
    }
    this.m_Queue = temporaryQueueArray;
    return objectAtFront;
}
function Queue_Peek()
{
    var objectAtFront = this.m_Queue[0];
    return objectAtFront;
}
function Queue_Contains(value)
{
    var currentIndex = 0;
    var quantityToInspect = this.count();
    while (quantityToInspect-- > 0)
    {
        if(value == this.m_Queue[currentIndex])
        {
            return true;
        }
        currentIndex = (currentIndex + 1) % this.count();
    }
    return false;
}
function Queue_Clear()
{
    this.m_Queue = new Array();
}
function Queue_ToArray()
{
    return this.m_Queue;
}
function Queue_Count()
{
    return this.m_Queue.length;
}



I haven't yet used it myself in anything, other than basic testing, but it does the basics and maybe someone can find use for it. It isn't rocket science, but in a pinch it sure beats spending the time to write your own (especially if supporting older browsers is important to you).

 

Kick It on DotNetKicks.com

posted on Friday, January 06, 2006 12:08:36 AM (Mountain Standard Time, UTC-07:00)  #    Comments [2]
# Tuesday, December 27, 2005


For those that use Paul Wilson's O/R mapper, here are some additional templates for generating a framework around that tool. While Paul Welter provides templates for this purpose, I don't particularly care for the pattern used in his generated classes (follows the 'Active Record' design pattern, AFAIK).

I personally don't like having business objects that 'know' anything about the concept of persistence (saving, retrieving, etc.); while this is a relatively common way of doing things (I did the same thing in the past), it doesn't work for me any longer simply because of my current personal opinions as it pertains to application architecture. Granted, 'it depends' on the application - I simply don't find myself ever needing to write an application using that pattern. :P

There is a readme.txt file that contains more than enough verbosity on what these do/don't do. However, here are some big ones:

  1. These have been verified to work in the following versions of CodeSmith (i.e. I have tried them in these versions, they may also work in others as well, YMMV):
       v2.6 (the 'free' version)
       v3.1.6
  2. These generate C# code.
  3. These have been used against SQL Server 2000 (theoretically, they work against any that CodeSmith and WilsonORMapper support)
  4. They currently target v1.1 of the .NET Framework (though they work against 2.0 as well, they simply don't support generics (yet)).

I hope someone finds these useful.

Thanks.

Kick It on DotNetKicks.com

posted on Tuesday, December 27, 2005 11:47:38 PM (Mountain Standard Time, UTC-07:00)  #    Comments [2]
# Monday, November 21, 2005

Most of the time, I am happy writing ASP.NET applications; I have been doing web development for almost 5 years, beginning with 'classic' ASP. As time goes on, I find myself writing more and more software for myself and this tends to be of the WinForms variety. Currently I am developing some software to help manage the seemingly unmanageable quantities of digital pictures that my wife and I have amassed over the last 5 years. I am still in the architecting phase of the project, but when I go to design the UI, I want to use something that will make it look slick (read: make it look familiar so that my wife will feel comfortable using it).

Via a post by Jay Kimble, I found out about a free (even for commercial use!) toolkit that provides some slick UI controls for WinForms applications (targeted at Visual Studio 2005 and 2.0 of the .NET Framework); it is called The Krypton Toolkit, and I plan on seeing how I can fit it into the aforementioned application's client piece. You can download this toolkit from Component Factory's website.

Kick It on DotNetKicks.com

posted on Monday, November 21, 2005 10:01:55 PM (Mountain Standard Time, UTC-07:00)  #    Comments [0]
# Tuesday, October 11, 2005


One of the classic "problems" with code generation is the situation where you need to add custom code to generated code. For example, it is very easy to generate simple ("anemic") domain objects from a database schema, but what about when you get to the point when you want to add behaviors to those objects? Where do you put that code? If you place it in the file that was generated, you will lose the handcrafted code unless you either never regenerate that file (very unlikely) or manually (or programmatically) remove and then re-insert the code; with the exception of programmatically preserving handcrafted code, you don't want to bother with those options.

Up until recently, the way you typically get around this is to use an inheritance model. You put all of your generated code in a base class and all of the custom code in a derived class. This allows you to regenerate the base class any time you would like without fear of losing handcrafted code. Of course, some would say there are cons to this approach, such as namespace pollution, issues accessing private base class members, etc. - I personally haven't had any problems with the inheritance model, but maybe I just don't write code that is interesting enough to suffer from these issues. :P

So, where do partial classes come into play? Well, they were, at first (by those who didn't think hard about actual implementation), hailed as a solution to the problem alluded-to previously. Instead of using contrived inheritance, we could now have one type spread across two or more files. Yippee! Now that we can have a generated file and a custom, handcrafted file that define the same type, all of our code gen related problems would be solved! But not so fast. While it does provide a great construct for some code gen situations, it is not necessarily the ideal in all cases (which is to be expected, nothing is a silver bullet) - of course, I am examining one simple situation here, it doesn't mean partial classes will not work well for other situations. Let's use an example that came up recently in my own work. In the past, I would generate code and use the following construct for the beginnings of my domain objects (i.e. before I added the handcrafted behavioral code to the domain object):


Base class:

public abstract class UserBase
{
   private string m_FirstName = string.Empty;
   private string m_LastName = string.Empty;
   private int m_Age = 0;

   public string FirstName
   {
      get { return m_FirstName; }
      set { ValidateFirstName(value); m_FirstName = value; }
   }
   
   public string LastName
   {
      get { return m_LastName; }
      set { ValidateLastName(value); m_LastName = value; }
   }

   public int Age
   {
      get { return m_Age; }
      set { ValidateAge(value); m_Age = value; }
   }

   public UserBase() { }

   public UserBase(string firstName, string lastName, int age)
   {
      FirstName = firstName;
      LastName = lastName;
      Age = age;
   }

   protected virtual void ValidateFirstName(string firstName) { }
   
   protected virtual void ValidateLastName(string lastName) { }

   protected virtual void ValidateAge(int age) { }

}


Derived class:

public
class User : UserBase
{
   public User() : base() { }
   
   public User(string firstName, string lastName, int age) : base(firstName, lastName, age) { }
   
   protected override void ValidateFirstName(string firstName)
   {
      if (firstName.ToUpper() == "FOOBAR")
      {
         throw new InvalidDataException(string.Format("Your first name cannot possibly be '{0}'!!!", firstName));
      }
   }
}


The thing I want to point out is that in the property setters in the base class, we call some virtual methods to validate data. As you can see, those methods have no implementation, so if we derive a class from UserBase, and don't override those methods, no data validation happens. That is just fine, because maybe our code gen process doesn't provide for generating that type of validation (it could if we had a more robust code gen process, but let's simply examine this simple case). So, now we are free to override the virtual methods in the derived class in order to provide data validation (as illustrated by the overridden ValidateFirstName method).

Well, guess what? This is not so easy using partial classes. If I have the following generated partial class, how do I duplicate the same behavior as illustrated above by the inheritance model?

Generated partial:

public partial class User
{
   private string m_FirstName = string.Empty;
   private string m_LastName = string.Empty;
   private int m_Age = 0;

   public string FirstName
   {
      get { return m_FirstName; }
      set { ValidateFirstName(value); m_FirstName = value; }
   }

   public string LastName
   {
      get { return m_LastName; }
      set { ValidateLastName(value); m_LastName = value; }
   }

   public int Age
   {
      get { return m_Age; }
      set { ValidateAge(value); m_Age = value; }
   }

   public User() { }

   public User(string firstName, string lastName, int age)
   {
      FirstName = firstName;
      LastName = lastName;
      Age = age;
   }

   protected void ValidateFirstName(string firstName) { }
   
   protected void ValidateLastName(string lastName) { }

   protected void ValidateAge(int age) { }

}

  

Custom partial:

public partial class User
{
   // how do I take care of writing custom data validation within this file?!
}

I was in this situation today. We (coworkers and myself) decided a few weeks ago, without giving it a terribly good deal of thought, that we would go the partial class route on our generation of domain objects and such. But now I needed to validate data on the setter of one of the properties of the class. How was I going to do that? I came up with a completely horrible hack involving delegates which I decided was out of the question. I may not write the most elegant code, but I want the code to be somewhat readable - having a delegate for each property's setter was NOT in keeping with that idea. I am either going to go back to using the inheritance model or will start using the PreserveRegions functionality of CodeSmith to preserve my handcrafted code - partial classes have not been as useful as I once hoped they would be. Oh well!

Kick It on DotNetKicks.com

posted on Tuesday, October 11, 2005 12:14:22 AM (Mountain Daylight Time, UTC-06:00)  #    Comments [0]
# Sunday, September 18, 2005

I had been on a project for the last 8 months for which we used code generation to build basic business objects and some persistence management classes based on metadata available via the database schema. We used CodeSmith templates that I originally wrote for myself (I have been using code gen in one form or another for years now; I don't see how people live without it), which generated C# code, but modified them to produce VB.NET code as required by our client (they told us that we would be doing C# when we were interviewed - that changed to VB.NET after they hired us, much to our dismay).

Coupled with Paul Wilson's excellent O/R mapper ('WilsonORMapper," aka "WORM"), the code generation framework made developing the applications we needed very enjoyable (because who really likes writing persistence layer code?!) and quick. The part of the process that we didn't really care for was when it came time to regenerate the code (this usually happened when a database change was made) - if a table was added, which usually mapped to a new business object, you would open CodeSmith and generate the code, go to Visual Studio, manually add the newly-generated files to the appropriate projects, finally you would then check those into source control (we used SourceGear's Vault, without Visual Studio integration (we had our reasons)). Sounds simple enough, but this became a tedious process (changes were made to the database almost on a daily basis (the client had modeled the database before we started on the project, and suffice it to say they didn't know much about modeling data (not to mention they were simultaneously developing other applications against the same database schema, and would neglect to tell us of fields that were added (we worked off-site, they were in another state, so we had a copy of the database)))) which we would usually screw up (forgetting to check in the new project file, and/or newly-generated code), not to mention we generated code on a certain machine because we wanted to have a single place for that to happen, to help enforce our process (you would be more likely to check things into source control, since you had just generated them, for example).

Okay, enough background - all I really want to say is that we finally took some time the other day (we are off the project alluded-to above and onto another) to add to the code generation process some things we have wanted for a long time but never took the time to create. Namely, the CodeSmith templates we use now add any newly-generated classes to the appropriate Visual Studio project files (we are using Beta 2 of VS2005) and we can also run the entire process from our own machines from within Visual Studio (no more opening CodeSmith as a separate application - we use it in batch mode (with a cmd file)) using the simple key chord of Ctrl-G, Ctrl-C (GC for 'generate code' - original, eh? ;)). Our next item is to then have it automatically check the code into Vault as well. Once that is done, the process will be muy sexy: make some changes to the DB within Enterprise Manager, switch to VS2005 and hit Ctrl-G, Ctrl-C and within a few moments, voila! Ah, the power of being lazy! Oh, and we are using partial classes now (to get around the problem of potentially losing handcrafted code associated with the generated code); while this is not ideal to me, it works and makes us feel cool for now (the reasons I feel partial classes are not ideal is another story - maybe I will blog about that sometime, or maybe I won't).

 

Kick It on DotNetKicks.com

posted on Sunday, September 18, 2005 12:09:44 AM (Mountain Daylight Time, UTC-06:00)  #    Comments [0]