コード例 #1
0
        public int AddOrUpdateLink(SensorLink link)
        {
            int db_Id = link.db_Id;

            SensorLink oldLink = GetLink(link.db_Id);

            if (oldLink == null)
                db_Id = AddLink(link);
            else
                UpdateLink(link);

            return db_Id;
        }
コード例 #2
0
        public int AddLink(SensorLink link)
        {
            int db_Id;
            using (var db = new SqlConnection(connectionString))
            {
                db.Open();

                var sqlQuery = "INSERT INTO SensorsLinks (fromSensorDbId,fromNodeId,fromSensorId,fromDataType,fromSensorDescription, toSensorDbId, toNodeId, toSensorId,toDataType,toSensorDescription) "
                                          + "VALUES(@fromSensorDbId,@fromNodeId,@fromSensorId,@fromDataType,@fromSensorDescription, @toSensorDbId, @toNodeId, @toSensorId,@toDataType,@toSensorDescription); "
                            + "SELECT CAST(SCOPE_IDENTITY() as int)";

                db_Id = db.Query<int>(sqlQuery, link).Single();
            }
            return db_Id;
        }
コード例 #3
0
 public void UpdateLink(SensorLink link)
 {
     using (var db = new SqlConnection(connectionString))
     {
         db.Open();
         var sqlQuery =
             "UPDATE SensorsLinks SET " +
             "fromSensorDbId = @fromSensorDbId, " +
             "fromNodeId = @fromNodeId, " +
             "fromSensorId = @fromSensorId, " +
             "fromDataType = @fromDataType, " +
             "fromSensorDescription = @fromSensorDescription, " +
             "toSensorDbId = @toSensorDbId, " +
             "toNodeId = @toNodeId, " +
             "toSensorId = @toSensorId " +
             "toDataType = @toDataType " +
             "toSensorDescription = @toSensorDescription " +
             "WHERE db_Id = @db_Id";
         db.Execute(sqlQuery, link);
     }
 }
コード例 #4
0
ファイル: LinksController.cs プロジェクト: almj/MyNetSensors
        public ActionResult New(string from, string to)
        {
            string[] args = from.Split('-');
            int fromNodeId = Int32.Parse(args[0]);
            int fromSensorId = Int32.Parse(args[1]);
            SensorDataType fromDataType;
            SensorDataType.TryParse(args[2], true, out fromDataType);

            args = to.Split('-');
            int toNodeId = Int32.Parse(args[0]);
            int toSensorId = Int32.Parse(args[1]);
            SensorDataType toDataType;
            SensorDataType.TryParse(args[2], true, out toDataType);

            Sensor fromSensor = gatewayDb.GetSensor(fromNodeId, fromSensorId);
            Sensor toSensor = gatewayDb.GetSensor(toNodeId, toSensorId);

            if (fromSensor == null || toSensor == null)
                return new HttpNotFoundResult();

            bool linkPossible = CheckLinkPossible(fromSensor, toSensor);
            if (!linkPossible)
            {
                ModelState.AddModelError("", "Link impossible");
                return RedirectToAction("New");
            }

            Node fromNode = gatewayDb.GetNodeByNodeId(fromSensor.ownerNodeId);
            Node toNode = gatewayDb.GetNodeByNodeId(toSensor.ownerNodeId);

            SensorLink link = new SensorLink()
            {
                fromNodeId = fromNodeId,
                fromSensorId = fromSensorId,
                fromDataType = fromDataType,
                fromSensorDbId = fromSensor.db_Id,
                fromSensorDescription = String.Format("{0} {1}",
                    fromNode.GetSimpleName1(),
                    fromSensor.GetSimpleName1()),
                toNodeId = toNodeId,
                toSensorId = toSensorId,
                toDataType = toDataType,
                toSensorDbId = toSensor.db_Id,
                toSensorDescription = String.Format("{0} {1}",
                    toNode.GetSimpleName1(),
                    toSensor.GetSimpleName1())
            };

            linksDb.AddLink(link);
            context.Clients.Client(GatewayHubStaticData.gatewayId).updateSensorsLinks();
            return RedirectToAction("List", new { id1 = link.toNodeId, id2 = link.toSensorId });
        }
コード例 #5
0
ファイル: LinksController.cs プロジェクト: almj/MyNetSensors
        public ActionResult New(int? id1 = null, int? id2 = null)
        {
            if (id1 != null && id2 != null)
            {
                Sensor sensor = gatewayDb.GetSensor(id1.Value, id2.Value);

                if (sensor == null)
                    return new HttpNotFoundResult();

                ViewBag.from = gatewayDb.GetNodes();
                ViewBag.description = sensor.GetSimpleName1();

                List<Node> toList=new List<Node>();
                Node toNode = gatewayDb.GetNodeByNodeId(sensor.ownerNodeId);
                toNode.sensors.Clear();
                toNode.sensors.Add(sensor);
                toList.Add(toNode);

                ViewBag.to = toList;

                SensorLink link = new SensorLink()
                {
                    toNodeId = sensor.ownerNodeId,
                    toSensorId = sensor.sensorId
                };

                return View(link);
            }
            else if (RouteData.Values.Count <= 2)
            {
                ViewBag.from = gatewayDb.GetNodes();
                ViewBag.to = ViewBag.from;

                return View();
            }

            return new HttpNotFoundResult();
        }
コード例 #6
0
        public ActionResult New(string from, string to)
        {
            string[] args = from.Split('-');
            int fromNodeId = Int32.Parse(args[0]);
            int fromSensorId = Int32.Parse(args[1]);
            SensorDataType fromDataType;
            SensorDataType.TryParse(args[2], true, out fromDataType);

            args = to.Split('-');
            int toNodeId = Int32.Parse(args[0]);
            int toSensorId = Int32.Parse(args[1]);
            SensorDataType toDataType;
            SensorDataType.TryParse(args[2], true, out toDataType);

            Sensor fromSensor = gatewayDb.GetSensor(fromNodeId, fromSensorId);
            Sensor toSensor = gatewayDb.GetSensor(toNodeId, toSensorId);

            if (fromSensor == null || toSensor == null)
                return new HttpNotFoundResult();

            bool linkPossible = CheckLinkPossible(fromSensor, toSensor);
            if (!linkPossible)
            {
                ModelState.AddModelError("", "Link impossible");
                return RedirectToAction("New");
            }

            Node fromNode = gatewayDb.GetNodeByNodeId(fromSensor.nodeId);
            Node toNode = gatewayDb.GetNodeByNodeId(toSensor.nodeId);

            SensorLink link = new SensorLink()
            {
                fromNodeId = fromNodeId,
                fromSensorId = fromSensorId,
                fromDataType = fromDataType,
                fromSensorDbId = fromSensor.db_Id,
                fromSensorDescription = $"{fromNode.GetSimpleName1()} {fromSensor.GetSimpleName1()}",
                toNodeId = toNodeId,
                toSensorId = toSensorId,
                toDataType = toDataType,
                toSensorDbId = toSensor.db_Id,
                toSensorDescription = $"{toNode.GetSimpleName1()} {toSensor.GetSimpleName1()}"
            };

            linksDb.AddLink(link);

            GatewayAPIController gatewayApi = new GatewayAPIController();
            gatewayApi.UpdateSensorsLinks();

            return RedirectToAction("List", new { id = link.toNodeId, id2 = link.toSensorId });
        }