public IActionResult Index() { //return View(); SensoresContext context = HttpContext.RequestServices.GetService(typeof(coreNetMysql.Models.SensoresContext)) as SensoresContext; return(View(context.GetAll())); }
public IActionResult About() { ViewData["Message"] = "Your application description page."; SensoresContext context = HttpContext.RequestServices.GetService(typeof(CoreUI.Mvc.SensoresContext)) as SensoresContext; //SensoresContext c2 = new SensoresContext("server=citra-test.cmmqgr4kvqxz.us-east-2.rds.amazonaws.com;port=3306;database=citra;user=admin;password=12345678"); List <SensorModel> lista = context.GetAllSensors(); var Graphic = new List <SimpleReportViewModel>(); var Tiempo = lista.ElementAt(0).M; Graphic.Add(new SimpleReportViewModel { //DimensionOne = Tiempo, }); return(View(lista)); }
// GET: /<controller>/ public IActionResult Index() { SensoresContext context = HttpContext.RequestServices.GetService(typeof(CoreUI.Mvc.Models.SensorModel)) as SensoresContext; return(View(context.GetAllSensors())); }
// BeginReceive()'s call back fucntion public void CallBack_ReceiveMsg(IAsyncResult ar) { int length; String MsgRecvStr = null; SensoresContext context = new SensoresContext(Configuration.GetConnectionString("DefaultConnection")); //CheckHub a = new CheckHub(); try { // If the socket close, return the 0 value length = clientsock.EndReceive(ar); if (length > 0) { MsgRecvStr = Encoding.Default.GetString(MsgRecvBuff, 0, length); Console.WriteLine("Dato recibido:" + MsgRecvStr + "\n"); string[] res = MsgRecvStr.Split(" "); //Seteo la temperatura //a.SetTemp(MsgRecvStr); //Guardo en base de datos los registros // try { /* * System.Globalization.CultureInfo customCulture = new System.Globalization.CultureInfo("en-US", true); * * customCulture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd h:mm tt"; * * System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; * System.Threading.Thread.CurrentThread.CurrentUICulture = customCulture; * * DateTime newDate = System.Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd h:mm tt")); */ //string f = DateTime.Now.ToString("yyyy-MM-dd H:mm:ss"); DatosSensores datosSensores = new DatosSensores(); //System.Globalization.CultureInfo customCulture = new System.Globalization.CultureInfo("en-US", true); //datosSensores.Fecha = newDate; datosSensores.Temperatura = Convert.ToDecimal(res[0]); datosSensores.Humedad = Convert.ToDecimal(res[1]); datosSensores.Luminosidad = Convert.ToDecimal(res[2]); datosSensores.Voltspanel = Convert.ToDecimal(res[3]); datosSensores.Voltsbateria = 0; //datosSensores.Voltsbateria = Convert.ToDecimal(res[4]); context.Save(datosSensores); } catch (Exception ex) { Console.WriteLine("Error al querer grabar", ex.Message); } /*Conexion con MongoDb*/ /* * try * { * * MongoClient dbClient = new MongoClient("mongodb://127.0.0.1:27017"); * * //Database List * var dbList = dbClient.ListDatabases().ToList(); * * Console.WriteLine("Las base de datos son:"); * foreach (var item in dbList) * { * Console.WriteLine(item); * } * * Console.WriteLine("\n\n"); * * //Get Database and Collection * IMongoDatabase db = dbClient.GetDatabase("pruebadb"); * var collList = db.ListCollections().ToList(); * Console.WriteLine("las listas de colecciones son :"); * Console.WriteLine("\n\n"); * foreach (var item in collList) * { * Console.WriteLine(item); * * } * } * catch (Exception ex) { * Console.WriteLine("Fallo la conexión con Mongodb"); * } */ //MySql context = new SensoresContext().ConnectionString(); //HttpContext.RequestServices.GetService(typeof(coreNetMysql.Models.SensoresContext)) as SensoresContext; // context.GetAll(); //SensoresContext context = new SensoresContext(); // The socket can continuedly wait the receive message because of this function clientsock.BeginReceive(MsgRecvBuff, 0, MsgRecvBuff.Length, SocketFlags.None, new AsyncCallback(CallBack_ReceiveMsg), clientsock); } else { // If the socket close, return the 0 value // Then, socket close. clientsock.Close(); } } catch (Exception er) { Console.WriteLine(er.Message); } }