private async void btnSynchronizeCalender_Click(object sender, RoutedEventArgs e) { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); await _pc.StartBackgroundTask(PebbleConnector.Initiator.Synchronize); //await _TimeLineSynchronizer.Synchronize(); }
/// <summary> /// Initialize /// </summary> private void Initialize() { _pc = Connector.PebbleConnector.GetInstance(); if (_geoLocater == null) { _geoLocater = new Geolocator(); _geoLocater.DesiredAccuracy = PositionAccuracy.High; } _ConnectionToken = -1; }
/// <summary> /// Set the active watch face /// </summary> /// <param name="_item"></param> public async Task SetActiveWatchApp(vmWatchApp _item) { try { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); await _pc.Launch(_item.Model); } catch (Exception) { } }
/// <summary> /// Remove all messages from timeline and cached data /// </summary> /// <returns></returns> public async Task Clear() { _PebbleConnector = Connector.PebbleConnector.GetInstance(); for (int i = 6; i >= 0; i--) { await RemoveWeatherMessage(i); } ClearCache(); return; }
private async void SynchronizeCalender(object obj) { try { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); await _pc.StartBackgroundTask(PebbleConnector.Initiator.Synchronize); } catch (Exception exp) { Log.Add("An exception occurred while synchronizing."); Log.Add(exp.Message); } }
/// <summary> /// Set the active watch face /// </summary> /// <param name="_item"></param> public async Task SetActiveWatchFace(vmWatchFace _item) { try { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); await _pc.Select(_item.Model, WatchItemType.WatchFace); ActiveItem = _item; } catch (Exception) { } }
/// <summary> /// Connect to Pebble Time and start a new background communication task /// </summary> private async void Connect(object obj) { try { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); Log.Add("Connecting..."); await _pc.StartBackgroundTask(PebbleConnector.Initiator.Manual); } catch (Exception exp) { _vmBinder.Log.Add("An exception occurred while connecting."); _vmBinder.Log.Add(exp.Message); } }
/// <summary> /// Delete selected items from phone and watch /// </summary> public async Task DeleteSelectedItems() { int _ConnectionToken = -1; try { //Collect all GUIDs of selected items List <Guid> GuidSelectedItems = new List <Guid>(); var SelectedItems = WatchFaces.Where(x => x.Selected); foreach (var SelectedItem in SelectedItems) { GuidSelectedItems.Add(SelectedItem.Model); } //Connect Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); _ConnectionToken = await _pc.Connect(_ConnectionToken); //Remove all selected items foreach (var GuidSelectdItem in GuidSelectedItems) { var selecteditem = _pc.WatchItems.Where(x => x.ID == GuidSelectdItem); await _pc.DeleteWatchItemAsync(selecteditem.First()); } //Disconnect if (_pc.IsConnected) { _pc.Disconnect(_ConnectionToken); } } catch (Exception) { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); if (_pc.IsConnected) { _pc.Disconnect(_ConnectionToken); } } NotifyPropertyChanged("ItemsSelected"); }
/// <summary> /// Connect to a pebble /// </summary> /// <returns></returns> private async Task Connect() { if (_ConnectionToken != -1) { throw new Exception("Notification connection still active."); } //Connect to the watch _pc = Connector.PebbleConnector.GetInstance(); _ConnectionToken = await _pc.Connect(_ConnectionToken); if (!_pc.IsConnected) { throw new Exception("No connection with Pebble Time"); } }
/// <summary> /// Synchronize the weather forecast every 12 hours /// </summary> /// <returns></returns> public async Task Synchronize() { try { //Get last synchronisation DateTime LastWeatherSynchronization = DateTime.MinValue; var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; if (localSettings.Values.Keys.Contains("weathersynchronization")) { try { LastWeatherSynchronization = DateTime.Parse((string)localSettings.Values["weathersynchronization"]); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Weather:Synchronize:ParseDateTime: " + e.Message); } } TimeSpan _ts = DateTime.Now - LastWeatherSynchronization; //Update the weather message if last synchronization was more than 6 hours ago if (_ts.TotalHours > 5) { _PebbleConnector = Connector.PebbleConnector.GetInstance(); await WeatherSynhronize(); } //set new synchronization time if (localSettings.Values.Keys.Contains("weathersynchronization")) { localSettings.Values["weathersynchronization"] = DateTime.Now.ToString(); } else { localSettings.Values.Add("weathersynchronization", DateTime.Now.ToString()); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Weather:Synchronize: " + e.Message); } }
/// <summary> /// Disconnect Pebble Time and stop background communication task /// </summary> private void Disconnect(object obj) { try { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); Log.Add("Disconnecting..."); if (WipeHandler != null && WipeHandler.IsConnected) { WipeHandler.Disconnect(); } else { _pc.StopBackgroundTask(PebbleConnector.Initiator.Manual); } } catch (Exception exp) { Log.Add("An exception occurred while disconnecting."); Log.Add(exp.Message); } }
/// <summary> /// Clear the previously sent timeline items /// </summary> /// <returns></returns> public async Task Clear() { try { _PebbleConnector = Connector.PebbleConnector.GetInstance(); //Load synchronized items PreviousSynchronizedItems = null; String XMLList = await Common.LocalStorage.Load("calenderitems.xml"); if (XMLList.Length > 0) { PreviousSynchronizedItems = (List <CalenderItem>)Common.Serializer.XMLDeserialize(XMLList, typeof(List <CalenderItem>)); if (PreviousSynchronizedItems != null) { //Send all items to Pebble foreach (CalenderItem _item in PreviousSynchronizedItems) { if (_item.CalenderItemID.Length != 0) { await RemoveCalenderItem(Guid.Parse(_item.CalenderItemID)); } if (_item.ReminderID.Length != 0) { await RemoveCalenderReminderItem(Guid.Parse(_item.ReminderID)); } } await ClearCache(); Log.Add("Cache cleared on phone"); } } } catch (Exception e) { } }
private async void Backup(object obj) { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); await _pc.WatchItems.Backup(); }
//Synchronize calender public async Task Synchronize() { try { _PebbleConnector = Connector.PebbleConnector.GetInstance(); //Load synchronized calender items PreviousSynchronizedItems = null; SynchronizedItems = null; String XMLList = await Common.LocalStorage.Load("calenderitems.xml"); if (XMLList.Length > 0) { PreviousSynchronizedItems = (List <CalenderItem>)Common.Serializer.XMLDeserialize(XMLList, typeof(List <CalenderItem>)); } if (PreviousSynchronizedItems == null) { PreviousSynchronizedItems = new List <CalenderItem>(); } SynchronizedItems = new List <CalenderItem>(); PreviousSynchronizedItems.RemoveAll(x => x.Time < (DateTime.Now - new TimeSpan(3, 0, 0, 0))); // remove old items from items //Retrieve all appointments for the previous 2 days and next var appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly); FindAppointmentsOptions findOptions = new FindAppointmentsOptions(); findOptions.MaxCount = 64; findOptions.FetchProperties.Add(AppointmentProperties.Subject); findOptions.FetchProperties.Add(AppointmentProperties.Location); findOptions.FetchProperties.Add(AppointmentProperties.StartTime); findOptions.FetchProperties.Add(AppointmentProperties.Duration); findOptions.FetchProperties.Add(AppointmentProperties.Details); findOptions.FetchProperties.Add(AppointmentProperties.Reminder); IReadOnlyList <Appointment> _appointments = await appointmentStore.FindAppointmentsAsync(DateTime.Now - new TimeSpan(2, 0, 0, 0), TimeSpan.FromDays(4), findOptions); //Send all items to Pebble foreach (Appointment _appointment in _appointments) { await AddCalenderItem( _appointment.RoamingId, _appointment.Subject, _appointment.Location, _appointment.StartTime.DateTime, (int)_appointment.Duration.TotalMinutes, _appointment.Details, _appointment.Reminder); Log.Add("Appointment: " + _appointment.Subject); } //Remove items foreach (CalenderItem _item in PreviousSynchronizedItems) { if (_item.CalenderItemID.Length != 0) { await RemoveCalenderItem(Guid.Parse(_item.CalenderItemID)); } if (_item.ReminderID.Length != 0) { await RemoveCalenderReminderItem(Guid.Parse(_item.ReminderID)); } } //Save synchronized items XMLList = Common.Serializer.XMLSerialize(SynchronizedItems); await Common.LocalStorage.Save(XMLList, "calenderitems.xml", false); } catch (Exception e) { } }