Example #1
0
        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Log.Debug("e=" + e.DumpStr());
            Log.Debug("NavigationContext.QueryString=" + NavigationContext.QueryString.DumpStr());
            //Log.Debug("App.RecusiveBack=" + App.RecusiveBack);


            if (NavigationContext.QueryString.GetValue("Op", "") == "Add"
                //&& App.RecusiveBack==true
                && e.NavigationMode == NavigationMode.New)
            {
                while (NavigationService.CanGoBack)
                {
                    JournalEntry jo = NavigationService.RemoveBackEntry();
                    Log.Debug("jo.Source=" + jo.Source);
                }

                DataService.AddBus(new BusTag
                {
                    busName = NavigationContext.QueryString["busName"],
                    station = NavigationContext.QueryString["station"],
                    dir     = (BusDir)Enum.Parse(typeof(BusDir), NavigationContext.QueryString["dir"]),
                    tag     = NavigationContext.QueryString["tag"]
                });
                //App.RecusiveBack = false;
                //DataService.SaveData();
            }
            DataContext = new KeyedBusTagVM();

            Log.Debug("exit");
            //NavigationContext.QueryString.Clear();
        }
Example #2
0
        public static void SaveData()
        {
            lock (m_mutex)
            {
                Log.Msg("enter");
                try
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.NullValueHandling = NullValueHandling.Ignore;

                    using (StreamWriter sw = new StreamWriter(
                               IsolatedStorageFile.GetUserStoreForApplication().OpenFile(@"Shared\ShellContent\saved_buses.json",
                                                                                         FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)))
                        using (JsonWriter writer = new JsonTextWriter(sw))
                        {
                            var buses = m_busTags.Select(x => x.BusTag).ToArray();

                            serializer.Serialize(writer, buses);
                        }
                }
                catch (Exception ex)
                {
                    Log.Error("ex=" + ex.DumpStr());
                }
                Log.Msg("exit");
            }
        }
Example #3
0
        public static void LoadData()
        {
            lock (m_mutex)
            {
                Log.Msg("enter");
                JsonSerializer serializer = new JsonSerializer();
                serializer.NullValueHandling = NullValueHandling.Ignore;

                if (IsDesignTime ||
                    !IsolatedStorageFile.GetUserStoreForApplication().FileExists((@"Shared\ShellContent\saved_buses.json")))
                {
                    LoadDefaultData();
                    Log.Msg("exit");
                    return;
                }

                using (StreamReader sr = new StreamReader(
                           IsolatedStorageFile.GetUserStoreForApplication().OpenFile(@"Shared\ShellContent\saved_buses.json",
                                                                                     FileMode.Open, FileAccess.Read, FileShare.Read)))
                    using (JsonReader reader = new JsonTextReader(sr))
                    {
                        var buses = serializer.Deserialize(reader, typeof(List <BusTag>)) as List <BusTag>;
                        if (buses == null || buses.Count() == 0)
                        {
                            Log.Error("File \"{0}\" is corrupted!".Fmt(@"Shared\ShellContent\saved_buses.json"));
                            //LoadDefaultData();
                            m_busTags = new ObservableCollection <BusTagVM>();
                            Log.Msg("exit");
                            return;
                        }
                        m_busTags = new ObservableCollection <BusTagVM>(buses.Select(x => new BusTagVM(x)));
                    }
                Log.Msg("exit");
            }
        }
Example #4
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)
 {
     Log.Debug("Application_Closing, e=" + e);
     DataService.SaveData();
     MainPage.StartPeriodicAgent();
     // Ensure that required application state is persisted here.
     //Log.Close();
 }
Example #5
0
        // Code to execute when the application is activated (brought to foreground)
        // This code will not execute when the application is first launched
        private void Application_Activated(object sender, ActivatedEventArgs e)
        {
            Log.Debug("e.IsApplicationInstancePreserved=" + e.IsApplicationInstancePreserved);
            DataService.LoadData();

            // Ensure that application state is restored appropriately
            MainPage.RemoveAgent();
        }
Example #6
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            Log.Debug("e=" + e.DumpStr());
            Log.Debug("NavigationContext.QueryString=" + NavigationContext.QueryString.DumpStr());

            Log.Debug("exit");
            //NavigationContext.QueryString.Clear();
        }
Example #7
0
 // Code to execute if a navigation fails
 private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
 {
     Log.Debug("e={{ Exception={0}, e.Handled={1}, e.Uri={2} }}".Fmt(e.Exception, e.Handled, e.Uri));
     if (Debugger.IsAttached)
     {
         // A navigation has failed; break into the debugger
         Debugger.Break();
     }
 }
Example #8
0
 private void BusCatLLS_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     if (BusCatLLS.SelectedItem == null)
     {
         Log.Debug("e={{ OriginalSource={0}, Handled={1} }}".Fmt(e.OriginalSource, e.Handled));
         return;
     }
     GotoDetailsPage(BusCatLLS.SelectedItem as BusTagVM);
 }
 private void llsStations_Tap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     Log.Debug("");
     if (llsStations.SelectedItem == null)
     {
         return;
     }
     Log.Debug("llsStations.SelectedItem=" + (llsStations.SelectedItem as StringVM).String);
     tbStation.Text = (llsStations.SelectedItem as StringVM).String;
 }
Example #10
0
 // Code to execute on Unhandled Exceptions
 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
 {
     Log.Error("e={{ ExceptionObject={{ Message={0},StackTrace={1} }},  Handled={2} }}".Fmt(
                   e.ExceptionObject.Message, e.ExceptionObject.StackTrace, e.Handled));
     if (Debugger.IsAttached)
     {
         // An unhandled exception has occurred; break into the debugger
         Debugger.Break();
     }
 }
Example #11
0
        public static void StartPeriodicAgent()
        {
            string taskName = "refreshBusTileTask";
            // Obtain a reference to the period task, if one exists
            PeriodicTask refreshBusTileTask = ScheduledActionService.Find(taskName) as PeriodicTask;

            // If the task already exists and background agent is enabled for the
            // app, remove the task and then add it again to update
            // the schedule.
            if (refreshBusTileTask != null)
            {
                RemoveAgent();
            }
            refreshBusTileTask             = new PeriodicTask(taskName);
            refreshBusTileTask.Description = "Refresh Bus Due Time on Tile at Hub (HomeScreen)";

            // Place the call to add a periodic agent. This call must be placed in
            // a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(refreshBusTileTask);

                ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(1));
                Log.Debug("ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(1))");
            }
            catch (InvalidOperationException exception)
            {
                Log.Error(exception.ToString());
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    Log.Error("Background agents for this application have been disabled by the user.");
                }
                else if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                    Log.Error("BNS Error: The maximum number of ScheduledActions of this type have already been added.");
                }
                else
                {
                    Log.Error("An InvalidOperationException occurred.\n" + exception.ToString());
                }
            }
            catch (SchedulerServiceException e)
            {
                Log.Error(e.ToString());
            }
            finally
            {
                // Determine if there is a running periodic agent and update the UI.
                //refreshBusTileTask = ScheduledActionService.Find(taskName) as PeriodicTask;
                //if (refreshBusTileTask != null)
                //{
                //}
            }
        }
Example #12
0
        private void CheckForResetNavigation(object sender, NavigationEventArgs e)
        {
            Log.Debug("e=" + e.DumpStr());

            // If the app has received a 'reset' navigation, then we need to check
            // on the next navigation to see if the page stack should be reset
            if (e.NavigationMode == NavigationMode.Reset)
            {
                RootFrame.Navigated += ClearBackStackAfterReset;
            }
        }
Example #13
0
        // Do not add any additional code to this method
        private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
        {
            Log.Debug("e=" + e.DumpStr());
            // Set the root visual to allow the application to render
            if (RootVisual != RootFrame)
            {
                RootVisual = RootFrame;
            }

            // Remove this handler since it is no longer needed
            RootFrame.Navigated -= CompleteInitializePhoneApplication;
        }
Example #14
0
 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
 {
     Log.Debug("e.Cancel=" + e.Cancel);
     if (tbTag.Text != m_orig_tag)
     {
         Log.Debug("m_orig_tag={0}, tbTag.Text={1}".Fmt(m_orig_tag, tbTag.Text));
         BusDir dir = (tbDir.Text == "往↓" ? BusDir.go : BusDir.back);
         DataService.BusTags.First(x
                                   => x.busName == tbBusName.Text &&
                                   x.station == tbStation.Text &&
                                   x.dir == dir &&
                                   x.tag == m_orig_tag).tag = tbTag.Text;
     }
     base.OnBackKeyPress(e);
     //NavigationService.GoBack();
 }
Example #15
0
        private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
        {
            Log.Debug("e=" + e.DumpStr());

            // Unregister the event so it doesn't get called again
            RootFrame.Navigated -= ClearBackStackAfterReset;

            // Only clear the stack for 'new' (forward) and 'refresh' navigations
            if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh)
            {
                return;
            }

            // For UI consistency, clear the entire page stack
            while (RootFrame.RemoveBackEntry() != null)
            {
                ; // do nothing
            }
        }
Example #16
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            Log.Debug("App ctor()");
            //Log.Debug("App ctor() m_RecusiveBack=" + m_RecusiveBack);
            //Log.Debug("App ctor() {0} {1}".Fmt(Debugger.IsAttached, Application.Current.ApplicationLifetimeObjects.Count));
            DataService.IsDesignTime = false;
            IsolatedStorageFile.GetUserStoreForApplication().CreateDirectory(@"Shared\ShellContent");

            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard XAML initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Language display initialization
            InitializeLanguage();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }
            //Log.Create(true);
            MainPage.RemoveAgent();
        }
Example #17
0
        // Do not add any additional code to this method
        private void InitializePhoneApplication()
        {
            Log.Debug("phoneApplicationInitialized=" + phoneApplicationInitialized);
            if (phoneApplicationInitialized)
            {
                return;
            }

            // Create the frame but don't set it as RootVisual yet; this allows the splash
            // screen to remain active until the application is ready to render.
            RootFrame            = new PhoneApplicationFrame();
            RootFrame.Navigated += CompleteInitializePhoneApplication;

            // Handle navigation failures
            RootFrame.NavigationFailed += RootFrame_NavigationFailed;

            // Handle reset requests for clearing the backstack
            RootFrame.Navigated += CheckForResetNavigation;

            // Ensure we don't initialize again
            phoneApplicationInitialized = true;
        }
Example #18
0
        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            BusDir dir = (tbDir.Text == "往↓" ? BusDir.go : BusDir.back);

            try
            {
                BusTagVM bt = DataService.BusTags.First(x
                                                        => x.busName == tbBusName.Text &&
                                                        x.station == tbStation.Text &&
                                                        x.dir == dir &&
                                                        x.tag == m_orig_tag);

                bool bRemoveSuccess = DataService.BusTags.Remove(bt);
                Log.Debug("bRemoveSuccess=" + bRemoveSuccess);
                NavigationService.GoBack();
            }
            catch (Exception ex)
            {
                Log.Error("{0} {1} {2} {3} cannot be found!".Fmt(tbBusName.Text, tbStation.Text, dir, m_orig_tag));
                Log.Error("BusTags={" + ",".Joyn(DataService.BusTags.Select(x => x.ToString())) + "}");
                Log.Error("ex=" + ex.DumpStr());
            }
        }
Example #19
0
        public static void RemoveAgent()
        {
            string taskName = "refreshBusTileTask";

            Log.Debug("taskName=" + taskName);
            PeriodicTask refreshBusTileTask = ScheduledActionService.Find(taskName) as PeriodicTask;

            if (refreshBusTileTask == null)
            {
                Log.Debug("ScheduledActionService.Find(" + taskName + ") returns null.");
                return;
            }

            try
            {
                Log.Debug("ScheduledActionService.Remove(" + taskName + ")");
                ScheduledActionService.Remove(taskName);
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
Example #20
0
        public static void DeleteBus(BusTagVM item)
        {
            bool removeSuccess = m_busTags.Remove(item);

            Log.Debug("removeSuccess=" + removeSuccess);
        }
Example #21
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)
 {
     Log.Debug("e.Reason=" + e.Reason);
     DataService.SaveData();
     MainPage.StartPeriodicAgent();
 }
Example #22
0
        //static bool m_RecusiveBack = false;
        //public static bool RecusiveBack { get { return m_RecusiveBack; } set { m_RecusiveBack = value; } }

        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            Log.Debug("e=" + e.ToString());
        }
Example #23
0
 private void PhoneApplicationService_RunningInBackground(object sender, RunningInBackgroundEventArgs e)
 {
     Log.Debug("e=" + e.ToString());
 }