Tuesday, February 26, 2013

What do I do as an IT Manager?

So you might be wondering what it's like to be the IT manager.  Maybe you're looking to change careers or you're a programmer, network administrator or PC repair person and you're wondering what it is that an IT manager does.  While the IT manager job description is very broad, there are certain aspects of the job that are the same across the board:

1. Even though it's a management position, it requires knowledge of a technology field.
2. The technology is always changing and an effective IT manager must keep up.
3. When everything is running smooth, you're almost invisible, when things break, everybody knows who you are.

I work for a small company (less than 50 people), so I'm more than just a manager.  I am in charge of the entire infrastructure of the company.  I establish the annual IT budget and prepare 5 year budget projections every year.  I'm involved in deciding what hardware we'll use.  Should we standardize on one platform?  Purchase warranties on hardware?  What software license plan should we use?

Our company has an inventory database that tracks both hardware and software.  Due to end of year capitalization requirements, our database also tracks purchases made.  I have a full-time network administrator on staff so he handles all the PC repairs, network troubleshooting, server configurations, security checks, firewall updates, tape backups, etc.  I still need to know what his job is and my company has documentation that he must update to help me do his functions if he calls in sick.

Currently I have only one programmer on staff.  I'm looking for another advanced C# programmer.  The list of enhancements authorized by the CEO and COO stands at about 32 items as of this writing.  It amounts to about 3,500 man-hours of programming in total.  This list grows at about 12 items per year, so we're sinking fast.  Hence the reason I'm looking for a second programmer.  If we get too far behind, I'm going to outsource some of it to a local programmer shop.

I do the software design work for our company.  Most of our software is my vision.  I collect ideas from a lot of people and I jot down notes every time someone comes by with a suggestion (or drops it in my email, sticky-note, hand-written sheet in my mail-box, etc.).  We typically have an enhancement prioritization meeting with the CEO, COO and others about twice a year (or sooner if I run out of authorized tasks).  The authorized enhancements must be designed and I have to provide an estimate. 

I also do some programming.  A little less than 50% of my time is available for this task.  I have to throw in my time whenever I can to move the development effort along.  Many of our current tasks will cut down on the manual labor it's taking our production people to enter data into the system and print reports.  The sooner this software is available, the more money we can save and the faster we can get our customer data in their hands.

I attend bi-weekly operations meetings.  These are only tentatively related to my department, but I have to keep an ear to what production issues are brought up and many times I offer solutions (and that folks, is why the enhancement wish list grows!).  Normally, I'm required to provide a rough estimate for each project on the list and sometimes it's just a wild guess, since I don't have a design created yet.  These man-hours are used for the justification phase of each project.  For enhancements that are going to make our operations more efficient, we need to know how much time will be saved and who it will save time for.  This can be used to compute the payback time (sometimes measured in years, mostly measured in months).  Our management tries to pick the best bang for the buck using this analysis.

Some enhancement requests come directly from customers.  When we acquire a new customer, we have technical people who teach the customer how to use the web site to access their information.  Our customer might be interested in seeing their data sliced or presented in a different manner.  We normally drop what we're doing and put priority on making that happen.

In addition to all the above, I am responsible for the functioning of our company's entire computer system.  I have to plan ahead for everything.  Sometimes I have to think on my feet.  What if the building burns down?  Do we have the customer data protected?  What about the source code to our software?  How would we re-construct our system if everything were lost in a flood or fire?  What if our site gets hacked?  Do we know if someone is trying to hack our network right now?  What if our network provider has a regional failure?  What if the electric company has a regional power outage?

Oh the stories I could tell....

But that will be the subject for a future posting...

Sunday, February 24, 2013

Another Book

Eons ago I bought and read a book called "Code Complete."  It was written by Microsoft back in the days when I scratched my head and wondered if they read their own book.  Looking back on Microsoft's operating systems I can see a point where they finally got serous about software quality.  My assumption is that it took them some time to fix all the code that they had created.  Anyway, the book is good.  I enjoyed the book because it revealed techniques for testing code, naming methods and variables, what to watch out for (fence post errors, buffer overflows, etc.).  As I was scanning Amazon for a new book to read, I came accross the second edition of "Code Complete" which includes new techniques like unit testing.

