Advertisement
hackerferret

My EventProMobile App file

May 3rd, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 KB | None | 0 0
  1. using System;
  2. using System.Reactive.Linq;
  3. using System.Reactive.Threading.Tasks;
  4. using Akavache;
  5. using EventProApp;
  6. using EventProApp.Helpers;
  7. using EventProApp.Page.Dashboard;
  8. using EventProApp.Page.Login;
  9. using EventProClientApi;
  10. using Microsoft.Azure.Mobile;
  11. using Microsoft.Azure.Mobile.Analytics;
  12. using Microsoft.Azure.Mobile.Crashes;
  13. using ReactiveUI;
  14. using Splat;
  15. using Xamarin.Forms;
  16.  
  17. namespace EventProMobile
  18. {
  19.     public partial class App : Application
  20.     {
  21.         public static MasterDetailPage MasterDetailPage = new MasterDetailPage();
  22.  
  23.         public static string AppName
  24.         {
  25.             get { return Constants.ApplicationName; }
  26.         }
  27.  
  28.         public App()
  29.         {
  30.             LogHelper.LogDebug("At the start of the constructor");
  31.             InitializeComponent();
  32.  
  33.             MainPage = new NavigationPage(new Xamarin.Forms.Page());
  34.  
  35.         }
  36.  
  37.         protected override void OnStart()
  38.         {
  39.             // Handle when your app starts
  40.             MobileCenter.Start(typeof(Analytics), typeof(Crashes));
  41.             BlobCache.ApplicationName = "EventPro";
  42.             MainPage = RunCredentialCheck();
  43.         }
  44.  
  45.         protected override void OnSleep()
  46.         {
  47.             // Handle when your app sleeps
  48.         }
  49.  
  50.         protected override void OnResume()
  51.         {
  52.             // Handle when your app resumes
  53.         }
  54.  
  55.         public static NavigationPage RunCredentialCheck()
  56.         {
  57.             NavigationPage result = null;
  58.             var seq = SecurityHelper.HasUserCredentials()
  59.                                     .ToObservable<bool>()
  60.                           .ObserveOn(RxApp.MainThreadScheduler)
  61.                           .Timeout(TimeSpan.FromSeconds(6))
  62.                             .Select((hasCreds) =>
  63.                             {
  64.                                 return (hasCreds) ? new NavigationPage(new RootPage(true)) : new NavigationPage(new StartPage());
  65.                             }).FirstAsync();
  66.  
  67.             seq.Subscribe((NavigationPage nav) =>
  68.             {
  69.                 result = nav;
  70.             }, ex =>
  71.             {
  72.                 Logger.Write($"Error:{ex.Message}", Splat.LogLevel.Error);
  73.                 throw ex;
  74.             });
  75.             return result;
  76.         }
  77.  
  78.         public static ILogger Logger
  79.         {
  80.             get
  81.             {
  82.                 return Splat.Locator.Current.GetService<ILogger>();
  83.             }
  84.         }
  85.  
  86.         private static ViewModelLocator _locator;
  87.  
  88.         public static ViewModelLocator Locator
  89.         {
  90.             get
  91.             {
  92.                 return _locator ?? (_locator = new ViewModelLocator());
  93.             }
  94.         }
  95.  
  96.         public static Xamarin.Forms.Page GetMainPage()
  97.         {
  98.             return new RootPage(true);
  99.         }
  100.  
  101.         public static Xamarin.Forms.Page GetLoginPage()
  102.         {
  103.             return new Login();
  104.         }
  105.  
  106.         public static Xamarin.Forms.Page GetSignupPage()
  107.         {
  108.             return new Signup();
  109.         }
  110.  
  111.         public static Xamarin.Forms.Page GetStartPage()
  112.         {
  113.             return new StartPage();
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement