Wednesday, April 23, 2008

Central Ohio Day of .NET 2008 Synopsis

I rode down to the Central Day of Central Ohio Day of .NET 2008 with Rich Hamilton and Joe Kunk on Saturday.



I attended these session:


  1. A Linq to Everything (Leon Gersing)

  2. User Interface Design for Programmers (Chris Poteet)

  3. Happy Marriage of Agile and TFS (Alexei Govorine)

  4. Test Driven Development (Phil Japikse)

  5. Well, Isn't that Spatial... (Jason Follas)

I had heard of recording users running an application but have never done it before. Chris's presentation had some recorded user sessions. It was interesting to watch the sessions and listen to his commentary about the design changes viewing the user interaction caused.


After the conference Jeff Blankenburg held a poker tournament back in his hotel room. It was a lot of fun to hang out with like minded individuals in a casual atmosphere. This was my favorite part of the conference.

Tuesday, April 22, 2008

00 Querying Named instance Linked SQL Server

This is how you query against a linked named instance of sql server.


sp_addlinkedserver 'servername\instanceName' --create the link.

select * from [servername\instanceName].databaseName.dbo.TableName --execute the query.

Wednesday, April 16, 2008

Search for Detroit Software Developer Community

I ran across an interesting group this morning in my search for the Detroit Software Developer Community: the detroit software engineers' grotto. The group's goal is interesting for anyone to read. They are trying to rent a space for software engineers to work instead of their office. The space will have comfortable couches, chairs, and like minded individuals. It is modeled on a Writer's Grotto founded in San Francisco.

Unfortunately for me it states Windows is a legacy operating system, Web 2.0 is dead, and Mac OS X is the wave of the future. Interesting ideas.

I'm looking to get involved in the Detroit software developer community. We have companies with lots of developers here: Compuware, Electronic Data Systems (EDS), Accenture, and Deloitte come to mind right off the top of my head.

The Great Lakes .net Users Group, but as that is in Southfield I have to battle traffic to get out there. I came from the Lansing area which has a great developer community especially for the relatively low population of the area. Being involved in the Greater Lansing User Group .net continues to positively impact my life.

This morning I went looking for the Detroit developer community. My assumption is that it must exist given the larger population and I'm just not connected. Yet :)

Tuesday, April 1, 2008

Clustered Index slows down BCP signiificantly

Our 19 hour job was reduced to about 30 minutes using this technique.

We had to import 110 million rows into a SQL Server table containing 5 ints during 4 import sessions. There was a clustered index over 4 of those ints.

We used the System.Data.SqlClient.SqlBulkCopy class to do the import (class mirroring the sql server bcp utility). The initial import took ~19 hours. On a new table we removed the clustered index and inserted all the rows again. This took about 12 minutes. Applying the clustered index took about 20 minutes.

Monday, March 24, 2008

Programmatically Executing SQL Scripts

I didn't realize GO is not a SQL keyword. When I was trying to execute a script that worked in SQL Server Management Studio I was getting SQLException Incorrect syntax near 'Go'. The solution is to split the input script on GOs and execute those scripts.

const char splitChar = '☻'; //this character should never appear in command files
if (createDatabaseScript.Contains(splitChar.ToString()) == true)
throw new Exception("Aborting. Splitting this file may break the script because the script contains the split character");
using (dbConnnection)
{
dbConnnection.Open();
SqlCommand createDbCommand = new SqlCommand(string.Empty, dbConnnection);

//split the input script into multiple scripts based on GOs
foreach (string command in createDatabaseScript.Replace("GO", splitChar.ToString()).Split(new Char[] { splitChar }))
{
try
{
createDbCommand.CommandText = command;
createDbCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
//log the error for later review.
results += ex.Message + Environment.NewLine;
}
}
}
Console.Write(results);

Monday, March 17, 2008

FxCop bug - CA1709 & CA 1707

CA 1707 IdentifiersShouldNotContainUnderscores
CA 1709 IdentifiersShouldBeCasedCorrectly

I ran into a surprise last week. FxCop is throwing warnings for properties on 2 out of 5 interfaces in a particular project. Interface A implements interface B.

