|
using System;
using System.ComponentModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PortableLibrary;
using PortableLibrary.Common;
using SilverlightClient.Common;
using SilverlightClient.Mapping;
namespace SilverlightClient.Core
{
public class ModelManager
{
#region SINGLETON
static ModelManager instance = null;
static readonly object padlock = new object();
public static ModelManager Instance
{
get
{
lock (padlock)
{
if (instance == null)
{
instance = new ModelManager();
}
return instance;
}
}
}
#endregion SINGLETON
private GlobalCache cache;
private LoginService.LoginClient loginServiceClient;
public ModelManager()
{
this.cache = new GlobalCache();
this.loginServiceClient = new LoginService.LoginClient();
}
public void Load(BaseViewModel viewModelContext, String operation, Array parameters)
{
switch (operation)
{
case OperationType.LOAD_USER:
if (null != cache.LoadProperty(CacheMapping.USER_CONTEXT))
{
viewModelContext.WriteProperty(MainViewModelMapping.USER_CONTEXT, cache.LoadProperty(CacheMapping.USER_CONTEXT), typeof(UserContext));
}
else
{
LoadForce(viewModelContext, operation, parameters);
}
break;
}
}
public void LoadForce(BaseViewModel viewModelContext, String operation, Array parameters)
{
switch (operation)
{
case OperationType.LOAD_USER:
UserLogin(viewModelContext, parameters);
break;
}
}
private void UserLogin(BaseViewModel viewModelContext, Array parameters)
{
String username = parameters.GetValue(0) as String;
String password = parameters.GetValue(1) as String;
loginServiceClient.UserLoginCompleted += (sender, e) =>
{
var uc = e.Result as UserContext;
cache.WriteProperty(CacheMapping.USER_CONTEXT, uc, typeof(UserContext));
viewModelContext.WriteProperty(MainViewModelMapping.USER_CONTEXT, uc, typeof(UserContext));
};
loginServiceClient.UserLoginAsync(username, password);
}
}
}
|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.