Tuesday, July 24, 2012

Disconnected WPF Applications

I was recently tasked with presenting a plan to turn an existing WinForms program into an enterprise level application. They wanted to stick with a Windows client, but since each form would already need significant rework to extract the business logic, I suggested moving to WPF using the Model-View-ViewModel (MVVM) presentation pattern.

MVVM is basically a type of Model-View-Presenter (MVP) pattern that makes use of declarative bindings. State and logic are stored in the Presenter (ViewModel) which presents an abstract view of the UI with no knowledge of what View will implement it.

With the Presentation Layer taken care of, it was time to address the heart of the Application. The immediate need was for a smart client, however the solution was still very young and continually changing so it seemed a Service Oriented Architecture (SOA) would provide the most flexability and reuse. The question was how a disconnected client would use services.

Microsoft used to offer an application block for this specific purpose. The Disconnected Service Agent Application Block helped maintain a queue of web service requests while working disconnected (offline), then submit them to the server when it became available. Unfortunately, it is no longer being maintained and I have not found a suggested replacement. My guess is that they would encourage use of Sync Framework, which is designed to synchronize databases and files, but can use custom providers as well.

We're using Sync Framework to replicate data down to the client for offline use, but to utilize SOA and keep business logic/validation on the server we need a way of queuing web service calls and resolving any conflicts that occur. I'm currently in the process of researching whether a Sync Framework custom provider would be a good fit or if the old disconnected service agent application block would be a good starting point.

The existing relies very heavily on SQL stored procedures. Fortunately, Entity Framework (EF4) supports calling the existing stored procedures so they wont all have to be rewritten immediately. The plan is to gradually move business logic up into the application layer and use entity model. I've also added a generic repository to allow mocking.

I welcome feedback and suggestions. If you've tinkered with custom providers for Sync Framework or have suggestions for how to best queue and resolve service calls I'd love to hear from you, either by leaving a comment below or on twitter (@gainesk).

Thursday, July 19, 2012

Water pressure issues? Let it flow!

Most of my articles are about technology and software development, however I recently purchased a new home and, as I worked on various things around the house I realized others might benefit from a few of the more common issues I've addressed. Some of these problems might seem simple to fix, however I figure there are others like me who are learning these things for the first time and might find my experiences helpful.

Problem: Water pressure is fine at first, but within a few seconds flow decreases significantly. The hot water never gets beyond warm, but both hot and cold suffer from the same decreased flow.

Diagnosis: It's important to distinguish between water pressure and volume. Low water pressure results in a lower flow as soon as valve is opened. This can result from undersized pipes or the use of valves/connections that reduce flow as well as simply receiving low pressure from the source. A volume issue results from some restriction farther down the line that allows a higher pressure to build over time, but once that pressure is released (such as in the first few seconds of running water) then the pressurized volume is exhausted and flow is limited by the restriction. If both hot and cold lines suffer from the same symptoms then the problem most likely exists on the main water line before the water heater.

Solution: Every situation is different, but in my case I found that the main cutoff valve at the meter box was not completely open. One and a half turns more and the restriction was gone restoring full flow to the house.

If you've run into a similar problem I'd love to hear about it. Comments are appreciated and you can find me on twitter (@gainesk).

Friday, June 8, 2012

Should Internet Access be a Right?

Internet access has become a mainstay of our society and arguably more important to staying informed and the ability to make a living than phone or television. It's something that can be taken for granted when living in a densely populated city, but many rural areas are left with spotty or non-existent broadband service. For software developers in particular this can make working remotely and offering after-hours support difficult or even impossible.

I'm all for capitalism and a competitive market and I understand that most utility/service companies are out to make a profit so providing service to new areas is something they have to consider carefully, however when it comes to regional services these companies often have a monopoly that discourages new competitors and leaves residents with limited choices, and sometimes no choice at all. That's one reason why companies are often required to sign franchise agreements with city, county or state where they agree to provide a certain level of service in exchange for their territory.

For example, Comcast signed a franchise agreement with Franklin County (TN) which states they will, "provide Cable Service to every dwelling unit wtihin the Franchise Area reaching the minimum density of at least twenty-five (25) dwelling units per mile". To put this in perspective, if you split one square mile up into equal lots then each resident would have approximately 25 acres. This means that they have committed to providing service to all but the most rural and sparsely populated areas.

One important point regarding this agreement is that it only addresses Cable Service, which is defined as, "(A) the one-way transmission to Customers of (i) video programming, or (ii) other programming service, and (B) Customer interaction, if any, which is required fo rthe selection or use of such video programming or other programming service." While it makes sense they would offer additional services once the company has invested in running lines out to new areas, they have no commitment to providing internet access.

Does the area you live in have a franchise agreement with local internet service providers? Do you think that internet access is something they should be required to provide to residents or is it a luxury?

Tuesday, May 15, 2012

Using ODAC with EF4 via WCF

Oracle Data Access Components (ODAC) 11.2 Release 4 (11.2.0.3.0) with Oracle Developer Tools for Visual Studio includes support for Entity Framework and LINQ. Implementation is simple, however when I called the query from a WCF service I got the error:

System.ArgumentException was unhandled by user code
  Message=The specified store provider cannot be found in the configuration, or is not valid.
  Source=System.Data.Entity
  StackTrace:
       at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
       at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
       at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
       ...
  InnerException: System.ArgumentException
       Message=Unable to find the requested .Net Framework Data Provider.  It may not be installed.

A bit of research discovered that 32-Bit Applications are disabled by default in the IIS Application Pool. As soon as I changed Enable 32-Bit Applications to True everything worked fine.


Tuesday, May 8, 2012

Testing the Untestable with VS2012 Fakes

One of the new features included with Visual Studio 2012 is the Fakes Framework which offers the ability to detour code at runtime and isolate functionality for true unit testing, regardless of whether the code was written with testing in mind.

I began speaking on Fakes back when it was a beta product from Microsoft Research called Moles. While the core functionality remains the same, Microsoft has streamlined the implementation and now calls the detour mechanism a shim rather than a mole.

If you have attended this or another of my talks at a user group or conference, please take a moment to share your feedback on SpeakerRate.

The PowerPoint is available on SlideShare and below are links to the code demonstrated in the presentation.

Demos
Y2K Checker (simple introduction)
DateTime Audit (avoiding non-deterministic tests)
File Reader (shimming file system access)
Repository (stubbing interfaces)

Resources
Visual Studio 2011
Fakes MSDN Documentation

Friday, March 16, 2012

Ignite Talk on Gaming

I signed up to give an Ignite talk this evening on why everyone should play games. For anyone who's not familiar with Ignite talks, presenters share a personal or professional passion, using 20 slides that auto-advance every 15 seconds for a total of five minutes.

My slides can be found on my SlideShare profile:
http://www.slideshare.net/gaines/ignite-reasons-to-play-games

If you attended one of my talks, please feel free to provide feedback at SpeakerRate:
http://speakerrate.com/gaines