public async Task AppInit(Frame rootFrame, LaunchActivatedEventArgs args)
{
if (args == null) return;
_args = args;
_rootFrame = rootFrame;
// if network connection is not available, navigate to NetworkConnectivityPage
await Task.FromResult(CheckNetworkAvailability());
if (!IsNetworkConnectionAvaliable)
{
if (!rootFrame.Navigate(typeof(NetworkConnectivityPage), args.Arguments))
{
throw new Exception("Failed to navigate to network connectivity page");
}
}
if (rootFrame.Content == null || IsNetworkConnectionAvaliable)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation parameter
// initialize static properties
App.OrganizationUrl = GetKeyValueFromResources("OrganizationUrl").ToLower();
App.PortalUri = new UriBuilder(string.Format(App.SharingRest, App.OrganizationUrl));
App.AppServerId = GetKeyValueFromResources("AppServerId");
App.AppRedirectUri = GetKeyValueFromResources("AppRedirectUri");
App.IsOrgOAuth2 = !string.IsNullOrEmpty(App.AppServerId) && !string.IsNullOrEmpty(App.AppRedirectUri);
// if credentials were persisted or anonymous access is enabled navigate to main page.
if (App.SignInVM.IsCredentialsPersisted) // || SignInVM.IsAnonymousAccessEnabledAsync())
{
if (!(rootFrame.Content is MainPage))
{
if (!rootFrame.Navigate(typeof (MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// try signing in
await App.SignInVM.TrySigningInAsync();
}
else
{
// if Anonymous access is enabled also navigate to main page
bool b = await App.SignInVM.GetAnonymousAccessStatusAsync();
if (b)
{
if (!(rootFrame.Content is MainPage))
{
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// try signing in anonymously
await App.SignInVM.SignInAnonymouslyAsync();
}
// else challenge the user by navigating to the signing in page
else
{
if (!rootFrame.Navigate(typeof(ArcGISBlankPage), args.Arguments))
{
throw new Exception("Failed to create login page");
}
}
}
}
}