Archive for the ‘Uncategorized’ Category

Microsoft Earns Freemind Certified Pardner Status for 2010

pardner.pngEAGAN, MN – Freemind Solutions is proud to announce that it has conveyed its “Certified Pardner” status upon the upstart software company, Microsoft Corporation. Microsoft, with its primary offices located in Redmond, Washington, has submitted three products to Freemind for its use and analysis. The results of arduous selection and review process has deemed Microsoft worthy of the status of “Certified Pardner” for 2010.

A media representative for Microsoft has likely contacted Freemind Solutions to thank them for this honor and to express the desire for Freemind’s coveted “Gold Pardner Status” for 2011. “It’s a solid goal for a rather plucky outfit,” said James Swanson, one of the principals at Freemind Solutions on Microsoft’s 2011 ambitions. Ira Mitchell, another principal at the firm chimed in, “I think they’ve got a shot at it, but it won’t be because of Expression Studio or IE8.”

“I’m thinking that they probably shouldn’t submit the Entity Framework either,” said Swanson, “but that new Visual Studio and what they’re doing with Azure could be enough to put them over the top. It’s early though, we’ll have to take a closer look later next year.”

Congratulations to Microsoft Corporation for this momentous achievement! The lucite plaque is in the mail.


In related news, Freemind Solutions has qualified as a Microsoft Certified Partner for the third consecutive year.





About the companies:

Microsoft Corporation is a multinational computer technology corporation that develops, manufactures, licenses, and supports a wide range of software products for computing devices.

Freemind Solutions, an Eagan, Minnesota corporation is a highly regarded professional services firm. Their client background includes litigation support, finance, government services, commercial and retail. For more information, please contact them at (612) 424-9699 or my emailing them at info@freemind.net.

A number of writers contributed to this release.

© 2009 The Freemind Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed. Learn more about our Privacy Policy.

WCF REST Starter Kit to Constant Contact Sample Application

I’ve had a few requests to get more details on how I used the WCF REST Starter Kit to integrate with the Constant Contact AtomPub API (posted here). It’s shamefully simple but here it is. If you are not satisfied I will give you your money back.

Requires:

Download Sample App

Notes:

  • Update the app.config with your account settings from Constant Contact.
  • Sample is using Http Digest for authentication. If there is interest I can update for OAuth.
using System;
using System.Configuration;
using System.Collections.Generic;
using Freemind.Domain.Email;

namespace Freemind.ConstantContactSample
{
   class Program
   {
      static void Main(string[] args)
      {
         try
         {
            Console.WriteLine("Begin loading Contact Lists");

            // Connect and list Contact Lists
            ContactListProvider provider = new ContactListProvider(
               ConfigurationManager.AppSettings["ConstantContactAccountName"],
               ConfigurationManager.AppSettings["ConstantContactPassword"]);

            List lists = provider.GetContactLists();

            if (lists != null)
            {
               foreach (ContactList list in lists)
               {
                  Console.WriteLine("  list:{0} id:{1}", list.Name, list.id);
               }
            }

            Console.WriteLine("Completed loading Contact Lists");
            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
         }
         catch (Exception ex)
         {
            Console.WriteLine("Error: {0}",ex.Message);
         }
      }
   }
}

Using WCF REST Starter Kit to Access Constant Contact API

Problem: Allow customers to sign up for email newsletters and synchronize those accounts with Constant Contact.

Constant Contact is a company that provides Email Marketing services. You can use their editor to create nice looking emails and then configure a list of contacts. Constant Contact handles all the email sending, bounces, and unsubscribe activities. They also provide excellent reporting features to track how many people actually view your emails or click on the contained links.

The nice folks at Constant Contact provide a set of web services for accessing account data. These interfaces are implemented as REST services utilizing the Atom Publication Protocol (AtomPub) and Atom Syndication Format. At first it might seem odd to be accessing data objects via a blogging protocol but it actually works quite naturally. So well that Google’s GData and Microsoft’s ADO.NET Data Services also support this technique.

Writing all the HTTP, Auth, and XML parsing code can be a real drag. Luckily Microsoft is releasing a WCF REST Starter Kit. From the CodePlex summary:

The WCF REST Starter Kit is a set of .Net Framework classes and Visual Studio features and templates that enable users to create and access REST-style Windows Communication Foundation (WCF) services. These services are based on the WCF web programming model available in .Net 3.5 SP1. The starter kit also contains the full source code for all features, detailed code samples, and unit tests.

This starter kit makes accessing the Constant Contact API quite simple. Call GetEntry or GetFeed with a URI and get back a SyndicationItem or SyndicationFeed (collection of items). Similar methods exist for adding and updating data (AddEntry and UpdateEntry).

The following is one method from my ContactListProvider class:

