public IActionResult Update([FromBody] SensorSettings newObject) { try { var c = repositorio.Update(newObject); return(this.Ok(c)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(BadRequest()); } }
public static void Main(string[] args) { try { settingsConf = File.Open("settings.conf", FileMode.OpenOrCreate); StreamReader reader = new StreamReader(settingsConf); string jsonstring = reader.ReadToEnd(); sensorSettings = new SensorSettings(); sensorSettings = (SensorSettings)JsonConvert.DeserializeObject(jsonstring, typeof(SensorSettings)); sensorSettings.State = 0; operationStateRepo.Update(new OperationState( ) { State = 0 }); List <string> url = new List <string>(); string hostName = Dns.GetHostName(); // Retrive the Name of HOST Console.WriteLine(hostName); // nao efetivo se a rede nao possuir um roteador caseiro que atualiza o dns dinamicamente // ou seja, so funciona se o raspberry estiver inserido no dns da rede /* foreach(var ip in Dns.GetHostEntry(hostName).AddressList){ * if(ip.ToString().Contains('.')) * { * // Console.WriteLine("My IP Address is :"+ip); * var temp = (ip.ToString().Contains(":")?"["+ip+"]":ip.ToString()); * url.Add("http://"+temp+":1000"); * } * } */ //Get IP. Funciona sempre foreach (NetworkInterface netif in NetworkInterface.GetAllNetworkInterfaces()) { if (netif.Name != "lo" && netif.Name != "wlan0") { IPInterfaceProperties prop = netif.GetIPProperties(); var listaIps = (from p in prop.UnicastAddresses where !p.Address.ToString().Contains(":") select "http://" + p.Address.ToString() + ":1000").Distinct().ToList(); url = listaIps; Console.WriteLine("quase no for"); foreach (var p in url) { Console.WriteLine(p); } Console.WriteLine("sai do for"); } } //fim do Get Ip endereco = url; sensorSettings.HWIP = endereco[0]; } catch (System.Exception ex) { List <string> url = new List <string>(); string hostName = Dns.GetHostName(); // Retrive the Name of HOST Console.WriteLine(hostName); // Get the IP foreach (NetworkInterface netif in NetworkInterface.GetAllNetworkInterfaces()) { if (netif.Name != "lo") { IPInterfaceProperties prop = netif.GetIPProperties(); var listaIps = (from p in prop.UnicastAddresses where !p.Address.ToString().Contains(":") select "http://" + p.Address.ToString() + ":1000").Distinct().ToList(); url = listaIps; Console.WriteLine("quase no for"); foreach (var p in url) { Console.WriteLine(p); } Console.WriteLine("sai do for"); } } sensorSettings = new SensorSettings(); endereco = url; sensorSettings.HWIP = endereco[0]; sensorSettings.OperationType = 1; sensorSettings.State = 0; sensorSettings.ServersIP = "http://localhost:2005"; sensorSettings.HWIP = endereco.First(); System.Console.Write(ex.Message); } sensorSettingsRepo.Update(sensorSettings); longThread.Start(); CreateWebHostBuilder(args).Build().Run(); }