I have a bunch of metadata that I want to load before I render any pages (the page content depends on the meta data). Looking at the Application_Startup method in the App.xaml.cs I can see that there is the line of code
WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null);
This looks to be exactly what I want (the definition is:
public LoadUserOperation LoadUser(Action<LoadUserOperation> completeAction, object userState);
This method calls the "Action" when the operation is completed. How can I implement a similar approach for my LoadMetaData() method?
MetaDataClass
public static class MetaData
{
private static bool _modelEntitiesIsLoading;
private static TTASDomainContext _ttasContext;
static MetaData()
{
Initialize();
}
private static void Initialize()
{
_ttasContext = new TTASDomainContext();
}
public static void LoadData()
{
//Exit if currently loading, or there is no context
if (_modelEntitiesIsLoading || _ttasContext == null)
{
return;
}
_modelEntitiesIsLoading = true;
_ttasContext.ModelEntities.Clear();
var q = _ttasContext.GetModelEntityQuery();
_ttasContext.Load(_ttasContext.GetModelEntityQuery(), OnModelEntitiesLoaded, null);
}
private static void OnModelEntitiesLoaded(LoadOperation<ModelEntity> loadOperation)
{
if (loadOperation.Error != null)
{
//raise an event...
}
else
{
ModelEntities = loadOperation;
_modelEntitiesIsLoading = false;
}