Bill Robertson's Blog

Happy 21th Chad Starkey

I wrote the following eulogy years ago when my brother, Chad, was misdiagnosed by John Tilley of Phoenix Associates in Flower Mound.  He went to see the doctor Friday complaining of stomach pains.  The doctor examined him and sent him with medicine for a stomach virus.  He went to sleep that evening to get doctor ordered rest. During the night his appendix ruptured and was found dead the next morning.  He was 14 years old.

I was 11 when Chad was born.  I thought it was so awesome to have a brother that much younger.  I already had tying shoes all figured out when it was time to teach him.  Reading was covered. Multiplication tables all memorized.  I taught him that Might is Right when it comes to rough housing and fighting.  I wanted to teach him about being a catcher and pitcher.  I was waiting to teach him about computer programming.  Jimmy and I both were counting the days to teach him about mischief, but from what I have heard, he had that one figured out already.  And girls.  This year for Christmas I bought him a blue etch a sketch.  I told him it would come in handy when his girlfriend wanted to talk, because you girls love to talk on the phone.

Last night I during my dazed wandering among his scores of scores of friends, I began to see my brother’s life through their eyes.  I heard words such as “he always made me laugh”, “he was so nice”, “he never said anything mean about anyone”.  Much, much more was said through the awkward postures, the tearful embraces, seeing tough boys become real men, and the genuine pain I saw in your eyes.

I knew my brother was loved by me, but it was incredible witnessing how truly loved and respected he is by so many.  He has verily touched each and every one of us with his sparkling eyes, his infectious smile and his simple love of life.  Chad was quickly becoming the greatest man I know.  He has acquired more sincere and caring friends in his remarkable 14 years than I will in my entire life.

It’s been said to me many times that Chad has gone to a better place.  But he hasn’t gone anywhere.  He came into my heart on July 21, 1989 at 5 in the morning with Jimmy and me sleeping shoulder to shoulder on the hospital floor.  And he will abide in my heart until I join him again…and there, Chad, you will be my teacher.

Unfuddle SVN Power Commands

Came across this digging into unfuddle tonight.

http://unfuddle.com/docs/topics/powerful_commit_messages

I've always known about #40 creating a change set.  I found tonight that entering a checkin comment of:

resolves #40 Fixed spacing on the email line.

Will resolve ticket number 40 it and document it more fully in one step.  No more going to the website and filling it out twice.

image

 

There are assign commands a couple others.

resolve #26
assign #25 & #26 to alex

Will resolve one tickets and assign both of them to alex.  Nice trick if you’ven’t seen it.

DataContractSerializer Converting Objects to Xml String

This isn't so much a post as a place I could put a common pattern of code.  .NET 3.5 introduced the 10th or 12th iteration of a serializer.  I've stopped to look up this pattern many times and wanted to put a quick sample up with the serialize and deserialize pattern for xml to object mapping.

This will turn the tempData object into an xml string.

   1: var serializer = new DataContractSerializer(tempData.GetType());
   2: using (var backing = new System.IO.StringWriter())
   3: using (var writer = new System.Xml.XmlTextWriter(backing))
   4: {
   5:     serializer.WriteObject(writer, tempData);
   6:     data.XmlData = backing.ToString();
   7: }

This will return a full object.  This instance is using a generic based approach.

   1: var serializer = new DataContractSerializer(typeof(T));
   2: using (var backing = new System.IO.StringReader(data.XmlData))
   3: using (var reader = new System.Xml.XmlTextReader(backing))
   4: {
   5:     return serializer.ReadObject(reader) as T;
   6: }

If there are actual questions about this and how to use it post it below and I might put together a real post about this.
Killing Windows Live Messenger Photo Share "Feature"

(This post applies to version 14.0.8089.726)

Several versions ago windows live messenger decided it would be best to make the photo sending experience horrible.  If you want “attachment” based functionality where you can actual open, see it, zoom, basically make the image sent usable, the windows live team decided it wasn't going to support it anymore.

I’m only putting this post together so I can quickly send people who are complaining about it to fix it on their machines.  The following posts give a full explanation.

This is the best resource, but only works for older versions.

This covers the new version, but he only provided his site and not the post url, so you might have to dig for it.

  • Completely exit Microsoft Messenger
  • Download XVI32.
  • With XVI32, open c:\Program Files\Windows Live\Messenger\msnmsgr.exe
  • Browse in file to location: 0×164118
  • Change the Hex Code “74” to “EB”
  • Close the program and save the file.