public ContactList GetContactList(string id)
{
   AtomPubClient client = new AtomPubClient();
   client.TransportSettings.Credentials = GetLoginCredentials();

   // Place in a try block to ensure that any errors are caught
   try
   {
      SyndicationItem item = client.GetEntry(new Uri(id));

      ContactList list = new ContactList(item.Content as XmlSyndicationContent);

      return list;
   }
   catch (WebException ex)
   {
      _log.Error("WebException: " + ex.Status + " " + ex.Message, ex);
      return null;
   }
   catch (Exception ex)
   {
      // Get the exception type
      _log.Error("Exception: " + ex.Message, ex);
      return null;
   }
}

Contact me via comments if you want a copy of all the providers.

How to convert UPC-A to zero-compressed UPC-E

Universal Product Codes (UPCs) should be a very straight-forward topic. You give a product a number and that is the end of the story. Unfortunately it turns out to be a bit more complicated than that.

There is a great (well I guess that’s subjective) page on Wikipedia that does an excellent job explaining all the variations: Universal Product Codes. There are 14, 13, 12, 11, 10, 8, and 6 digit types of UPCs. There is also an interesting algorithm to convert from a fairly standard 12-digit UPC-A code into a zero-compressed UPC-E. This is a most uninteresting fact. Until the day comes when you actually have to convert some of these codes.

Here is some C# code to:

  • Convert UPC-A codes to UPC-E
  • Convert UPC-E codes to UPC-A
  • Calculate check digits

If google brought you here because you need these conversions then bask is it’s yucky goodness! If not, then just move right along (basically it’s a cup with dirt in it).

public string ConvertUPCAToUPCE(string UPCa)
{
   string UPCe = "";

   //Must be 12 digits
   if (UPCa.Length != 12)
   {
      return "";
   }

   string mfg = UPCa.Substring( 1, 5);
   string prod = UPCa.Substring(6, 5);

   if ((mfg.Substring(2) == "000") || (mfg.Substring(2) == "100") ||(mfg.Substring(2) == "200") )
   {
   //  0            XXNNN0  0XX000-00NNN + check
   //  1            XXNNN1  0XX100-00NNN + check
   //  2            XXNNN2  0XX200-00NNN + check
      UPCe = mfg.Substring(0, 2) + prod.Substring(2, 3) + mfg.Substring(2, 1);
   }
   else if (mfg.Substring(3,2) == "00")  
   {
   //  3            XXXNN3  0XXX00-000NN + check
      UPCe = mfg.Substring(0,3) + prod.Substring(3,2) + "3";
   }
   else if (mfg.Substring(4, 1) == "0")
   {
   //  4            XXXXN4  0XXXX0-0000N + check
      UPCe = mfg.Substring(0, 4) + prod.Substring(4,1) + "4";
   }
   else
   {
   //  5            XXXXX5  0XXXXX-00005 + check
   //  6            XXXXX6  0XXXXX-00006 + check
   //  7            XXXXX7  0XXXXX-00007 + check
   //  8            XXXXX8  0XXXXX-00008 + check
   //  9            XXXXX9  0XXXXX-00009 + check
      UPCe = mfg + prod.Substring(4);
   }

   return UPCe;
}

public string ConvertUPCEToUPCA(string UPCe)
{
   //Must be 12 digits
   if (UPCe.Length != 6)
   {
      return "";
   }

   string mfg = "";
   string prod = "";

   switch (UPCe.Substring(5, 1))
   {
      case "0":
         mfg = "0" + UPCe.Substring(0, 2) + "000";
         prod = "00" + UPCe.Substring(2, 3);
         break;

      case "1":
         mfg = "0" + UPCe.Substring(0, 2) + "100";
         prod = "00" + UPCe.Substring(2, 3);
         break;

      case "2":
         mfg = "0" + UPCe.Substring(0, 2) + "200";
         prod = "00" + UPCe.Substring(2, 3);
         break;

      case "3":
         mfg = "0" + UPCe.Substring(0, 3) + "00";
         prod = "000" + UPCe.Substring(3, 2);
         break;

      case "4":
         mfg = "0" + UPCe.Substring(0, 4) + "0";
         prod = "0000" + UPCe.Substring(4, 1);
         break;

      default:
         mfg = "0" + UPCe.Substring(0, 5);
         prod = "0000" + UPCe.Substring(5, 1);
         break;
      }

   return mfg + prod + CalculateCheckDigit(mfg + prod);
}

//In the UPC-A system, the check digit is calculated as follows:
//
//  1. Add the digits in the odd-numbered positions (first, third, fifth, etc.) together and multiply by three.
//  2. Add the digits in the even-numbered positions (second, fourth, sixth, etc.) to the result.
//  3. Find the result modulo 10 (i.e. the remainder when the result is divided by 10).
//  4. If the result is not zero, subtract the result from ten.
//
private string CalculateCheckDigit(string upc)
{
   int check = 0;
   char[] chars = upc.ToCharArray();

   // process string from right to left
   Array.Reverse(chars);

   for (int i =0;i<chars.Length;i++)
   {
      if ((i % 2)!= 0)
      {
         // even
         check += int.Parse(chars[i].ToString());
      }
      else
      {
         // odd
         check += (3 * int.Parse(chars[i].ToString()));
      }
   }

   check = check % 10;

   if (check != 0)
   {
      check = 10 - check;
   }

   return check.ToString();
}

