示例#1
0
        private void commuterList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (commuterList.SelectedIndex >= 0)
            {
                _showCommute = null;

                // selected weather data
                DataContextManager.SelectedCommute = DataContextManager.Commutes[commuterList.SelectedIndex];
                NavigationService.GoBack();
            }
        }
示例#2
0
        public static TimeSpan RefreshRoute(CommuteDefinition definition, RouteDefinition route, bool reverseRoute)
        {
            RouteRestRequest request = new RouteRestRequest();

            request.Waypoints = new List <RestWaypoint>();
            request.Waypoints.Add(new RestWaypoint());

            request.ApplicationId         = BingMapsApiKey;
            request.Waypoints[0].Location = new RestLocation();

            request.Waypoints[0].Location.Latitude  = definition.StartPoint.Location.Latitude;
            request.Waypoints[0].Location.Longitude = definition.StartPoint.Location.Longitude;

            foreach (MobileSrc.Commuter.Shared.RouteLocation wayPoint in route.WayPoints)
            {
                request.Waypoints.Add(new RestWaypoint());
                request.Waypoints[request.Waypoints.Count - 1].Location           = new RestLocation();
                request.Waypoints[request.Waypoints.Count - 1].Location.Latitude  = wayPoint.Location.Latitude;
                request.Waypoints[request.Waypoints.Count - 1].Location.Longitude = wayPoint.Location.Longitude;
            }

            request.Waypoints.Add(new RestWaypoint());
            request.Waypoints[request.Waypoints.Count - 1].Location           = new RestLocation();
            request.Waypoints[request.Waypoints.Count - 1].Location.Latitude  = definition.EndPoint.Location.Latitude;
            request.Waypoints[request.Waypoints.Count - 1].Location.Longitude = definition.EndPoint.Location.Longitude;

            if (route.AvoidanceMeasures != RouteAvoid.None)
            {
                request.Avoid = route.AvoidanceMeasures;
            }

            if (reverseRoute)
            {
                System.Collections.Generic.List <RestWaypoint> reversed = new System.Collections.Generic.List <RestWaypoint>();

                for (int i = request.Waypoints.Count - 1; i >= 0; --i)
                {
                    reversed.Add(request.Waypoints[i]);
                }

                request.Waypoints = reversed;
            }

            request.Optimize   = RouteOptimize.TimeWithTraffic;
            request.PathOutput = RoutePathOutput.Points;

            Route restRoute = request.Execute();

            return(TimeSpan.FromSeconds(restRoute.TravelDuration));
        }
示例#3
0
        public static TimeSpan RefreshRoute(CommuteDefinition definition, RouteDefinition route, bool reverseRoute)
        {
            RouteRestRequest request = new RouteRestRequest();

            request.Waypoints = new List<RestWaypoint>();
            request.Waypoints.Add(new RestWaypoint());

            request.ApplicationId = BingMapsApiKey;
            request.Waypoints[0].Location = new RestLocation();

            request.Waypoints[0].Location.Latitude = definition.StartPoint.Location.Latitude;
            request.Waypoints[0].Location.Longitude = definition.StartPoint.Location.Longitude;

            foreach (MobileSrc.Commuter.Shared.RouteLocation wayPoint in route.WayPoints)
            {
                request.Waypoints.Add(new RestWaypoint());
                request.Waypoints[request.Waypoints.Count - 1].Location = new RestLocation();
                request.Waypoints[request.Waypoints.Count - 1].Location.Latitude = wayPoint.Location.Latitude;
                request.Waypoints[request.Waypoints.Count - 1].Location.Longitude = wayPoint.Location.Longitude;
            }

            request.Waypoints.Add(new RestWaypoint());
            request.Waypoints[request.Waypoints.Count - 1].Location = new RestLocation();
            request.Waypoints[request.Waypoints.Count - 1].Location.Latitude = definition.EndPoint.Location.Latitude;
            request.Waypoints[request.Waypoints.Count - 1].Location.Longitude = definition.EndPoint.Location.Longitude;

            if (route.AvoidanceMeasures != RouteAvoid.None)
            {
                request.Avoid = route.AvoidanceMeasures;
            }

            if (reverseRoute)
            {
                System.Collections.Generic.List<RestWaypoint> reversed = new System.Collections.Generic.List<RestWaypoint>();

                for (int i = request.Waypoints.Count - 1; i >= 0; --i)
                {
                    reversed.Add(request.Waypoints[i]);
                }

                request.Waypoints = reversed;
            }

            request.Optimize = RouteOptimize.TimeWithTraffic;
            request.PathOutput = RoutePathOutput.Points;

            Route restRoute = request.Execute();
            return TimeSpan.FromSeconds(restRoute.TravelDuration);
        }