or

  • Download this fixed version. ONLY version 14.0.8089.726
  • Put in path C:\Program Files\Windows Live\Messenger

Luckily this seems to fix even when people without the fix send files and they come in correctly.

MVC Spaghetti Code

Some professional background info first.  I started my tech career as a network technician setting up networks and hardware support.  I was interested in programming back in 1997 (actually 321 Contact magazine on a Commodore 64) and it seemed back then, web was the way of the future.  I spent a week working on an asp (classic) project and knowing c++ just couldn’t stand the unstructured syntax for rendering the pages.  I left IT to go back to grocery stores.

I’ve been on this MVC project for 6 weeks now. I making progress and learning exactly what it behind the idea.  Simply put, your Controllers are the CodeBehind for your pages.  Rather than have one code file for each page, you have one code file for a plethora of “Views”.  I really don’t care.  A View is simply a page and changing the name doesn’t mean squat.

I am going with it and working within the framework they provide, but had to post how ugly this code was.  Remember, I avoided classic asp because of the slaughtering of readability.

alt

I just wanted to alternate the style on table rows.  I admit the <%= ip.AttemptedCount %> is worlds better than <% Eval( “AttemptedCount”) %>. The “.ToShortDateString” is better than googling (or binging) the string format codes.  But seriously, this is the default formatting for the code.  I’m confident there is a more readable way to do this.

I want to also add that intellisense is the greatest developer tool created by Microsoft and even that is failing in this situation.  I'd almost rather turn off the validation for this type of logic when it is inside a funky script block.  I highly tout intellisense and has enabled me to become a better developer around self discovery of code and sure beats the hell out of looking in a book, which is where I started before the web really took off.

You can lecture me about HtmlHelper extension methods, and I’ll accept that, but seriously, this doesn’t seem to be that crazy of an idea: let’s alternate the style on the table rows.

I’ll take any advice to make this more readable, but why abandon the entire idea of server controls.  Extracting this type of functionality is what makes server controls so much better than dryly rendering basic html.

Asp.net MVC Without SessionState

When writing my first real MVC application, I instinctively turned off SessionState in the web.config.

<sessionState mode="Off" />
 
When I started the application I received this error:

The SessionStateTempDataProvider requires SessionState to be enabled.

I crawled into it further and MVC by default requires SessionState for one type of ActionResult.  There is the concept of TempData in MVC where you can load some data, perform a redirect, and the temp data will be there on the next request.  Using TempData across web requests is a solution for keeping data across the stateless nature of the web.

The application I’m writing will be hosted in a Farm.  I know there are solutions for using session state across the farm, primarily through SqlStateServer or setting sticky sessions on the load balancer machines.  However, even sticky sessions won’t work for me because I like the ability to take a server out of rotation and it not affect my users.

The workaround is simply to create your own ITempDataProvider and attach it to your controller.  The ITempDataProvider has two methods: LoadTempData and SaveTempData.  Here is my implementation of ITempDataProvider I use now.

public class NoTempDataProvider : ITempDataProvider
{
    public IDictionary<string, object> LoadTempData(ControllerContext controllerContext)
    {
        return new Dictionary<string, object>();
    }
 
    public void SaveTempData(ControllerContext controllerContext, IDictionary<string, object> values)
    {
        if ( values.Count != 0 )
            throw new NotImplementedException("Can not set tempdata, no session state available");
    }
}
 
The Load method just returns an empty collection.  The Save method won’t do anything either.  However, you’ll notice the save method checks to make sure the framework doesn't try to persist any state.  If so, it will blow up, letting your developers know this isn’t supported.
 
Of course you can just create your own base Controller that you can use in your application; this sample is using the MVC Sample Application, AccountController. Now you have to wire this new provider to the controller, line 5: 
 
   1: public AccountController(IFormsAuthentication formsAuth, IMembershipService service)
   2: {
   3:     FormsAuth = formsAuth ?? new FormsAuthenticationService();
   4:     MembershipService = service ?? new AccountMembershipService();
   5:     this.TempDataProvider = new NoTempDataProvider();
   6: }
 
If you decide you need some sort of TempData storage you can just process the data in the Load/Save methods and use your own custom data storage.  I’m hoping to not need this as I move forward in this application.
Human Interaction Amazes Me

Sorry all for the bad photo, you could read it on my iphone, but when I uploaded it, it horribly mangled the photo.  Here is how it looked on my phone. with an transcription below.

I also realized my neighbor’s name was on the paper. However, I wanted to give those interested the story, and get around to writing another blog post.  That gets Windows Live Writer in my recent when I click start and should “hint” me to remember.

