Beispiel #1
0
 private void buttonDownArrow_Click(object sender, EventArgs e)
 {
     if (gridViewStops.FocusedRowHandle < gridViewStops.DataRowCount - 1)
     {
         BusRouteStop busStop  = (BusRouteStop)gridViewStops.GetFocusedRow();
         BusRouteStop nextStop = (BusRouteStop)gridViewStops.GetRow(gridViewStops.FocusedRowHandle + 1);
         nextStop.Sequence -= 1;
         busStop.Sequence  += 1;
         BindStops();
         _modified = true;
     }
 }
Beispiel #2
0
 private void buttonUpArrow_Click(object sender, EventArgs e)
 {
     if (gridViewStops.FocusedRowHandle > 0)
     {
         BusRouteStop busStop   = (BusRouteStop)gridViewStops.GetFocusedRow();
         BusRouteStop priorStop = (BusRouteStop)gridViewStops.GetRow(gridViewStops.FocusedRowHandle - 1);
         priorStop.Sequence += 1;
         busStop.Sequence   -= 1;
         BindStops();
         _modified = true;
     }
 }
Beispiel #3
0
 private void buttonDeleteStop_Click(object sender, EventArgs e)
 {
     if (gridViewStops.FocusedRowHandle >= 0)
     {
         BusRouteStop busStop = (BusRouteStop)gridViewStops.GetFocusedRow();
         bindingSourceStops.Remove(busStop);
         //Removing from the bindingsource just removes the object from its parent, but does not mark
         //it for deletion, effectively orphaning it.  This will cause foreign key errors when saving.
         //To flag for deletion, delete it from the context as well.
         _context.BusRouteStop.DeleteObject(busStop);
         BindStops();
         _modified = true;
     }
 }
Beispiel #4
0
        private void buttonAddStop_Click(object sender, EventArgs e)
        {
            BusRouteStop busStop = new BusRouteStop();

            if (_selectedRecord.BusRouteStop.Count == 0)
            {
                busStop.Sequence = 1;
            }
            else
            {
                busStop.Sequence = _selectedRecord.BusRouteStop.Max(b => b.Sequence) + 1;
            }
            _selectedRecord.BusRouteStop.Add(busStop);
            BindStops();
            gridViewStops.FocusedRowHandle = bindingSourceStops.Count - 1;
            _modified = true;
        }
Beispiel #5
0
 private void FinalizeBindings()
 {
     //Must end edit before setting MapColour below, because otherwise a NotificationChanged will fire
     //and all editors will refresh, losing the changes in the active editor (others will have posted
     //their changes in their Leave event)
     bindingSource.EndEdit();
     //colour picker is unbound
     _selectedRecord.MapColour = ColorTranslator.ToHtml(colorPickEditMap.Color);
     gridViewStops.CloseEditor();
     gridViewTimes.CloseEditor();
     gridViewStops.UpdateCurrentRow();
     //Set the sequence numbers for the stops to eliminate any gaps caused by deletion
     for (int rowCtr = 0; rowCtr < gridViewStops.DataRowCount; rowCtr++)
     {
         BusRouteStop busStop = (BusRouteStop)gridViewStops.GetRow(rowCtr);
         busStop.Sequence = rowCtr + 1;
     }
     bindingSourceStops.EndEdit();
     gridViewTimes.UpdateCurrentRow();
     bindingSourceTimes.EndEdit();
 }
Beispiel #6
0
        /// <summary>
        /// Updates the stop eta.
        /// </summary>
        /// <param name="stopClosure">The stop closure.</param>
        private static void UpdateStopEta(BusRouteStop stopClosure)
        {
            var stopEtaDetails = TransitClient.GetPlatformEta(stopClosure.StopModel.StopTag);
            var platform       = stopEtaDetails.GetPlatform(stopClosure);

            // if we don't have the platform, set Eta to 0, same if we don't have the detail
            if (platform != null)
            {
                var detail = platform.Route.FirstOrDefault(rt => rt.RouteNo == stopClosure.RouteModel.RouteNo);
                if (detail != null)
                {
                    stopClosure.Eta = detail.Destination.Trip.ETA;
                }
                else
                {
                    stopClosure.Eta = 0;
                }
            }
            else
            {
                stopClosure.Eta = 0;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets the platform GPS.
        /// </summary>
        /// <param name="stopAssociations">The stop associations.</param>
        /// <param name="stopClosure">The stop closure.</param>
        /// <param name="stopModel">The stop model.</param>
        /// <param name="routeAssociation">The route association.</param>
        private static void GetPlatformGps(List <BusRouteStop> stopAssociations, Platform stopClosure, BusStop stopModel, BusRouteStop routeAssociation)
        {
            // get the platform gps position
            var platformDetails = TransitClient.GetPlatform(stopClosure.PlatformTag);

            if (platformDetails.Position != null)
            {
                stopModel.Latitude  = platformDetails.Position.Lat;
                stopModel.Longitude = platformDetails.Position.Long;
            }
            lock (locker)
            {
                stopAssociations.Add(routeAssociation);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Updates the route information.
        /// </summary>
        /// <param name="xmlPattern">The XML pattern.</param>
        /// <param name="xmlRoutes">The XML routes.</param>
        /// <param name="routeModels">The route models.</param>
        /// <param name="threads">The threads.</param>
        private static void UpdateRouteInformation(RoutePattern xmlPattern, IEnumerable <RoutePatternProjectRoute> xmlRoutes, List <BusRoute> routeModels, List <Task> threads)
        {
            // update the expiration date for the route information
            expires = DateTime.Parse(xmlPattern.Content.Expires);
            foreach (var route in xmlRoutes.GroupBy(r => r.RouteNo))
            {
                // routestops are the association object between their individual stops and multiple routes
                List <BusRouteStop> stopAssociations = new List <BusRouteStop>();


                BusRoute model = new BusRoute()
                {
                    RouteNo          = route.Key,
                    RouteTimeWarning = false,
                    Stops            = stopAssociations
                };


                var pattern = route.SelectMany(r => r.Destination)
                              .Select(d => d.Pattern?.Where(p => p.Name.Equals(route.Key, StringComparison.CurrentCultureIgnoreCase)))
                              .Where(w => w != null)
                              .SelectMany(pt => pt.SelectMany(pl => pl.Platform.Select(p => p)));

                int stopCount = 0;

                foreach (var platform in pattern)
                {
                    // we need to capture the current platform because in this foreach loop it will change the object in the thread
                    // when we change the pointer
                    var stopClosure = platform;


                    // build this stop, they call them 'platforms
                    BusStop stopModel = new BusStop()
                    {
                        Address    = stopClosure.Name,
                        StopNumber = stopClosure.PlatformNo,
                        StopTag    = stopClosure.PlatformTag
                    };

                    // this is the association their system uses, ugh
                    BusRouteStop routeAssociation = new BusRouteStop()
                    {
                        RouteModel   = model,
                        StopModel    = stopModel,
                        StopPosition = stopCount++
                    };

                    threads.Add(Task.Run(() =>
                    {
                        GetPlatformGps(stopAssociations, stopClosure, stopModel, routeAssociation);
                    }));
                }

                // we'll give up after 20 seconds of trying to get all the gps details
                Task.WaitAll(threads.ToArray(), TransitConstants.ThreadTimeout);

                // order our stops using our custom comparer, logic inside!
                model.Stops = model.Stops.Distinct(TransitComparers.TransitComparer).ToList();

                routeModels.Add(model);
            }
        }