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

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

October 2003 - Posts

  • The Story of the Two Dotnet Gnomes and the Network Services Ogre

    Once upon a time, there were two dotnet gnomes.  They lived in a cave.  Everyday they got up and slaved away at their computers.  They were creating something that was going to be useful to the world, and they were very excited.  After 10 months of slaving away, eating nuts and berries, they finally launched their beautiful website.  And beautiful it was.  They were very proud.  It was n-tier, scalable, and used every buzz-word they’d heard in the forest, like “XML” and “Web Services” and “MSMQ” and on and on. 

     

    When the whole world found out about it, they were all very happy too.  They loved all of the new stuff the two gnomes had built to help them.  Everyone was dancing and singing joyful songs. 

     

    Then, one day, the gnomes noticed something funny about their new site.  It seemed slow.  So they looked into the problem.  They were confused because they thought they had done everything right, and couldn’t understand the slowness.  They noticed a very specific problem that they had not heard about before in all their years living in the forest.  Here was the problem:  One very tiny image that was used all over the site was making the pages appear to load very slowly!  So they diligently went about checking the source of this problem. They checked the file.  It was fine.  They checked the HTML, it was fine.  They checked the server resources. They were fine.  They checked the cache hits on IIS.  It was loyally doing what it was supposed to do.  Then they noticed something fishy.

     

    When the image was requested from outside the gnome’s local network, it loaded fine!  Better than fine, actually!   It loaded really fast!  They scratched their little gnome heads, and thought that it may possibly be a network issue on their local network.  Well, they aren’t the kind of gnomes that go around point fingers, so they had their little gnome hats in their hands, and knocked on the network services ogre’s door. 

     

    “WHAT DO YOU WANT?” asked the ogre. “We noticed a strange problem.” Said the gnomes, and they proceed to tell the ogre the story.  The ogre barked at them “IT’S NOT THE NETWORK!!! YOU GNOMES ARE ALWAYS BLAMING THE NETWORK!!”  Well the gnomes don’t think that way.  They weren’t blaming anyone, they were just trying to get their little site to load fast.  Finally, the ogre yelled at the gnomes “CHECK YOUR SHIT!”  So they went back and “checked their shit,” again.  Their shit was fine.

     

    The next day they knocked on the ogre’s door.  He was being particularly ogre-ish on this day, and wouldn’t even consider that his network may be a problem.  He screamed at the gnomes, yelling about how his network has “100 MEGABIT PIPES”, and “PIX” and “SWITCHES” and all kinds of other things that the gnomes didn’t understand too well.   Again, he sent them away, telling them to “CHECK YOUR SHIT!” 

     

    The gnomes were really sad at this point. They didn’t understand how they could check their shit any more than they already had.  So they set about, in their gnome-ish way, to try to reason with the ogre.  They pulled out their magic VS.NET bag of tricks, and in 10 minutes, wrote a little windows app that they thought would help prove their point.  It requested this little image over and over, and recorded the time it took to retrieve the image.  Lo and behold, the image loaded over and over again from outside the network at blazing speeds, but from inside the network, the image loaded slowly!  Really slow! We’re talking 6000 times slower at some points.   Same image.  Same server.  So they showed this research to the ogre.  He looked at it and said “THAT DOESN’T PROVE ANYTHING” and after they pleaded with him to consider their argument, he finally walked away saying “I’M NOT WORRIED ABOUT IT, IT’S ONLY INTERNAL ANYWAY.”  

     

    So what’s the moral of the story?   Well, the gnomes thought that the good people out there reading this story could help come up with one, because they haven’t a clue.

  • Crystal Reports - Poll

    Please take the following poll about Crystal Reports for .NET.

    1) I use Crystal Reports for .NET because...

    a) It's a great tool
    b) I'm forced to use it in my job
    c) MSSQL Reporting isn't released yet
    d) I don't use it

    2) If Crystal Reports for .NET was a person, I'd...

    a) Shake its hand, and say “Great Job!”
    b) Thank it for everything it's done and politely ask when its current bugs are going to be fixed
    c) Kidnap it, and force it to fix the current network installation of itself
    d) Give it a sharp kick on the knee

  • Red-gate is a must have tool for MS SQL...

    I want to shout out to Red-gate software.  I am in no way affiliated, just a big fan.  Today, I downloaded their latest  SQL Compare tool.  It's really good!  Find out more and download a free trial:
    http://www.red-gate.com/sql/version30x_sql_compare.htm.

    -B

    Music tip of the day... http://www.epitonic.com/ say no more.

     

  • The CssStyleCollection

    Last week I pointed out that you can use the CopyFrom() to copy font and control styles applied to a WebControl to it's contained controls.   If you missed it, you can use the Font.CopyFrom and ControlStyle.CopyFrom to achieve this.  But what if you don't have the CopyFrom method at your disposal?  This happens with controls in the System.Web.UI.HtmlControls namespace, for example.  Well, you can always use the Style property instead. This is an object of type System.Web.UI.CssStyleCollection.  With a little bit of help, you can use it to pass styles around from control to control.   The static helper methods CopyStyles and GetStyleString can be used to do this.

    System.Web.UI.HtmlControls.HtmlButton btn = new System.Web.UI.HtmlControls.HtmlButton();
    string style = GetStyleString(this.Style, false
    );
    CopyStyles(style, btn.Style);

    public static void CopyStyles(string sourceStyle, System.Web.UI.CssStyleCollection destinationStyle)
    {
      string [] keyvals = sourceStyle.Split(new char
    [1] {';'});
      foreach(string keyvalpair in
    keyvals)
      {
         keyvalpair.Trim();
         string [] keyVal = keyvalpair.Split(new char
    [1] {':'}, 2);
         if
    (keyVal.Length == 2)
         {
            destinationStyle.Add(keyVal[0],keyVal[1]);
         }
      }
    }

    public static string GetStyleString(System.Web.UI.CssStyleCollection s, bool withName)
    {
      string
    style = (withName) ? "STYLE=\"" : ""; 
      foreach(string key in s.Keys)
     
    {
        style += key + ":" + s[key] + ";";
      }

      style += (withName) ? "\"" : "";
      return
    style;
    }

    -Brendan

    Music tip of the day:  I've published some of the articles I write for the Portfolio magazine here.  Check em out!

  • Software in Limbo - The story of Intrinsigo

    Back in 2000, I was co-founder of a soon to be defunct tech startup company called Intrinsigo.  This was the twilight of the bubble.  We got just enough funding to get excited, develop a product, hire some people, buy a basement full of computers... and be seriously let down when investors realized that tech start-ups had to actually be profitable

    Here was the Idea:  A content authoring tool for handhelds.  You know.  Like Authorware, but for handhelds.  We were targeting PalmOS and PocketPC.  We used XML.  We wrote a SAXish XML parser for the PalmOS.  We were ahead of the game. We got really close to being acquired. We met with Palm.  Lycos had drafted up a term sheet.  We were going to be rich. 

    Well, Palm wasn't interested.  Lycos funded another startup instead.  Our angel investor went chapter 11.  I moved away from the big city.  I got married.  It was the best thing that ever happened to me.  But it left a product in limbo.

    So now, I have this software.  It's aging rapidly.  I think it could be useful to someone. I actually think it could make some money, but I could care less about that.  Sometimes, I wish there was a thrift store for donating old software.   I'd like to port the VB6 authoring tool into dotnet, but I don't have the time.  Anyhow.  If anyone has any ideas.  Let me know.

    -B

    Music tip: Belle and Sebastian - Dear Catastrophe Waitress./FONT>

  • Copying Font Properties

    Say you have a user control that contains some other web controls, such as a text box or drop down list.  Now say that you want the UI designer to be able to set the font properties of the contained controls, by setting the font properties of the control in the designer.  Well, if you've ever tried this:

    this.myContainedControl.Font = this.Font;

    You'll find that the Font property is read only.  You can set the individual properties, but this would be a pain for all of the properties that the FontInfo object supports.  Luckily, the FontInfo object has a CopyFrom method, which you can use to do accomplish this task in one fell swoop:

    this.myContainedControl.Font.CopyFrom(this.Font);

    Music tip o' the day: If you like REM, check out Placebo

  • String.Empty vs. ""

    So, I just converted a bunch of code that used "" as an empty string like this:

    if(myString == "") anotherString = "";

    to

    if(myString.Equals(String.Empty))  anotherString = String.Empty;

    and I'm wondering if I did the right thing, using String.Empty. I hate having quoted strings in code and prefer to stay away from them whenever possible.  This generally leads to code that is more strongly typed, and easier to maintain, so using String.Empty intuitively feels better than ““.   But, I've actually found a concrete reason to use String.Empty - I did some research and found that in a test, str.Equals(String.Empty) is faster than comparing to ""!   Well, okay.  Research isn't the right word, “Doing one google search and accepting on faith the first post I saw” is slightly more accurate.  I even created a little graph of the claims in this post here, that String.Empty is faster.  I'm too lazy to do the test myself, so if you want to verify this, knock yourself out.  I do love making graphs though.

     

     

     

     

  • Accessing Index Server.. Black Art?

    So, I'm fooling around with Index Server, to try and implement a site search here.  First of all, I have to admit it, I've never fully understood the technology, even though I can manage to get it to work.  I really don't like that kind of development.  I have no idea why it works when it does work, and no idea why it doesn't work when it's broken.  Maybe it's just me.

    Music tip of the day:  Want to see what all the critics say at once?   www.metacritic.com

  • Programmatically Remote Control a Windows Service

    I just thought this was cool, start and stop remote services like so:

    System.ServiceProcess.ServiceController sc2 =

    new System.ServiceProcess.ServiceController("ServiceName", "MACHINE_NAME");
    if
    (sc2.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Running))
    {
      sc2.Stop();
    }

    Today' music tip: Run, don't walk to CDNOW to get the new Outkast album... Speakerboxxx/The Love Below.  The track “Hey Ya” is soooooo good.  And only $17 for two separate albums!

  • Object Persistence and Remoting...

    I discovered something interesting this week.  Here's the scenario. I have a windows service which houses a singleton object that has live camera statistics generated from our gate traffic camera here at the port.  What this service does is

    1. Monitors a directory for file changes (camera images updated every minute)
    2. Does some fuzzy image analysis on the image to get a live traffic “count”
    3. Stores a copy of the image in a byte array

    The singleton object is marshaled like so:

    // Configure Remoting

    ChannelServices.RegisterChannel(new TcpChannel(8001));

    RemotingConfiguration.RegisterWellKnownServiceType(typeof(VIT.Common.Classes.GateStatusRemotable), "GateStatus", WellKnownObjectMode.Singleton);

    RemotingServices.Marshal(m_GateStatus, "GateStatus");

    Now, I have need to remote to this object from two places, a windows application that acts as a service controller, and a web control that actually consumes the images and data, and publishes it on the web. 

    Everything worked great, except that I found that the singleton object would disappear if I didn't access it!  Yikes!  Well, it turns out that the solution was simple.  MarshalByRefObjects contain a method called InitializeLifetimeService.  You can overload this to control the lifetime of your remotable objects.  To make my object live forever, I overloaded this method and returned null.  Works perfectly!  Here's the code.

    public class GateStatusRemotable : MarshalByRefObject
    {
     public GateStatusCollection GateStatus;

     public override Object InitializeLifetimeService()
     {
      return null;
     }
    }

    You can also return an ILease object if you want to get fancy with this.

  • Tap. Tap. Is this thing on?

    So, I'm sitting here trying to think up a theme for this blog, and it occurs to me that I need to fire up some tunes to get my creative juices flowing. So I launch BBC Radio 6 (www.bbc.co.uk/6music) over Windows Media and it hit's me!   Yeah! I'll write about music and coding!  Wait a second.  Does anyone really care what a 33 year old software developer has to say about music?  Probably not.  But, I do sometimes write articles for my city's local weekly free newspaper, the Portfolio, so I'm at least somewhat qualified. 

    Does anyone really care what a 33 year old software developer has to say about anything anyway?  Well, that's debatable, but I will promise to try to post helpful coding techniques and snippets of code that I've found useful in my job here at the Port of Virginia.  I'll leave the academic stuff to those who do it best, like Darrell Norton, for example and I’ll keep it straightforward.  So welcome to my blog: C# and Music

    So, how about a poll?    Do you listen to music while you code?  If so, what do you listen to?  If not, why?   Is it against company policy?  Should it be?

More Posts

Our Sponsors