You can find the book at Amazon by clicking here

This might be my next book to read.  If I buy and read this one, I'll report on it later.

I ordered the book and it's on its way.

Using Aspose.Cells

I use a couple 3rd party add-ons for my software.  Being able to import and create spreadsheets is a huge productivity boost for my company.  I began using Aspose products in 2008 and our company has added Words and Project to our libraries.  The Aspose website can be found by clicking here.  Their documentation is excellent, and you can download their libraries and use them without paying for them for evaluation purposes.  The Aspose.Cells library will create an excel spreadsheet with some text in the first tab indicating that this is for evaluation purposes only.  When you purchase a license, you can read the license file using the following code:

License license = new License();

I normally create a "license" folder inside my deployable project so that I can keep them neat and tidy (and away from the bin folder).

The Aspose libraries come with an installer and you can then add the reference using the "Assemblies" section of the reference add window in Visual Studio.  Once you have added the reference you'll need to add the using:

using Aspose.Cells;

If you go to Aspose's website, you can find the documentation called "Your first application.." under the "Programmers Guide."  An example from this documentation looks like this:

//Instantiate a Workbook object that represents Excel file.
Workbook wb = new Workbook();

//Note when you create a new workbook, a default worksheet //"Sheet1" is

//added (by default) to the workbook.
//Access the first worksheet "Sheet1" in the book.
Worksheet sheet = wb.Worksheets[0];

//Access the "A1" cell in the sheet.

Cell cell = sheet.Cells["A1"];

//Input the "Hello World!" text into the "A1" cell

cell.PutValue("Hello World!");

//Save the Excel file.

wb.Save("c:\\MyBook.xls", SaveFormat.Excel97To2003);

This example will save a file named "MyBook.xls" in the root directory of the "C:" drive of your PC.  If you're calling this from a website and you want it to pop-up from your site, you can replace the "Save" method above with the following code:

wb.Save("MyBook.xls", FileFormatType.Excel2003, SaveType.OpenInExcel, HttpContext.Current.Response);

So now it will send the excel file to the browser which will ask if you want to open or save to the download folder.

Now for a couple of tricks.  First, if you want to use a custom color for your cells (I use a different color for the background of my header row), you'll need to declare the color first (Color is contained in "System.Drawing" so you'll need to include that in your using statement):

wb.ChangePalette(Color.FromArgb(221, 208, 190), 55);

Then you can use this color to paint your cell (Excel calls it the foreground color):

sheet.Cells["A1"].Style.ForegroundColor = Color.FromArgb(255, 221, 208, 190);

Another trick is that you can freeze a row (or column).  The code to freeze the top row looks like this:

sheet.FreezePanes(0, 0, 1, 50);

This will freeze the top row so that it doesn't scroll when the user scrolls the data in the spreadsheet.

There are many more features that are convenient for producing a spreadsheet include column widths, row heights, cell formats (you can duplicate any Excel data format using information on this page).  Finally, you can read Excel workbooks.  Our company uses this feature to transfer data from one screen to another, or read raw data exported from other systems.  Our company also produces pie charts using this product.

I hope this information helps you with your project.  Drop me a message if you have questions.


Introduction to SVG, Silverlight, HTML5 Canvas

If you're not familiar with SVG or Silverlight, you should dabble with it a little.  It's very easy to use SVG and it opens up a lot of creative capabilities.  You can use SVG to paint shapes, text, png files within the content region of the browser.  If you use absolute coordinates for your div tags, buttons, text boxes, etc.  You can paint round these objects to spice up your web page.  Let me show you a tiny example to demonstrate how easy it is to get started:

<!DOCTYPE html>
<meta name='apple-mobile-web-app-capable' content='yes' />

<h1>Scalable Vector Graphics</h1>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
   <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />
   <rect x='25' y='150' width='150' height='25' style='fill:blue;' />

<input type='submit' name='btntest' value='Test' style='position:absolute; left:55px; top:60px; width:100px; height:25px;' />


This sample will display a submit button below a title "Scalable Vector Graphics" and then paint a red circle below the button and a blue rectangle below the circle.  My goto site for attributes and shapes is the w3schools website: http://www.w3schools.com/svg/default.asp

