CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

July 2004 - Posts

  • Fun with C# and HP Printers...

    Via John Galloway, hack your networked HP printer with a little C# console app.  His download is broken, but I compiled a quick version here

    Of course, I made ours say “PC LOAD LETTER”  I'm cracking myself up, and there's no one here today to appreciate it.  Oh well. Like a tree falling in the forest, or the Pope in the woods ... or is it a bear?  Anyway, I'm rambling.

    -B

  • An Object-Oriented UI for Web Applications

    This is something I've wanted to post about for a while... Scott Galloway posted today about UI Frustration so I thought I'd chime in.  I've always been interested in this concept of an OOUI (object-oriented user interface) in which you break the application down into “Objects” with a type, methods, properties and events...  I've been using this successfully for a number of years, and I really can't find anything better for Web application UIs. 

    So how does this work?  Start out with a big old tree/table-like view to hold your root and related objects.  Tabs are used to show different views of the object tree.  Main navigation is used to navigate to different object families.  As with OO programming, your UI objects will have a type, methods, properties and events.

    • The “object" has a "type" represented by an Icon and hyperlink title
    • Clicking the object's title opens it's properties
    • The object's "methods" are accessed by clicking an icon to the right-hand side of the row's tree
      • This comes naturally to users used to right-clicking on Windows objects
    • The object's sub objects are treed beneath it
    • When events are raised, the object's icon animates
    • Objects can be selected by clicking a check box to the right hand side of the object
    • Methods that don't act upon a specific object are represented as buttons above the tree, and can optionally act upon selected objects.

    So what does this all look like?

    So, as you read this, you may say to yourself  “duh!,“ but it really does help to keep this structure in mind and adhere to it throughout your application. 

    -B

  • Oh! Now THIS is Funny...

    So, I get this email today:

    Subject: .NET Blows Balls!!!
    Email: 1@2.com
    IP Address: [REMOVED AS OF 3:30]

    =====================================
    Why must you proliferate another Microsoft product by splattering their logo everywhere??? Can't you just try to hide the fact that you are not a web programmer, but a Microsoft Certified Asshole???

    First of all, I don't know where I've splattered their logo, I only know of one place on my blog with their logo...  And the sentence starting with “Can't you just..” has so many double-negatives, I can't even understand what he's trying to say, but I will agree with him that I'm not a “web programmer.”  But that't not the funny part, this is: as it happens, when you click on the IP address, you can find for yourself the real sender of this email. Try it.

    Here's an exerpt from his Resume:

    August 2003 - Present

    Modernized current business solutions. Wrote Perl scripts to run administrative, web-based CGI interface to automate scheduling, billing, and records system. Communicate regularly with faculty and staff to ensure a working and efficient product. Constructed multi-processor server to host https://coxsackietransport.com , assembling all hardware and compiling all software by hand to maximize performance and minimize CPU waste.

    Sounds very advanced... Using that fancy CGI.  How circa 1995 can you get..  Perhaps he should read this book here

    -Brendan

    Update @3:24... Matt made me think twice about bullying this guy, so I've removed his IP Address from this post, calling the dogs off if you will.  I guess I'm a bit thin-skinned when it comes to stuff like this, and outed his IP just because I could.  In hindsight, it probably wasn't the most mature thing to do....

  • Data Binding Custom Entities

  • OT: If you went to jail for 5 months like Martha, what would you do with your time?

    Okay, aside from the obvious remarks about not picking up soap, etc, and let's assume you had no computer access. Here's my top 5:

    1. Learn to speak aonther language
    2. Memorize deisgn patterns
    3. Lift weights to try to get as big as this guy
    4. Study fractal math
    5. Most importantly, I'd learn to beatbox

    What would you do? 

  • Boilerplate Entities?

    I'm finding myself creating a bunch of basic Entity objects, like MailStop, Contacts, etc and I'm wondering if anyone knows of any boilerplate entity designs out there?  Specifically, I'm finding myself wondering if my MailStop object should contain a CityStateZip object, how many street properties, etc.  Suff like that mostly.   I know there must be some best practices for this sort of thing out there, but I can't seem to find anything short of books on the subject.  Anyone have any good sources? 

    And here's another thought.  Wouldn't it be cool to have a boilerplate entity project on GotDotNet? Would this be useful?  

  • using Microsoft.ApplicationBlocksExceptionManagment again...

    So after a good thread of discussion relating to a post I made yesterday,  I've implemented a custom publisher for the ExceptionManagment Application Block.  I've simply switched off the Default publisher and routed exceptions to my custom publisher, which logs my exception somewhere other than the Event Log.

    Why did I need to do this?  Well, there really seem to be some issues with publishing to the Event Log under 2003 with a low trust impersonated account under IIS.  Trust me, it's not a simple registry permissions issue with the impersonated account...  Anyhow, publishing to the event log isn't so great so the point is really moot.  For one thing, event logs can fill up and cause errors, and on top of that permission problems can be tricky at the very least.

    With the version of the Exception Management block that I'm using, it doesn't appear to be possible to turn off logging to the Event Log without creating a custom publisher, but it turns out that this is quite easy, so that's what I ended up doing.. See a good article here.   Thanks to Sebastien too for all his help with this.

    -B

  • Not using Microsoft.ApplicationBlocks.ExceptionManagement;

    Today, I removed the references to the Exception Managment application block in our framework here at the port... The reason?  As far as I can tell,  there's an issue with impersonation and writing to the event log under 2003 that shows up when using Publish(System.Exception ex):

    [InvalidOperationException: Cannot open log for source {0}. You may not have
    write access.]

    There's a thread here and here and here all seeming to dead end, un-resolved that address this issue.  After a bunch of FileMon-ing and RegMon-ing, I started asking why I needed to publish to the Event Log in the first place.  My answer to myself was “I dunno.“  In fact, publishing to the Event Log is kind of a pain in the butt anyhow, with the log filling up, permissions, etc.  So, I implemented a custom Publish(System.Exception ex) method that puts the log somewhere else.

    This is the second Application block that I've had to un-use.  I stopped using the Data app block long ago because of bugs.  I'm still using the FileUpdater block which I'm happy with.

    .

  • Adventures with IIS Lockdown

    Recently, I installed and ran the Microsoft Baseline Security Analyzer (for IT Professionals) (I hope that includes me) on my development machine here at work.  It had a couple of recommendations for securing IIS... 1) Deleting Parent Paths and 2) Running the IIS Lockdown Tool

    Deleting Parent Paths was painless, but running IIS Lockdown caused a bit more of a headache for me. When I loaded my solution, I was unable to load the Web project (project unavailable in visual studio).  This was no biggie, I thought I'd just re-create the project from SourceSafe. Well when I tried to create a new Web project called “www.vit.org,“ I kept getting this message:

    Unable to create Web project 'www.vit.org'. The file path 'c:\inetpub\wwwroot\www.vit.org' does not correspond to the URL 'http://localhost/www.vit.org'. The two need to map to the same server location.

    To make a long morning short, it turned out that after running IIS Lockdown, I could no longer create a Web project with periods (.'s) in the name.  So, I created the project as “publicweb“ and it worked fine. 

    I haven't figured out why this happened yet, and I'm sure there's a good reason for this,  but wanted to report this behavior.

     

  • DotNetNuke!

    Like most of us, I've got a bunch of side-projects, mostly one-off web sites.  In the past, I'd do the design, HTML dreamweaver coding and hours and months later, finally abandon the thing on some web server somewhere.

    Over the weekend, I set up DotNetNuke on my new WebHost4Life account (thanks DonXML). This is one cool piece of software.  It took me a couple of hours to get the Skinning stuff figured out, but now that it's set up, I'll be able to do these pesky side-projects in a matter of hours, not days. 

    So, I showed a DNN-Enabled site to my customer this morning, he was thilled. My words to him were “You're getting a $10,000 site here for practically nothing.“ And I meant it.  Very cool.

  • Custom Entities, Equality and overriding GetHashCode()

    OBSOLETE CONTENT
    The author of this post has determined that this content is obsolete. Use at your own risk! Blog posts are a point-in-time snapshot of the blogger's thinking and should not be assumed to represent this blogger's current opinions. This post was left up for historical purposes.

    Last week I posted about starting a new project here at the port.  I'm entering new development territory with this, specifically, I'm 1) Doing test-driven developmet with NUnit, 2) Using Custom Entities instead of DataSets and 3) Developing my buisness tier components as WSE services.   I've been having fun.  I'm very into the test-driven developent thing, NUnit Rocks!  I'm definitely writing much more solid code.  I'm going to post about that later, but I wanted to share some thoughts on using Custom Entities vs. DataSets here.

    I'm adding a whole new layer to my Common tier, consisting of my new custom entities.  These are hopefully going to be the building blocks of our framework someday, and consist of our basic business entities. 

    DataBinding: This was one thing I was slightly worried about with Custom Entities, but it's works great.  I've created strongly-typed collection classes for each entity, and I can databind these no problem.  Being used to the ease of  binding with DataSets, this was a relief.   The one thing I do miss is having the UI component to assist with the DataBinding which you get with DataSets, but that's not a big deal. 

    Equality: This was somewhat of an eye opener for me.  As I was putting my entites into collections, I noticed that they were going in multiple times, because the hash codes for object that I consider equal were different.  Also, I noticed that if I created two entity objects with exactly the same data a test for equality would fail.  To fix this, I found I needed to override Equals(), ==, != and GetHashCode().

    Now, there are some suggestionsfrom MS (Guidelines for Implementing Equals and the Equality Operator (==)) that give some guidelines for doing this, and Overview of the Object Class had some good pointers too,  but I discovered (via my trusty NUnit) that it's a little more complicated than it seems.  First, a warning:  The suggestions in this article are not correct.  In fact, even the comments that attempt to correct the arcticle are incorrect!  And, definitely don't do this!  

    So after some testing, here's a few guidelines for overriding Equals(), ==, != and GetHashCode():

    If you're testing for NULL using = = comparisons within your overrides for = =, make sure you use the base class' (object)  operator.  This may seem obvious, but you'll get stack overflows really quickly without code like this.

       public static bool operator ==(USCity x, USCity y)
       {
         
       if ((object) x == null) return ((object) y == null);
            return x.Equals(y);
        }

    When overriding GetHashCode() make sure you test your reference types, like String, for NULL before bitwise - or'ing the hash codes.  For example, code like this will break if stateCode or city are NULL:

       public override int GetHashCode()
       {
             return this.stateCode.GetHashCode() ^
    this.city.GetHashCode();
        }

    This may seem obvious as well, but it took me some Unit testing to realize this.  So, once I got everything straight, my simple class ended up looking like this:

    public class USCity
    {

       private string city;
      
    private string stateCode;

       .. Public Properties Removed for Brevity ..

      
    public static bool operator ==(USCity x, USCity y)
      
    {
           
    if ((object) x == null) return ((object) y == null);
           
    return x.Equals(y);
       
    }

       public static bool operator !=(USCity x, USCity y) 
       
    {
          
    return !(x == y);
       
    }

      
    public override bool Equals(object obj)
      
    {
          
    if(obj is USCity)
             
    if(((USCity)obj).stateCode == this.stateCode &&
                 
    ((USCity)obj).city == this.city) 
                    
    return true;
          
    return false;
      
    }

      
    public override int GetHashCode()
      
    {
            
    int hashCode = 0;
            
    if(this.stateCode != null) hashCode ^= this.stateCode.GetHashCode();
            
    if(this.city != null) hashCode ^= this.city.GetHashCode();
            
    return hashCode;
        
    }
    }

    And here's my UnitTest that I used to sort this out this equality stuff:

    [Test]
    public void TestCityEquality()
    {
          USCity city =
    null;
          USCity city2 =
    null;

          Assert.AreEqual(city, city2, "Nulls Should be Equal");

         city =
    new USCity();
         city.City = "Norfolk";
         city.StateCode = "VA";
         Assert.IsTrue(city != city2, "Should not be Equal");

          city2 = new USCity();
          city2.City = "Norfolk";
          city2.StateCode = "VA";
          Assert.IsTrue(city == city2, "Should be Equal");

          city2.City = "Portsmouth";
          Assert.IsTrue(city != city2, "Should not be Equal");
    }

    -Brendan

  • Ok, this scares me a little...

    It seems that a link to one of my posts has popped up here.  I hope the title of this guy's blog has nothing to do with the content.
  • Bob the Build Breaker

    A couple of years ago, I had the pleasure of working with this guy. One thing he introduced me to was the “Build Breaker” award. The concept here is simple, if you check breaking code into source control, you get the award (until someone else gets it). It's a pretty good way to keep people from checking in bad code. Yeah, it's a litte mean too, but if you have a good, close team, it can be all in good fun.

    So I have proudly carried the Build Breaker tradition to the Port. But, instead of a dunce cap with Homer Simpson's face on it or anything like that, our award looks like this:

    It's more of a trophy, really... to put atop your monitor. Only the developers know what it really means (diabolical laughter)...

  • AXTools CodeSmart

    A while ago I posted that I had to uninstall AXTools CodeSmart for VS.NET due to bugs.   I'm happy to report that the latest fixpack (#6) seems to have fixed the major problems that led to me uninstalling.   So, I'm using it again, along with CodeRush, which I love BTW

     

More Posts

Our Sponsors