public void Subscribe() { Debug.WriteLine("Starting subscribing tracking messages"); if (_tokenStart != null) { Debug.WriteLine("You are trying to subscribe, already subscribed"); return; } _tokenStart = _messenger.Subscribe <StartTrackingMessage>(m => { Debug.WriteLine("Started tracking"); StartTime = m.TimeStamp; Duration = m.Duration; Token = m.Token; IsTracking = true; }); _tokenStop = _messenger.Subscribe <StopTrackingMessage>(m => { Debug.WriteLine("Stopped tracking"); IsTracking = false; }); _tokenLocation = _messenger.Subscribe <LocationMessage>(m => { Debug.WriteLine($"Location(WP) tracking {m.Lat} {m.Lng}"); if (CheckIfNotExpired() && !m.IsError) { Debug.WriteLine("Sending position"); _sendPositionService.SendPosition(Token, new Position(m.Lat, m.Lng), m.Address, m.Accuracy); } }); }
public void Subscribe() { if (_tokenStart != null) { return; } _tokenStart = _messenger.Subscribe <StartTrackingMessage>(m => { _startTime = m.TimeStamp; _duration = m.Duration; _token = m.Token; IsTracking = true; }); _tokenStop = _messenger.Subscribe <StopTrackingMessage>(m => { IsTracking = false; }); _tokenLocation = _messenger.Subscribe <LocationMessage>(m => { if (CheckIfNotExpired() && !m.IsError) { _sendPositionService.SendPosition(_token, new Position(m.Lat, m.Lng), m.Address, m.Accuracy); } }); }
private void Subscribe() { var messenger = Mvx.Resolve <IMvxMessenger>(); _locationMessageToken = messenger.Subscribe <LocationMessage>(async message => { if (message.Lat == (-1) && message.Lng == (-1)) { return; } if (DateTime.Now > EndTime) { StopSelf(); } if (Mvx.Resolve <IDeviceService>().IsInternetAvailable()) { await _sendPositionService.SendPosition(_token, new Position(message.Lat, message.Lng), message.Address, message.Accuracy); } }); }