using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Activation;
using Windows.UI.ApplicationSettings;
using Windows.ApplicationModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.ApplicationModel.Resources;
using Microsoft.Practices.Prism.StoreApps;
using Microsoft.Practices.Prism.Mvvm.Interfaces;
using Windows.Phone.UI.Input;
using Windows.Foundation.Metadata;
namespace Microsoft.Practices.Prism.Mvvm
{
public abstract class MvvmAppBase : Application
{
private bool _isRestoringFromTermination;
///
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
///
protected MvvmAppBase()
{
this.Suspending += OnSuspending;
}
///
/// Gets or sets the session state service.
///
///
/// The session state service.
///
protected ISessionStateService SessionStateService { get; set; }
///
/// Gets or sets the navigation service.
///
///
/// The navigation service.
///
protected INavigationService NavigationService { get; set; }
///
/// Factory for creating the ExtendedSplashScreen instance.
///
///
/// The Func that creates the ExtendedSplashScreen. It requires a SplashScreen parameter,
/// and must return a Page instance.
///
protected Func ExtendedSplashScreenFactory { get; set; }
///
/// Gets a value indicating whether the application is suspending.
///
///
/// true if the application is suspending; otherwise, false.
///
public bool IsSuspending { get; private set; }
///
/// Override this method with logic that will be performed after the application is initialized. For example, navigating to the application's home page.
///
/// The instance containing the event data.
protected abstract Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args);
///
/// Gets the type of the page based on a page token.
///
/// The page token.
/// The type of the page which corresponds to the specified token.
protected virtual Type GetPageType(string pageToken)
{
var assemblyQualifiedAppType = this.GetType().GetTypeInfo().AssemblyQualifiedName;
var pageNameWithParameter = assemblyQualifiedAppType.Replace(this.GetType().FullName, this.GetType().Namespace + ".Views.{0}Page");
var viewFullName = string.Format(CultureInfo.InvariantCulture, pageNameWithParameter, pageToken);
var viewType = Type.GetType(viewFullName);
if (viewType == null)
{
var resourceLoader = ResourceLoader.GetForCurrentView(PrismConstants.StoreAppsInfrastructureResourceMapId);
throw new ArgumentException(
string.Format(CultureInfo.InvariantCulture, resourceLoader.GetString("DefaultPageTypeLookupErrorMessage"), pageToken, this.GetType().Namespace + ".Views"),
"pageToken");
}
return viewType;
}
///
/// Used for setting up the list of known types for the SessionStateService, using the RegisterKnownType method.
///
protected virtual void OnRegisterKnownTypesForSerialization() { }
///
/// Override this method with the initialization logic of your application. Here you can initialize services, repositories, and so on.
///
/// The instance containing the event data.
protected virtual Task OnInitializeAsync(IActivatedEventArgs args)
{
return Task.FromResult