photo

 

Dear Neighbors

Whoever “took” my newspaper, I would appreciate if you would have allowed me to read it before you.

You are welcome to knock on my door and I would gladly give it to you, however, only after I’ve had the change to peruse it first.

Goto Statements

I've been quietly lobbying to my programmer friends about the utility of using the old "goto" keyword.  I've gotten a little push back from them, mostly dismissive scorn, but hey, not everyone can be good.  :) I should start a series on this and this will serve as my first post on the glories of GOTO.

The other day I posted a twitter image showing a good case of a goto statement.

goodgoto 

This is a utility method I use when parsing Xml documents into objects.  I received some push back from this specific twitter, mainly from my friend @gbattle.  The requirements I gave to Greg were: "no nested if's, no multiple exits, no unnecessary object assignments and better error explanation"

He posted about his code for doing the same thing without using gotos.  There were a couple points where he was incorrect, and I wanted to walk through his post.  I start trivially and then increase for performance and readability.  He still made his points regardless of the library being used.  There was only one point, property accessing, that does behave different in .NET than say C++.

I will accept from Greg that breaking down each error condition into exactly what caused the specific failure might be better, but on a utility method like this, if I can wrap up the failure condition into a single statement be accurate, I'm fine with it.  "Node should have one child CDATA section with data."  Sure, specifically telling the user which 3 words of the all inclusive error might be better, but any software dev that can't follow that error message and look at the node that caused the failure, prolly should not be programing anyway.

// For style reasons, I always put the constant on the lhs within an if statement
// for the compiler to automatically discover nasty undesired assignment errors
if (1 != node.ChildNodes.Count)

I understand the sentiment of the lhs positioning of constants, and in my c++ days, I was an advocate of his pattern; however in .NET it is an error to do an assignment in an IF evaluator.  (Which was extremely frustrating starting out because I wanted to do it sometimes)

// There is no reason for you to create a new XmlNode return the value.
// You waste time creating a new object and the assignment. Not needed.
XmlNode dataNode = node.FirstChild;

The assignment operator doesn't create a new object.  It creates a pointer to the return object of calling property FirstChild.  Creating a pointer to a Property result is the fastest way to access the property when you are accessing it more than once.  When loading an property it first must resolve the memory location of the containing object, then look into its method offset table, calling the accessor (get) method, which walks more memory offsets, to return an object.  Rather than repeatedly calling the Property (get method) I store the results in a stack variable pointer to the actual data returned by the Property call.  (I'm ignoring the code inlining that might occur at run time, but that doesn't meet the speed of storing the reference locally)

Now the money shot for why gotos are good in this situation is something in his code he did not account for.  When he is checking the number of ChildNodes off the parent node, if it comes out to zero, he has opened his code up for a NullReferenceException.  If ChildNodes.Count == 0, then FirstChild will be null.  Checking FirstChild.Value when first child is null will result in an exception.  And here lies the nested if statements that I'm trying to avoid.

If the ChildNodes.Count property is 0 (or negatively not 1, the actual node count we are looking for), then you must branch this utility method into either a quick return or a nested if statement that continues checking the validity of the XmlNode when there are the correct number of ChildNodes.

NYC January Code Camp and the Large Object Heap

I presented my Garbage Collection/Memory Management talk this last weekend at the NYC Code Camp at the Microsoft Office.  I had a great time and it was enjoyable catching up with old friends and meeting new people.

To the gentlemen who was asking about the Large Object Heap and DataSets.  A DataSet will not be placed on the LOH.  A value of a DataColumn instance might be placed there, but the DataSet itself has a footprint much smaller than the 85 K size required to be placed there.

The Large Object Heap is a heap structure used by .net to allocate large objects greater than 85K.  It is not the size of the object graph that places it on the large object heap.  Translated to this example, the memory allocation of the DataSet is NOT the size of all the rows and all the columns.  The size of the object is determined immediately before the constructor executes (before the DataSet has any rows).  This is determine purely by the size of all the fields in the object, and some additional object overhead.

When the memory size is determined and is (currently) above the threshold of 85K, it is placed in the Large Object Heap.  The LOH is very similar to the Small Object Heap in behavior with the ptrNextObj and serial allocation.  (The one covered in the session).  However, it does not have generational support and most importantly the LOH is never compacted.

The lack of compaction is what will create out of memory exceptions because the LOH becomes fragmented and with the new allocations always appearing at the end of the heap, you can run out of memory.

Using the new 2.0 MemoryFailPoint object you can test the allocation and create an InsufficientMemoryException rather than the more fatal OutOfMemoryException. 

