private void ToggleMode() { if (IsReportingPhaseActive) { if (BestPosition != null) { FSLog.Debug("Sending best position"); OnNewPosition(BestPosition); BestPosition = null; // to avoid sending position twice } else { FSLog.Info("Unable to resolve good position"); return; // keep trying } } else { SetReportingMode(ReportingMode.Reporting); } }
void LocationService_LocationChanged(object sender, LocationChangeEventArgs e) { FSLog.Debug(); var coords = e.Position.Coordinate; var location = new Geolocation( lat: coords.Latitude, lon: coords.Longitude, acc: coords.Accuracy, time: coords.Timestamp.UtcDateTime); Deployment.Current.Dispatcher.BeginInvoke(async() => { var resp = await ServerAPIManager.Instance.ReportLocation(location); if (!resp.IsSuccessful) { FSLog.Error("Failed to update location"); } }); }
/// <summary> /// Stop observing and reporting position /// </summary> public void Stop() { FSLog.Debug(); if (Timer != null) { Timer.Tick -= Timer_Tick; Timer = null; } if (Locator != null) { Locator.PositionChanged -= Locator_PositionChanged; Locator = null; } #if HAVE_IDLE_LOCATOR if (IdleLocator != null) { IdleLocator.PositionChanged -= IdleLocator_PositionChanged; IdleLocator = null; } #endif CurrentMode = ReportingMode.Stopped; }
public void Start() { FSLog.Debug(); // Already running? if (HttpNotificationChannel.Find(channelName) == null) { NotificationChannel = new HttpNotificationChannel(channelName); // register event handlers NotificationChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(NotificationService_ChannelUriUpdated); NotificationChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(NotificationService_ErrorOccurred); NotificationChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(NotificationService_ShellToastNotificationReceived); NotificationChannel.Open(); NotificationChannel.BindToShellToast(); NotificationChannel.BindToShellTile(); } else { // register event handlers NotificationChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(NotificationService_ChannelUriUpdated); NotificationChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(NotificationService_ErrorOccurred); NotificationChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(NotificationService_ShellToastNotificationReceived); FSLog.Info("Channel URL: ", NotificationChannel.ChannelUri.ToString()); SettingsManager.NotificationChannelUriString = NotificationChannel.ChannelUri.ToString(); } }
public Task <ContactData> GetContactData(string email) { FSAsyncResult task; var started = DateTimeOffset.UtcNow; //FSLog.Debug("start:", email); lock (Tasks) { lock (Contacts) { if (Contacts.ContainsKey(email)) { return(Task <ContactData> .Run(() => { FSLog.Debug("end:", email, DateTimeOffset.Now - started); return Contacts[email]; })); } } // See if search started for this email if (Tasks.ContainsKey(email)) { task = Tasks[email]; } else // Not running already { task = new FSAsyncResult(); Tasks[email] = task; //Start the asynchronous search. Contacts cons = new Contacts(); //Identify the method that runs after the asynchronous search completes. cons.SearchCompleted += (object sender, ContactsSearchEventArgs e) => { FSLog.Info("SearchCompleted:", email); ContactData data = new ContactData(); data.DisplayName = email; // Grab first match foreach (Contact con in e.Results) { data.IsFound = true; //No results if (!string.IsNullOrWhiteSpace(con.DisplayName)) { data.DisplayName = con.DisplayName; } System.IO.Stream stream = con.GetPicture(); if (stream != null) { BitmapImage img = new BitmapImage(); img.SetSource(stream); data.Photo = img; break; } } lock (Contacts) { Contacts[email] = data; } task.IsCompleted = true; }; cons.SearchAsync(email, FilterKind.EmailAddress, task); } } return(Task <ContactData> .Run(() => { //FSLog.Debug("wait:", email); task.Wait(); lock (Tasks) { Tasks.Remove(email); task.Dispose(); } lock (Contacts) { //FSLog.Debug("end:", email, DateTimeOffset.Now - started); return Contacts[email]; } })); }
public async Task ForceReportCurrentLocation() { FSLog.Debug(); await LocationService.Instance.GetCurrentLocation(accuracy : Windows.Devices.Geolocation.PositionAccuracy.Default); }
public void StopMonitoringGPS() { FSLog.Debug(); LocationService.Instance.Stop(); }