- MigrateToMvvmMef-Part3_Src.zip
- MigrateToMvvmMef-Part3_Src
- _Assemblies
- GalaSoft.MvvmLight.SL5.dll
- System.Windows.Interactivity.dll
- AnotherXap.Models
- AnotherXap.ViewModels
- AnotherXap.Views
- ProductApp.Common
- Bin
- Release
- Constants
- EventArguments
- Models
- ModuleServices
- obj
- ProductApp.Common.csproj
- ProductApp.Common.csproj.user
- Properties
- SaveState
- ProductApp.Main
- ProductApp.Models
- ProductApp.sln
- ProductApp.suo
- ProductApp.ViewModels
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
- MigrateToMvvmMef-Part1_Src.zip
- MigrateToMvvmMef-Part1_Src
- ProductApp.Common
- ProductApp.Main
- ProductApp.sln
- ProductApp.suo
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
- MigrateToMvvmMef-Part2_Src.zip
- MigrateToMvvmMef-Part2_Src
- _Assemblies
- GalaSoft.MvvmLight.SL5.dll
- System.Windows.Interactivity.dll
- ProductApp.Common
- Bin
- Release
- Constants
- EventArguments
- Models
- ModuleServices
- obj
- ProductApp.Common.csproj
- ProductApp.Common.csproj.user
- Properties
- ProductApp.Main
- ProductApp.Models
- ProductApp.sln
- ProductApp.suo
- ProductApp.ViewModels
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
|
using System;
using System.Windows;
using System.ServiceModel.DomainServices.Client;
using ProductRiaLib.Web.Services;
namespace ProductApp.Common
{
public class DataAsyncHandlers
{
public static void LoadQueryAsync<T>(ProductDomainContext context, EntityQuery<T> qry, object sender,
EventHandler<QueryResultsArgs<T>> queryResultEvent) where T : Entity
{
// Execute the load and wait for the asyn operation to get the
// dataset back in the callback argument
context.Load(qry, LoadBehavior.RefreshCurrent, r =>
{
if (queryResultEvent != null)
{
try
{
if (r.HasError)
{
queryResultEvent(sender, new QueryResultsArgs<T>(r.Error));
r.MarkErrorAsHandled();
}
else
{
queryResultEvent(sender, new QueryResultsArgs<T>(r.Entities));
}
}
catch (Exception ex)
{
queryResultEvent(sender, new QueryResultsArgs<T>(ex));
}
}
}, null);
}
public static void SaveChangesAsync(ProductDomainContext context, object sender,
EventHandler<SubmitOperationArgs> saveChangesCompleteEvent)
{
// Execute the submission and wait for the asyn operation to get the
// status in the callback argument
context.SubmitChanges(s =>
{
if (saveChangesCompleteEvent != null)
{
try
{
Exception ex = null;
if (s.HasError)
{
ex = s.Error;
s.MarkErrorAsHandled();
}
saveChangesCompleteEvent(sender, new SubmitOperationArgs(s, ex));
}
catch (Exception ex)
{
saveChangesCompleteEvent(sender, new SubmitOperationArgs(ex));
}
}
}, null);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Shenwei is a software developer and architect, and has been working on business applications using Microsoft and Oracle technologies since 1996. He obtained Microsoft Certified Systems Engineer (MCSE) in 1998 and Microsoft Certified Solution Developer (MCSD) in 1999. He has experience in ASP.NET, C#, Visual Basic, Windows and Web Services, Silverlight, WPF, JavaScript/AJAX, HTML, SQL Server, and Oracle.