I'm assuming the bug described in this article is causing it: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2344375&SiteID=1 and that it will be fixed in Visual Studio 2008 Service Pack 1.

Monday, March 10, 2008

Unit Testing Graphics Operations

We decided to verify our graphic operations here by doing a binary comparison.
Here is a simple implementation using Linq.

Setting up the expected value:

Bitmap aBitmap = new Bitmap(181,46); //exact size of the bitmap to reduce the number of bits
Graphics aGraphic = Graphics.FromImage(aBitmap);
target.DrawGrid(aGraphic); //the operation you want to verify
MemoryStream actual = new MemoryStream();
aBitmap.Save(actual,ImageFormat.Bmp);
string aBunch = string.Join(",", actual.ToArray().Select(b => b.ToString()).ToArray());

Copy the string aBunch. We will use this to create the expected byte array.
create the byte array like this but use your pasted values instead of my values
byte[] expected = new byte[] {66,77,78... };

Finishing the unit test:

Bitmap aBitmap = new Bitmap(181,46);
Graphics aGraphic = Graphics.FromImage(aBitmap);
target.DrawGrid(aGraphic);
MemoryStream actual = new MemoryStream();
aBitmap.Save(actual,ImageFormat.Bmp); // get our actual result.
byte[] expected = getExpected("DrawGridTest");

Assert.IsTrue(actual.ToArray().SequenceEqual(expected),"Binary comparison failed.");

