public async Task <ActionResult <GetGeoMessageDto> > CreateGeoMessage([FromQuery] Guid ApiKey, AddGeoMessageDto addGeoMessage) { if (addGeoMessage == null) { return(BadRequest()); } var user = await _userManager.GetUserAsync(this.User); var newGeoMessage = new GeoMessage { Title = addGeoMessage.Message.Title, Body = addGeoMessage.Message.Body, Author = $"{user.Firstname} {user.Lastname}", Longitude = addGeoMessage.Longitude, Latitude = addGeoMessage.Latitude }; await _context.AddAsync(newGeoMessage); await _context.SaveChangesAsync(); var getGeoMessage = new GetGeoMessageDto { Message = new GetMessageDto { Title = newGeoMessage.Title, Body = newGeoMessage.Body, Author = newGeoMessage.Author }, Longitude = newGeoMessage.Longitude, Latitude = newGeoMessage.Latitude }; return(CreatedAtAction(nameof(GetGeoMessage), new { id = newGeoMessage.Id }, getGeoMessage)); }
public async Task <ActionResult <object> > GetMessageV2(int id) { GeoMessage geoMessage = await _context.GeoMessages.FindAsync(id); if (geoMessage == null) { return(NotFound()); } GeoMessageDTO GeoMessageDTO = new() { Message = new Message { Body = geoMessage.Body, Author = geoMessage.Author, Title = geoMessage.Title, }, //Id = geoMessage.Id, Latitude = geoMessage.Latitude, Longitude = geoMessage.Longitude, }; return(new JsonResult(GeoMessageDTO)); }
public async Task Seed(UserManager <User> userManager) { await Database.EnsureDeletedAsync(); await Database.EnsureCreatedAsync(); var user = new User { UserName = "******", Firstname = "John", Lastname = "Doe" }; await userManager.CreateAsync(user); var geoMessage = new GeoMessage { Title = "Hej", Body = "Hallo", Author = user.Firstname + " " + user.Lastname, Latitude = 50.2, Longitude = 182.6 }; var token = new Token { Key = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00"), User = user }; await AddAsync(token); await AddAsync(geoMessage); await SaveChangesAsync(); }
///// <summary> ///// Represents conntroller, that initialize strategy ///// </summary> //private readonly ApiController _controller; #endregion #region Constructors /// <summary> /// Initializes a new instance of<see cref= "Strategy" /> class /// </summary> //protected Strategy() //{ //} /// <summary> /// Initialized a new instance of<see cref= "Strategy" /> class /// </summary> /// <param name = "controller" > App contoller instance</param> //protected Strategy(ApiController controller) //{ // _controller = controller; //} #endregion #region Properties /// <summary> /// Gets private api controller /// </summary> //protected ApiController Controller => _controller; #endregion #region Methods /// <summary> /// Virtual method for treating incoming marker message /// </summary> /// <param name="message">Marker message</param> /// <returns>Allways return UnknownServerError(-1) in base strategy class</returns> public virtual ResultMessage Execute(GeoMessage message) { return(new ResultMessage() { Type = ResultType.UnknownError, Message = "Server tries to execute base strategy method." }); }
public ResultMessage TakeGeo([FromBody] GeoMessage message) { Strategy strategy; switch (message.Type) { case MessageType.Marker: { strategy = new MarkerStrategy(); break; } case MessageType.Sos: { strategy = new SosStrategy(); break; } default: { strategy = new UnknownTypeStrategy(); break; } } return(strategy.Execute(message)); }
public async Task <ActionResult <GeoMessage> > PostGeoMessage(GeoMessage geoMessage) { var newGeoMessage = new GeoMessage { Message = geoMessage.Message, Latitude = geoMessage.Latitude, Longitude = geoMessage.Longitude }; var geoMessageV2DTO = new Models.V1.GeoMessageV1_DTO { Message = newGeoMessage.Message, Latitude = newGeoMessage.Latitude, Longitude = newGeoMessage.Longitude }; var newGeoMessageV2 = new GeoMessageV2 { Latitude = geoMessageV2DTO.Latitude, Longitude = geoMessageV2DTO.Longitude }; await _context.AddAsync(newGeoMessage); await _context.AddAsync(newGeoMessageV2); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGeoMessage", new { id = newGeoMessage.ID }, newGeoMessage)); }
static GeoMessagev1DTO PostGeoMessageToDTOV1(GeoMessage geoMessage) { return(new GeoMessagev1DTO { Message = geoMessage.Body, longitude = geoMessage.Longitude, latitude = geoMessage.Latitude }); }
/// <summary> /// Write new marker to db /// </summary> /// <param name="message">Inforamtion ablit new marker</param> protected override void WriteToDb(GeoMessage message) { MainContext.Instance.Marker.Insert(new Marker() { Latitude = message.Latitude, Longitude = message.Longitude, UserId = _user.UserId }); }
static GeoMessageDTO PostGeoMessageToDTO(GeoMessage geoMessage) { return(new GeoMessageDTO { Message = new Message { Title = geoMessage.Title, Author = geoMessage.Author, Body = geoMessage.Body, }, Longitude = geoMessage.Longitude, Latitude = geoMessage.Latitude }); }
public IActionResult ClearSession(GeoMessage tile) { // There are two cases for this, one where the QueueObserverClient // // is NULL, meaning this is a responder // if (observerClient == null) { return(this.NotFound()); } else { observerClient.Results.Clear(); return(this.Accepted()); } }
public async Task <ActionResult <GeoMessage> > PostGeoMessage(GeoMessage geoPostMessage) { GeoMessage geoMessage = new GeoMessage { Title = null, Body = geoPostMessage.Body, Author = null, Longitude = geoPostMessage.Longitude, Latitude = geoPostMessage.Latitude }; _context.GeoMessage.Add(geoMessage); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGeoMessage", new { id = geoPostMessage.Id }, geoPostMessage)); }
public async Task <ActionResult <GeoMessagev1DTO> > CreateNewPostAsync(GeoMessagev1DTO DTO) { var geoMessagePost = new GeoMessage { Longitude = DTO.longitude, Latitude = DTO.latitude, Body = DTO.Message, }; var GeoMessageV1DTOresponse = PostGeoMessageToDTOV1(geoMessagePost); await _context.AddAsync(geoMessagePost); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetMessagev2), new { id = geoMessagePost.Id }, GeoMessageV1DTOresponse)); }
public async Task <ActionResult <GeoMessageV1> > PostGeoMessage([FromBody] GeoMessageV1 geoMessageV1) { GeoMessage geoMessage = new GeoMessage { Body = geoMessageV1.Message, Author = null, Title = null, Longitude = geoMessageV1.Longitude, Latitude = geoMessageV1.Latitude, }; _context.GeoMessages.Add(geoMessage); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGeoMessage", new { id = geoMessage.Id }, geoMessage)); }
public async Task <ActionResult <GeoMessageV2Post> > PostGeoMessage([FromBody] GeoMessageV2Post geoMessage) { var geoMessagePost = new GeoMessage { Author = _userManager.GetUserName(User), Title = geoMessage.Message.Title, Body = geoMessage.Message.Body, Longitude = geoMessage.Longitude, Latitude = geoMessage.Latitude }; _context.GeoMessages.Add(geoMessagePost); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGeoMessage", new { id = geoMessagePost.Id }, geoMessage)); }
public async Task <ActionResult <IEnumerable <GeoMessage> > > GetGeoMessages() { var GeoMessages = await _context.GeoMessage.ToListAsync(); List <GeoMessage> newGeoMessages = new List <GeoMessage>(); foreach (var msg in GeoMessages) { GeoMessage newGeoMessageParse = new GeoMessage { Body = msg.Body, Longitude = msg.Longitude, Latitude = msg.Latitude }; newGeoMessages.Add(newGeoMessageParse); } return(newGeoMessages); }
/// <summary> /// Write to log message about sos call /// </summary> /// <param name="message">Information about sos call</param> protected override void WriteToDb(GeoMessage message) { try { MainContext.Instance.Log.Insert(new Log() { DeviceId = message.DeviceId, EventDate = DateTime.Now, EventId = MainContext.Instance.Event.GetBy(x => x.Name == "SOS_BUTTON_CLICK").ToList()[0].EventId, Message = $"Sos call on the mark: {message.Latitude}, {message.Longitude}" }); } catch (Exception ex) { Debug.WriteLine($"Internal DB Exception:{ex.Message}"); } }
public async Task<ActionResult<GeoMessageV1DTO>> PostGeoMessage(GeoMessageV1DTO geoMessage) { var newMessage = new GeoMessage { Longitude = geoMessage.Longitude, Latitude = geoMessage.Latitude, Message = geoMessage.Message }; await _context.AddAsync(newMessage); await _context.SaveChangesAsync(); return CreatedAtAction("GetGeoMessage", new { id = newMessage.Id }, geoMessage); /*_context.GeoMessages.Add(geoMessage); await _context.SaveChangesAsync(); return CreatedAtAction("GetGeoMessage", new { id = geoMessage.Id }, geoMessage);*/ }
public async Task <ActionResult <GeoMessagev1DTO> > GetMessagev2(int id) { GeoMessage geoMessage = await _context.GeoMessages.FindAsync(id); if (geoMessage == null) { return(NotFound()); } else { var geoMessagePost = new GeoMessagev1DTO { longitude = geoMessage.Longitude, latitude = geoMessage.Latitude, Message = geoMessage.Body }; return(geoMessagePost); } }
public async Task <ActionResult <IEnumerable <GeoMessage> > > GetGeoMessages(double minLon, double maxLon, double minLat, double maxLat) { var GeoMessages = await _context.GeoMessage.Where(o => (o.Longitude <= maxLon && o.Longitude >= minLon) && (o.Latitude <= maxLat && o.Latitude >= minLat)).ToListAsync(); List <GeoMessage> newGeoMessages = new List <GeoMessage>(); foreach (var msg in GeoMessages) { GeoMessage newGeoMessageParse = new GeoMessage { Title = msg.Title, Body = msg.Body, Author = msg.Author, Longitude = msg.Longitude, Latitude = msg.Latitude }; newGeoMessages.Add(newGeoMessageParse); } return(newGeoMessages); }
/// <summary> /// Gets user with deviceId from db /// </summary> /// <param name="message">Marker message</param> /// <returns>Return info of user, that have deviceId from message. /// If There're no users with that deviceId - insert new with login, /// password and equal to deviceId and return information about him</returns> protected virtual User GetOrCreateUser(GeoMessage message) { var exist = MainContext.Instance.User.GetBy(x => x.DeviceId == message.DeviceId); if (exist == null) { MainContext.Instance.User.Insert(new User() { DeviceId = message.DeviceId, IsAdmin = false, Login = message.DeviceId, Password = message.DeviceId }); exist = MainContext.Instance.User.GetBy(x => x.DeviceId == message.DeviceId); MainContext.Instance.Person.Insert(new Person() { UserId = exist.ToList()[0].UserId }); } return(exist.ToList()[0]); }
///// <summary> ///// Initializes a new instance of the <see cref="SosStrategy"/> class ///// </summary> //public SosStrategy() //{ //} ///// <summary> ///// Initialized a new instance of the <see cref="SosStrategy"/> class ///// </summary> ///// <param name="controller">App contoller instance</param> //public SosStrategy(AppController controller) : base(controller) //{ //} #endregion #region Properties #endregion #region Methods /// <summary> /// Treating incoming sos-type message /// </summary> /// <param name="message">Sos-type message</param> /// <returns>Returns Success(0) if process was successful and /// InternalServerError(-1) if there're is some server exception</returns> public override ResultMessage Execute(GeoMessage message) { try { var index = GetOrCreateUser(message).UserId; var temp = StaticInfo.SosList.FirstOrDefault(x => x.UserId == index); if (temp == null) { StaticInfo.SosList.Add(new SosMessage() { Latitude = message.Latitude, Longitude = message.Longitude, UserId = index, Timestamp = DateTime.Now }); } else { temp.Longitude = message.Longitude; temp.Latitude = message.Latitude; temp.Timestamp = DateTime.Now; } WriteToDb(message); return(new ResultMessage() { Type = ResultType.Success, Message = "Server succesfully read incoming sos message" }); } catch (Exception ex) { Debug.WriteLine($"Exception in SosStrategy.Execute: {ex.Message}"); return(new ResultMessage() { Type = ResultType.UnknownError, Message = "Internal server error " + $"{ex.Message}" }); } }
public async Task <IActionResult> CreateGeoMessage(GeoMessage newGeoMessage) { if (String.IsNullOrWhiteSpace(newGeoMessage.Message.Title)) { return(BadRequest()); } var user = await _userManager.GetUserAsync(User); if (user != null) { try { var geoMessage = new GeoMessage { Message = new Message { Title = newGeoMessage.Message.Title, Author = user.FirstName + " " + user.LastName, Body = newGeoMessage.Message.Body }, Latitude = newGeoMessage.Latitude, Longitude = newGeoMessage.Longitude }; await _context.GeoMessages.AddAsync(geoMessage); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetGeoMessage), new { id = geoMessage.Id }, geoMessage)); } catch { return(BadRequest()); } } else { return(Unauthorized()); } }
public async Task <ActionResult <GeoMessageDTOPost> > CreateNewPostAsyncV2(GeoMessageDTOPost DTO) { var userId = User.Identity.GetUserId(); var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId); var author = user.FirstName + " " + user.LastName; var geoMessage = new GeoMessage() { Author = author, Body = DTO.Message.Body, Title = DTO.Message.Title, Longitude = DTO.Longitude, Latitude = DTO.Latitude, }; var GeoMessageDTOresponse = PostGeoMessageToDTO(geoMessage); _context.GeoMessages.Add(geoMessage); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetMessagev2), new { id = geoMessage.Id, }, GeoMessageDTOresponse)); }
public async Task Seed(UserManager <MyUser> userManager) { await Database.EnsureDeletedAsync(); await Database.EnsureCreatedAsync(); var user = new MyUser { UserName = "******", FirstName = "John", LastName = "Userman" }; var userWithAuth = new MyUser { UserName = "******", FirstName = "George", LastName = "Costanza" }; await userManager.CreateAsync(user); await userManager.CreateAsync(userWithAuth, "Admin!123"); var geoMessage = new GeoMessage { Message = "GetTest", Latitude = 80.5, Longitude = 90.3 }; var token = new Token { Key = new Guid(), User = user }; await AddAsync(token); await AddAsync(geoMessage); await SaveChangesAsync(); }
public async Task Seed(UserManager <User> userManager) { await Database.EnsureDeletedAsync(); await Database.EnsureCreatedAsync(); User testUser = new User { UserName = "******", FirstName = "Tester", LastName = "Userson", }; await userManager.CreateAsync(testUser, "Passw0rd!"); var message = new GeoMessage { Latitude = 57.69, Longitude = 12.85, Body = "This is a drill. Do not worry!", Author = "Test Userson" }; await AddAsync(message); var messagev2 = new GeoMessage { Title = "Testtitle", Author = "Test Author", Body = "This is for testing V2", Longitude = 51.69, Latitude = 12.85 }; await AddAsync(messagev2); await SaveChangesAsync(); }
public virtual IActionResult StartAnalysis([FromBody] GeoMessage message) { this.queueClient.SendMessages(message); return(this.Created("Analysis Started", message)); }
private bool IsInRange(GeoMessage gm, int minLon, int maxLon, int minLat, int maxLat) { return(gm.Longitude > minLon && gm.Longitude < maxLon && gm.Latitude > minLat && gm.Latitude < maxLat); }
private void init() { Buzzer.init(breakout2.CreatePwmOutput(GT.Socket.Pin.Nine)); StatusLed.led = ledStrip; StatusLed.led.SetLed(0, true); DisplayLCD.lcd = displayTE35; DisplayTimer(); while (!wifi.NetworkInterface.Opened) { try { Debug.Print("Opening Wifi interface"); wifi.NetworkInterface.Open(); Thread.Sleep(1000); } catch (Exception) { Thread.Sleep(1000); continue; } } GeoMessage geomessage = new GeoMessage(wifi.NetworkInterface.Scan()); wifi.NetworkInterface.Close(); RemovableMedia.Insert += (sender, e) => { mountEvent.Set(); Debug.Print("SD Mounted"); }; while (!sdCard.IsCardInserted) { DisplayLCD.addSDInfo(false, 0); Thread.Sleep(1000); Debug.Print("Waiting for sd card"); } while (!sdCard.IsCardMounted) { DisplayLCD.addSDInfo(false, 0); Thread.Sleep(1000); if (!sdCard.IsCardMounted) { sdCard.Mount(); } } //mountEvent.WaitOne(); //byte[] data = Encoding.UTF8.GetBytes("Hello World!"); //sdCard.StorageDevice.WriteFile("measure" + 0, data); //sdCard.StorageDevice.CreateDirectory(@"test"); /*if (VolumeInfo.GetVolumes()[0].IsFormatted) * { * string rootDirectory = * VolumeInfo.GetVolumes()[0].RootDirectory; * string[] files = Directory.GetFiles(rootDirectory); * string[] folders = Directory.GetDirectories(rootDirectory); * * Debug.Print("Files available on " + rootDirectory + ":"); * for (int i = 0; i < files.Length; i++) * { * Debug.Print("Deleted " + files[i]); * sdCard.StorageDevice.Delete(files[i]); * } * Debug.Print("Folders available on " + rootDirectory + ":" + folders.Length); * } * else * { * Debug.Print("Storage is not formatted. " + * "Format on PC with FAT32/FAT16 first!"); * }*/ DisplayLCD.addSDInfo(true, 0); Ethernet eth = new Ethernet(ethernetJ11D); Debug.Print("Ethernet created"); mqtt = eth.MQTT; Debug.Print("Mqtt created"); MeasureOrchestrator.setMqtt(mqtt); MeasureDB.sd = sdCard; Debug.Print("Time updated"); TimeSync.update(); while (!mqtt.isConnected()) { Thread.Sleep(1000); } POSTContent pc = POSTContent.CreateTextBasedContent(GeoMessage.Json(geomessage)); try { HttpRequest wc = HttpHelper.CreateHttpPostRequest("http://52.57.156.220/geolocation", pc, "application/json"); wc.ResponseReceived += wc_ResponseReceived; wc.SendRequest(); } catch (Exception) { mqtt.Publish("cfg", Configuration.Json(new Configuration(45.0631, 7.66004))); } //send a request with GeoMessage.Json(message) and set the configuration FlameSensor flame = new FlameSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Three), "0"); SmokeSensor smoke = new SmokeSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Four), "1"); COSensor co = new COSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Five), "2"); TemperatureSensor temperature = new TemperatureSensor(breakout3.CreateAnalogInput(GT.Socket.Pin.Three), "3"); registerSensor(temperature); registerSensor(smoke); registerSensor(co); registerSensor(flame); pubTimer(3000); pubOldTimer(2000); }
public virtual IActionResult MakeTile([FromBody] GeoMessage tile) { this.queueClient.SendMessages(tile); return(this.Created("TileRequestCreated", tile)); }
/// <summary> /// Virtual method for writing to db information /// </summary> /// <param name="message"></param> protected virtual void WriteToDb(GeoMessage message) { }