Update: CheckDigit right to left processing.

Beware of Windows Server 2008 Network Optimization

Problem:

Recently I was migrating some Windows Server 2003 applications to new hardware and Windows Server 2008. The applications were mostly simple ASP.NET applications using either NHibernate or ADO.NET to communicate to a Windows Server 2003 x64 box running Sql Server 2005sp3.

Each of the new Win2k8 machines were having performance issue retrieving data from the database. After firing up Sql Profiler I was able to see that executing a simple statement like “SELECT * FROM Store” was taking over 5sec to return 40 rows. The slowness was the same in both ADO.NET and NHibernate apps. More research from that the WinForms apps running as admin were having the same issues. And executing the queries in SSMS showed same behavior.

So Win2k3 servers talking to the same database are running fast. Blowing my mind I found that using the Win2k8 servers to connect to a different Sql Server 2005sp2 on 32bit runs just fine (no delays). That’s right I can load the data onto a different server and see no delays!

If you are reading this you might be starting to form some theories. Both the Win2k3 and Win2k8 servers are on the same subnet.

At this point I requested help from the smart support guys from Microsoft. We verified that the Sql execution plans were not changing. We also verified the network settings on the database, Win2k3, and Win2k8 servers.

Next step netmon. After capturing and reviewing the netnom logs we were able to see that there were packets getting fragmented and there were long delays in sending the secondary packets. There are many newer features in Win2k8 to optimize the network performance (receive side scaling, tcp chimney offload, network direct memory access, and autotuning). Learn more here: http://support.microsoft.com/kb/951037

Root Cause:

In my situation the autotuning feature was trying to adjust the tcp receive window (RWIN) and was timing out waiting for an acknowledgment from the database server. It is possible that the router was holding onto the response packet, I wasn’t able to completely correlate all the send/receives.

Learn more about RWIN behavior here: http://www.nerdgrind.com/speed-up-windows-vista-network-performance-with-tcp-windows-tuning/2/

Resolution:

It is possible that we could have reconfigured the router to increase the frame sizes to prevent the packet fragmentation. It is also possible that change could have hidden the delays

The way I choose to resolve the issue was to turn off the autotuning with the following statement:

netsh interface tcp set global autotuning=disabled

Some network card drivers have the ability to control this setting via the advanced properties.

Why the hell am I still forced to type runat=”server” after all these years?

We’ve all seen the Microsoft guys stumble over this time and time again in demos. Why are we still forced to add this? I mean, if it’s a server control (the control starts with “<asp:”) it should be assumed — or added automatically by the Visual Studio IDE. What is this, the fourth version of Visual Studio for .NET?

Why is runat=”server” not the default condition?

Minnebar 2008

Jim and I went to Minnebar this morning at Coffman Union on the campus of the University of Minnesota — 398 geeks and us. We hit three sessions and then went to the “State of the State” panel discussion with Jamie Thingelstad (former Dow Jones), Robert Stephens (Geek Squad), Dan Grigsby (Unpossible), Matthew Downquast (Crashplan), Douglas Olson (Microsoft), and Michael Gorman (Split Rock Partners).

They’re all really smart guys who are uniquely qualified to speak on the state of software in Minnesota, even if they did contradict themselves on one key point. They were all in agreement that Minnesota is a great place to build a development team — that it has a great community of developers and that our Midwestern work-ethic and loyalty are things that contribute to that, that we tend to be more thoughtful and risk-adverse. Only moments later, talk shifted to the need for developers as entrepreneurs to take the chances to start the next start-ups. Apparently our weakness needs to be our strength. All that considered, I could have listened to these guys for two or three hours.

It’s been many years since I first sat in a room listening to Robert Stephens talk about geek squad — back when they had the place in the Warehouse district. If you ever get a chance to hear him speak, take it. Actually, if you ever get a chance to hang out with any of these guys and listen to them, drop what you’re doing and make it happen.

One more point that hit home with me is that the University of Minnesota is a great school, but that it’s our duty collectively to do what we can to improve the state of the Computer Science and Business programs through mentoring, offering internships and with our wallets.

It’s amazing how prevalent the Rails stuff has gotten. Every session we attended had a Rails tie-in it seemed. Open-source is the buzzword with the development community to be sure. Everyone is looking to maximize the dollars spent on tools with the excellent free offerings.

All in all, I wish I had been able to stay for the entire event, but holding the whole Mother’s Day weekend thing (and my mom’s birthday) threw a monkey wrench into the works.

Good stuff. Thanks to Ben and all who helped organize this thing.