This method is getting expected from a function because Visual Studio responds slowly when there are long lines of text. I created a partial class containing the instantiation of expected (I'm using a switch statement). I thought about putting the results in a resource or a file, but I'm preferring code for now.

Friday, February 29, 2008

Speeding up Unit Testing in Visual Studio 2008

I've been doing unit testing in Visual Studio 2008. I noticed it takes a while for the tests to execute after I start the test run.

Initially I thought it was copying data into the TestResults directory. Some of our unit tests rely on files and our test run copies ~30 MB of data into the TestResults directory.

I found out it was the code coverage instrumentation process slowing it down. On my machine it seems to take about a second to instrument an assembly for code coverage. Our project has 8 assemblies which adds ~8 seconds to every run. While it is important for our server build to have all the assemblies instrumented, when I'm creating unit tests I just need to have my assembly instrumented. Going into the GeneralRun.testrunconfig --> Code Coverage and instrumenting only the assembly I'm working on reduces the run speed by about 7 seconds.

If you do this, ensure you don't accidentally check this change into Team Foundation Server or you won't get complete code coverage results.

Skipping the deployment of the 30MB of data had no noticeable effect on the test run times.

Monday, February 25, 2008

Creating a metafile in .NET

Metafiles are a way to save scalable vectory graphics. This blog creates a simple image containing a diagonal line. It also shows the proper way to save the metafile, as the class method saves it as a png file.

MSDN article on MetaFiles: http://msdn2.microsoft.com/en-us/library/ms536391.aspx



using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;




MemoryStream metafileStream = new MemoryStream();


Graphics offScreenDC = Graphics.FromHwndInternal(IntPtr.Zero);


IntPtr myImagePointer = offScreenDC.GetHdc();


Metafile meta =
//new Metafile(myImagePointer, EmfType.EmfOnly); //unable to do memoryStreamSave
new Metafile(metafileStream, myImagePointer, EmfType.EmfOnly); //able to do memoryStreamSave


Graphics aGraphic = Graphics.FromImage(meta);


aGraphic.DrawLine(new Pen(Brushes.Black), new Point(0, 0), new Point(29, 29));


aGraphic.Dispose(); //Dispose must be called to flush the drawing instructions.


offScreenDC.ReleaseHdc();
meta.Save(@"c:\metaSave.wmf"); //saves as a png file.


FileStream aWrite = new FileStream(@"c:\StreamSave.wmf",FileMode.Create); //saves as a wmf file


metafileStream.WriteTo(aWrite);

Saturday, September 22, 2007

Rudolf Melik, CEO of Tenrox speaks at PMI-MCAC

I'm the Vice President of Programs for the Project Management Institute Michigan Capital Area Chapter (PMI-MCAC). Our 2007-2008 program year inaugural meeting featured Rudolf Melik, CEO and one of the founders of Tenrox. He gave a great presentation on Empowering Your Project Workforce. During his presentation he mentioned how business is changing due to globalization, workflow tools, outsourcing, off shoring, and the internet. Mr. Melik discussed ways to avoid MESS (Meetings Email & Spreadsheets) to increase productivity. On a personal level he recommended committing to projects, de-commoditizing your job, leveraging other individuals, keeping up with innovations, and using 21st century tools.

Thursday, September 13, 2007

Jay Wren speaks at Flint branch of GLUG.net

Jay Wren gave an excellent demonstration of Test Driven Development at the Flint branch of GLUG.net monthly meeting last night. We had nine members in attendance and everyone got a prize.

Jay is relatively new to speaking. I was very impressed by his personable, enthisiastic, and engaging style. He replied with well thought out answers to each question he was asked. He introduced Test Driven Development with a few slides and then dove into a live demo of NUnit. He asked the audience for sample requirements and used the non trivial task of developing a two way dictionary as his sample. Generally I dislike live coding samples because things go wrong. Jay showed his .net prowess and mastery of Coderush by quickly correcting all type os and errors.

I think Jay summarized test driven development with this statement "How do I use this vs. what do I need." When we code first we are creating what we need. When Jay codes tests first he is consuming his API and thus gains a new perspective on the API which leads to better design and usability.

Jay briefly gave a demo of NCoverExplorer and Coderush. I recently installed Coderush, and thanks to Jay's brief demo I started effectively learning it today. NCoverExplorer is a test analysis tool which shows executed lines, cover % how many times a particular method was called etc.

I was reading Jay's blog today which has some good entries.

Friday, August 17, 2007

Jeff McWherter speaks at GLUG.net

Chris Woodruff was scheduled to speak at our .net user group last night. Unfortunately he came down with the flue. Luckily Jeff, one of our program directors, stepped up and gave a presentation on Optimizing and Performance Tuning your ASP.net Applications.

Jeff has a cool website where you can do a bit of stalking to see what TV shows he is going to record, and if he is at home (based on if his laptop is on the network or not).

We had 17 members attend and everyone won a prize!

Thursday, August 16, 2007

Inagural Flint branch of GLUG.net Meeting

We had 10 members attend our inagural Flint branch GLUG.net meeting yesterday. Paul Kimmel presented on Visual Studio 2008. His presentation was very technical and interactive. The smaller audience size allowed us to ask questions and prompted discussions. If you are interested in some of the new features in Visual Studio 2008 have a look at Paul's blog.

Friday, August 10, 2007

SQL Server random number generator

This SQL Script generates a random number between 1 and 5.

It demonstrates a few interesting ideas:
1) Temporary tables - These are in memory temporary tables (I use these all the time)
2) SQL Server looping with While (you may use these instead of cursors. I've heard cursors are slower)
3) Random number generation with newid() (select top 5 * from [table] order by newid() returns 5 random rows.
4)

declare @tempTable table (column1 int) --declaring a temporary table
declare @i int
set @i =1
While @i <=1000000 begin insert into @temptable (column1) select abs(cast(cast(newid() as varbinary) as int))%5+1 set @i = @i +1 end

--select * from @temptable

select column1 as [value],count(*) as [Occurrences],
cast(count(*)*100 / cast((select count(*) from @temptable) as decimal) as int) as [Percentage] from @temptable
group by column1

Wednesday, July 18, 2007

Jing, a Free Image Capture & Screen Recording tool

TechSmith released a free image capture / screen recorder tool yesterday called Jing. I focused on the video recording features because we have SnagIt here at work. Jing is very easy to use. I installed it, configured it (setting up Screencast), and created a video in about 10 minutes. Jing is cool because it allows you to record your entire screen, an entire application or objects within applications. After recording one click sends your video up to Screencast and even puts the URL to your video in your clipboard!

We will probably use this tool for training.

Thursday, July 12, 2007

Greater Lansing User Group .net (GLUG.net) July Meeting

Where: 1145 Engineering Building, Michigan State University

When: Thursday July 19th 6:00-8:00 PM

What: We always have give away hundreds or thousands of dollars worth of swag along with free pizza and pop for everyone. This month we will also be announcing the opening of the Flint branch and our Vice President Vivek has secured all our membership 100 MB of free hosting from Verio.

