There was a gutter in my window and it was mocking me and so I squashed it.
Contents tagged with C#
-
GridView and Gutter Squash
-
Web API Routing by Content-Type
Implementing a custom Route Attribute for Web API that considers Content-Type. This allows for routing based on the data encoding being supplied by the HTTP Request, not just the path and parameters it was sent to.
-
Getting Started with the Speech Server 2007 API
Speech Server 2007 has a really cool Windows Workflow based programming model that lets you quickly build interactive voice response applications. For many applications it is all you will ever need.
Sometimes however you find the workflow model just isn't the right fit. If you're looking for really fine-grained control over the application, or you simply prefer to work in code, then the Core API is what you need.
Unfortunately figuring out you want to use the API is a lot easier than figuring out how to start using it. There is very little documentation and no Visual Studio project templates or samples included with Speech Server.
I'll do my best to give a brick-simple explanation of how to get your first core API project started. You can also download the zipped project files.
1) First you'll need to create a new Voice Response Workflow Application. We'll use the project that gets generated as our foundation.
2) When asked for the application resources you'll want to uncheck everything.
3) Open up the Class1.cs file and remove all of the references to the VoiceResponseWorkflow1 class. The resulting class should look like the following (I removed the comments in the code for brevity):
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SpeechServer ;
using Microsoft.SpeechServer.Dialog;namespace VoiceResponseWorkflowApplication1
{
public class Class1 : IHostedSpeechApplication
{
private IApplicationHost _host;public void Start(IApplicationHost host)
{
if (host != null)
{
_host = host;
_host.TelephonySession.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
}
else
{
throw new ArgumentNullException("host");
}
}
public void Stop(bool immediate)
{
}public void OnUnhandledException(Exception exception)
{
if (exception != null)
{
_host.TelephonySession.LoggingManager.LogApplicationError(100, "An unexpected exception occurred: {0}", exception.Message);
}
else
{
_host.TelephonySession.LoggingManager.LogApplicationError(100, "An unknown exception occurred: {0}", System.Environment.StackTrace);
}_host.OnCompleted();
}
}
}That's all folks. Class1.cs is now the starting point of your Core API application. As a further example, lets take the project and add some code to turn it into an outbound dialing "Hello World" application.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SpeechServer ;
using Microsoft.SpeechServer.Dialog;namespace VoiceResponseWorkflowApplication1
{
public class Class1 : IHostedSpeechApplication
{
private IApplicationHost _host;public void Start(IApplicationHost host)
{
if (host != null)
{
_host = host;
_host.TelephonySession.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
// Dial and outbound call (make sure you change these numbers :-)
_host.TelephonySession.OpenCompleted += new EventHandler<AsyncCompletedEventArgs>(TelephonySession_OpenCompleted);
_host.TelephonySession.OpenAsync("7813062200", "8887006263");
}
else
{
throw new ArgumentNullException("host");
}
}void TelephonySession_OpenCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
_host.TelephonySession.Close();
}
else
{
_host.TelephonySession.Synthesizer.SpeakCompleted += new EventHandler<Microsoft.SpeechServer.Synthesis.SpeakCompletedEventArgs>(Synthesizer_SpeakCompleted);
_host.TelephonySession.Synthesizer.SpeakAsync("Hello World", Microsoft.SpeechServer.Synthesis.SynthesisTextFormat.PlainText);
}
}void Synthesizer_SpeakCompleted(object sender, Microsoft.SpeechServer.Synthesis.SpeakCompletedEventArgs e)
{
_host.TelephonySession.Close();
}
public void Stop(bool immediate)
{
}public void OnUnhandledException(Exception exception)
{
if (exception != null)
{
_host.TelephonySession.LoggingManager.LogApplicationError(100, "An unexpected exception occurred: {0}", exception.Message);
}
else
{
_host.TelephonySession.LoggingManager.LogApplicationError(100, "An unknown exception occurred: {0}", System.Environment.StackTrace);
}_host.OnCompleted();
}
}
} -
Outlook 2003 Add-in with Visual Studio 2005?
Thinking of building an add-in for Outlook 2003 with Visual Studio 2005? Don't do it. Really, don't do it. What? Ok, if you must...
I've just spend the last three days building an add-in and installing on on a single PC. This totaled about 3 hours of development time and the rest was getting the darn thing to load! Honestly, it was the single most frustrating thing I've ever encountered in years.
The problem was that the setup program that Visual Studio 2005 automatically generates when you create an add-in project doesn't include everything you need.
Here is how I fixed the problem:
Before you can load your add-in you need to make sure the following is installed:
- Visual Studio 2005 Tools for Office Second Edition Runtime (found at http://shrinkster.com/mnh)
- Office 2003 Update: Redistributable Primary Interop Assemblies (found at http://shrinkster.com/mni)
After that you'll need to "fully trust" your assemblies. This can only be done with signed assemblies. I remember being a pain with VS 2003 but turns out is a breeze with VS 2005. Just open up the Properties for the project and select the Signing tab. From there is was fairly self explanatory.
Now comes the part that gave me problems. After you have everything installed (including your nice newly signed assemblies) you need to give permission to those assemblies. This is done using a tool called CASPOL.EXE. Here is the command line for registering your file:
caspol -u -ag All_Code -url "<full path to your file>" FullTrust -n "<assembly name>"
If you have more than one file (or the above didn't work) you can also do this for a directory.
caspol -u -ag All_Code -url "<directory path>\*" FullTrust
I hope this helps save someone from the pain I experienced over the last few days. Hopefully this will get easier with the next release of Visual Studio...
Updated to reference Outlook 2003. I wasn't clear about that in the original post.