When I first started designing and architecting online applications, we decided to move custom settings from a database to an XML file for more versatile settings for our customers. With hundreds of agencies using our system, we needed to have the ability to easily and quickly change settings on a customers website without making core-code changes, XML allowed this. However, a year after we released we found issues with this setup. 

The setup it self was solid, however we didn’t expect the needs of our customers to be so… unique.

Enter the 80/20 rule.

Where once a button click would say print a Circle on a screen, we found soon that 20% of our customers wanted that to be an oval – so we bite the bullet and make a few code changes to accept more settings and voila, a customer can either have an oval or a circle.

Oh, if it was that easy! Soon, every customer now wanted something different. A Triangle, square, 3D Sphear, dishwasher, and some wanted  a few Ninjas! Come on! Ninjas are rare and priceless, we can’t just give thos…. sorry I digressed.

What what to do? Do we throw in 100 conditional statements? Do we build a system that is intelligent enough to almost be self aware to know what our customers want? (Any programmer knows that we need to know what our customers need/want/deserve before they actually know they need/want/deserver it).

So where did we go? The solution was custom libraries for each customer, using reflection at run time to load those libraries up.

You see, the customer who wants a triangle, didn’t care about the sphear, the circle, the ninja. They wanted triangle, pointy edges and all.  The same went for other customers, so the answer was clear.

With this implementation, we rarely have to make any core-code changes. Instead, we derive a new library off of a base class, add the functionality needed for our customer, and release it. Plain and simple. 

A sample of this will be uploaded shortly.

The Model 

BicNet.Projects.FactoryExample.Factory

 image

This project holds the 2 classes I’ll be working with. Each class(factory) has a static method called “Create” which creates the correct Object based on the passed in path.

 

 BicNet.Projects.FactoryExample.Base

image

There are two  classes in this project: Greeting and Shape.

These two classes will be the ones overridden by our “factories” to produce custom actions and events.

 

 BicNet.Projects.FactoryExample.Triangle / Square

 image

This is derived from BicNet.Projects.FactoryExample.Base.  Greeting and Shape both inherit from Base.Greeting and Base.Shape. This allows me to cast a BicNet.Projects.FactoryExample.Triangle.Shape object as a BicNet.Projects.FactoryExample.Base.Shape, while retaining all the functionality of .Triangle.Shape (Gota love Managed Code).

 

I’m not going to show BicNet.Projects.FactoryExample.Square because it’s the same as Triangle

 

So how does this all work. Let’s look at the FactoryExample.Factory project.

Some Code

   1:  namespace BicNet.Projects.FactoryExample.Factory
   2:  {
   3:      public class FGreeting
   4:      {
   5:          public static BicNet.Projects.FactoryExample.Base.Greeting Create(string path)
   6:          {
   7:              string className = path + ".Greeting";
   8:              //Must use System.Reflection.Assembly - can not just use Assembly as the name as 
   9:              //it will not work. Can also use [Assembly] instead
  10:              return (BicNet.Projects.FactoryExample.Base.Greeting)System.Reflection.Assembly.Load(path).CreateInstance(className);
  11:   
  12:          }
  13:      }
  14:  }

What’s being passed into the Create(..) method would be: “BicNet.Projects.FactoryExample.Square”.  What this then does is look for that assembly and return the “Greeting” object from that Library. It will then return it, giving me full control over that object.

   1:          protected void btnLoadFactory_Click(object sender, EventArgs e)
   2:          {
   3:              BicNet.Projects.FactoryExample.Base.Shape shape = BicNet.Projects.FactoryExample.Factory.FShape.Create(ddlFactories.SelectedItem.Text);
   4:              BicNet.Projects.FactoryExample.Base.Greeting greeting = BicNet.Projects.FactoryExample.Factory.FGreeting.Create(ddlFactories.SelectedItem.Text);
   5:   
   6:              lblGetShapeName.Text = shape.GetShapeName();
   7:              lblGetShape.Text = shape.GetCustomText();
   8:              lblGetGreeting.Text = greeting.GetGreeting();    
   9:          }

What’s the Point?

Yes, this is very simple with shapes and such, however what about real world scenarios? One of the main questions I’ve been asked about with this model is:

If you just did market research and you knew what your customers wanted, you wouldn’t need to make a system like this. Why spend the extra time and effort to build a system that’s capable of doing this when you could just do what customers wanted in the first place?

Anyone in the Software industry can tell you customers don’t always know what they want, and customer’s needs change every day / week / year (hour?). And, for those that deal with $$, maintenance on any application is usually the big killer for time (effort) and money.