This is only a tease because you still can't force a compaction of the LOH.  It is valid, in some scenarios, force a GC.Collect to help with the SMO and free up some memory.  However, the SMO is usually handled quite well by the CLR's collector and calling GC.Collect is nothing more than Jazz Hands to make you feel important.  Don't call it, ever...unless you have a good reason...but never call it.

PDC 2008 Recommends List

I thought I would share the sessions at the PDC I really enjoyed and would recommend for viewing for those that didn't attend.  And you know who you are.  :)  And those who did attend but didn't get to watch these.  I'm sure there are more that were great, but these are the ones that stuck out to me.

Deep Dive: Dynamic Languages in Microsoft .NET

Jim Hugunin gives a great session on Dynamic Languages.  This was the best talk I went to the entire PDC so I'm listing it first, but you should watch The Future of C# below first.  It is very reminiscent of the few Computer Sciences courses I've taken.  You won't learn any skills here that will directly apply, but covers theoretical aspects of cross language support.  He is also very entertaining to boot!

The Future of C#

Anders Hejlsberg shows what's coming in C# 4.0.  He covers Dynamic Languages with javascript from c#, optional parameters values for overloads and named arguments.

named optional parameters

With the dynamic language potentials, they must find a way to have an intellisense generator just like how the asp.net designer has its own plug in framework.  Maybe with interop type generation?

dynamic video = youTubeServer.GetVideo( "" ); // returns xml

   1: dynamic video = GetYouTubeVideo( "3f73fv" ); //returns wrapped xml string 
   2: ltTitle.Text = video.Title;
   3: ltObject.Text = video.Embed;

The c# interpreter was really neat at the end.

ASP.NET and JQuery

Stephen Walther taught me everything I needed to know about jquery in his hour long talk about it.  I know javascript extremely well and this just filled in the gaps so I could transfer my existing knowledge.  In fact, I am refactoring my advanced javascript talk to include jquery now, especially since it was announced Visual Studio will formally support JQuery.

ASP.NET: Cache Extensibility

Stefan Schackow explains how the new Cache Api can work and what you can do when you open up the caching framework.  This will allow more powerful extensions such as David Penton's Cache Pattern being tied directly into the framework.

Project "Velocity": A First Look

Murali Krishnaprasad does a good job introducing the new distributed caching framework called "velocity".  The option of a sending a read/write provider to a cache call  has some interesting possibilities.

Posted: Nov 02 2008, 12:15 AM by Bill Robertson | with 1 comment(s)
Filed under:
How to log remote user off...remotely

You're about to leave for the day, but you need to push one more thing to the data center.  You pop open trusty Remote Desktops and connect to your environment.  Then this message hits you in the face like a wet, smelly dog tail.

remotedesktopexceeed-thumb1

"Connect to console"?  Nope that doesn't help.  Normally, you holler across your team and tell whoever isn't on the servers, to log off; however it's late and everyone else is gone.  Or if someone is already on the server, ask them to use taskmgr to find your least favorite person and force them out of the server.  (Does anyone else get a power rush out of that?)

logoffremote

The above only works when you have access to the server.  When you don't, you can log people off remotely.

There are two commands that are included in at least Windows Server 2003 and beyond:

  • quser.exe - used for querying users logged on to a server
  • logoff.exe - used for logging user off a server

Using just quser.exe will give you the list of users that are logged onto the current machine.  You can also query a remote machine using the /server:<machinename>.  This will give a list of users.  The import things to notice are the ID and the State.  There are two states that I use when deciding who to kick off: Active and Disc.

