Esempio n. 1
0
        public bool AddRoute(Guid deviceId, Guid commuteId, MobileSrc.Commuter.Shared.RouteDefinition route)
        {
            LogRequest(deviceId, "AddRoute");
            try
            {
                using (SqlConnection connection = new SqlConnection(@"Data Source=wpcommuter.db.3448251.hostedresource.com; Initial Catalog=wpcommuter; User ID=wpcommuter; Password='******';"))
                {
                    connection.Open();

                    SqlCommand command = new SqlCommand("AddRoute", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("idRoute", route.Id);
                    command.Parameters.AddWithValue("idCommute", commuteId);

                    using (StringWriter writer = new StringWriter())
                    {
                        _routeSerializer.Serialize(writer, route);
                        command.Parameters.AddWithValue("Definition", writer.ToString());
                    }

                    command.ExecuteNonQuery();
                }
            }
            catch
            {
                return false;
            }
            return true;
        }
        void _commuterServiceClient_GetCommuteHistoryCompleted(object sender, MobileSrc.Services.CommuterServices.GetCommuteHistoryCompletedEventArgs e)
        {
            if (null != e.Error)
            {
                Utils.DisplayNetworkError();
            }
            else
            {
                XmlSerializer xsTo = new XmlSerializer(typeof(MobileSrc.Commuter.Shared.CommuteHistory));
                XmlSerializer xsFrom = new XmlSerializer(typeof(MobileSrc.Services.CommuterServices.CommuteHistory));

                using (StringWriter writer = new StringWriter())
                {
                    xsFrom.Serialize(writer, e.Result);
                    using (StringReader reader = new StringReader(writer.ToString()))
                    {
                        DataContextManager.SelectedCommute.History = (MobileSrc.Commuter.Shared.CommuteHistory)xsTo.Deserialize(reader);
                    }
                }
            }

            if (null != RefreshComplete)
            {
                RefreshComplete(this, null);
            }

            if (_isSelected)
            {
                ProcessHistory(DataContextManager.SelectedCommute.History);
            }
        }
        void ProcessHistory(MobileSrc.Commuter.Shared.CommuteHistory commuteHistory)
        {
            departureRouteSeries.Clear();
            returnRouteSeries.Clear();

            foreach (MobileSrc.Commuter.Shared.RouteDefinition route in DataContextManager.SelectedCommute.Routes)
            {
                ObservableCollection<KeyValuePair<string, int>> depSeriesData = new ObservableCollection<KeyValuePair<string, int>>();
                ObservableCollection<KeyValuePair<string, int>> retSeriesData = new ObservableCollection<KeyValuePair<string, int>>();

                BarSeries retSeries = new BarSeries();
                retSeries.Title = route.Name;
                retSeries.ItemsSource = retSeriesData;
                retSeries.IndependentValueBinding = new System.Windows.Data.Binding("Key");
                retSeries.DependentValueBinding = new System.Windows.Data.Binding("Value");

                BarSeries depSeries = new BarSeries();
                depSeries.Title = route.Name;
                depSeries.ItemsSource = depSeriesData;
                depSeries.IndependentValueBinding = new System.Windows.Data.Binding("Key");
                depSeries.DependentValueBinding = new System.Windows.Data.Binding("Value");

                departureRouteSeries.Add(route.Id, depSeries);
                returnRouteSeries.Add(route.Id, retSeries);
            }

            foreach (MobileSrc.Commuter.Shared.RouteHistory history in commuteHistory.Routes)
            {
                if (departureRouteSeries.ContainsKey(history.RouteId))
                {
                    ObservableCollection<KeyValuePair<string, int>> depSeriesData = (ObservableCollection<KeyValuePair<string, int>>)departureRouteSeries[history.RouteId].ItemsSource;
                    ObservableCollection<KeyValuePair<string, int>> retSeriesData = (ObservableCollection<KeyValuePair<string, int>>)returnRouteSeries[history.RouteId].ItemsSource;

                    Dictionary<DayOfWeek, double> depDayValues = new Dictionary<DayOfWeek, double>();
                    Dictionary<DayOfWeek, double> retDayValues = new Dictionary<DayOfWeek, double>();

                    foreach (MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay historyDay in history.DepartureAverages)
                    {
                        if (!depDayValues.ContainsKey((DayOfWeek)historyDay.Day))
                        {
                            depDayValues.Add((DayOfWeek)historyDay.Day, historyDay.Minutes);
                        }
                    }
                    foreach (MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay historyDay in history.ReturnAverages)
                    {
                        if (!retDayValues.ContainsKey((DayOfWeek)historyDay.Day))
                        {
                            retDayValues.Add((DayOfWeek)historyDay.Day, historyDay.Minutes);
                        }
                    }
                    Dictionary<DayOfWeek, double> dayValues = new Dictionary<DayOfWeek, double>();

                    for (int i = 0; i <= (int)DayOfWeek.Saturday; ++i)
                    {
                        int value = (int)Math.Pow(2, i);

                        if (0 != ((int)DataContextManager.SelectedCommute.DaysOfWeek & value))
                        {
                            double depTimeValue = 0;
                            double retTimeValue = 0;

                            if (depDayValues.ContainsKey((DayOfWeek)i))
                            {
                                depTimeValue = depDayValues[(DayOfWeek)i];
                            }
                            if (retDayValues.ContainsKey((DayOfWeek)i))
                            {
                                retTimeValue = retDayValues[(DayOfWeek)i];
                            }

                            string dayName = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[i].Substring(0, 3);
                            depSeriesData.Add(new KeyValuePair<string, int>(dayName, (int)depTimeValue));
                            retSeriesData.Add(new KeyValuePair<string, int>(dayName, (int)retTimeValue));
                        }
                    }
                }
            }
            BindRouteData();
        }
Esempio n. 4
0
 public RouteDirection(MobileSrc.Commuter.Shared.RouteServices.Rest.Instruction instruction)
 {
     this.Action = instruction.Value;
 }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
 public static void _commuterServiceClient_RequestTileUpdateCompleted(object sender, MobileSrc.Services.CommuterServices.RequestTileUpdateCompletedEventArgs e)
 {
     if (null != e.Error)
     {
         MessageBox.Show("Error Updating Live Tile", e.Error.ToString(), MessageBoxButton.OK);
     }
 }
Esempio n. 7
0
 public static void RegisterCommute(MobileSrc.Commuter.Shared.CommuteDefinition definition)
 {
     _commuterServiceClient.AddCommuteAsync(UniqueID, CopyCommuteDefinition(definition));
 }
Esempio n. 8
0
        public static RouteLocation CreateRouteLocation(MobileSrc.Services.GeocodeServices.GeocodeResult result)
        {
            RouteLocation routeLoc = new RouteLocation();

            routeLoc.Location = new GpsLocation();
            routeLoc.Location.Latitude = result.Locations[0].Latitude;
            routeLoc.Location.Longitude = result.Locations[0].Longitude;
            routeLoc.Location.Altitude = result.Locations[0].Altitude;

            routeLoc.Address = result.Address.FormattedAddress;

            return routeLoc;
        }
Esempio n. 9
0
        public bool RegisterDevice(Guid deviceId, string name, bool enableTile, bool enableToast, int timeZoneOffset, string accentColor, string channelURI, MobileSrc.Commuter.Shared.CommuteDefinition[] commutes)
        {
            LogRequest(deviceId, "RegisterDevice");
            try
            {
                using (SqlConnection connection = new SqlConnection(@"Data Source=wpcommuter.db.3448251.hostedresource.com; Initial Catalog=wpcommuter; User ID=wpcommuter; Password='******';"))
                {
                    connection.Open();

                    SqlCommand command = new SqlCommand("AddDevice", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("idDevice", deviceId);
                    command.Parameters.AddWithValue("Name", name);
                    command.Parameters.AddWithValue("timeZoneOffset", timeZoneOffset);
                    command.Parameters.AddWithValue("enableTile", enableTile);
                    command.Parameters.AddWithValue("enableToast", enableToast);
                    command.Parameters.AddWithValue("accentColor", accentColor);
                    command.Parameters.AddWithValue("channelURI", channelURI);

                    command.ExecuteNonQuery();
                }

                foreach (MobileSrc.Commuter.Shared.CommuteDefinition commute in commutes)
                {
                    AddCommute(deviceId, commute);
                }
                using (SqlConnection connection = new SqlConnection(@"Data Source=wpcommuter.db.3448251.hostedresource.com; Initial Catalog=wpcommuter; User ID=wpcommuter; Password='******';"))
                {
                    connection.Open();

                    SqlCommand command = new SqlCommand("CleanupDevice", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("idDevice", deviceId);
                    command.ExecuteNonQuery();
                }
            }
            catch
            {
                return false;
            }
            return true;
        }
Esempio n. 10
0
        public SearchResult(MobileSrc.Services.GeocodeServices.GeocodeResult result, double lat, double lon)
        {
            this.Result = result;
            this.DisplayName = result.DisplayName;

            this.Distance = Utils.CalculateDistance(result.Locations[0].Latitude, result.Locations[0].Longitude, lat, lon) * 0.62137119;
            this.DisplayDistance = string.Format("{0:0.00} miles", this.Distance);
        }
Esempio n. 11
0
        void _geocodeClient_GeocodeCompleted(object sender, MobileSrc.Services.GeocodeServices.GeocodeCompletedEventArgs e)
        {
            //listBox.ItemsSource = null;
            if (e.Error != null)
            {
                Utils.DisplayNetworkError();
                return;
            }

            System.Collections.ObjectModel.ObservableCollection<SearchResult> results = new System.Collections.ObjectModel.ObservableCollection<SearchResult>();

            foreach (MobileSrc.Services.GeocodeServices.GeocodeResult result in e.Result.Results)
            {
                results.Add(new SearchResult(result, _watcher.Position.Location.Latitude, _watcher.Position.Location.Longitude));
            }

            if (results.Count > 0)
            {
                listBox.ItemsSource = results;
                listBox.Visibility = System.Windows.Visibility.Visible;
                loadingLabel.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                listBox.Visibility = System.Windows.Visibility.Collapsed;
                loadingLabel.Visibility = System.Windows.Visibility.Visible;
                loadingLabel.Text = "No Results Found.";
            }
        }
Esempio n. 12
0
 public RouteAvoidPair(MobileSrc.Commuter.Shared.RouteServices.Rest.RouteAvoid avoid)
 {
     this.Avoid = avoid;
 }
Esempio n. 13
0
 void client_ReverseGeocodeCompleted(object sender, MobileSrc.Services.GeocodeServices.ReverseGeocodeCompletedEventArgs e)
 {
     if (null != e.Error)
     {
         Utils.DisplayNetworkError();
         return;
     }
     _routeLocation = Utils.CreateRouteLocation(e.Result.Results[0]);
     ((MenuItem)menu.Items[0]).Header = string.Format("{0}", _routeLocation.Address);
 }