public static void Load() { try { //engine Constants.ENGINE_ENABLED = Convert.ToBoolean(SettingsDAC.Get("ENGINE_ENABLED")); Constants.ENGINE_INTERVAL = Convert.ToInt32(SettingsDAC.Get("ENGINE_INTERVAL")); Constants.APP_USAGE_COUNT = Convert.ToInt32(SettingsDAC.Get("APP_USAGE_COUNT")); SettingsDAC.Set("APP_USAGE_COUNT", (Constants.APP_USAGE_COUNT + 1).ToString()); //weather Constants.WEATHER_READ_INTERVAL = Convert.ToInt32(SettingsDAC.Get("WEATHER_READ_INTERVAL")); Constants.TEMPERATURE_ALERT_THRESHOLD = Convert.ToDouble(SettingsDAC.Get("TEMPERATURE_ALERT_THRESHOLD")); //location Constants.VISITED_DISTANCE_THRESHOLD = Convert.ToDouble(SettingsDAC.Get("VISITED_DISTANCE_THRESHOLD")); Constants.LEFT_FROM_DURATION_THRESHOLD = Convert.ToInt32(SettingsDAC.Get("LEFT_FROM_DURATION_THRESHOLD")); Constants.CAR_SERVICE_INTERVAL = Convert.ToInt32(SettingsDAC.Get("CAR_SERVICE_INTERVAL")); Constants.MAX_GYM_VACATION = Convert.ToInt32(SettingsDAC.Get("MAX_GYM_VACATION")); //network Constants.NEWS_EMAIL = SettingsDAC.Get("NEWS_EMAIL"); Constants.NEWS_READ_INTERVAL = Convert.ToInt32(SettingsDAC.Get("NEWS_READ_INTERVAL")); Constants.NEWS_PROVIDERS = SettingsDAC.Get("NEWS_PROVIDERS"); Constants.NEWS_TOPICS = SettingsDAC.Get("NEWS_TOPICS"); Constants.NEWS_PEOPLE = SettingsDAC.Get("NEWS_PEOPLE"); //social Constants.GTALK_ENABLED = Convert.ToBoolean(SettingsDAC.Get("GTALK_ENABLED")); Constants.GTALK_USERNAME = SettingsDAC.Get("GTALK_USERNAME"); Constants.GTALK_PWD = SettingsDAC.Get("GTALK_PWD"); Constants.SKYPE_ENABLED = Convert.ToBoolean(SettingsDAC.Get("SKYPE_ENABLED")); Constants.MEETING_AUTOREPLY_MESSAGE = SettingsDAC.Get("MEETING_AUTOREPLY_MESSAGE"); Constants.BATTERYLOW_AUTOREPLY_MESSAGE = SettingsDAC.Get("BATTERYLOW_AUTOREPLY_MESSAGE"); Constants.BATTERY_WARNING_THRESHOLD = Convert.ToInt32(SettingsDAC.Get("BATTERY_WARNING_THRESHOLD")); //lifestyle Constants.MEETING_ALERT_HOUR = SettingsDAC.Get("MEETING_ALERT_HOUR"); Constants.TIMESHEET_ALERT_HOUR = SettingsDAC.Get("TIMESHEET_ALERT_HOUR"); Constants.WEEKLY_SUMMARY_ALERT_DAY = SettingsDAC.Get("WEEKLY_SUMMARY_ALERT_DAY"); Constants.WEEKLY_SUMMARY_ALERT_HOUR = SettingsDAC.Get("WEEKLY_SUMMARY_ALERT_HOUR"); Constants.APP_TO_LAUNCH_ON_SHAKE = SettingsDAC.Get("APP_TO_LAUNCH_ON_SHAKE"); Constants.APP_TO_LAUNCH_ON_LANDSCAPE = SettingsDAC.Get("APP_TO_LAUNCH_ON_LANDSCAPE"); Constants.DROPBOX_DOCUMENTS = SettingsDAC.Get("DROPBOX_DOCUMENTS"); //load known-locations KnownLocations.Load(); LocationHelper.LoadHistory(); } catch (Exception exception) { Log.Error(exception); } }
private LocationInfo CreateDummyLocationInfo(string identifier, string name, Guid uniqueId) { const long dummyLocationId = 0; var locationInfo = InternalConstructor <LocationInfo> .Invoke( name, identifier, dummyLocationId, uniqueId, UtcOffset.TotalHours); if (KnownLocations.Any(l => l.LocationIdentifier == identifier)) { throw new ArgumentException($"Can't add duplicate location for Identifier='{identifier}'"); } KnownLocations.Add(locationInfo); return(locationInfo); }
void mapWindow_Chosen(Position obj) { KnownLocations.Set(obj); }
private void CarShowroomButton_Click(object sender, RoutedEventArgs e) { DoChooseLocation(KnownLocations.Get(KnownLocations.CAR_SHOWROOM)); }
private void GymButton_MouseDown(object sender, RoutedEventArgs e) { DoChooseLocation(KnownLocations.Get(KnownLocations.GYM)); }
private void WorkButton_Click(object sender, RoutedEventArgs e) { DoChooseLocation(KnownLocations.Get(KnownLocations.WORK)); }
private void HomeButton_Click(object sender, RoutedEventArgs e) { DoChooseLocation(KnownLocations.Get(KnownLocations.HOME)); }
private void SaveButton_Click(object sender, RoutedEventArgs e) { try { SaveButton.IsEnabled = false; //engine Constants.ENGINE_INTERVAL = (int)EngineIntervalUpDown.Value; //weather Constants.WEATHER_READ_INTERVAL = (int)WeatherReadIntervalUpDown.Value; Constants.TEMPERATURE_ALERT_THRESHOLD = (double)TemperatureAlertThresholdUpDown.Value; //location Constants.VISITED_DISTANCE_THRESHOLD = (double)VisitedDistanceThresholdUpDown.Value; Constants.LEFT_FROM_DURATION_THRESHOLD = (int)LeftFromDurationUpDown.Value; Constants.CAR_SERVICE_INTERVAL = (int)CarServiceIntervalUpDown.Value; Constants.MAX_GYM_VACATION = (int)MaxGymVacationUpDown.Value; //network Constants.NEWS_EMAIL = NewsEmailTextBox.Text; Constants.NEWS_READ_INTERVAL = (int)NewsReadIntervalUpDown.Value; Constants.NEWS_TOPICS = NewsTopicsTextBox.Text; Constants.NEWS_PEOPLE = NewsPeopleTextBox.Text; List <string> providers = new List <string>(); if ((bool)MSTopCheckBox.IsChecked) { providers.Add(Constants.MS_TOP); } if ((bool)GoogleTechCheckBox.IsChecked) { providers.Add(Constants.GOOGLE_TECH); } if ((bool)YahooTechCheckBox.IsChecked) { providers.Add(Constants.YAHOO_TECH); } if ((bool)BbcTechCheckBox.IsChecked) { providers.Add(Constants.BBC_TECH); } Constants.NEWS_PROVIDERS = string.Join(";", providers); //social Constants.GTALK_ENABLED = (bool)GTalkCheckBox.IsChecked; Constants.GTALK_USERNAME = GTalkEmailTextBox.Text; Constants.GTALK_PWD = new SimpleAES().EncryptToString(GTalkPwdTextBox.Password); Constants.SKYPE_ENABLED = (bool)SkypeCheckBox.IsChecked; Constants.MEETING_AUTOREPLY_MESSAGE = MeetingAutoReplyTextBox.Text; Constants.BATTERYLOW_AUTOREPLY_MESSAGE = BatteryLowAutoReplyTextBox.Text; Constants.BATTERY_WARNING_THRESHOLD = (int)BatteryWarningThresholdUpDown.Value; //lifestyle Constants.MEETING_ALERT_HOUR = MeetingAlertHourComboBox.SelectedItem.ToString(); Constants.TIMESHEET_ALERT_HOUR = TimeSheetAlertHourComboBox.SelectedItem.ToString(); Constants.WEEKLY_SUMMARY_ALERT_DAY = WeeklySummaryDayOfWeekComboBox.SelectedItem.ToString(); Constants.WEEKLY_SUMMARY_ALERT_HOUR = WeeklySummaryAlertHourComboBox.SelectedItem.ToString(); Constants.APP_TO_LAUNCH_ON_SHAKE = LaunchOnShakeComboBox.SelectedItem.ToString(); Constants.APP_TO_LAUNCH_ON_LANDSCAPE = LaunchOnLandscapeComboBox.SelectedItem.ToString(); List <string> docTypes = new List <string>(); if ((bool)WordCheckBox.IsChecked) { docTypes.Add(Constants.WORD); } if ((bool)ExcelCheckBox.IsChecked) { docTypes.Add(Constants.EXCEL); } if ((bool)PowerPointCheckBox.IsChecked) { docTypes.Add(Constants.POWERPOINT); } Constants.DROPBOX_DOCUMENTS = string.Join(";", docTypes); bool restartSuccessful = false; Task.Run(() => { //engine SettingsDAC.Set("ENGINE_ENABLED", Constants.ENGINE_ENABLED.ToString()); SettingsDAC.Set("ENGINE_INTERVAL", Constants.ENGINE_INTERVAL.ToString()); //weather SettingsDAC.Set("WEATHER_READ_INTERVAL", Constants.WEATHER_READ_INTERVAL.ToString()); SettingsDAC.Set("TEMPERATURE_ALERT_THRESHOLD", Constants.TEMPERATURE_ALERT_THRESHOLD.ToString()); //location SettingsDAC.Set("VISITED_DISTANCE_THRESHOLD", Constants.VISITED_DISTANCE_THRESHOLD.ToString()); SettingsDAC.Set("LEFT_FROM_DURATION_THRESHOLD", Constants.LEFT_FROM_DURATION_THRESHOLD.ToString()); SettingsDAC.Set("CAR_SERVICE_INTERVAL", Constants.CAR_SERVICE_INTERVAL.ToString()); SettingsDAC.Set("MAX_GYM_VACATION", Constants.MAX_GYM_VACATION.ToString()); //network SettingsDAC.Set("NEWS_EMAIL", Constants.NEWS_EMAIL); SettingsDAC.Set("NEWS_READ_INTERVAL", Constants.NEWS_READ_INTERVAL.ToString()); SettingsDAC.Set("NEWS_TOPICS", Constants.NEWS_TOPICS); SettingsDAC.Set("NEWS_PEOPLE", Constants.NEWS_PEOPLE); SettingsDAC.Set("NEWS_PROVIDERS", Constants.NEWS_PROVIDERS); //social SettingsDAC.Set("GTALK_ENABLED", Constants.GTALK_ENABLED.ToString()); SettingsDAC.Set("GTALK_USERNAME", Constants.GTALK_USERNAME); SettingsDAC.Set("GTALK_PWD", Constants.GTALK_PWD); SettingsDAC.Set("SKYPE_ENABLED", Constants.SKYPE_ENABLED.ToString()); SettingsDAC.Set("MEETING_AUTOREPLY_MESSAGE", Constants.MEETING_AUTOREPLY_MESSAGE); SettingsDAC.Set("BATTERYLOW_AUTOREPLY_MESSAGE", Constants.BATTERYLOW_AUTOREPLY_MESSAGE); SettingsDAC.Set("BATTERY_WARNING_THRESHOLD", Constants.BATTERY_WARNING_THRESHOLD.ToString()); //lifestyle SettingsDAC.Set("MEETING_ALERT_HOUR", Constants.MEETING_ALERT_HOUR); SettingsDAC.Set("TIMESHEET_ALERT_HOUR", Constants.TIMESHEET_ALERT_HOUR); SettingsDAC.Set("WEEKLY_SUMMARY_ALERT_DAY", Constants.WEEKLY_SUMMARY_ALERT_DAY); SettingsDAC.Set("WEEKLY_SUMMARY_ALERT_HOUR", Constants.WEEKLY_SUMMARY_ALERT_HOUR); SettingsDAC.Set("APP_TO_LAUNCH_ON_SHAKE", Constants.APP_TO_LAUNCH_ON_SHAKE); SettingsDAC.Set("APP_TO_LAUNCH_ON_LANDSCAPE", Constants.APP_TO_LAUNCH_ON_LANDSCAPE); SettingsDAC.Set("DROPBOX_DOCUMENTS", Constants.DROPBOX_DOCUMENTS); //save locations KnownLocations.Save(); //restart engine //Engine.Instance.Stop(); //await Engine.Instance.Start(); restartSuccessful = true; //Log.Write("Engine Restarted"); }); Log.Write("Settings Saved Successfully"); string statusMessage = string.Empty; if (restartSuccessful) { statusMessage += "Settings saved successfully!"; } else { statusMessage = "Settings saved, but unable to restart the Engine. You have to do it manually, in order for new settings to take effect."; } MessageBox.Show(statusMessage, Constants.APP_ID, MessageBoxButton.OK, MessageBoxImage.Information); Engine.Instance.Stop(); Engine.Instance.Start(); SaveButton.IsEnabled = true; } catch (Exception exception) { Log.Error(exception); MessageBox.Show("Error: " + exception.Message, Constants.APP_ID, MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Navigates to a page using a well known location in the app /// </summary> /// <typeparam name="TPage"></typeparam> /// <param name="knownLocation"></param> /// <returns></returns> public TPage Navigate <TPage>(KnownLocations knownLocation) where TPage : IPage { // Translate the well known location to a relative URL and use that to navigate. return(NavigateUrl <TPage>(KnownLocationAttribute.Parse(knownLocation))); }
public static void ExecuteLifestyleRecipes() { try { var meetingRecipe = Repository.Instance.GetRecipe("Meeting"); if (meetingRecipe != null && meetingRecipe.IsAvailable && meetingRecipe.IsEnabled) { if (BatteryHelper.SystemInUse) //if PC is being used { string firstAppointmentInfo = OutlookHelper.GetFirstAppointmentInfo(); if (firstAppointmentInfo != null) { int alertHour = Constants.TimesOfDay[Constants.MEETING_ALERT_HOUR]; if (DateTime.Now.Hour >= alertHour & DateTime.Now.Hour <= alertHour + 1) { var arguments = new Dictionary <string, object>() { { "HeaderText", "You have a meeting!" }, { "AlertText", firstAppointmentInfo }, { "Persistent", true }, { "Delay", 500 } }; SendNotification(meetingRecipe, arguments); } } } } var timeSheetRecipe = Repository.Instance.GetRecipe("TimeSheet"); if (timeSheetRecipe != null && timeSheetRecipe.IsAvailable && timeSheetRecipe.IsEnabled) { if (DateTime.Now.DayOfWeek != DayOfWeek.Saturday && DateTime.Now.DayOfWeek != DayOfWeek.Sunday) { var work = KnownLocations.Get(KnownLocations.WORK); if (VisitedThisPlaceWithinLastNMinutes(work, 8 * 60)) //within last 8 hours { int alertHour = Constants.TimesOfDay[Constants.TIMESHEET_ALERT_HOUR]; if (DateTime.Now.Hour >= alertHour & DateTime.Now.Hour <= alertHour + 1) { var arguments = new Dictionary <string, object>() { { "HeaderText", "Remember your day?" }, { "AlertText", "Its time to fill your TimeSheet, before you leave for the day." }, { "Persistent", true }, { "Delay", 500 } }; SendNotification(timeSheetRecipe, arguments); } } } } var weeklyReportRecipe = Repository.Instance.GetRecipe("Weekly Report"); if (weeklyReportRecipe != null && weeklyReportRecipe.IsAvailable && weeklyReportRecipe.IsEnabled) { DayOfWeek dow = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), Constants.WEEKLY_SUMMARY_ALERT_DAY); if (DateTime.Now.DayOfWeek == dow) { var work = KnownLocations.Get(KnownLocations.WORK); if (VisitedThisPlaceWithinLastNMinutes(work, 8 * 60)) //within last 8 hours { int alertHour = Constants.TimesOfDay[Constants.WEEKLY_SUMMARY_ALERT_HOUR]; if (DateTime.Now.Hour >= alertHour & DateTime.Now.Hour <= alertHour + 1) { var arguments = new Dictionary <string, object>() { { "HeaderText", "1 more task before weekend!" }, { "AlertText", "Have you sent Weekly Summary Report to your manager?" }, { "Persistent", true }, { "Delay", 500 } }; SendNotification(weeklyReportRecipe, arguments); } } } } } catch (Exception exception) { Log.Error(exception); } }
public static void ExecuteLocationRecipes() { try { //execute buy-milk recipe var buyMilkRecipe = Repository.Instance.GetRecipe("Buy Milk"); if (buyMilkRecipe != null && buyMilkRecipe.IsAvailable && buyMilkRecipe.IsEnabled) { var work = KnownLocations.Get(KnownLocations.WORK); if (VisitedThisPlaceWithinLastNMinutes(work, Constants.LEFT_FROM_DURATION_THRESHOLD)) { var arguments = new Dictionary <string, object>() { { "HeaderText", "Isn't your wife waiting?" }, { "AlertText", "Hope you have bought milk before going home." }, { "Persistent", true }, { "Delay", 500 } }; buyMilkRecipe.ScopeHours = TimeSpan.FromMinutes(Constants.LEFT_FROM_DURATION_THRESHOLD).TotalHours + 1; SendNotification(buyMilkRecipe, arguments); } } //execute car-service recipe var carServiceRecipe = Repository.Instance.GetRecipe("Car Service"); if (carServiceRecipe != null && carServiceRecipe.IsAvailable && carServiceRecipe.IsEnabled) { var carShowroom = KnownLocations.Get(KnownLocations.CAR_SHOWROOM); if (carShowroom.IsValid()) { LocationEntry lastVisit = LocationHelper.GetLastVisit(carShowroom); if (lastVisit != null) { var daysSinceVisited = DateTime.Now.Subtract(lastVisit.VisitedOn).TotalDays; if (daysSinceVisited >= Constants.CAR_SERVICE_INTERVAL) { var arguments = new Dictionary <string, object>() { { "HeaderText", "Your car is doing good?" }, { "AlertText", "It's " + daysSinceVisited + " days since you visited the Car Showroom." }, { "Persistent", true }, { "Delay", 500 } }; SendNotification(carServiceRecipe, arguments); } } } } //execute gym recipe var gymRecipe = Repository.Instance.GetRecipe("Gym"); if (gymRecipe != null && gymRecipe.IsAvailable && gymRecipe.IsEnabled) { var gym = KnownLocations.Get(KnownLocations.GYM); if (gym.IsValid()) { LocationEntry lastVisit = LocationHelper.GetLastVisit(gym); if (lastVisit != null) { var daysSinceVisited = DateTime.Now.Subtract(lastVisit.VisitedOn).TotalDays; if (daysSinceVisited >= Constants.MAX_GYM_VACATION) { var arguments = new Dictionary <string, object>() { { "HeaderText", "Aren't you health conscious?" }, { "AlertText", "It's " + daysSinceVisited + " days since you visited the Gym." }, { "Persistent", true }, { "Delay", 500 } }; SendNotification(gymRecipe, arguments); } } } } } catch (Exception exception) { Log.Error(exception); } }