Julia Lerman will be our first female speaker. She will be presenting on ADO.NET Entity Framework.

Visit our website for more details: www.glugnet.org

Friday, July 6, 2007

Updating Binary Data in a Gridview

Our customer needed the ability to update an image in a database. I wanted them to be able to view and edit all the data through the datagrid.

In your data source you need to specify the select command to display the data and the updateCommand to update the data:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:campDBConnection %>"

SelectCommand="usp_CAMP_get_rejected_batches"
SelectCommandType="StoredProcedure"
UpdateCommand="usp_camp_resubmit_deposit_ticket"
UpdateCommandType="StoredProcedure">


<UpdateParameters>
<asp:Parameter Name="deposit_id" Type="Int32" />
<asp:Parameter Name="deposit_slip_no" Type="String" />
<asp:Parameter Name="deposit_date" Type="DateTime" />
<asp:Parameter Name="Amount" Type="Decimal" />
<asp:Parameter Name="image" /> </UpdateParameters>
</asp:SqlDataSource>


I used a TemplateField to include the FileUpload control which allows a user to select a file from their computer for upload. This also allowed the same column to be used to display the image and change it.

<asp:TemplateField HeaderText="Deposit Ticket">
<EditItemTemplate>
<asp:FileUpload ID="imgUpload" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Image ImageUrl='<%#DataBinder.Eval(Container.DataItem, "DEPOSIT_IMAGE_URL")%>' runat = "server" />
</ItemTemplate>
</asp:TemplateField>

I needed to add in the binary data into e.NewValues:

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating

e.NewValues.Add("image", CType(GridView1.Rows(e.RowIndex).Cells.Item(5).Controls(1), FileUpload).FileBytes)

End Sub


I also found a couple more gotchas:

  1. To format data in the grid you need to have HtmlEncode
    turned off

  2. For the upldate to send the primary key field and have that field set to invisible you need to specify the primary key in the DataKeyNames property for the GridView.

Friday, June 15, 2007

ArcREADY: Reinforcing the Foundations of Solutions Architecture

I went to ArcREADY: Reinforcing the Foundations of Solutions Architecture in Grand Rapids. It was presented by Josh Holmes. Josh presented these ideas by making analogies between software and other products (Wii, Xbox, can openers, Espresso makers etc.)

Here are my main take aways from the presentation:

Steps in architecting the user experience:
  • User Interface Design
  • User Research
  • Design Planning
  • Information Design
  • Usability Testing

There are 4 concepts to consider when architecting the user experience:

  1. Function (works great)
  2. Aesthetics (looks great)
  3. Interaction (relates to you)
  4. Process

There are 3 business principles to consider:

  1. What is possible?
  2. What is viable?
  3. What is desirable to users?

Tuesday, June 12, 2007

XSLT Tool - Cooktop

I've been using XML Notepad to help view XML files. Unfortunately XML Notepad doesn't have an XSLT editor.

I found a free one today: Cooktop

It worked for what I wanted and it was free. I would like to have one tool for viewing XML files and editing XSLT, but I don't like CookTop's display as well as I like XML Notepad's hierarchical view

Tuesday, May 29, 2007

Visual Studio 2005 Class Diagrammer

I like the Visual Studio 2005 Class Diagrammer

I looked at the Visual Studio 2005 Class Diagrammer briefly when I first started using the product. I didn't think it did much, thought Visio was better, and didn't use it anymore. End of story.

While preparing a presentation on my current project I found Visio wasn't creating the pretty diagrams I wanted. I decided to try the Diagrammer again. After you create a class diagram, you can hit the + key or hit the triple upside down ^ icon to get the diagram to expand. It does a nice job of displaying your class.

I've found a few useful features in the class diagram menu: Show Base Class, Show Derived Class, Change Members Format --> display full signature. There is also a Refactor -->Extract Interface which looks handy.

Changes made to the diagram or in code are instantly synchronized between the two.

Unfortunately there is no integration between Visio and the Class Diagrammer. You can click on an object in the class designer and copy paste it as a picture into PowerPoint Visio (I took independent pictures of each object and created new connector lines in Visio)