Ejemplo n.º 1
0
        public JsonResult getDataDevice(string PLC, string Unit)
        {
            var listTagName = _db.Catalog_Datas.Where(x => x.Unit == Unit && x.DeviceName.Contains(PLC));
            var data        = (from d in _db.Datas
                               join c in _db.Catalog_Datas on d.TagName equals c.TagName
                               select new { TagName = d.TagName, DeviceName = d.DeviceName, Time = d.Time, Value = d.Value, Unit = c.Unit, Connected = d.Connected })
                              .Where(s => s.DeviceName.Contains(PLC));



            List <ListDataDevice> result = new List <ListDataDevice>();

            foreach (var item in listTagName.ToList())
            {
                var x = data.Where(x => x.TagName == item.TagName);

                List <DataDevice> dataDevices = new List <DataDevice>();
                foreach (var y in x.ToList())
                {
                    DataDevice dataDevice = new DataDevice();
                    dataDevice.TagName    = y.TagName;
                    dataDevice.DeviceName = y.DeviceName;
                    dataDevice.Time       = y.Time;
                    dataDevice.Value      = y.Value;
                    dataDevice.Unit       = y.Unit;
                    dataDevice.Connected  = y.Connected;
                    dataDevices.Add(dataDevice);
                }
                result.Add(new ListDataDevice(item.TagName, dataDevices));
            }
            return(Json(result));
        }
Ejemplo n.º 2
0
        async void PopulateDevice()
        {
            try
            {
                var ctx = await RemoteDatabase.GetDbContextAsync();

                var lstDev = ctx.Devices.ToList();
                EditedDevice = new Device();
                DataDevice.Clear();
                foreach (var dv in lstDev)
                {
                    DataDevice.Add(dv);
                }
                ctx.Database.Connection.Close();
                ctx.Dispose();
            }
            catch (Exception error)
            {
                await mainview0.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error in Populate Device");
                    exp.ShowDialog();
                }));
            }
        }
Ejemplo n.º 3
0
        public JsonResult loadTableData(string DeviceName)
        {
            try
            {
                /*db.Configuration.ProxyCreationEnabled = false;*/
                int    length         = int.Parse(Request.Query["length"]);
                int    start          = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(int.Parse(Request.Query["start"]) / length))) + 1;
                string searchValue    = Request.Query["search[value]"];
                string sortColumnName = Request.Query["columns[" + Request.Query["order[0][column]"] + "][name]"];
                string sortDirection  = Request.Query["order[0][dir]"];

                /*int length = 10;
                 * int start = 1;
                 * string searchValue = "";
                 * string sortColumnName = "ID";
                 * string sortDirection = "asc";*/
                DataPaging apg = new DataPaging();
                apg.data = new List <DataDevice>();
                start    = (start - 1) * length;
                List <Data> listData = _db.Datas.Where(x => x.DeviceName == DeviceName).ToList <Data>();
                apg.recordsTotal = listData.Count;
                //filter
                if (!string.IsNullOrEmpty(searchValue))
                {
                    listData = listData.Where(x => x.TagName.ToLower().Contains(searchValue.ToLower())).ToList <Data>();
                }


                apg.recordsFiltered = listData.Count;
                //paging
                listData = listData.Skip(start).Take(length).ToList <Data>();

                foreach (var i in listData)
                {
                    DataDevice d = new DataDevice
                    {
                        TagName    = i.TagName,
                        DeviceName = i.DeviceName,
                        Time       = i.Time,
                        Value      = i.Value,
                        Connected  = i.Connected
                    };
                    apg.data.Add(d);
                }

                apg.draw = int.Parse(Request.Query["draw"]);
                return(Json(apg));
                /*return Json(apg, JsonRequestBehavior.AllowGet);*/
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        public IActionResult SendData([FromBody] DataDevice dataDevice)
        {
            Console.WriteLine($"Device name {dataDevice.DeviceName}");
            Console.WriteLine($"Value {dataDevice.Value}");
            Console.WriteLine($"Api Key {dataDevice.ApiKey}");

            // No es la forma apropiada obviamente, se tiene que cambiar a un servicio y autorizar.
            ConnectionFactory cf = new ConnectionFactory();
            IConnection       c  = cf.CreateConnection();

            var json = JsonConvert.SerializeObject(dataDevice);

            c.Publish(dataDevice.ApiKey, Encoding.UTF8.GetBytes(json));
            c.Close();

            return(Json("true"));
        }