Another argument might be:

You have 500 customers working on an Item Tracking  System (Tasks, to-do’s etc.).

  1. 300 of those customers want it when they submit an item, for an email to be sent to themselves, and to the people assigned to the task.
  2. 100 of those customers want 2 sub-tasks created for each Task created, and both those tasks to be automatically assigned to “Mary Smith” in the system.
  3. 50 of the 100 remaining customers want a PDF created as soon as the Task is created to be saved as a snapshot of the original task.
  4. 25 of the 100 want any task that is completed to have a PDF snapshot taken, saved in a specific directory so their FTP program can look for them.
  5. The final 25 customers don’t know what they want, but we are safe because as soon as they come up with whatever customers come up with, we have the ability to plug it in without changing base code because we can just change their factory.

That’s it?

Well pretty much. Yes, you could get the above done with XML – if you knew what you were facing before you started. However, that’s not the problem we face in our industry. We are always changing and always improving. Having the ability to quickly change something for a customer or set of customers without interupting the flow of everything else, is what we want. Maintenance is always the big cost item with Web Applications because of the ongoing changes to it.

So Here I am trying to figure out how to test my application in IE6, IE7, IE8 and the rest of the plethora of browsers. Aside from the fact that my customers still use IE6… … I couldn’t find a computer / RDP / VM Machine that has IE6 on it.  Through my searching, I found this beauty:

http://www.webdesignerdepot.com/2009/03/microsoft-announces-superpreview-for-ie-browser-testing/

This gives the ability to have multiple versions of IE looking at the same web page. Now, it’s not perfect but it’s a start (it’s still in beta). you can see by the picture below that the textbox I’ve selected on the left side (IE8), selects the same textbox on the right side, however the position is off.

image

My thoughts:

  • It’s good if you’re looking at a plain page, however there is no user interaction. You can’t navigate, you can’t type, you can’t do much except watch and look at positioning.
  • It does help with CSS issues… like putting : style=”display:none;” on a textbox. It works in IE7+ but not in IE6.
  • The download for the install is 236MB, yet the program you’re installing is only 36megs after install… what else is in there?

 

So if you’re looking for a page by page comparison, don’t need to test ajax, or anything else, this works.  Personally, I’m getting someone to build me a Win98 VM and a Windows XP VM so I can have those running to test my apps.

We had an issue today at work. A few developer machines couldn’t debug any ASP.NET 2.0 web application. After an hour of looking, we found out that some of our host files had the entry:

::0       localhost

instead of:

127.0.0.1     localhost

If you are getting issues with trying to debug your ASP.NET Website (Like the following):

image 

image

Check your hosts file to make sure it’s correct.

I’ve spent most of my professional career working on Enterprise Applications (mostly web based). Sometimes you release your code and everything goes smoothly (this is where praise is warranted by rarely given). However, there are times when code has been in place for many days, weeks, months without any issues and all of a sudden – all hell breaks loose and it stops (this is where harsh comments are never wanted but always received).

So, what do we do when that happens? If we cannot see what’s going on, we’re pretty much hosed. Sure we could start doing some knee-jerk reactions, do code changes to try trapping for situations, but come on… knee-jerk reactions are bad. Say it with me: “BAD”.

So this is where application logging comes in.  Below are 2 lists. The first list contains some things you just should not do… though everyone has probably done these. We learn through making mistakes, others and school (… yea), so the list below is mostly mistakes I’ve made in my career so hopefully some can learn from them.

What Not To do.

There are many ways to “log” what happens in an application. What I want to do here is list some of the ones I’ve encountered that really don’t give much info.

Rely on just Exception Logs

There is something to be said about logging exceptions, however, relying on just exception logs is a mistake. Exceptions are raised either when a code error, system exception, user exception or when a user manually throws it. However there are cases where there’s an error with your system, and it’s not throwing an exception.

Write out every action to the Hard Disk

I love this one. I’ve seen a system log over 100Mb an HOUR to the hard disk based on actions happening on it. Sure, it could be useful… if you had a hard disk that had a crap load of room on it. But come on, you let it run for a month un-checked. 100 * 24… um * 30… dot the i…  … that’s around 72GB of logging. Yes, some of it “might” be useful but who would want the daunting task of looking through that mess when we could doing real work.

Use a single log file

