Thursday, May 26, 2011

Free Programatic Interface to Excel in C# - EPPlus

Needing a way to programatically create Excel spreadsheets, I found EPPlus and it works great. It took about 10 minutes to create my first multi-workbook excel file.
You can download it at epplus.codeplex.com.
My toy code:
private static void WriteExcelBrandsList(BrandAndCodeRepository brandsRepository, Choice choice)
{
  using (ExcelPackage pck = new ExcelPackage()) {
    //Create the worksheet for each list
    foreach (var listName in brandsRepository.GetLists())
    {
      ExcelWorksheet ws = pck.Workbook.Worksheets.Add(listName);
      ws.Cells["A1"].Value = "Brand";
      ws.Cells["B1"].Value = "Fieldwork";
      var brandAndCodes = brandsRepository.GetList(listName);
      int i = 2;
      foreach (var brandAndCode in brandAndCodes)
      {
          ws.Cells["A" + i].Value = brandAndCode.BrandId;
          ws.Cells["B" + i].Value = "2011-01";
          i++;
      }
    }
    string fileName = string.Format("C:\\BrandLists_{0}_{1}.xlsx", choice.Category, choice.Locale);
    Console.Out.WriteLine("writing to fileName = {0}", fileName);
    pck.SaveAs(new FileInfo(fileName));
  }
}

Wednesday, May 25, 2011

Austin on Rails, May 24, 2011

I drop in on the Austin on Rails community occasionally to get a taste of what's coming to .Net in a few years. Eighty people crammed into a stuffy room to catch the latest in Rails technology.
Matt Thompson gave an overview of CoffeeScript, a semantically more pleasant version of JavaScript that gets translated into real JavaScript.
Adam Michela, aka soopa, presented Sass, Syntactically Awesome Style Sheets, a layer of abstraction above css which get translated into real css files.
The pairing of the technologies was a nice touch by Damon Clinkscales since both will be in the next version of Rails and both are essentially the same thing - a more human language that gets translated down to a tried and true web component.

Tuesday, May 03, 2011

Agile Austin May 3, 2011 - Steven “Doc” List: The Agile Lego Game

Steven "Doc" List of ThoughtWorks led the Agile group in a fun game of learning agile principles by playing with Legos. One member of each team volunteered to be the "customer", our team was fortunate enough to have Scott Killen. The customer provided each team with a set of user stories like 'your animal should have wings'. We walked through three iterations of estimating, planning, building, and retrospection. The game was a fun way to learn Agile and get to know other members better.











C#: Does a Close() automatically call a Flush()

The following C# code always looked a little clunky to me, because a Close() should probably perform a flush as well. I quickly Googled around and my suspicions were confirmed that the Close() method would automatically do a Flush().
Response.Write(qdbXml);
Response.Flush();
Response.Close();
So while cleaning up some other code I removed the Flush() call. Then everything stopped working. I thought it was the other changes I made at first. Chrome gave this helpful message:
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
I restored the Flush() and everything worked great again. The Response object above is a System.Web.Mvc.Controller.Response object which doesn't necessarily work like some other stream objects and needs flushing before closing.
TIL not all stream objects behave alike and I can get in trouble by assuming hastily gathered Googled results apply to me.

Friday, April 22, 2011

SQL Server: Joining on NULLs

Today I learned you can't join tables on NULLs because SQL Server deems a NULL to be an ambiguous quantity so two NULLs are not the same NULL. You can force SQL Server to do the join by doing something like this
... colors c JOIN points p ON (c.color = p.color OR (c.color IS NULL AND p.color IS NULL))
This example assumes only one team will have a NULL color.
CREATE TABLE colors (
  team      varchar(16) NOT NULL,
  color     varchar(32) NULL,
)
CREATE TABLE points (
  color     varchar(32) NULL,
  points    int
)

INSERT INTO colors VALUES ('lobsters','red')
INSERT INTO colors VALUES ('swans','white')
INSERT INTO colors VALUES ('jellyfish',NULL)

INSERT INTO points VALUES ('red',100)
INSERT INTO points VALUES ('white',90)
INSERT INTO points VALUES (NULL,80)
SELECT * FROM colors c JOIN points p ON c.color = p.color
-- returns:
--lobsters         red                              red                              100
--swans            white                            white                            90
SELECT * FROM colors c JOIN points p ON (c.color = p.color OR (c.color IS NULL AND p.color IS NULL))
-- returns:
--lobsters         red                              red                              100
--swans            white                            white                            90
--jellyfish        NULL                             NULL                             80

Wednesday, March 30, 2011

Austin Java User's Group March 29th, Android and OSGi


We had a great meeting - it never hurts to start with free pizza.
Only five of the fifty two people attending were looking for jobs, and lots of jobs were being offered. Charles Schwab had a few dozen jobs available; HP and NetSpend also had positions to fill. Jeff Hennigan from KForce was also present - it's always a good sign to have recruiters come to the JUG.
Sam Griffin gave an excellent introduction to Android programming. He gave a demo on how to create and publish an app to a phone. Sam said it was very easy to access features like GPS, Speech Recognition, TextToSpeech, OpenGL for 2 and 3d graphics. Android also has SqlLite builtin.

Simon Chen talked about the basics of OSGi - which is a good thing since before the meeting I couldn't even spell OSGi. Simon described OSGi as a fancy classloader that manages components of a java application. It's like Service Oriented Architecture within an application; you call components embedded in bundles and you only have to load them once.



Thanks to Georgina Chen for the pictures.

Wednesday, March 23, 2011

How to prevent NUnit from running some tests on the build server

Certain NUnit tests you only want to run on your local machine and some you only want to run on the build server. To make this easy NUnit offers the "Category" attribute.
[Test][Category("DoNotRunOnBuildServer")]
public void ReadFromLocalWebServiceTest()
{
    var qdbBrandHttpReader = new QdbBrandHttpReader();
    string xml = qdbBrandHttpReader.ReadFromLocalWebService();
    ...
}
On your build server, when you invoke NUnit console add the option "/exclude:DoNotRunOnBuildServer", then it will not even try to run these tests.
Typically this is used with a category like "LongRunningTests" to prevent tests from running on your local box.