using pre & post images

using System.Collections.Generic;
//# CRM 2011: Using PRe & Post Images
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.ServiceModel;

namespace TestCompany.CRM.Plugin
{

public class officeUpdate : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context;
IOrganizationServiceFactory factory;
IOrganizationService service;
Entity PreImage;
Entity PostImage;

try
{
context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
service = factory.CreateOrganizationService(context.UserId);

PreImage = (Entity)context.PreEntityImages["PreUpdateImage"];
PostImage = (Entity)context.PostEntityImages["PostUpdateImage"];

int _preOfficestatusVal = 0;
int _postOfficestatusVal = 0;

if (PreImage.Contains("new_officestatus"))
{
_preOfficestatusVal = ((OptionSetValue)PreImage["new_officestatus"]).Value;
}

if (PostImage.Contains("new_officestatus"))
{
_postOfficestatusVal = ((OptionSetValue)PostImage["new_officestatus"]).Value;
}

if ((_preOfficestatusVal == 100000002) && (_postOfficestatusVal == 100000001))
{

// Logic for - Sub converted to Regional

}

}
catch (FaultException e)
{
throw e;
}
finally
{
service = null;
factory = null;
context = null;
PreImage = null;
PostImage = null;
}
}
}
}