SVG requries HTML 5 in order to work properly.  That means that you need to have ie9 or better, or you can use chrome, opera, firefox or safari.  SVG rendering will reder identically across all 5 browsers (I know, I've written complex graphical viewers that works on all 5).  In addition to these browsers, the SVG viewer will work on the iPad and iPhone as well as Android devices.  Silverlight has an advantage that it utilizes graphical hardware rendering on the PC, so ie will be blazing fast in Silverlight, but Silverlight does not work on hand-held devices and it requires the Silverlight plug-in.

So you're probably thinking "why SVG and not HTML5 Canvas?"  You can.  Here's an example of a square painted in the content region of the browser:

<!DOCTYPE html>

<meta name='apple-mobile-web-app-capable' content='yes' />

<canvas id="myCanvas" width="300" height="200"></canvas>
      var canvas = document.getElementById('myCanvas');
      var context = canvas.getContext('2d');

      context.rect(5, 50, 200, 100);
      context.fillStyle = 'yellow';
      context.lineWidth = 2;
      context.strokeStyle = 'black';



First, you'll noticed that you need to use Javascript in order to render.  Second, you still need HTML 5 compatibility.  Last, but not least, you cannot change your rendered shape after it is rendered.  Canvas is like a paint program.  The image is painted into the canvas and you must erase the canvas and re-paint the image to make it move.  In SVG, each object exists in the browser, so you can use Javascript to move, scale, rotate and manipulate attributes of your shapes.  Silverlight also can be manipulated with Javascript.  Silverlight can also be written with C# that is compiled and run locally on the browser within the Siliverlight plug-in.  This capability is very powerful and allows very smooth interaction, however, it is restricted to PCs only.

For the following Silverlight example, you can download the "Silverlight.js" file from here by right-clicking and downloading the file to your computer.  Then you'll need to create the basic HTML file containing this code:

<!DOCTYPE html>

<script src="Silverlight.js" type="text/javascript"></script>


<div id="Ag1Host" style="background:#FFFFFF">
<script type="text/javascript">
var pe1 = document.getElementById("Ag1Host");


<script>Silverlight.createObjectEx({source: 'MyFirstSilverlightPage.xml', parentElement:pe1, id:'Ag1', properties:{width:'300', height:'100', background:'#00FFFFFF', isWindowless:'true', framerate:'24', version:'0.90.0'}, events:{onError:null, onLoad:null}, context:null});</script>


Then you'll need a file named "MyFirstSilverlightPage.xml" that contains the following:


<Rectangle Width="200" Height="100" Fill="Blue" Stroke="Black" StrokeThickness="4" />

As you can tell, Silverlight is a little more involved.  If you're using Visual Studio, you can ignore this setup and run your Silverlight project as a project.  Then all the necessary files will be automatically generated.  Here's a link to getting started using this method: Walkthrough: Creating Your First Silverlight Application.

If you are serious about adding graphical output to your website, you should investigate all of these technologies and get familiar with their basic behaviour.

Friday, February 22, 2013

Just for Fun

A tiny bit off-subject.  As many have noticed I read books.  I like real books more than e-books, but e-books are convenient and I can crank up the font size so I don't have to squint so hard.  Anyway, I read a lot of technical stuff, but I also read recreational books.  Some of which fit the subject of computers.  One such book that I read years ago (about 1982 or 83) is called "The Soul of a New Machine" by Tracy Kidder.  Amazon has the kindle version for $8.89 as of this writing.  Anyway, I remember the first time I read this book (that's right, I'm re-reading it), it is very gripping.  The author just sucks you into the store right away and it just gets more and more interesting as the story develops.  The story is about Data General in 1980 when they developed a minicomputer called the "Eagle."  If you go to Amazon and read the "Prologue" section of this book, you'll know exactly what I'm talking about.  The story features a man named Tom West who was an electronic engineer that designed CPU's for Data General.

When I read this book in the early 80's the computer that Data General produced was still being sold and minicomputers were just another type of computer that a business could purchased.  Now, minicomputers don't really exist anymore.  Servers have replaced them and all the minicomputer companies such as Data General have either gone bankrupt or they were bought out by companies like Compaq and HP (OK, HP bought Compaq too).  So now it's like reading a history book, but the story, none-the-less is still interesting.

Most of the story is about the engineers and programmers that breathed life into their machine.  Interlaced with this story is some computer details broken down so a laymen can understand it.  This is not a hyper-technical story that only an egg-head could read and understand, Kidder did an excellent job of describing what the engineers at Data General told him.

Another book that I've read for fun is called The Cuckoo's Egg: Tracking a Spy Through the Maze of Computer Espionage by Cliff Stoll. This too is an older book and it involves an astronomer academic who was assigned to look into a hiccup in the Unix based accounting system.  He stumbled onto a program that was planted by a spy that managed to get into their system by breaking into other systems.  The book goes onto how he discovers who this person is by getting cooperation with the phone company (to find out what number dialed in) and his frustration with government agencies that didn't view computer crimes as part of their jurisdictions (in fact there was no agency to handle such acts of crimes back then).  I won't spoil the story, but the trail leads him to discover that the hacker/spy broke into several military sites connected to the Internet, and they didn't know that they had been compromised.  If you don't have time to read a book, don't start this one, because it's not the kind of book that you can put down after one or two pages.

More on NHibernate

I've done more research and discovered that NHibernate is normally used to store persistent data in a database.  The idea is that a programmer can define the structure used by an object and an associated table in a database and NHibernate will handle the CRUD (Create, Read, Update, Delete) commands.  I'm not sure I'll have the time to research this subject much further since my projects already have a defined database tables and objects.  Also, most of the data my company stores isn't directly mapped to an object.  However, as I mentioned in an earlier post, I always research new techniques and technologies.  I'll be filing this away for possible use in a future project.

Also, I wanted to know where the name "NHibernate" came from, so I looked it up (thanks wiki).  The "N" in NHibernate is for Dot-Net.  The original product was called Hibernate and was designed for Java.  Hibernate is an apt description for how the data behaves.  Basically, web data stored in objects in memory "hibernate" in the database until the user returns to the web page and the data is re-read.

There are two books that I came across that look interesting if you want to learn more about this subject.  I went to Amazon and flipped through the "Look Inside" and I like what I see.  When I catch up on my other reading, I might dive into this subject a little deeper.

The first one is this one:

NHibernate 3 Beginner's Guide

The second book is this one:

NHibernate 3.0 Cookbook

If anybody has read these books, feel free to post your impression in the comments and I'll update this post with your information.

Sunday, February 17, 2013

More Microsoft Enterprise Libraray Stuff...

Now, let's say you have a DataSet of data that you just queried, but you want to sort it two different ways, but you don't want to re-query the data.  This is a situation where the DataView object can come in handy.  First, let's query some data:

MyDatabase lMyDatabase = new MyDatabase();

string lsQuery = "SELECT * FROM sys.all_columns";
DataSet laData = lMyDatabase.SelectQuery(lsQuery);

Now, let's sort by column_id (this data set is a table of information that is built into MS SQL, so it should work as is, no need to create a database):

DataView laDataView = new DataView(laData.Tables[0]);
laDataView.Sort = "column_id";

Now you can spin through the sorted data:

foreach (DataRow lpRow in laDataView.Table.Rows)

Using Microsoft Enterprise Library Database Connection

One of the advantages of using the Microsoft Enterprise Library for website database access is that you can treat data queried as an array.  Here's the download page: Microsoft Enterprise Library.

You'll need 3 references in your project to make this example work:


You'll also need these three usings:

using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

I'm going to setup a generic database class that you can copy into your source and change the names to fit your application:

namespace MyDatabaseNS
    Database cpDatabase;
    DbCommand cpCommand;

    public class MyDatabase
        public MyDatabase()
            cpDatabase = DatabaseFactory.CreateDatabase("MYDB");

        public DataSet SelectQuery(string psQuery)
             cpCommand = cpDatabase.GetSqlStringCommand(psQuery);
            return cpDatabase.ExecuteDataSet(cpCommand);

        public int ExecuteNonQuery(string psQuery)
            cpCommand = cpDatabase.GetSqlStringCommand(psQuery);
            return cpDatabase.ExecuteNonQuery(cpCommand);

In addition to this code, you'll need to modify your web.config file (I'm assuming you are using an MS SQL server database):