Whenever you log information to the system – split it up into files. One file per day, or one file per hour. If you have a log file that’s massive (look above) and you’re reading it every time you log something, you’ll be overloading your system in no time on read/writes. What i do is:    name files like:

  • BicNet.Enfora_LOG_19_FEB_2008_0800.log
  • BicNet.Enfora_LOG_19_FEB_2008_0900.log
  • BicNet.BlueTree_LOG_19_FEB_2008_0800.log
  • BicNet.AI.NinjaRevengePlan2000_LOG_59_SEPTEBURARY_2108_0800.log

If an error occurs at 8:30AM with some customers sending in GPS Data through an Enfora Modem, it’s pretty self-explanatory where I need to look.

Do nothing

YES! Awesome!… die… well actually this is better than the next one.

Log useless information

Have you ever seen a log file that looks like:

>Awesome function just called. Woo I rock. Go Canucks go!

>Another Awesome function was just called. It’s now 12:34PM. GO CANADA GO!

>WOO I ROCK!

>… Stupid user did an error. Message is “Object reference not set to an instance of an object”. COME ON!

>ANOTHER ERROR!? Gah button1 was clicked. Check the code to see why I was written. DO IT! DO IT NOW!

If you looked through some of my college programs you might find some error logs like this.

 

What to do

Honestly, don’t do any of the above and you’re better off already. There’s an example of a logging system I have in place that writes logs out.

Don’t bloat your logs

When doing logs – I rarely use XML. Wha!? NO XML!? HERESY! Yes yes it formats nicely, and yes it’s well it’s XML. However, there’s an overhead on using it. Only use it if you need to. If you can get by with writing logs in plain text, do it. XML can be used when you have complex object you need to write out, or if you nave a lot of data, however, for simple logging – use plain text.

Log raw information coming into the system

Whenever you have a system that needs it’s information logged, log the incoming data. If you don’t log that data, it could be transformed or corrupted at the time you do log it. If you log it when it’s coming in you can later on run tests against that function with the correct data if there’s an error. For web services, there’s ways of tapping into the raw SOAP data (using ASP.NET) before it hits your web-service. This allows you to log/trace that information to your disk before your web-service gets the data, very useful.

 

Example – UDP / TCP Listener

I have a service running on our servers that listens on TCP and UDP Ports. Whenever a device connects to our servers, my listener service picks it up and processes the information.  Every time I get a connection on our server, I log who connected, the message received, and the time (I don’t write anything out at this time). Every time I send something to a user, I log the IP, the message and the time. Every 10 minutes I’ll stream the output to one file, and the input to another file. If an exception is raised, I write out all the information, as well as the exception to an exception log file. Every hour I create a new file so they’re never too large.

I don’t log every function, I don’t log simple operations, I don’t need to because if they ever throw an exception, I already have it. If there is bad data coming in which is compromising the integrity of my system, I have it already logged with the date/time. This gives us all the information we need to perform tests to see what has gone wrong, and it catches exceptions. It also allows me to quickly count the # of connections coming in, to debug connectivity issues.

Code Example – Generic Log Entry Method

Here’s a sample “Logging” method I use to fill my StringBuilder with the data I need to log out:

   1:   private void LogEntry(string message, string customer, int reportID)
   2:          {
   3:              string sReportID = null;
   4:              char c = ' ';
   5:   
   6:              System.Diagnostics.Debug.WriteLine(message);
   7:   
   8:              if (_sbLog == null)
   9:                  _sbLog = new StringBuilder();
  10:   
  11:              if (reportID > -1)
  12:                  sReportID = reportID.ToString();
  13:   
  14:              if (customer != null && customer.Length > 25)
  15:                  customer = customer.Substring(0, 25);
  16:   
  17:              if (sReportID != null && sReportID.Length > 9)
  18:                  sReportID = "XX" + sReportID.Substring(2, 7);
  19:   
  20:              if (message.ToLower().IndexOf("exception") > -1)
  21:              {
  22:                  _sbLog.AppendLine(
  23:                      DateTime.Now
  24:                      + " - "
  25:                      + (customer == null ? new string(c, 25) : customer + new string(c, 25 - customer.Length))
  26:                      + " - "
  27:                      + (sReportID == null ? new string(c, 9) : sReportID + new string(c, 9 - sReportID.Length))
  28:                      + " - "
  29:                      + "Exception occured.");
  30:   
  31:                  _sbLog.AppendLine(message);
  32:              }
  33:              else
  34:              {
  35:                  _sbLog.AppendLine(
  36:                      DateTime.Now
  37:                      + " - "
  38:                      + (customer == null ? new string(c, 25) : customer + new string(c, 25 - customer.Length))
  39:                      + " - "
  40:                      + (sReportID == null ? new string(c, 9) : sReportID + new string(c, 9 - sReportID.Length))
  41:                      + " - "
  42:                      + message);
  43:              }
  44:          }