I always try to kick off Disc before active.  (There's no additional explanation)

After you pinpointed the user to bounce, look at the ID column because that's what the logoff.exe command needs.

The screen shot below shows how to query the users on WEB01 and then log off the disconnected session, named Session ID 2.

logoffcommandline

With nearly all dos commands, passing "/?" as the only parameter will give you additional information about these commands.

August NDDNUG Advanced Javascript Presentation

I had a great time presenting an advanced javascript and MS Ajax at the North Dallas .NET User Group.  Attached is the slide deck and code samples I used.  I know...I didn't clean up the project files so there are some extra dll's included.

The code samples are located at /Default.aspx and they run in increasing complexity.

The code samples include:
  • Ajax Helper - Helper class for registering client side script to work with MS Ajax, including the powerful RenderUserControl method.
  • Object pattern - This includes a javascript singleton pattern, namespaces, constructors, inheritance, static and instance methods.
  • Event Modal - Two different patterns for event handling in javascript, with a focus on my preference Event Level 0, inline function declarations.
  • JSProcessor - This will combine multiple JS files into one and will remove excess spacing, comments to make the raw JS as small as possible.
  • JSShortCircuiter - For reaching around the embed scripts when in debug mode so you don't have to constantly rebuild the dlls.
There are many examples of client side caching, retrieving html from server, getting and saving Server Side objects.

There was more interest than I thought on the client side ThreadPool object, so I've included that.  It isn't functional as it stands because there are some other frameworks it relies on.  Send me a message or post in the comments if there is interest for me to make this object standalone and only require the .net framework and I'll work towards that.

Also, if there is any interest I can release a ajax back button module.  It is different from the MS Ajax one in that it is delegate based rather than serialized querystrings.

Hit me with any feedback or questions you have on the presentation or the code.

Thanks!

download

Posting Again

After a long hiatus, I'm back to posting again.  Look forward to more frequent updates.  :)

Thoughtiest Decision of my Life

I've been working at Telligent for the last year and a half; it is without question the single best employer I've ever worked for.  [Or traded value with depending on your economic theory]  August 14 was my last day of employment with Telligent.  This post took a while to write because I've been reflecting on the changes brought to my life by Telligent.

Increased Caloric Intake.  At previous employers we would have lunch provided for us at the yearly or bi-yearly company outings, or if I was lucky enough to go out of town I would have an expense account provided.  However, at Telligent, we started with Monday/Friday lunch, sometimes catered, sometimes a menu was passed around, then no lunches at all, then lunches returned for Monday.  It's been an ephemeral lunch schedule at times. 

There were two refrigerators full of nearly every type of coke, and if the variety of beverage didn't suite your taste, a little sweet talk with Laura [redundant, she is so sweet] would buy any beverage you wanted.  There was a constant stream of snacks to help with the low-blood-sugar and ping pong fatigue.  I won't forget the beer in the fridge [not until after 4], or the game nights where you could destroy each other virtually or with a playing card.

Name Dropping.  I've worked with some of the industry heads in the .NET community.  I've been beat in ping pong by Rob Howard, been shot with balls of paint by Jason Alexander.  Scott Dockendorf has given me the confidence to publicly speak at user groups.  I've learned much about architectural design from Scott Watermasysk.  I've been invited to private parties at developer conferences through these connections.

Professional Development.  I've worked with some of the brightest developers that bring me humbleness.  The hiring process at Telligent is intense, and you interview with random developers on the team, not the HR staff.  You have to be knowledgeable, be able to communicate, and have a genuine ego.  Even the "best" developer will meet someone at Telligent more brilliant in an area.

I have increased my javascript skills, database skills, project management skills, sales theory skills, public speaking skills, and any other skill you could imagine.  I'm not going to name the contributors individually because 1) I know I will forget someone and 2) this post must end at some point.

I totally recommend [like totally, Valley Girl style] seeking employment with Telligent.  If the situation ever presents itself, I know I would re-seek employment. Everyone there will be sorely missed by me, probably more than they miss me.

So long, and thanks for all the [teaching me how to] fish.

American Airlines Business Practices

I booked a flight for a trip to New York City and was completely floored by what was presented to me.  I found a 9 hour American Airlines return flight from JFK to DFW.

Nine hours?!  What could possible be the cause of that?  I pulled the details for the flight and saw there were two stops.  Remember my goal is to return to Dallas.  I had to read the chart below several times.  I've highlighted the piece that had me completely confused.  Let's play "What's wrong with this picture?"

 

trip

 

Give up?  Yeah, remember my goal flying from New York to Dallas.  My first stop is in...Dallas.  WTF?  To get to Dallas I have to first fly to Dallas, change planes, and fly to Austin.  Then I must change plans again and fly back to Dallas.

Seriously guys?  My first thought was I'll just deplane [their term] in Dallas the first time and cut 5 hours from my trip.  However, if I want to get my luggage I must:

  • Bribe a TSA agent to let me in the restricted area so I can claim my baggage before it gets moved to another plan.  [Sadly, it probably won't be very expensive to bribe them.]
  • Come back to the airport 5 hours later after my trip to claim my baggage.
  • or, Sit in the airport and wait for my baggage to return from its trip.

The fourth option, also the option I executed, was to fly with an Airline that has some semblance of a efficient company, ie Continental.  Sure, requiring me to buy two extra tickets efficiently increases the cash in the coffers of America Airlines, but that sure isn't how I want to allocate my resources. 

More Posts Next page »