Hello,
I am fairly new to the MVVM model and need some help.
My application is called with a GUID on the querystring.
In my App.xaml.cs I gather the GUID, run a sub called SetupUserPrincipal with that guid. Inside that function I create object UserPrincipal.
My question is there a way to stop the system pre-bootstrapper to allow the userprincipal object to acquire the information? Or should I be doing something different?
Thanks
I am fairly new to the MVVM model and need some help.
My application is called with a GUID on the querystring.
In my App.xaml.cs I gather the GUID, run a sub called SetupUserPrincipal with that guid. Inside that function I create object UserPrincipal.
private void Application_Startup(object sender, StartupEventArgs e)
{
string val = HtmlPage.Document.QueryString["GUID"];
Bootstrapper bootStrapper = new Bootstrapper(this.SetupUserPrincipal(val));
bootStrapper.Run();
}
private UserPrincipal SetupUserPrincipal(string userid)
{
UserPrincipal principal = new UserPrincipal(userid);
return principal;
}
Inside of my UserPrincipal class, I set the GUID and then call a web service to see if that GUID is correct and if so, gather some more information out of it.public class UserPrincipal
{
private string _guid;
private Int32 _userID;
private DateTime _lastAccess;
public DateTime LastAccess
{
get { return this._lastAccess; }
}
public string GUID
{
get { return this._guid; }
}
public Int32 UserID
{
get { return this._userID; }
}
public UserPrincipal(string guid)
{
_guid = guid;
LoadUserInfo();
}
public void LoadUserInfo()
{
UserSecurityServiceClient service = new UserSecurityServiceClient();
service.GetUserByGUIDCompleted += new EventHandler<GetUserByGUIDCompletedEventArgs>(UserInfo);
service.GetUserByGUIDAsync(this._guid);
}
void UserInfo(object sender, GetUserByGUIDCompletedEventArgs e)
{
NSAMedia.VendorAutomation.Infrastructure.UserSecurityService.Users serviceResponse = e.Result;
for (int j = 0; j < serviceResponse.User.UserSecurity.Count; j++)
{
this._userID = serviceResponse.User.UserSecurity[j].userID;
this._lastAccess = serviceResponse.User.UserSecurity[j].lastAccess;
}
ServiceLocator.Current.GetInstance<IEventAggregator>().GetEvent<UserInitialized>().Publish(true);
}
}
Since I am in Silverlight, this is a async call. This means the call to run the bootstrapper and register my modules and even Register the Instance of my UserPrincipal object is called and loaded before my web service is called. public class Bootstrapper : UnityBootstrapper
{
UserPrincipal userPrincipal;
protected override DependencyObject CreateShell()
{
Shell rootShell = new Shell();
Application.Current.RootVisual = rootShell;
return rootShell;
}
protected override void ConfigureContainer()
{
Container.RegisterInstance(typeof(UserPrincipal), userPrincipal, new ContainerControlledLifetimeManager());
base.ConfigureContainer();
}
public Bootstrapper(UserPrincipal principal)
{
this.userPrincipal = principal;
}
protected override IModuleCatalog CreateModuleCatalog()
{
ModuleCatalog modules = new ModuleCatalog();
//modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.HelloWorld.HelloWorldModule));
modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.VendorDetail.VendorDetailModule));
modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.VendorSelection.VendorSelectionModule));
modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.ProductSelection.ProductSelectionModule));
modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.ProductDetails.ProductDetailsModule));
return modules;
}
}
At this point I wanted to use the UserPrincipal object in each of my Modules constructors to determine if they have the ability to access the page or items on the page. public VendorSelectionViewModel(IVendorSelectionView view, IEventAggregator eventAggregator, User user)
{
View = view;
View.Model = this;
_user = user;
//this.HeaderInfo = "Hello World";
this.VendorList = new ObservableCollection<NSAMedia.VendorAutomation.Infrastructure.Model.VendorModel>();
this.eventAggregator = eventAggregator;
//this.eventAggregator.GetEvent<UserInitialized>().Subscribe(this.checkUser);
try
{
this.LoadVendors();
}
catch
{
// log service faults
//this.AddError("Failed to set up data for Specialties, please see the event log for more details!");
}
}
Because of the async call, my user object that was Registered has none of the information populated from my web service call.My question is there a way to stop the system pre-bootstrapper to allow the userprincipal object to acquire the information? Or should I be doing something different?
Thanks