示例#4
0
        private void addCommuteButton_Click(object sender, RoutedEventArgs e)
        {
            // selected weather data
            MobileSrc.Commuter.Shared.CommuteDefinition commuter = new MobileSrc.Commuter.Shared.CommuteDefinition();
            commuter.Name  = "untitled";
            commuter.IsNew = true;

            _showCommute = commuter;

            DataContextManager.Commutes.Add(commuter);
            DataContextManager.Save();

            DataContextManager.SelectedCommute = commuter;
            NavigationService.GoBack();
        }
示例#5
0
文件: Utils.cs 项目: nbclark/commuter
        static MobileSrc.Services.CommuterServices.CommuteDefinition CopyCommuteDefinition(MobileSrc.Commuter.Shared.CommuteDefinition definition)
        {
            MobileSrc.Services.CommuterServices.CommuteDefinition newDefinition = new MobileSrc.Services.CommuterServices.CommuteDefinition();

            XmlSerializer xsFrom = new XmlSerializer(typeof(MobileSrc.Commuter.Shared.CommuteDefinition));
            XmlSerializer xsTo   = new XmlSerializer(typeof(MobileSrc.Services.CommuterServices.CommuteDefinition));

            using (StringWriter writer = new StringWriter())
            {
                xsFrom.Serialize(writer, definition);
                using (StringReader reader = new StringReader(writer.ToString()))
                {
                    newDefinition = (MobileSrc.Services.CommuterServices.CommuteDefinition)xsTo.Deserialize(reader);
                }
            }

            newDefinition.DepartureTime = newDefinition.DepartureTime.ToUniversalTime();
            newDefinition.ReturnTime    = newDefinition.ReturnTime.ToUniversalTime();

            foreach (MobileSrc.Services.CommuterServices.RouteDefinition route in newDefinition.Routes)
            {
                route.RoutePoints = new MobileSrc.Services.CommuterServices.GpsLocation[0];
            }

            return(newDefinition);
        }
示例#6
0
文件: Utils.cs 项目: nbclark/commuter
 public static void RegisterCommute(MobileSrc.Commuter.Shared.CommuteDefinition definition)
 {
     _commuterServiceClient.AddCommuteAsync(UniqueID, CopyCommuteDefinition(definition));
 }
示例#7
0
文件: Utils.cs 项目: nbclark/commuter
 public static void RefreshRoutes(CommuteDefinition definition, bool reverseRoute)
 {
     Thread thread = new Thread(new ParameterizedThreadStart(_RefreshRoutesAsync));
     thread.IsBackground = true;
     thread.Start(new object[] { definition, reverseRoute });
 }
示例#8
0
文件: Utils.cs 项目: nbclark/commuter
        public static void RefreshRoute(CommuteDefinition definition, RouteDefinition route, bool reverseRoute)
        {
            Route restRoute = null;

            try
            {
                restRoute = RefreshRoute(definition.StartPoint, definition.EndPoint, route, reverseRoute);
            }
            catch
            {
            }

            if (null == restRoute)
            {
            }
            else
            {
                if (reverseRoute)
                {
                    route.EstimatedRetDistance = restRoute.TravelDistance;
                    route.EstimatedRetDuration = TimeSpan.FromSeconds(restRoute.TravelDuration);
                }
                else
                {
                    route.EstimatedDistance = restRoute.TravelDistance;
                    route.EstimatedDuration = TimeSpan.FromSeconds(restRoute.TravelDuration);
                }

                route.Directions.Clear();

                foreach (RouteLeg leg in restRoute.RouteLeg)
                {
                    foreach (ItineraryItem item in leg.ItineraryItem)
                    {
                        route.Directions.Add(new RouteDirection(item.Instruction));
                    }
                }

                route.RoutePoints.Clear();

                foreach (MobileSrc.Commuter.Shared.RouteServices.Rest.Point location in restRoute.RoutePath.Line.Point)
                {
                    route.RoutePoints.Add(Utils.CreateGpsLocation(location.Latitude, location.Longitude));
                }

                route.LastUpdated = DateTime.Now;
            }
            route.FireUpdated();
        }
示例#9
0
        private void commuterList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (commuterList.SelectedIndex >= 0)
            {
                _showCommute = null;

                // selected weather data
                DataContextManager.SelectedCommute = DataContextManager.Commutes[commuterList.SelectedIndex];
                NavigationService.GoBack();
            }
        }
示例#10
0
        private void addCommuteButton_Click(object sender, RoutedEventArgs e)
        {
            // selected weather data
            MobileSrc.Commuter.Shared.CommuteDefinition commuter = new MobileSrc.Commuter.Shared.CommuteDefinition();
            commuter.Name = "untitled";
            commuter.IsNew = true;

            _showCommute = commuter;

            DataContextManager.Commutes.Add(commuter);
            DataContextManager.Save();

            DataContextManager.SelectedCommute = commuter;
            NavigationService.GoBack();
        }