void SetEnabled(bool isLoad) { bool isComplete = false; if (!string.IsNullOrEmpty(DataContextManager.SelectedCommute.StartPoint.Address) && !string.IsNullOrEmpty(DataContextManager.SelectedCommute.EndPoint.Address)) { if (!string.Equals(Convert.ToString(startTextBox.Tag), DataContextManager.SelectedCommute.StartPoint.Address, StringComparison.InvariantCultureIgnoreCase)) { if (!string.Equals(Convert.ToString(endTextBox.Tag), DataContextManager.SelectedCommute.EndPoint.Address, StringComparison.InvariantCultureIgnoreCase)) { isComplete = true; } } } routePivot.IsEnabled = weekDaysButton.IsEnabled = addButton.IsEnabled = routeList.IsEnabled = DepartDatePicker.IsEnabled = ReturnDatePicker.IsEnabled = isComplete; if (routePivot.IsEnabled && !isLoad) { if (DataContextManager.SelectedCommute.Routes.Count == 0) { MobileSrc.Commuter.Shared.RouteDefinition routeHighway = new MobileSrc.Commuter.Shared.RouteDefinition(); routeHighway.Name = "highway"; routeHighway.AvoidanceMeasures = MobileSrc.Commuter.Shared.RouteServices.Rest.RouteAvoid.None; MobileSrc.Commuter.Shared.RouteDefinition routeBackroads = new MobileSrc.Commuter.Shared.RouteDefinition(); routeBackroads.Name = "backroads"; routeBackroads.AvoidanceMeasures = MobileSrc.Commuter.Shared.RouteServices.Rest.RouteAvoid.AvoidHighways; DataContextManager.SelectedCommute.Routes.Add(routeHighway); DataContextManager.SelectedCommute.Routes.Add(routeBackroads); } //pivotControl.SelectedItem = routePivot; } }
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); }
private void addButton_Click(object sender, RoutedEventArgs e) { MobileSrc.Commuter.Shared.RouteDefinition route = new MobileSrc.Commuter.Shared.RouteDefinition(); DataContextManager.SelectedCommute.Routes.Add(route); DataContextManager.SelectedRoute = route; Uri uri = new Uri("/RouteEditor.xaml", UriKind.Relative); NavigationService.Navigate(uri); }
private void editRouteLink_Click(object sender, RoutedEventArgs e) { MobileSrc.Commuter.Shared.RouteDefinition route = (MobileSrc.Commuter.Shared.RouteDefinition)((Control)sender).Tag; DataContextManager.SelectedRoute = route; Uri uri = new Uri("/RouteEditor.xaml", UriKind.Relative); NavigationService.Navigate(uri); routeList.ItemsSource = null; routeList.ItemsSource = DataContextManager.SelectedCommute.Routes; }
void control_RefreshComplete(object sender, EventArgs e) { _refreshCount--; if (_refreshCount <= 0) { detailControl.Refresh(); if (returnCheck.IsChecked.Value) { DataContextManager.SelectedCommute.LastUpdatedRet = DateTime.Now; } else { DataContextManager.SelectedCommute.LastUpdated = DateTime.Now; } updatedLabel.Text = string.Concat("", DateTime.Now.ToString("MM/dd @ hh:mm tt")); ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true; progressBar.Visibility = System.Windows.Visibility.Collapsed; _refreshCount = 0; if (0 != (DataContextManager.SelectedCommute.DaysOfWeek & (int)Math.Pow(2, (int)DateTime.Now.DayOfWeek))) { MobileSrc.Commuter.Shared.RouteDefinition bestRoute = null; foreach (MobileSrc.Commuter.Shared.RouteDefinition route in DataContextManager.SelectedCommute.Routes) { if (bestRoute == null) { bestRoute = route; } else { TimeSpan durA = (returnCheck.IsChecked.Value) ? route.EstimatedRetDuration : route.EstimatedDuration; TimeSpan durB = (returnCheck.IsChecked.Value) ? bestRoute.EstimatedRetDuration : bestRoute.EstimatedDuration; if (durA < durB) { bestRoute = route; } } } if (null != bestRoute) { string tileUrl = string.Format(@"http://mobilesrc.com/commuter/LiveTile.aspx?commute={0}&route={1}&duration={2}&interval={3}&day={4}&color={5}", DataContextManager.SelectedCommute.Name, bestRoute.Name, (int)((returnCheck.IsChecked.Value) ? bestRoute.EstimatedRetDuration.TotalMinutes : bestRoute.EstimatedDuration.TotalMinutes), "min", DateTime.Now.ToString("dddd @ hh:mm tt"), App.AccentColor); Utils.RequestTileUpdate(tileUrl); } } DataContextManager.Save(); } }
private void deleteRouteLink_Click(object sender, RoutedEventArgs e) { Button button = (Button)sender; MobileSrc.Commuter.Shared.RouteDefinition definition = (MobileSrc.Commuter.Shared.RouteDefinition)button.Tag; string szTitle = definition.Name; string szMessage = "Are you sure you want to delete this route?"; if (MessageBox.Show(szMessage, szTitle, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { DataContextManager.SelectedCommute.Routes.Remove(definition); } routeList.ItemsSource = null; routeList.ItemsSource = DataContextManager.SelectedCommute.Routes; }
void SetRouteRecommendation(bool triggerRefresh) { if (this.Source.Routes.Count > 0) { MobileSrc.Commuter.Shared.RouteDefinition bestRoute = this.Source.Routes[0]; foreach (MobileSrc.Commuter.Shared.RouteDefinition route in this.Source.Routes) { TimeSpan durA = (_isReturn) ? route.EstimatedRetDuration : route.EstimatedDuration; TimeSpan durB = (_isReturn) ? bestRoute.EstimatedRetDuration : bestRoute.EstimatedDuration; if (durA < durB) { bestRoute = route; } } // we got our new data here... statusLabel.Text = "Recommended Route: " + bestRoute.Name; if (_isReturn) { durationLabel.Text = ((int)bestRoute.EstimatedRetDuration.TotalMinutes).ToString(); } else { durationLabel.Text = ((int)bestRoute.EstimatedDuration.TotalMinutes).ToString(); } } else { statusLabel.Text = "No Routes Defined"; durationLabel.Text = "-"; } if (triggerRefresh) { if (null != RefreshComplete) { RefreshComplete(this, null); } } }
private static void ProcessUpdate(object param) { // We want to loop through try { object[] args = (object[])param; AutoResetEvent waiter = (AutoResetEvent)args[0]; bool isDeparture = (bool)args[2]; string channelUri = (string)args[3]; double timeZoneOffset = (double)args[4]; string accentColor = (string)args[5]; DateTime sendTime = (DateTime)args[6]; MobileSrc.Commuter.Shared.CommuteDefinition commute = (MobileSrc.Commuter.Shared.CommuteDefinition)args[1]; Directory.CreateDirectory("logs"); using (FileStream fs = File.Create(string.Format(@"logs\{0}_{1}.log", commute.Id, DateTime.Now.ToString("MM_dd_hh_tt")))) { using (StreamWriter sw = new StreamWriter(fs)) { sw.AutoFlush = true; DateTime startTime = DateTime.Now; //DateTime sendTime = startTime.AddMinutes(DurationQueryRange); DateTime endTime = sendTime.AddMinutes(DurationQueryRange); Console.WriteLine(string.Format("{0} - Processing Update for {1}", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name)); sw.WriteLine(string.Format("{0} - Processing Update for {1}", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name)); bool hasSentUpdate = false; while (DateTime.Now <= endTime) { try { SortedList <TimeSpan, MobileSrc.Commuter.Shared.RouteDefinition> times = new SortedList <TimeSpan, MobileSrc.Commuter.Shared.RouteDefinition>(); MobileSrc.Commuter.Shared.RouteDefinition bestRoute = null; bool sendUpdate = false; if (!hasSentUpdate && DateTime.Now >= sendTime) { sendUpdate = true; hasSentUpdate = true; } foreach (MobileSrc.Commuter.Shared.RouteDefinition route in commute.Routes) { TimeSpan duration = MobileSrc.Commuter.Shared.Utils.RefreshRoute(commute, route, !isDeparture); while (times.ContainsKey(duration)) { duration = duration.Add(TimeSpan.FromSeconds(1)); } times.Add(duration, route); try { using (SqlConnection writeConnection = new SqlConnection(@"Data Source=wpcommuter.db.3448251.hostedresource.com; Initial Catalog=wpcommuter; User ID=wpcommuter; Password='******';")) { writeConnection.Open(); SqlCommand updateCommand = new SqlCommand("UpdateRoute", writeConnection); updateCommand.CommandType = CommandType.StoredProcedure; updateCommand.Parameters.AddWithValue("idRoute", route.Id); updateCommand.Parameters.AddWithValue("idCommute", commute.Id); updateCommand.Parameters.AddWithValue("Date", DateTime.Now.ToUniversalTime()); updateCommand.Parameters.AddWithValue("Duration", duration.TotalMinutes); updateCommand.Parameters.AddWithValue("IsDeparture", isDeparture); updateCommand.Parameters.AddWithValue("IsRequested", sendUpdate); updateCommand.ExecuteNonQuery(); } } catch (Exception ex2) { Console.WriteLine(string.Format("{0} - Exception for {1} - {2}", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name, ex2.ToString())); sw.WriteLine(string.Format("{0} - Exception for {1} - {2}", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name, ex2.ToString())); } } if (sendUpdate && times.Count > 0) { bestRoute = times.Values[0]; DateTime updateTime = DateTime.Now.AddHours(timeZoneOffset); string tileUrl = string.Format(@"http://mobilesrc.com/commuter/LiveTile.aspx?commute={0}&route={1}&duration={2}&interval={3}&day={4}&color={5}", commute.Name, bestRoute.Name, (int)bestRoute.EstimatedDuration.TotalMinutes, "min", updateTime.AddHours(-timeZoneOffset).ToString("dddd @ hh:mm tt"), accentColor); MobileSrc.Commuter.Shared.NotificationResponse toast = MobileSrc.Commuter.Shared.Notifications.SendToast(channelUri, commute.Name, string.Format("{0} {1} minutes", times.Values[0].Name, (int)times.Keys[0].TotalMinutes)); MobileSrc.Commuter.Shared.NotificationResponse tile = MobileSrc.Commuter.Shared.Notifications.SendTileUpdate(channelUri, "", 0, tileUrl); Console.WriteLine(string.Format("{0} - Responses for {1} [toast: {2}, tile: {3}]", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name, toast, tile)); sw.WriteLine(string.Format("{0} - Responses for {1} [toast: {2}, tile: {3}]", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name, toast, tile)); } } catch (Exception ex) { Console.WriteLine(string.Format("{0} - Exception for {1} - {2}", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name, ex.ToString())); sw.WriteLine(string.Format("{0} - Exception for {1} - {2}", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name, ex.ToString())); } finally { waiter.Set(); } Thread.Sleep(DurationQueryInterval * 60 * 1000); } Console.WriteLine(string.Format("{0} - Finished Update for {1}", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name)); sw.WriteLine(string.Format("{0} - Finished Update for {1}", DateTime.Now.ToString("MM/dd hh:mm tt"), commute.Name)); } } } catch { } }
void SetEnabled(bool isLoad) { bool isComplete = false; if (!string.IsNullOrEmpty(DataContextManager.SelectedCommute.StartPoint.Address) && !string.IsNullOrEmpty(DataContextManager.SelectedCommute.EndPoint.Address)) { if (!string.Equals(Convert.ToString(startTextBox.Tag), DataContextManager.SelectedCommute.StartPoint.Address, StringComparison.InvariantCultureIgnoreCase)) { if (!string.Equals(Convert.ToString(endTextBox.Tag), DataContextManager.SelectedCommute.EndPoint.Address, StringComparison.InvariantCultureIgnoreCase)) { isComplete = true; } } } routePivot.IsEnabled = weekDaysButton.IsEnabled = addButton.IsEnabled = routeList.IsEnabled = DepartDatePicker.IsEnabled = ReturnDatePicker.IsEnabled = isComplete; if (routePivot.IsEnabled && !isLoad) { if (DataContextManager.SelectedCommute.Routes.Count == 0) { MobileSrc.Commuter.Shared.RouteDefinition routeHighway = new MobileSrc.Commuter.Shared.RouteDefinition(); routeHighway.Name = "highway"; routeHighway.AvoidanceMeasures = MobileSrc.Commuter.Shared.RouteServices.Rest.RouteAvoid.None; MobileSrc.Commuter.Shared.RouteDefinition routeBackroads = new MobileSrc.Commuter.Shared.RouteDefinition(); routeBackroads.Name = "backroads"; routeBackroads.AvoidanceMeasures = MobileSrc.Commuter.Shared.RouteServices.Rest.RouteAvoid.AvoidHighways; DataContextManager.SelectedCommute.Routes.Add(routeHighway); DataContextManager.SelectedCommute.Routes.Add(routeBackroads); } //pivotControl.SelectedItem = routePivot; } }
private void addButton_Click(object sender, RoutedEventArgs e) { MobileSrc.Commuter.Shared.RouteDefinition route = new MobileSrc.Commuter.Shared.RouteDefinition(); DataContextManager.SelectedCommute.Routes.Add(route); DataContextManager.SelectedRoute = route; Uri uri = new Uri("/RouteEditor.xaml", UriKind.Relative); NavigationService.Navigate(uri); }