Ejemplo n.º 1
0
        public ActionResult <Model.DeviceStatus> Get(string id)
        {
            var status = new Model.DeviceStatus();

            if (string.IsNullOrWhiteSpace(id))
            {
                return(status);
            }

            var devStatusCollection =
                stateManager.GetOrAddAsync <IReliableDictionary <string, Model.DeviceStatus> >(
                    ReliableObjectNames.DeviceStatusDictionary)
                .GetAwaiter()
                .GetResult();

            using (var txn = stateManager.CreateTransaction())
            {
                var devData = devStatusCollection.TryGetValueAsync(txn, id).GetAwaiter().GetResult();
                if (devData.HasValue)
                {
                    status = devData.Value;
                }
                else
                {
                    status.Id     = id;
                    status.Status = "Unknown";
                }
            }

            return(status);
        }
Ejemplo n.º 2
0
        public bool add(Model.DeviceStatus devStatus)
        {
            try
            {
                OracleParameter[] parms = new OracleParameter[] {
                    new OracleParameter(":DEVCODE", devStatus.DEVCODE),
                    new OracleParameter(":STATUS", (object)0),
                    new OracleParameter(":SENSORTYPECODE", devStatus.SensorTypeCode)
                };
                string SQL = "INSERT INTO ALARM_DEVICE_STATUS (DBID,DEVCODE,STATUS,SENSORTYPECODE) "
                             + "VALUES"
                             + " (SEQ_ALARM_DEVICE_STATUS_ID.NEXTVAL,:DEVCODE,:STATUS,:SENSORTYPECODE)";

                string strCnn = OracleHelper.ConnectionStringOrderDistributedTransaction;
                using (OracleConnection cnn = new OracleConnection(strCnn))
                {
                    OracleHelper.ExecuteNonQuery(cnn, CommandType.Text, SQL, parms);
                }
                return(true);
            }
            catch (Exception e)
            {
                return(false);

                throw e;
            }
        }
