in

ASP.NET Weblogs

This Blog

Syndication

ShowUsYour<Blog>

Irregular expressions regularly

February 2005 - Posts

  • Kingdomality Test

    Ok, these things always get me; apparently I'm a White Knight... giddy-up!

    White Knight

     

  • Code to easily create zip files on the fly

    The other day I posted about a free .NET library for creating zip files on the fly:

         http://weblogs.asp.net/dneimke/archive/2005/02/23/378781.aspx

    Here's a little method that I wrote which wraps the functionality of the ICSharpCode library to easily package one or more files into a zip file.

     

    private static void WriteZipFile( string[] filesToZip, string writeToFilePath ) {
    
      try {
        if ( EnsureDirectory(writeToFilePath) ) {
          
          Crc32 crc = new Crc32();
          ZipOutputStream s = new ZipOutputStream(File.Create(writeToFilePath));
          s.SetLevel(9); // 0 - store only to 9 - means best compression
    
          for( int i=0; i<filesToZip.Length; i++ ) {
          
            // Must use a relative path here so that files show up in the Windows Zip File Viewer
            // .. hence the use of Path.GetFileName(...)
            ZipEntry entry = new ZipEntry(Path.GetFileName(filesToZip[i]));
            entry.DateTime = DateTime.Now;
    
            // Read in the 
            using(FileStream fs = File.OpenRead(filesToZip[i])) {
      
              byte[] buffer = new byte[fs.Length];
              fs.Read(buffer, 0, buffer.Length);
    
              // set Size and the crc, because the information
              // about the size and crc should be stored in the header
              // if it is not set it is automatically written in the footer.
              // (in this case size == crc == -1 in the header)
              // Some ZIP programs have problems with zip files that don't store
              // the size and crc in the header.
              entry.Size = fs.Length;
              fs.Close();
          
              crc.Reset();
              crc.Update(buffer);
              entry.Crc  = crc.Value;
              s.PutNextEntry(entry);
              s.Write(buffer, 0, buffer.Length);
            }
          }
      
          s.Finish();
          s.Close();
        }
      } 
      catch( Exception ex ) {
        HttpContext.Current.Trace.Warn( ex.ToString() ) ;
      }
    }
  • SqlServer 2005 pricing details

    Posted Feb 25 2005, 09:44 AM by digory with 1 comment(s)
    Filed under:
  • Listen to tunes while you swim or workout

    Here's my next purchase:

    It's a watertight casing for your MP3 player so that you can listen to music while you swim.  It comes with waterproof headphones.


    http://www.h2oaudio.com/products/i700sv.php#
    Posted Feb 24 2005, 10:40 PM by digory with no comments
    Filed under:
  • Nested sub-queries always elude me

    Tonight I was writing the stored procedure which will return lists of data to the Codewise nighly updates.  Basically, each night, Codewise will call a webservice and you need to return a list of all GUID's which have been either ADDED, UPDATED or REMOVED since the last time they called your service.  The return Xml will look something like this:

      <ContentItemIds>
        <Added>
            <Guid ... />
        </Added>
        <Updated>
            <Guid ... />
        </Updated>
        <Removed>
            <Guid ... />
        </Removed>
      </ContentItemIds>


    I wanted to have a stored procedure that I could pass a "type" and a start date and get back a list of Guids that have changed to that type since the starting date.  This kind of Sql is often munged-up as a string and Exec'd back to the caller.  I'm not a big fan of sql strings in the middle-tier or building strings in the database so I thought that I'd find a straight sql approach.  I was trying the following query which was failing:

    SELECT CASE 
        WHEN @diffType = 1 AND [CreationDate] > @beginDate THEN [GUID]
        WHEN @diffType = 2 AND [LastUpdatedDate] > @beginDate THEN [GUID]
        WHEN @diffType = 3 AND [RemovedDate] > @beginDate THEN [GUID]
    END As [GUID]
    FROM dbo.Codewise_ContentItem
    WHERE 1 IS NOT NULL


    So, I pinged Thomas who whipped up the following pre-breakfast solution:

    SELECT [GUID]
    FROM dbo.Codewise_ContentItem
    WHERE [GUID] IN (
        SELECT 
            CASE 
                WHEN @diffType = 1 AND [CreationDate] > @beginDate THEN [GUID]
                WHEN @diffType = 2 AND [LastUpdatedDate] > @beginDate THEN [GUID]
                WHEN @diffType = 3 AND [RemovedDate] > @beginDate THEN [GUID]
            END As [GUID]
        FROM dbo.Codewise_ContentItem
    )

     

  • Codewise posts

    I've already blog'ged a bit about Codewise and how ProjectDistributor will be a participating site in that program.  Over the next week or so, I'm planning to do some blogging about what I had to do to add Codewise functionality into the ProjectDistributor application.  I'll also be blogging about the "experience" that ProjectDistributor users will have when adding Codewise samples.

  • Code Review Tip: Poorly named variables are symptoms

     

    When reviewing code one of the ways to quickly spot "messy" logic is to look for module-scoped variables with whacky names.  Poor naming is often an indicator that the reason for writing code was unclear to the developer at the time. 

     

    Let's get an example eh?...

     

        bool _flagWhichGetsSetOnReturn = false ;

     

    That's a pretty whacky name right?  Once I've identified a prospective refactoring candidate I'll do a "Find" operation to see where and how it is used.

     

    Most times, after a quick scan through you have an epiphany moment when you suddenly understand what it was that the developer was trying to do at the time.

  • Do you remember...

    Geoff asks how old I am.

    I am:

    48 years 2 months younger than Pope John Paul II
    44 years 1 month younger than George Herbert Bush
    22 years 1 month younger than George W. Bush
    12 years 9 months younger than Bill Gates
    2 years 1 month younger than Mike Tyson
    2 years 0 months older than Jennifer Lopez
    7 years 5 months older than Tiger Woods

    and I was:

    33 years old at the time of the 9-11 attack on America
    29 years old when Princess Diana was killed in a car crash
    26 years old at the time of Oklahoma City bombing
    25 years old when O. J. Simpson was charged with murder
    24 years old at the time of the 93 bombing of the World Trade Center
    22 years old when Operation Desert Storm began
    21 years old during the fall of the Berlin Wall
    17 years old when the space shuttle Challenger exploded
    15 years old when Apple introduced the Macintosh
    12 years old when Pres. Reagan was shot by John Hinckley, Jr.
    11 years old at the time the Iran hostage crisis began
    7 years old on the U.S.'s bicentennial Fourth of July
    6 years old when President Nixon left office
    not yet 1 year old at the time the first man stepped on the moon

  • Health monitoring in ASP.NET V2

    Here's a couple of nice articles about the new HealthMonitoring feature in Whidbey:

        http://weblogs.asp.net/dr.netjes/archive/2004/12/09/279101.aspx
        http://msmvps.com/gbvb/archive/2004/09/15/13578.aspx

    Definitely worth a read as this makes it super-easy to put custom logging code into your applications. 

     

     

    Posted Feb 24 2005, 07:41 AM by digory with 2 comment(s)
    Filed under:
  • Zip'ping files

    Tonight I was using the ICSharpCode zip library to zip files for my Codewise implementation.  Basically, when users nominate to make a Relase visible to Codeshare, I create a manifest file and package it and the Release file into a Codewise package.

    I ran the code which comes in the .chm file but, noticed that my .zip files wouldn't show any content when viewing them through the default Windows Zip File viewer.  I little bit of investigation led me to the FAQ site for the library which answered my question.  Basically, you cannot pass a fullpath to the ZipEntry class if you want it to be visible to Windows.  So, you just remove the path portion of the filename:

    ZipEntry entry = new ZipEntry(Path.GetFileName(fullPath)); 

    ICSharpCode Zip Library:  www.icsharpcode.net/OpenSource/SharpZipLib
    FAQ Wiki: http://wiki.sharpdevelop.net/default.aspx/SharpZipLib.FrequentlyAskedQuestions
More Posts Next page »