It's been 28 months since I last updated my blog, many more since my last decent programming content. When I took this job with Microsoft, I knew there would be limits to what I can blog about and the safe bet was to not talk about software publically.

At the same time, I found that I wanted an online location to be able to publish long-form content targetting my friends, co-workers, and fellow enthusiasts. This is that location.

I am looking into writing a sales order imported form scratch for Interprise and wanted to see how it works from a fundamentals point of view. The following describes how to programmatically read data from a remote Interprise server using just DLLs and code.

This does not require the SDK or Interprise Plug-In Guidance module.

Creating the console project

I am using Visual Studio 2010, go File –> New Project

Right-click on the project, select Properties and change the Target Framework from “.NET Framework 4 Client Profile” to “.NET Framework 4” and close the window.

Adding References

Add the following references to the project. I am not sure they are all required, but I needed each of them at some point during my troubleshooting, so why not.

From the GAC (I.E. just in the list)

System.Configuration

From C:\Program Files (x86)\Interprise Solutions\Interprise Suite 6.0

Interprise.Business.Base

Interprise.Business.Customer

Interprise.Connectivity.Database.Configuration.Design

Interprise.Extendable.Base

Interprise.Extendable.Customer

Interprise.Facade.Base

Interprise.Facade.Customer

Interprise.Facade.Utility

Interprise.Framework.Base

Interprise.Framework.Customer

Interprise.Licensing.Base

Microsoft.Practices.EnterpriseLibrary.Caching

Microsoft.Practices.EnterpriseLibrary.Common

Microsoft.Practices.EnterpriseLibrary.Data

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling

Microsoft.Practices.EnterpriseLibrary.Logging

Microsoft.Web.Services3

Finally, Add the following to the top of your Program.cs:

using Interprise.Facade.Base; using Interprise.Facade.Customer; using Interprise.Framework.Base.Shared; using Interprise.Framework.Customer.DatasetGateway;

Configuration and Sign-in

This logic signs into Interprise using the information in your project’s app.config file. The process looks like this (as far as I can tell):

Look for a cached executible config

If that is not found, copy the current config file to the cache directory

Load the values

Sign-in

I want to call out a note on the cache. The directory where the cache happens is : C:\ProgramData\Interprise Suite\1.0.0.0\Debug (with the version being your application’s version). It is important to note that if you make changes to your app.config, you must delete the cached version of the file.

As for what to put in your app.config file, you can use the AppConfig tool included with Interprise. Or you can steal it out of the current cached copy (C:\ProgramData\Interprise Suite\6.0.6.10\Interprise Suite 6.0\InterpriseSuite.exe.config) and paste it into your app.config.

Troubleshooting: Add the following line of code before the sign-in:

var MyConfig = InterpriseConfiguration.Instance;

using a breakpoint, inspect the values in MyConfig for sanity. If they are not what you would expect, something is wrong with your config file.

Getting Some Data

Now for the big moment, getting some data. Add the following method to Program.cs:

So the first step, loading your dataset and façade is pretty simple and there is not that much logic here.

The next step is to have the façade load the desired rows from the database into the data set. The Commands variable tells it what table and stored procedures to use. I don’t yet know a good way to look these up, so be prepared to get REALLY good at using SQL Server Management Studio (SSMS). Once you have the stored procedure, you can add the required params. Again, use SSMS to look these up.

Finally, we call LoadDataSet to populate the database and view the result. Simple.

So, you enjoy the MVVM pattern for your Silverlight or Windows Phone 7 application, but you can't figure out how to perform your navigation from your ViewModel? Here is a guide that allows you to do this from your ViewModel:

// Option 1

GotoProductCatalogCommand = newRelayCommand(

() => Navigate("/Views/ProductCatalogPage.xaml"));

// Option 2, now without strings!

GotoProductCatalogCommand = newRelayCommand(

() => Navigate<ProductCatalogPageViewModel>());

The first option allows you to give a URI to navigate to, just like you would expect, but option two allows your application to navigate based on convention. Never miss-type a URI again!

All you have to do is add the following to your ViewModel base class or MVVM Light’s ViewModelBase:

publicvoid Navigate<T>()

{

var UriFragment = String.Format(@"/Views/{0}.xaml"

, typeof(T).Name.Replace("ViewModel", ""));

Navigate(UriFragment);

}

publicvoid Navigate(String uriFragment)

{

var MyFrame = Application.Current.RootVisual asFrame;

MyFrame.Navigate(newUri(uriFragment, UriKind.Relative));

}

publicvoid GoBack()

{

(Application.Current.RootVisual asFrame).GoBack();

}

Notice that my ‘convention’ for Views is to basically take the type name of your ViewModel, remove the string “ViewModel” and look up the file in the “/Views” directory. Obviously you can move to a more comprehensive convention as your needs require.

I am a fan of keeping strings out of my .NET Applications. In the past I used CSLA and enjoyed the way it loaded properties and change notification without using strings. Because why work now-a-days is all about creating samples, I use MVVM Light instead.

For those who don’t understand the what I am talking about, take a look at this example: