Exemplo n.º 1
0
        private async void UpdateUI(ThreadPoolTimer timer)
        {
            // Perform the data computations
            string estimateTextBlockText = await Task <string> .Run(() => MainDataStore.GetArrivalEstimates(currOrigin, currDest));

            Tuple <List <string>, string, string> scheduleResults = await DataStore.Scheduler.CreateSchedule(currOrigin, currDest);

            // Update the UI
            bool isRunning = false;
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
                isRunning = UpdateTextBoxes(scheduleResults.Item1, scheduleResults.Item2, scheduleResults.Item3, estimateTextBlockText);
            });

            if (!isRunning)
            {
                scheduleResults = null;
                return;
            }

            // Grab more data
            Dictionary <string, Tuple <string, string, List <List <Point> > > > routeMap2;

            routeMap2 = await MainDataStore.GetRoutes(currOrigin, currDest);

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
                Dictionary <string, Tuple <string, string, List <LocationCollection> > > routeMap = ConvertToRouteMap(routeMap2);
                // If there are no routes, hide map and color code, replace with message that there are no routes currently running
                if (routeMap.Keys.Count == 0)
                {
                    this.shuttleMap.Visibility           = Visibility.Collapsed;
                    this.ColorCodePanel.Visibility       = Visibility.Collapsed;
                    this.notRunningTextBlock.Visibility  = Visibility.Visible;
                    this.notRunningTextBlock2.Visibility = Visibility.Visible;
                }
                else
                {
                    // Update the cache of route IDs and their colors
                    commonRouteIDsColors.Clear(); // race condition here with shuttles, but it will be resolved the period after if there's a failure
                    foreach (var key in routeMap.Keys)
                    {
                        commonRouteIDsColors[key] = routeMap[key].Item2;
                    }
                }

                // clean up
                routeMap.Clear();
                routeMap = null;
            });

            // clean up
            routeMap2 = null;
            scheduleResults.Item1.Clear();
            scheduleResults = null;
        }
        public override void OnLoadData()
        {
            MainDataStore.DataInit();
            MainDataStore.saveData = new byte[438272];
            DebugLog.LogToFileOnly("OnLoadData");
            DebugLog.LogToFileOnly("startload");

            MainDataStore.saveData = SaveAndRestore._serializableData.LoadData("AdvancedJunctionRule MainDataStore");
            if (MainDataStore.saveData == null)
            {
                DebugLog.LogToFileOnly("no AdvancedJunctionRule MainDataStore save data, please check");
            }
            else
            {
                MainDataStore.load();
            }
        }
Exemplo n.º 3
0
        private async void UpdateShuttles(ThreadPoolTimer timer)
        {
            List <Tuple <string, Point> > shuttleLocs = await MainDataStore.GetShuttles(commonRouteIDsColors.Keys.ToList <string>());

            var oldShuttles = shuttleMap.Children.ToList <UIElement>();

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => {
                foreach (var oldShuttle in oldShuttles)
                {
                    if (oldShuttle.GetType() == typeof(ShuttlePin))
                    {
                        shuttleMap.Children.Remove(oldShuttle);
                    }
                }
                AddShuttles(shuttleLocs);
            });

            // clean up
            oldShuttles = null;
            shuttleLocs = null;
        }
Exemplo n.º 4
0
        private async Task <Dictionary <string, Tuple <string, string, List <LocationCollection> > > > PopulateUI()
        {
            // Grab arrival estimates and the schedule
            string estimateTextBlockText = await Task <string> .Run(() => MainDataStore.GetArrivalEstimates(currOrigin, currDest));

            Tuple <List <string>, string, string> scheduleResults = await DataStore.Scheduler.CreateSchedule(currOrigin, currDest);

            // Update the UI
            bool isRunning = UpdateTextBoxes(scheduleResults.Item1, scheduleResults.Item2, scheduleResults.Item3, estimateTextBlockText);

            if (!isRunning)
            {
                return(null);
            }

            // Create a route map for updating the color code and the routes
            Dictionary <string, Tuple <string, string, List <List <Point> > > > routeMap2;

            routeMap2 = await MainDataStore.GetRoutes(currOrigin, currDest);

            Dictionary <string, Tuple <string, string, List <LocationCollection> > > routeMap = ConvertToRouteMap(routeMap2);

            // update the color code UI
            // if there are no routes, hide map and color code, replace with message that there are no routes currently running
            if (routeMap.Keys.Count == 0)
            {
                this.shuttleMap.Visibility           = Visibility.Collapsed;
                this.ColorCodePanel.Visibility       = Visibility.Collapsed;
                this.notRunningTextBlock.Visibility  = Visibility.Visible;
                this.notRunningTextBlock2.Visibility = Visibility.Visible;
                routeMap = null; // return null if there's nothing to show
            }

            // clean up
            routeMap2       = null;
            scheduleResults = null;

            return(routeMap);
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            origin = (DataItem)navigationParameter;
            ObservableCollection <DataGroup> toGroup = new ObservableCollection <DataGroup>();
            DataGroup        destGroup = new DataGroup("Dest-Group", "To", "", "Assets/DarkGray.png", "");
            HashSet <string> destSet   = await MainDataStore.GetDestinations(origin.Title);

            DataGroup itemGroup = DataSource.GetGroup("All-Group");

            foreach (DataItem item in itemGroup.Items)
            {
                if (destSet.Contains(item.Title))
                {
                    destGroup.Items.Add(item);
                }
            }

            toGroup.Add(destGroup);

            // Update the view
            this.DefaultViewModel["Groups"] = toGroup;
            this.pageTitle.Text             = "From " + origin;
        }
 public static void gatherSaveData()
 {
     MainDataStore.save();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            Tuple <string, string> items = (Tuple <string, string>)navigationParameter;

            currOrigin = items.Item1;
            currDest   = items.Item2;
            UpdateFavoritesCache(currOrigin, currDest);

            // Register the background task
            if (GroupedItemsPage.asyncStatus != BackgroundAccessStatus.Denied &&
                GroupedItemsPage.asyncStatus != BackgroundAccessStatus.Unspecified)
            {
                RegisterBackgroundTask();
            }

            this.pageTitle.Text = "Trip Results";
            UpdateOriginDest(currOrigin, currDest);

            // grab the route map (route id -> (name, color, segment list)
            commonRouteIDsColors = new Dictionary <string, string>();
            Dictionary <string, Tuple <string, string, List <LocationCollection> > > routeMap;

            routeMap = await PopulateUI();

            uiUpdaterTimer = ThreadPoolTimer.CreatePeriodicTimer(UpdateUI, TimeSpan.FromSeconds(30));
            if (routeMap == null)
            {
                return;
            }

            // cache route IDs and their colors
            commonRouteIDsColors = new Dictionary <string, string>();
            foreach (var key in routeMap.Keys)
            {
                commonRouteIDsColors[key] = routeMap[key].Item2;
            }

            MakePolylines(routeMap);

            // update color codes on UI
            foreach (var key in commonRouteIDsColors.Keys)
            {
                string name = routeMap[key].Item1;
                this.ColorCodePanel.Children.Add(new ColorCodeBox(commonRouteIDsColors[key], name));
            }

            // plot shuttles
            List <Tuple <string, Point> > shuttleLocs = await MainDataStore.GetShuttles(commonRouteIDsColors.Keys.ToList <string>());

            if (shuttleLocs != null) // there is internet
            {
                AddShuttles(shuttleLocs);
            }
            PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(UpdateShuttles, TimeSpan.FromMilliseconds(2500));

            FadeInMap();

            // clean up
            shuttleLocs = null;
            routeMap    = null;
        }