Exemplo n.º 1
0
        public static void FinalizeSession()
        {
            if (LastInitCalled.AddSeconds(5) > DateTime.Now)
            {
                // Start was called in the last 5 seconds; we're navigating (not pushing to the background). Lets not finalize
                return;
            }

            LastInitCalled = DateTime.MinValue;

            //5 * 60 * 1000
            // if we're still not back in 4 seconds, finalize the session
            BackgroundTask.Start(4000, () =>
            {
                Platform.RunSafeOnUIThread("FinalizeSession", () =>
                {
                    //FoodJournal.Model.Data.FoodJournalBackup.Log("FinalizeSession", null, null);

                    if (LastInitCalled != DateTime.MinValue)
                    {
                        return; // we are back before our timeout, dont finalize the session now either
                    }
                    try
                    {
                        SessionLog.Push();
                        AppStats.Reset();
                        UserSettings.Reset();
                        MessageCenter.Reset();
                    }
                    catch (Exception ex)
                    {
                        LittleWatson.ReportException(ex, "Resetting");
                    }

                    IsSessionInitialized = false; // now we are closed. next time initsession is called, we have to start a new session
                });
            });
        }
Exemplo n.º 2
0
 // Code to execute when the application is closing (eg, user hit Back)
 // This code will not execute when the application is deactivated
 private void Application_Closing(object sender, ClosingEventArgs e)
 {
     SessionLog.RecordTrace("Application_Closing");
     SessionLog.Push();
 }
Exemplo n.º 3
0
 // Code to execute when the application is deactivated (sent to background)
 // This code will not execute when the application is closing
 private void Application_Deactivated(object sender, DeactivatedEventArgs e)
 {
     SessionLog.RecordTrace("Application_Deactivated");
     SessionLog.Push();
 }
Exemplo n.º 4
0
        public static bool InitSession(Context ApplicationContext)
#endif
        {
            LastInitCalled = DateTime.Now;

            if (IsSessionInitialized)
            {
                return(false);
            }


            //FoodJournal.Model.Data.FoodJournalBackup.Log("InitSession", null, null);

            IsSessionInitialized = true;

            // if we're still getting too many session logs, we could consider only proceeding here if FinalizeSession succeeded longer than 1 hour ago or something

            AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) =>
            {
                LittleWatson.ReportException(e.ExceptionObject as Exception, "unhandledexception");
                if (e.IsTerminating)
                {
                    FinalizeSession();
                }
            };
            AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs e) =>
            {
                SessionLog.Push();
            };

#if WINDOWS_PHONE
            if (DateTime.Now > AppStats.Current.LastUpgrade.AddMonths(3))
            {
#else
            FoodJournal.Android15.AlarmService.ResetNotifications();
            InitializeLanguage();

            if (DateTime.Now > AppStats.Current.LastUpgrade.AddMonths(48))
            {
#endif

                SessionLog.RecordTrace("App Expired");

#if WINDOWS_PHONE
                if (MessageBox.Show(AppResources.ExpiredMessage, AppResources.ExpiredCaption, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    (new Microsoft.Phone.Tasks.MarketplaceDetailTask()).Show();
                }

                SessionLog.RecordTrace("Terminating");
                Application.Current.Terminate();
#else
                new AlertDialog.Builder(ApplicationContext)
                .SetPositiveButton("Ok", (sender, args) =>
                {
                    //Navigate.navigationContext = ApplicationContext;
                    Navigate.StartReviewTask();
                })
                .SetNegativeButton("Cancel", (sender, args) =>
                {
                    SessionLog.RecordTrace("Terminating");
                    throw new Exception();
                })
                .SetMessage(AppResources.ExpiredMessage)
                .SetTitle(AppResources.ExpiredCaption)
                .Create()
                .Show();

                return(false);
#endif
            }

            //			UserSettings.Current.SelectedProperties = new List<Property> () {
            //				StandardProperty.Calories,
            //				StandardProperty.TotalFat,
            //				StandardProperty.Carbs,
            //				StandardProperty.Protein
            //			};

            try
            {
                // processes live tile and other settings:
                var x = UserSettings.Current;
            }
            catch (Exception ex)
            {
                LittleWatson.ReportException(ex);
            }

            // 9/6/15: I thikn this is not needed to be done this quickly anymore, and its a pretty heavy operation (loading SQL dependencies, etc)
            // commenting out for now

            // 9/19/15: this is messing with purchase stats, so bringing it back, but asynch for now
            BackgroundTask.Start(4000, () =>
            {
                if (AppStats.Current.SessionId == 1)
                {
                    MessageQueue.Push(AppStats.Current);
                }
                else
                {
                    MessageQueue.StartPump();
                }
            });

            SyncQueue.StartLoad();

            return(true);
        }