From here, you just have to tell it to write this out whenever you need.

Who’s heard of the term : “Too many cooks in the kitchen”? It’s a fundamental problem if ruling.

I was talking to someone awhile ago about this problem where they needed to get Task A done in a specific time frame and his boss wanted him to just hire more developers.

So I’ll give the same answer to you that we talked about:

It takes 9 months for a baby to be born. If you add 9 women into the fray, would the baby be born in 1 month?

I’ll stop there so minds don’t wander… yea that means you!

I work with a lot of databases. Currently, we have over 500 databases on our one SQL box. Whenever I have to go in and modify a a specific XML section, I need a quick way to find any DataBase that has that specific XML text. I came up with a quick Script that goes through every database, searches for the table I want to see if it contains my XML text.

Here’s a script that has done well for me:

Exec sp_MSforeachdb @command1= 'USE ? IF ''?'' <> ''master'' AND ''?'' <> ''model'' AND ''?'' <> ''msdb'' AND ''?'' <> ''tempdb'' 
begin 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(''[dbo].[tblProcessConfigurations]'') AND type in (''U'')) 
BEGIN 
SELECT * FROM dbo.tblProcessConfigurations 
END 
end'

 

What this will do is print out the contents of every tblProcessConfigurations of every database on my server. However, I had an issue – what Databases were they from?

I add the simple function: db_name() to my query and voila:

 

Exec sp_MSforeachdb @command1= 'USE ? IF ''?'' <> ''master'' AND ''?'' <> ''model'' AND ''?'' <> ''msdb'' AND ''?'' <> ''tempdb'' 
begin 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(''[dbo].[tblProcessConfigurations]'') AND type in (''U'')) 
BEGIN 
print db_name() 
SELECT * FROM dbo.tblProcessConfigurations 
END 
end'

 

I can now document every DataBase that will need to be updated, and what the Updates need to be. 

So today I'm playing with Google Chrome at work.  From my first look at it, it has promise. There's some beautiful things about it like when one tab freezes for one reason or another (something that would likely shut down Firefox / IE), only that tab freezes and not the entire application - allowing you to continue to work rather than stare at an un-responsive browser.

The one major beef I have is when fully maximized, there is a 10 pixel gap at the bottom of the screen where you can click on windows behind Chrome – this does annoy me because I have a habit of clicking there – and now that I know it’s there… it will annoy me… …

There are some cool features thought:

  • Ability to resize any textarea control
  • Screen realastate is huge!
  • Google keeps a record of previous and most visited sites. So when you open chrome, you can see them all right there.
    • image
  • The: Right Click –>Page Info is quite amusing
    • image
    • But what do you expect from a Beta… oh wait… isn’t everything from Google in Beta?

JavaScript

First off I try it against my Vehicle Tracking application I wrote for police agencies in the states. Heck, it's quick. It does everything great! I then started to play with overlaying ESRI data on top of my maps, and working with my playback and history functions and again it amazed me with how quick it is.  The only hiccups I got was when I played around with running 50 simultaneous functions at the same time, each one doing a lot of trig. math. The browser finally gave up and crashed.  I'm not surprised, IE and Firefox did the same.

So as far as I'm concerned - it works great.

CSS

There is a bit of issues with CSS styling - mainly I believe it's being too pedantic.  Chrome has a feature that highlights <input /> elements with an orange glow. I can see how this is nice, however to those of us that sometimes spend too much time making our application visual appealing, it’s annoying.

 

INcogNITO!

IE8 has one, why not Chrome! HIDE EVERYTHING! No Cookies (sorry cookie monster), no traces… can we turn this off? I am personally not putting this browser on my computer at home because I do like to see what goes on with the history – and I don’t want to give anyone using my computer (<cough> kids) the ability to view bad (<wheeze> Sites with Barny the Dinosaur on them) sites without me knowing… stupid dinosaur…

image

Developer Tools

Google Chrome comes with a few developer tools built in.   The JavaScript debugger failed to impress me. I've used Firebug for the past few years and It's the only one that I will recommend. The JavaScript consol caused Chrome to freeze on me fully.

image JavaScript Consol

 

image Javascript Debugger (Command line? What is this COBOL?)

 

Having the Document Source open in a tab is... ok... and I can see the uses however I do like to move source around while I look at WebPages - why else would you use multiple monitors!?

The task manager is quite... "nifty", easy way of telling what applications are running under chrome. I especially appreciate the "Stats for Nerds" option which loads up the memory usage of the browsers (Firefox, IE, Chrome) opened and the processes (tabs) used.