Ejemplo n.º 3
0
        private Model.DeviceStatus GetDeviceStatusByOracleDataReader(OracleDataReader rdr)
        {
            string[]  colsName;
            int[]     colsOrdinal;
            const int colsCount = 5;

            Model.DeviceStatus deviceStatus;


            colsName = new string[colsCount] {
                "DBID", "DEVCODE", "LASTTIME",
                "STATUS", "SENSORTYPECODE"
            };
            colsOrdinal = new int[colsCount];

            if (GetColumnsOrdinal(rdr, colsName, colsOrdinal) < 0)
            {
                throw (new Exception("Error"));
            }

            deviceStatus = new Model.DeviceStatus();

            for (int i = 0; i < colsCount; i++)
            {
                //if (colsOrdinal[i] < 0 || rdr.IsDBNull(colsOrdinal[i]))
                if (colsOrdinal[i] < 0)
                {
                    continue;
                }
                switch (i)
                {
                case 0:
                    deviceStatus.DBID = rdr.GetInt32(colsOrdinal[i]);
                    break;

                case 1:
                    deviceStatus.DEVCODE = rdr.GetString(colsOrdinal[i]);
                    break;

                case 2:
                    if (!rdr.IsDBNull(colsOrdinal[i]))
                    {
                        deviceStatus.LASTTIME = rdr.GetDateTime(colsOrdinal[i]);
                    }
                    break;

                case 3:
                    deviceStatus.STATUS = false;
                    break;

                case 4:
                    deviceStatus.SensorTypeCode = rdr.GetString(colsOrdinal[i]);
                    break;
                }
            }

            return(deviceStatus);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update a deviceConfig in the database
        /// </summary>
        /// <param name="ate">Adapter information to update</param>
        public void update(Model.DeviceStatus devStatus)
        {
            OracleParameter[] parms = GetDeviceStatusParameters();
            SetDeviceStatusParameters(parms, devStatus);

            try
            {
                int rst = OracleHelper.ExecuteNonQuery(OracleHelper.ConnectionStringOrderDistributedTransaction, CommandType.Text, SQL_UPDATE_ALARM_DEVICE_STATUS, parms);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
0
 public void updateDevStatus(List <Model.CasicWaterMeter> djPressInfoList)
 {
     foreach (Model.CasicWaterMeter pressInfo in djPressInfoList)
     {
         Model.DeviceStatus deviceStatus = new Model.DeviceStatus();
         deviceStatus = new BLL.DeviceStatus().getByDevCode(pressInfo.DEVCODE);
         if (deviceStatus == null)
         {
             continue;
         }
         deviceStatus.LASTTIME = DateTime.Now;
         deviceStatus.STATUS   = false;
         new BLL.DeviceStatus().update(deviceStatus);
     }
 }
Ejemplo n.º 6
0
 public void updateDevStatus(List <SlNoiseInfo> slNoiseInfoList)
 {
     foreach (SlNoiseInfo slNoiseInfo in slNoiseInfoList)
     {
         Model.DeviceStatus deviceStatus = new Model.DeviceStatus();
         deviceStatus = new BLL.DeviceStatus().getByDevCode(slNoiseInfo.SRCID);
         if (deviceStatus == null)
         {
             continue;
         }
         deviceStatus.LASTTIME = DateTime.Now;
         deviceStatus.STATUS   = false;
         new BLL.DeviceStatus().update(deviceStatus);
     }
 }
Ejemplo n.º 7
0
 public void updateDevStatus(List <DjLiquidInfo> djLiquidInfoList)
 {
     foreach (DjLiquidInfo djLiquidInfo in djLiquidInfoList)
     {
         Model.DeviceStatus deviceStatus = new Model.DeviceStatus();
         deviceStatus = new BLL.DeviceStatus().getByDevCode(djLiquidInfo.DEVID);
         if (deviceStatus == null)
         {
             continue;
         }
         deviceStatus.LASTTIME = DateTime.Now;
         deviceStatus.STATUS   = false;
         new BLL.DeviceStatus().update(deviceStatus);
     }
 }
Ejemplo n.º 8
0
        public Model.DeviceStatus getByDevCodeAndType(String devCode, String sensorTypeCode)
        {
            using (OracleConnection conn = new OracleConnection(OracleHelper.ConnectionStringOrderDistributedTransaction))
            {
                String SQL = " SELECT * " +
                             " FROM ALARM_DEVICE_STATUS " +
                             " WHERE DEVCODE = :DEVCODE AND SENSORTYPECODE= :SENSORTYPECODE";
                OracleParameter[] oraParams = new OracleParameter[] {
                    new OracleParameter(":DEVCODE", devCode),
                    new OracleParameter(":SENSORTYPECODE", sensorTypeCode)
                };
                DataTable dt = OracleHelper.ExecuteDataset(conn, CommandType.Text, SQL, oraParams).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Model.DeviceStatus deviceStatus = new Model.DeviceStatus();
                    if (dt.Rows[0]["DBID"] != null)
                    {
                        deviceStatus.DBID = long.Parse(dt.Rows[0]["DBID"].ToString());
                    }

                    if (dt.Rows[0]["DEVCODE"] != null)
                    {
                        deviceStatus.DEVCODE = dt.Rows[0]["DEVCODE"].ToString();
                    }

                    if (dt.Rows[0]["LASTTIME"] != null && !dt.Rows[0]["LASTTIME"].ToString().Equals(""))
                    {
                        deviceStatus.LASTTIME = (DateTime)dt.Rows[0]["LASTTIME"];
                    }

                    if (dt.Rows[0]["STATUS"] != null)
                    {
                        if (dt.Rows[0]["STATUS"].ToString().Equals("0"))
                        {
                            deviceStatus.STATUS = false;
                        }
                        else
                        {
                            deviceStatus.STATUS = true;
                        }
                    }
                    return(deviceStatus);
                }
            }
            return(null);
        }
Ejemplo n.º 9
0
        public void Delete(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return;
            }

            var devStatusCollection =
                stateManager.GetOrAddAsync <IReliableDictionary <string, Model.DeviceStatus> >(
                    ReliableObjectNames.DeviceStatusDictionary)
                .GetAwaiter()
                .GetResult();

            var status = new Model.DeviceStatus();

            using (var txn = stateManager.CreateTransaction())
            {
                devStatusCollection.TryRemoveAsync(txn, id).GetAwaiter().GetResult();
                txn.CommitAsync().GetAwaiter().GetResult();
            }
        }
Ejemplo n.º 10
0
        public void Put([FromBody] Model.DeviceStatus data)
        {
            if (data == null ||
                string.IsNullOrWhiteSpace(data.Id))
            {
                return;
            }

            var devStatusCollection =
                stateManager.GetOrAddAsync <IReliableDictionary <string, Model.DeviceStatus> >(
                    ReliableObjectNames.DeviceStatusDictionary)
                .GetAwaiter()
                .GetResult();

            var status = new Model.DeviceStatus();

            using (var txn = stateManager.CreateTransaction())
            {
                devStatusCollection.SetAsync(txn, data.Id, data).GetAwaiter().GetResult();
                txn.CommitAsync().GetAwaiter().GetResult();
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// An internal function to bind values parameters for insert
 /// </summary>
 /// <param name="parms">Database parameters</param>
 /// <param name="doc">Values to bind to parameters</param>
 private void SetDeviceStatusParameters(OracleParameter[] parms, Model.DeviceStatus devStatus)
 {
     parms[0].Value = devStatus.LASTTIME;
     parms[1].Value = devStatus.STATUS;
     parms[2].Value = devStatus.DBID;
 }
Ejemplo n.º 12
0
        public bool save(Model.DeviceStatus devStatus)
        {
            IDeviceStatus iDeviceStatus = SensorHub.DALFactory.DeviceStatus.Create();

            return(iDeviceStatus.add(devStatus));
        }
Ejemplo n.º 13
0
        public void update(Model.DeviceStatus devStatus)
        {
            IDeviceStatus iDeviceStatus = SensorHub.DALFactory.DeviceStatus.Create();

            iDeviceStatus.update(devStatus);
        }