<add name="MYDB" connectionString="Data Source=SQLDATABASENAME;Persist Security Info=True;Max Pool Size=500;Connect Timeout=600;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>


OK, now, how do you use it?  First you will need to include System.Data:

using System.Data;

Then you can instantiate a new object and use the select method to read a DataSet:

MyDatabase lMyDatabase = new MyDatabase();

string lsQuery = "SELECT * FROM sys.all_columns";
DataSet laData = lMyDatabase.SelectQuery(lsQuery);

Now you can spin through your data and perform some function (like printing it to a web page):

foreach (DataRow lpRow in laData.tables[0].rows)

Also, be aware that there is a timeout for the query.  If you're having issues with this, then put this into your SelectQuery and ExecuteNonQuery methods before calling the return command:

cpCommand.CommandTimeout = 0;

I hope this helps with your database coding.  Drop me a comment if something doesn't seem to work.  I've been using this code since 2008 and I've had my share of "issues" with database systems.

Tuesday, February 12, 2013

Fluent NHibernate

I've recently finished reading the book Test Driven Development with C#.  I would recommend this book to anyone interested in unit testing, integration testing and end-to-end testing.  If you're attempting to enter into the complex world of test driven development, this book is excellent and presenting examples that work and make it all clear.  One of the packages used in the integration testing section is called NHibernate, specifically a version called Fluent NHibernate.  This package takes the place of a database engine and allows you to mock a few tables with values in them avoiding the need to maintain a real database with test data.  If you're looking for more information on this package, I would recommend this wiki page for starters:

Fluent NHibernate, Getting Started

You'll have to startup the Tools -> Library Package Manager -> Package Manager Console.  Then use this command to install Fluent NHibernate:

PM> Install-Package FluentNHibernate

Now go back to Tools -> Library Package Manager -> Manage NuGet Packages for Solution and "Manage" Fluent NHibernate.  Make sure there is a check next to the unit test project you want to use this package for:

In order to use Fluent NHibernate, you'll need to also add NHibernate.  I used the search in the NuGet package manager.

Don't forget to add your usings:

using NHibernate;
using NHibernate.Mapping;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using FluentNHibernate;
using FluentNHibernate.Mapping;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Cfg;

I had to dig through the sample code to get the proper usings to work with the code fragments that were provided on the wiki page.  I hope the above list saves you some time and frustration.

I'll revisit this subject after I've become more familiar with it's use.  So far, from what I've played with, it provides a capability that I've been wanting for years.

VS2012 Reference Has Yellow Triangle

This seems to be a common problem where a reference to another project has a yellow triangle on it.  Like this:

Check your warnings:

In my case the project targeted had a .NET library set to 4.5 and my main project had a .NET of 3.5.  The warning, however, gives all the details needed:


For me, the project in question was created with .NET 4.5 automatically, so I had no idea what was going on when I ran into this original problem.  To fix it, right click on the project and select properties:

Then change the ".NET Framework" dropdown to the same version as all other projects.  You'll be presented with a warning that the current project should be closed and re-opened after changing.  Click the "Yes" and continue.  Then close and re-open your solution.

Friday, February 8, 2013


I'm playing with NBehave today.  First of all, I'm using Visual Studio 2012 and I'm planning to use MSTest.  I went through various instructions for installing and I finally stumbled onto this article that worked:

Github NBehave Assert Extensions

I went to the Tools -> Library Package Manager -> Package Manager Console.  Then I copied and pasted this command:

Install-Package nbehave.spec.mstest

and hit enter.  It did some processing and voila!  It worked.  OK, actually, I had previously added a using and some sample code:

using NBehave.Spec.MSTest;

namespace OSIM.UnitTests
    public class Specification
        public void TestMethod1()
            var numbers = new[] { 1, 2, 3 };

Then I ran the unit test and it passed.  I changed one of the expected values (the should equal I changed to a 3) and re-ran the tests to see if it failed.  It failed as expected.

Hopefully you stumbled onto this posting and cut right to the chase.  I had to go through a few failed install instructions before I stumbled onto this.  Sometimes things are difficult in getting started.  After you learn the tricks, then it's a piece of cake.