image Task manager

image Memory Usage

 

All in All, it’s better than the beta of IE8 (Sorry MS), but I don’t think It’s going to be the next best thing to hit the Internet. Ninjas did that a long time ago.

I love watching people. I like to sit back, and watch peoples expressions, their body movements, their reactions to certain things. I don't really consider it eavesdropping, as I am not paying attention to the conversation, and I don't usually hear what's going on.  The other day I was watching a few developers from a larger company here in town bicker about something.. A friend of mine joined their group and saw I was drinking some coffee and invited me over.  The conversation soon turned towards working conditions, job satisfaction, salary, management etc... really whatever a group of developers talk about at a coffee shop. Now many would think we'd talk about games, however as "Geeks" we must maintain the persona that we have lives (note Geeks, not nerds... Geeks).

One person then mentioned the well coined phrase "Well the grass is always greener on the other side of the fence". At that point I had to but in and tell him to give his head a shake. The grass is greener where you water it!

As a working individual it is your duty, heck it's your God given duty to put 100% into your career / job. It doesn't matter if it's full time, part time, a "stepping stone", or whatever. If you are getting paid for a job, put your all into it because that's really what you're getting paid for. If you think the grass is greener on the other side, look at where you're at. Think of what makes the grass greener on the other side and bring it up with your manager / boss. Now there are some cases where the grass you're currently on was laid on a bed of concrete, in those rare occasions even the dirt looks greener (And you might want to either talk to your manager about buying an excavator if you're in this boat).

Yes this is a bit of a rant, and it might be because I'm a new dad and my career is very important to my family. But wherever you are in your career, make it the best it can be. Put your all into it. Yes, the company across the street might have the newest computers, or the company across the way has lunch time gaming time... whatever it is, if you put your all into where you are, whenever you decide to move on you'll do it with integrity.

 I'm going to change my babies poopy diaper now.
 

Yes the Acid 3 test has been released. The official announcement is here, and because I loath copy/paste blog posts you will need to go there to read all the nitty/gritty about it. Pretty much Acid3 tests specifications for "web 2.0" (What the heck is web 2.0 anyways? When did the web get an update... I'm still waiting for my CD!). Too see exactly what's tested, check this out.

The cool this about this is that It shows the "Percent" on how good your browser is. Believe it or not, IE7 gets like 13%. FireFox 2.0 gets around 52%.

 I'm not even going to attempt to do this in IE8 beta.
 

 

 

Holy Cow! I know this isn't new news.  IE8 and FireFox 3.. Acid 2 tests, heck Acid 3 tests. When is it going to stop?!?

 As some know, I'm writing a very complicated vehicle tracking system that is all web based. It can track up to 200 vehicles at once (in one browser instance), draw them on the map, and give you all the nice tid-bits of information about them. This application is very heavy CSS and JavaScript. I pretty much took most of .NET out of the application except for 3 web service calls.

 However, To make applications like the one I'm developing work in a real world environment, they need to be efficient. That means that if I'm going to be doing collision detection on vehicle labels (so they don't overlap) I would rather use a few extra bits of memory to remember the answers from complicated math (storing the values that are returned by using COS / SIN calculations) than to have to calculate them each time. If you didn't know anything done using COS, SIN, TAN etc.  are extremely expensive.

 So back on topic, I have my application, It's as efficient as I can make it, and now I have to test the efficiency in not 4, but SIX browsers. And to top it off, those browsers have tweaked Javascript engines. WHY WHY WHY! I already tried my app in these 2 new browsers, and they "do" work, but not as well as I would've hoped.  Come on, when can a Guy run a simple <div> collision detection script that checks over 100 divs and repositions them in a self expanding circle every second? Why does it need to take 3.2 seconds?
 
I know... to better humanity and all other species on this earth, new web browsers are pertinent in order to form an electronic self sustaining ecosystem. Anyways, WHY! I already have 4 browsers to test (IE7, FireFox 2.0, Opera, safari... stupid Safari), and now I need to test on 2 more? You know, the day when those 2 browsers (or days) get released I'll forget to test on them and I'll get over 100 emails in my inbox stating that my website broke the internet (if that were true then I'd really have something to blog about).

Can we invest more money in holograms like on Star Trek so I can get a duplicate to do the testing? I know testing is the bestest most funnestest thing ever and that programmers everywhere are running at the opportunity to test... but I'll sacrifice my ego and let my hologram clone do it for me.

 
Ok I'll stop whining now.
 


 

More Posts Next page »