Showing posts from January, 2013

When to Use the Builder Design Pattern

Have you ever looked back at old code you wrote and asked yourself, "Why did I do it that way?"  I do that quite a bit and found myself doing just that on the open source project VoiceModel that I coordinate and contribute to.  I think it is healthy to question your method of coding as it can lead to refactoring that makes the code easier to understand and maintain, to name just a few benefits of refactoring.

The section of code in question had to do with how states where created in a state machine.  VoiceModel has a built-in state machine that make it easy to build voice application call flows.  You add states to the state machine that represent actions like playing a prompt to the user or get input from the user from a telephone keypad or using speech recognition.  These states are specific to the voice part of the application, but you can also have states that perform background operations, such as a query a database.  The states that are used for voice needed to be wired…

Blogger Inserts XML Tags in Source Code Listing

I recently did a post on how to use SyntaxHighlighter in Blogger Dynamic Views.
Everything was working great except in some my posts I started seeing these strange closing XML tags. I would remove the tags and soon as I updated the post these phantom tags would return. I finally figured out what the problem was. It was happening in some of my C# listings and I noticed that the common item with each listing was that they were using C# Generics.  So if in my source code I had something like
List<myObject> , Blogger would insert a closing
</myObject> at the end of the source code. The solution was to go into the HTML editor and replace an opening bracket with &lt;.  So in the previous example the source code would be
List&lt;myObject>  Problem solved.

Architecture and Database Configuration for a Voice Enabled Survey Application

In a previous post I introduced a new example added to the VoiceModel Project that shows how to create a voice enabled survey application that allows customers to take a survey over the phone.  This sample project uses Entity Framework (EF) 5 as the ORM for persisting the survey meta-data and results.

This solution uses the code-first model where you define your entities as classes first. You will find the entities for this solution in the project Survey.Entities. This solution also uses the Repository Design Pattern to abstract EF to a higher level and allow for easy swapping to another ORM or a mock-up for unit testing.  You will find the code for the Repository in Survey.Repository.  This solution also uses the Fluent API to map the entities to the database schema; setting the primary and foreign keys, as well as the SQL types to store the entity properties in. You will find this configuration in Survey.Repository.ModelConfiguration. To handle transactions this solution uses the U…

Adding SyntaxHighlighter to Blogger Dynamic Views

This blog uses Blogger Dynamic Views and since I write a lot about software development I wanted a way to add nice formatting to the source code snippets.  I have used SyntaxHighlighter before and really liked the results. But I was having trouble getting it to work in Dynamic Views. So I did some research and came up with a decent solution.  It is a conglomeration of different approaches taken by different people that I found to be the simplest method for using SyntaxHighlighter with Dynamic Views.

To get started open up Blogger and select Templates.  Then select the Edit HTML button as shown in the following illustration.

In the dialog that opens find the closing head tag and insert this code just before it and save your changes.

<link href="" rel="stylesheet" type="text/css"/> <link href="" rel="stylesheet&q…

Seeding & Customizing ASP.NET MVC SimpleMembership

In ASP.NET MVC 4 Microsoft introduced a new membership provider that is referred to as SimpleMembership.  SimpleMembership makes it easier to customize user profiles and incorporates OAuth support.  I have seen a lot of questions on StackOverflow on how to customize SimpleMembership and seed it with data and in this post I will discuss some methods for achieving both .

SimpleMembership uses Entity Framework (EF) 5 and the code-first model. To initialize the database that contains the users and roles a filter is used called InitializeSimpleMembershipAttribute.  This attribute is decorated on the AccountController as shown here:

[Authorize] [InitializeSimpleMembership] public class AccountController : Controller { ... } This is setup this way so that the initialization code is only called when accessing the actions on the AccountController.  If you look at the code for InitializeSimpleMembershipAttribute you will see a lot of code to setup initialization which is basically there so…

VoiceModel Now Available on NuGet

VoiceModel is now available on NuGet, which is the recommended method for starting a VoiceModel project in Visual Studio.  NuGet handles all of the dependencies and if you follow these instruction you will have a working "Hello World" voice application as a starting point.

To install VoiceModel with NuGet just create an Empty MVC 4 project.  Remove the Global.asax file and remove App_Start\RouteConfig.cs file. Right click on References, select "Manage NuGet Packages...", and search for VoiceModel. Select the VoiceModel package and install. When installation is complete you will have a running "Hello World" example that will run on any VoiceXML compatible IVR and Tropo.

The reason for deleting the RouteConfig.cs and Global.asax file is that NuGet does not have an easy method for modifying existing source files yet.  If you do not delete these files you will have to modify them yourself to get the application to work.  The modifications are minor.  The Rout…

Creating a Survey Application with VoiceXML and Entity Framework

A new example has been added to the VoiceModel Project that shows how to create a flexible survey application.  Surveys are powerful tools for soliciting information from customers that can improve business.  Using a voice application over a telephone to perform the survey as another channel of communicating with your customers can be extremely beneficial to understanding what they think of a companies products and services. This survey application is very flexible in that that the survey configuration is stored in a database so that new surveys can be created and old ones modified without creating a new voice application call flow each time.  This the first in a series of posts that describes how the Survey Application is designed and areas of future work to make it even more robust and flexible.

The Survey Application uses Entity Framework (EF) version 5 for object-relational mapping (ORM) and uses the code-first model.  The code-first model allows you to define your objects/entitie…