public void ShouldThrowExceptionWhenAddressIsNull() { ISendMessage message = new LocationMessage() { Title = "Title" }; ExceptionAssert.Throws <InvalidOperationException>("The address cannot be null.", () => { message.Validate(); }); }
public override Task <Empty> UpdateLocation(LocationMessage request, ServerCallContext context) { Location l = ConversionStuff.MessageToLocation(request); if (!ValidationUtility.IsLocationValid(l)) { return(Task.FromResult(new Empty())); } unitOfWork.LocationRepo.Update(l); unitOfWork.Save(); return(Task.FromResult(new Empty())); }
public void ShouldThrowExceptionWhenTitleIsNull() { var message = new LocationMessage() { Address = "Address" }; ExceptionAssert.Throws <InvalidOperationException>("The title cannot be null.", () => { LocationMessage.Convert(message); }); }
public void Convert_TextMessageWithoutTitle_ThrowsException() { LocationMessage message = new LocationMessage() { Address = "Address" }; ExceptionAssert.Throws <InvalidOperationException>("The title cannot be null.", () => { MessageConverter.Convert(new ISendMessage[] { message }); }); }
public void ShouldNotThrowExceptionWhenMessageIsLocationMessage() { var message = new LocationMessage() { Title = "Foo", Address = "Bar" }; ISendMessageExtensions.Validate(new ISendMessage[1] { message }); }
public void ShouldPreserveInstanceWhenValueIsLocationMessage() { var message = new LocationMessage() { Title = "Title", Address = "Address" }; var locationMessage = LocationMessage.Convert(message); Assert.AreSame(message, locationMessage); }
public void ShouldThrowExceptionWhenAddressIsNull() { LocationMessage message = new LocationMessage() { Title = "Title", }; ExceptionAssert.Throws <InvalidOperationException>("The address cannot be null.", () => { LocationMessage.Convert(message); }); }
public void ShouldConvertCustomILocationMessageToLocationMessage() { var message = new TestLocationMessage(); var locationMessage = LocationMessage.Convert(message); Assert.AreNotEqual(message, locationMessage); Assert.AreEqual("Title", locationMessage.Title); Assert.AreEqual("Address", locationMessage.Address); Assert.AreEqual(53.2014355m, locationMessage.Latitude); Assert.AreEqual(5.7988737m, locationMessage.Longitude); }
public void Convert_LocationMessage_InstanceIsPreserved() { LocationMessage message = new LocationMessage() { Title = "Title", Address = "Address" }; ISendMessage[] messages = MessageConverter.Convert(new ISendMessage[] { message }); Assert.AreEqual(1, messages.Length); Assert.AreEqual(message, messages[0]); }
/// <summary> /// Called when [success]. /// </summary> /// <param name="location">The location.</param> private void OnSuccess(MvxGeoLocation location) { lock (this.lockObject) { this.latestLocation = location; } LocationMessage message = new LocationMessage( this, location.Coordinates.Latitude, location.Coordinates.Longitude); this.messenger.Publish(message); }
public async Task GetLocationAsync(CancellationToken token) { await Task.Run(async() => { var message = new LocationMessage(); message.Position = await CrossGeolocator.Current.GetPositionAsync(System.TimeSpan.FromSeconds(5)); Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send <LocationMessage>(message, "LocationMessage"); }); }, token); }
private void OnLocationMessage(LocationMessage locationMessage) { // TODO: Create map bindings and move this message handler and state to viewmodel _location = new LatLng(locationMessage.Lat, locationMessage.Lon); if (_viewModel != null && !_viewModel.Panned) { var position = new CameraPosition.Builder() .Bearing(locationMessage.Hdg.GetValueOrDefault(0)) .Target(_location) .Build(); _mapboxMap?.AnimateCamera(CameraUpdateFactory.NewCameraPosition(position)); } }
public void ShouldCreateSerializeableObject() { var message = new LocationMessage() { Title = "Correct", Address = "Somewhere", Latitude = 13.4484625m, Longitude = 144.7562962m }; var serialized = JsonSerializer.SerializeObject(message); Assert.AreEqual(@"{""type"":""location"",""title"":""Correct"",""address"":""Somewhere"",""latitude"":13.4484625,""longitude"":144.7562962}", serialized); }
private static CloudQueueMessage CreateApiMessage(string cityName, string blobUrl, string guid) { LocationMessage message = new LocationMessage { CityName = cityName, Blob = blobUrl, Guid = guid }; var messageJson = JsonConvert.SerializeObject(message); var filledMessage = new CloudQueueMessage(messageJson); return(filledMessage); }
private void OnLocationMessage(LocationMessage locationMessage) { Lat = locationMessage.Lat; Lon = locationMessage.Lon; Acc = locationMessage.Acc; Alt = locationMessage.Alt; AltAcc = locationMessage.AltAcc; Hdg = locationMessage.Hdg; HdgAcc = locationMessage.HdgAcc; Spd = string.Format("{0:0.0}", locationMessage.Spd); ErrorLbl = locationMessage.ErrorLbl; Error = locationMessage.Error; Updated = locationMessage.Updated; }
public LocationMessage AddLocationMessage(string text, string chatIdentifier, double latitude, double longitude) { var msg = new LocationMessage(); msg.ChatIdentifier = chatIdentifier; msg.Text = text; msg.Latitude = latitude; msg.Longitude = longitude; db.Add(msg); return(msg); }
public void Constructor_SerializedCorrectly() { LocationMessage message = new LocationMessage() { Title = "Correct", Address = "Somewhere", Latitude = 13.4484625m, Longitude = 144.7562962m }; string serialized = JsonConvert.SerializeObject(message); Assert.AreEqual(@"{""type"":""location"",""title"":""Correct"",""address"":""Somewhere"",""latitude"":13.4484625,""longitude"":144.7562962}", serialized); }
/// <summary> /// xml字符串解析为消息 /// </summary> /// <param name="xml"></param> /// <returns></returns> public PushBase XmlToMessage(string xml) { XmlUtils deserialize = new XmlUtils(xml); string msgtype = deserialize.GetValue("/xml/MsgType").ToLower(); PushBase message = null; switch (msgtype) { //普通消息 case "text": message = new TextMessage(); break; case "image": message = new ImageMessage(); break; case "voice": message = new VoiceMessage(); break; case "video": message = new VideoMessage(); break; case "shortvideo": message = new ShortVideoMessage(); break; case "location": message = new LocationMessage(); break; case "link": message = new LinkMessage(); break; //事件推送 case "event": message = GetEventModel(deserialize); break; default: return(null); } deserialize.FillModel(message); return(message); }
public void BuildMessage_LocationJSON_TelegramLocationMessage() { var expected = new LocationMessage { From = _user, Location = _location }; AttachGeneralProperties(expected); var actual = MessageBuilder.BuildMessage <LocationMessage>(_messageToken); var compareLogic = new CompareLogic(_config); var comparisonResult = compareLogic.Compare(expected, actual); Assert.IsTrue(comparisonResult.AreEqual, comparisonResult.DifferencesString); }
public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger) { _watcher = watcher; _messenger = messenger; _locationMessage = new LocationMessage(this); _updateLoc_token = _messenger.Subscribe <UpdateLocMessage>(OnUpdateLocMessage); var options = new MvxLocationOptions { Accuracy = MvxLocationAccuracy.Fine, TimeBetweenUpdates = TimeSpan.FromSeconds(2), TrackingMode = MvxLocationTrackingMode.Foreground }; _watcher.Start(options, OnLocation, OnError); }
public Response SendLocation(LocationMessage message) { string url = baseUrl + "sendlocation"; string content = Utils.Serialize(message); HttpResponseMessage response = client.PostAsync(url, new StringContent(content, Encoding.UTF8, "application/json")).Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { string result = response.Content.ReadAsStringAsync().Result; Response res = Utils.Deserialize <Response>(result); return(res); } return(new Response()); }
private void HandleLocationUpdateEvent(IPSEventMessage message) { if (!message.HasLocationMsg) { return; } LocationMessage msg = message.LocationMsg; var args = new LocationEventArgs(msg.DeviceId, msg.MapId, msg.X, msg.Y); if (OnLocationChanged != null) { OnLocationChanged(this, args); } }
public async Task <IList <IRequestMessage> > GetReplyMessagesAsync() { var msg = new LocationMessage( title: "臺北101", address: "北市信義區信義路五段7號", Convert.ToDecimal(25.0338041), Convert.ToDecimal(121.5645561) ); await Task.CompletedTask; return(new List <IRequestMessage> { msg }); }
public void Convert_CustomILocationMessage_ConvertedToTextMessage() { TestLocationMessage message = new TestLocationMessage(); ISendMessage[] messages = MessageConverter.Convert(new ISendMessage[] { message }); Assert.AreEqual(1, messages.Length); Assert.AreNotEqual(message, messages[0]); LocationMessage textMessage = messages[0] as LocationMessage; Assert.AreEqual("Title", textMessage.Title); Assert.AreEqual("Address", textMessage.Address); Assert.AreEqual(53.2014355m, textMessage.Latitude); Assert.AreEqual(5.7988737m, textMessage.Longitude); }
public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); Task.Run(() => { try { var message = new LocationMessage(); message.Position = CrossGeolocator.Current.GetPositionAsync(System.TimeSpan.FromSeconds(5)).Result; Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send <LocationMessage>(message, "LocationMessage"); }); Task.Run(async() => { var locationTask = new LocationTask(); await locationTask.SendLocation(message.Position); }); DisplayNotification($"{message.ToString()} às: {System.DateTime.Now.ToString("hh:mm:ss")}"); //DisplayNotification($"{message.Position.Latitude.ToString("N2")},{message.Position.Longitude.ToString("N2")} às: {System.DateTime.Now.ToString("hh:mm:ss")}"); } catch (OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread( () => MessagingCenter.Send(message, "CancelledMessage") ); } } }); return(StartCommandResult.Sticky); //return base.OnStartCommand(intent, flags, startId); }
public async Task UpdateLocation(LocationMessage locationMessage) { if (client == null || token == "") { Debug.WriteLine("Null client or token"); return; } try { await client.UpdateLocationAsync(locationMessage, headers); } catch (Exception e) { Debug.WriteLine(e.Message); } }
private void MarkedLastLocation() { if (locationHistories.Count == 0) { return; } InitGmap(); LocationMessage locationMessage = (LocationMessage)locationHistories[0]; gMap.Position = new GMap.NET.PointLatLng(locationMessage.latitude, locationMessage.longitude); GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(locationMessage.latitude, locationMessage.longitude), GMarkerGoogleType.red) { ToolTipText = locationMessage.timeTracking.ToString("dd/MM/yy HH:mm:ss") }; gMapOverlay.Markers.Add(marker); gMap.Overlays.Add(gMapOverlay); }
public void sendLocation(Guid clientId, double latitude, double longitude) { LocationMessage locationMessage = new LocationMessage(); locationMessage.clientId = clientId; locationMessage.timestamp = DateTime.UtcNow; locationMessage.location = new GeoData() { latitude = latitude, longitude = longitude }; string json = JsonSerializer.Serialize(locationMessage); using (var producer = new ProducerBuilder <Null, string>(config).Build()) { producer.Produce(geoTopic, new Message <Null, string> { Value = json }); producer.Flush(); } Console.WriteLine("Location sent"); }
private void AddMessageToGPSHistory(LocationMessage message) { if (_gpsLocations.Count == 20) { _gpsLocations.RemoveAt(0); } if (_gpsLocations.Count == 0) { _gpsLocations.Add(message); } else { // add only if distance in 5 meters from last point var lastMessage = _gpsLocations.Last(); var distance = Distance.CalculateDistanceBetween2PointsKMs(message.Latitude, message.Longitude, lastMessage.Latitude, lastMessage.Longitude); if (distance >= 0.005) { _gpsLocations.Add(message); } } }
public async Task Run(CancellationToken token) { await Task.Run(async() => { System.Diagnostics.Debug.WriteLine(getRunningStateLocationService()); while (getRunningStateLocationService()) { token.ThrowIfCancellationRequested(); try { await Task.Delay(2000); var request = new GeolocationRequest(GeolocationAccuracy.High); var location = await Geolocation.GetLocationAsync(request); if (location != null) { var message = new LocationMessage { Latitude = location.Latitude, Longitude = location.Longitude }; Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send <LocationMessage>(message, "Location"); }); } } catch (Exception ex) { Device.BeginInvokeOnMainThread(() => { var errormessage = new LocationErrorMessage(); MessagingCenter.Send <LocationErrorMessage>(errormessage, "LocationError"); }); } } return; }, token); }