diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.vshost.exe.manifest b/bin/BRServerTest.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/BRServerTest.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.vshost.exe.manifest b/bin/BRServerTest.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/BRServerTest.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Logs/debug.log b/bin/Logs/debug.log index 6257246..2f3a156 100644 --- a/bin/Logs/debug.log +++ b/bin/Logs/debug.log @@ -1,7 +1,70 @@ -2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! -2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered -2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! -2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started -2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:08:45,557 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:08:45,602 [8252] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:08:45,617 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:08:48,250 [8252] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:08:48,255 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:16:58,302 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:16:58,340 [12228] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:16:58,353 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:17:01,040 [12228] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:17:01,045 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:19:42,735 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:19:42,776 [8260] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:19:42,789 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:19:45,571 [8260] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:19:45,575 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:23:28,089 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:23:28,135 [7220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:23:28,147 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:23:30,756 [7220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:23:30,763 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:47:58,915 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:47:58,964 [5404] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:47:58,981 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:48:01,743 [5404] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:48:01,747 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:52:27,821 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:52:27,864 [6648] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:52:27,879 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:52:30,594 [6648] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:52:30,599 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:03:04,186 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:03:04,242 [6784] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:03:04,258 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:03:07,053 [6784] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:03:07,058 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:18:16,795 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:18:16,843 [6008] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:18:16,859 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:18:19,566 [6008] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:18:19,571 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:21:37,702 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:21:37,742 [9316] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:21:37,756 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:21:40,397 [9316] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:21:40,406 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:22:53,293 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:22:53,346 [8452] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:22:53,363 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:22:56,059 [8452] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:22:56,066 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.vshost.exe.manifest b/bin/BRServerTest.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/BRServerTest.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Logs/debug.log b/bin/Logs/debug.log index 6257246..2f3a156 100644 --- a/bin/Logs/debug.log +++ b/bin/Logs/debug.log @@ -1,7 +1,70 @@ -2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! -2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered -2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! -2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started -2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:08:45,557 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:08:45,602 [8252] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:08:45,617 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:08:48,250 [8252] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:08:48,255 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:16:58,302 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:16:58,340 [12228] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:16:58,353 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:17:01,040 [12228] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:17:01,045 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:19:42,735 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:19:42,776 [8260] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:19:42,789 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:19:45,571 [8260] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:19:45,575 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:23:28,089 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:23:28,135 [7220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:23:28,147 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:23:30,756 [7220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:23:30,763 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:47:58,915 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:47:58,964 [5404] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:47:58,981 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:48:01,743 [5404] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:48:01,747 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:52:27,821 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:52:27,864 [6648] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:52:27,879 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:52:30,594 [6648] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:52:30,599 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:03:04,186 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:03:04,242 [6784] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:03:04,258 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:03:07,053 [6784] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:03:07,058 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:18:16,795 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:18:16,843 [6008] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:18:16,859 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:18:19,566 [6008] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:18:19,571 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:21:37,702 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:21:37,742 [9316] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:21:37,756 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:21:40,397 [9316] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:21:40,406 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:22:53,293 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:22:53,346 [8452] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:22:53,363 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:22:56,059 [8452] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:22:56,066 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/debug.log20190312 b/bin/Logs/debug.log20190312 new file mode 100644 index 0000000..6257246 --- /dev/null +++ b/bin/Logs/debug.log20190312 @@ -0,0 +1,7 @@ +2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.vshost.exe.manifest b/bin/BRServerTest.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/BRServerTest.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Logs/debug.log b/bin/Logs/debug.log index 6257246..2f3a156 100644 --- a/bin/Logs/debug.log +++ b/bin/Logs/debug.log @@ -1,7 +1,70 @@ -2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! -2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered -2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! -2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started -2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:08:45,557 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:08:45,602 [8252] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:08:45,617 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:08:48,250 [8252] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:08:48,255 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:16:58,302 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:16:58,340 [12228] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:16:58,353 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:17:01,040 [12228] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:17:01,045 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:19:42,735 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:19:42,776 [8260] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:19:42,789 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:19:45,571 [8260] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:19:45,575 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:23:28,089 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:23:28,135 [7220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:23:28,147 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:23:30,756 [7220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:23:30,763 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:47:58,915 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:47:58,964 [5404] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:47:58,981 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:48:01,743 [5404] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:48:01,747 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:52:27,821 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:52:27,864 [6648] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:52:27,879 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:52:30,594 [6648] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:52:30,599 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:03:04,186 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:03:04,242 [6784] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:03:04,258 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:03:07,053 [6784] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:03:07,058 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:18:16,795 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:18:16,843 [6008] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:18:16,859 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:18:19,566 [6008] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:18:19,571 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:21:37,702 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:21:37,742 [9316] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:21:37,756 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:21:40,397 [9316] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:21:40,406 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:22:53,293 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:22:53,346 [8452] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:22:53,363 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:22:56,059 [8452] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:22:56,066 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/debug.log20190312 b/bin/Logs/debug.log20190312 new file mode 100644 index 0000000..6257246 --- /dev/null +++ b/bin/Logs/debug.log20190312 @@ -0,0 +1,7 @@ +2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/err.log b/bin/Logs/err.log index af8a711..bdd985b 100644 --- a/bin/Logs/err.log +++ b/bin/Logs/err.log @@ -1,34 +1,48 @@ -2019-03-12 09:26:55,597 [8684] ERROR DefaultBootstrap - Failed to create server instance TelecomServer! -System.IO.FileNotFoundException: δ�ܼ����ļ�����򼯡�BRServer��������ijһ�������ϵͳ�Ҳ���ָ�����ļ��� -�ļ���:��BRServer�� - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) - �� System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) - �� System.Type.GetType(String typeName, Boolean throwOnError) - �� SuperSocket.SocketEngine.DefaultBootstrap.CreateWorkItemInstance(String serviceTypeName, StatusInfoAttribute[] serverStatusMetadata) - �� SuperSocket.SocketEngine.DefaultBootstrap.InitializeAndSetupWorkItem(WorkItemFactoryInfo factoryInfo) - -=== Ԥ��״̬��Ϣ === -��־: DisplayName = BRServer - (Partial) -����: Ϊ�����ṩ�˲��ְ���Ϣ: -����: ��������: BRServer | �� ID: 1 -����: �����ṩ������ʾ���Ƶ�һ����ʱ�����������ְ󶨡� -����: ����ܵ������������ش���ij��򼯡� -����: ����Ϊ�����ṩ��ȫָ�������ֱ�ʶ�� -����: ���ɼ����ơ��汾�������Ժ͹�Կ�����ɡ� -����: �йش��������ϸ��Ϣ�ͳ��������������μ���Ƥ�� http://go.microsoft.com/fwlink/?LinkId=109270�� -��־: Appbase = file:///E:/gwq/BRServer/bin/ -��־: ��ʼ PrivatePath = NULL -���ó���: SuperSocket.SocketEngine, Version=1.6.2.0, Culture=neutral, PublicKeyToken=6c80000676988ebb�� -=== -��־: �˰󶨴� default ���������Ŀ�ʼ�� -��־: ����ʹ��Ӧ�ó��������ļ�: E:\gwq\BRServer\bin\BRCJServerTest.vshost.exe.Config -��־: ʹ�����������ļ�: -��־: ʹ�� C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config �ļ���������ļ��� -��־: ��ʱû��Ϊ����Ӧ�ò���(˽�С��Զ��塢�ֲ������λ�õij��򼯰�)�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.EXE�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.EXE�� - +2019-03-14 11:19:55,014 [11964] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 66 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:37,328 [8624] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:57,890 [11700] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:25:44,997 [5460] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:52:39,160 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:55:57,449 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:57:38,760 [6112] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:18:39,687 [10844] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:08,846 [4896] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:36,057 [8500] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.vshost.exe.manifest b/bin/BRServerTest.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/BRServerTest.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Logs/debug.log b/bin/Logs/debug.log index 6257246..2f3a156 100644 --- a/bin/Logs/debug.log +++ b/bin/Logs/debug.log @@ -1,7 +1,70 @@ -2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! -2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered -2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! -2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started -2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:08:45,557 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:08:45,602 [8252] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:08:45,617 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:08:48,250 [8252] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:08:48,255 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:16:58,302 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:16:58,340 [12228] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:16:58,353 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:17:01,040 [12228] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:17:01,045 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:19:42,735 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:19:42,776 [8260] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:19:42,789 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:19:45,571 [8260] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:19:45,575 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:23:28,089 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:23:28,135 [7220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:23:28,147 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:23:30,756 [7220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:23:30,763 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:47:58,915 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:47:58,964 [5404] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:47:58,981 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:48:01,743 [5404] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:48:01,747 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:52:27,821 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:52:27,864 [6648] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:52:27,879 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:52:30,594 [6648] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:52:30,599 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:03:04,186 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:03:04,242 [6784] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:03:04,258 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:03:07,053 [6784] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:03:07,058 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:18:16,795 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:18:16,843 [6008] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:18:16,859 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:18:19,566 [6008] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:18:19,571 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:21:37,702 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:21:37,742 [9316] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:21:37,756 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:21:40,397 [9316] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:21:40,406 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:22:53,293 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:22:53,346 [8452] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:22:53,363 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:22:56,059 [8452] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:22:56,066 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/debug.log20190312 b/bin/Logs/debug.log20190312 new file mode 100644 index 0000000..6257246 --- /dev/null +++ b/bin/Logs/debug.log20190312 @@ -0,0 +1,7 @@ +2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/err.log b/bin/Logs/err.log index af8a711..bdd985b 100644 --- a/bin/Logs/err.log +++ b/bin/Logs/err.log @@ -1,34 +1,48 @@ -2019-03-12 09:26:55,597 [8684] ERROR DefaultBootstrap - Failed to create server instance TelecomServer! -System.IO.FileNotFoundException: δ�ܼ����ļ�����򼯡�BRServer��������ijһ�������ϵͳ�Ҳ���ָ�����ļ��� -�ļ���:��BRServer�� - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) - �� System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) - �� System.Type.GetType(String typeName, Boolean throwOnError) - �� SuperSocket.SocketEngine.DefaultBootstrap.CreateWorkItemInstance(String serviceTypeName, StatusInfoAttribute[] serverStatusMetadata) - �� SuperSocket.SocketEngine.DefaultBootstrap.InitializeAndSetupWorkItem(WorkItemFactoryInfo factoryInfo) - -=== Ԥ��״̬��Ϣ === -��־: DisplayName = BRServer - (Partial) -����: Ϊ�����ṩ�˲��ְ���Ϣ: -����: ��������: BRServer | �� ID: 1 -����: �����ṩ������ʾ���Ƶ�һ����ʱ�����������ְ󶨡� -����: ����ܵ������������ش���ij��򼯡� -����: ����Ϊ�����ṩ��ȫָ�������ֱ�ʶ�� -����: ���ɼ����ơ��汾�������Ժ͹�Կ�����ɡ� -����: �йش��������ϸ��Ϣ�ͳ��������������μ���Ƥ�� http://go.microsoft.com/fwlink/?LinkId=109270�� -��־: Appbase = file:///E:/gwq/BRServer/bin/ -��־: ��ʼ PrivatePath = NULL -���ó���: SuperSocket.SocketEngine, Version=1.6.2.0, Culture=neutral, PublicKeyToken=6c80000676988ebb�� -=== -��־: �˰󶨴� default ���������Ŀ�ʼ�� -��־: ����ʹ��Ӧ�ó��������ļ�: E:\gwq\BRServer\bin\BRCJServerTest.vshost.exe.Config -��־: ʹ�����������ļ�: -��־: ʹ�� C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config �ļ���������ļ��� -��־: ��ʱû��Ϊ����Ӧ�ò���(˽�С��Զ��塢�ֲ������λ�õij��򼯰�)�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.EXE�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.EXE�� - +2019-03-14 11:19:55,014 [11964] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 66 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:37,328 [8624] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:57,890 [11700] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:25:44,997 [5460] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:52:39,160 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:55:57,449 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:57:38,760 [6112] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:18:39,687 [10844] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:08,846 [4896] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:36,057 [8500] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 diff --git a/bin/Logs/info.log b/bin/Logs/info.log index c43e11c..7663110 100644 --- a/bin/Logs/info.log +++ b/bin/Logs/info.log @@ -1 +1,168 @@ -2019-03-12 09:28:51,437 [8220] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:08:48,251 [8252] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:17:01,040 [12228] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:19:45,572 [8260] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:19:49,320 [10844] INFO TelecomServer - Session: 23a74cbb-c647-4247-8c58-91de32a47913/192.168.8.107:54103 +A new session connected! +2019-03-14 11:19:51,476 [11964] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - �豸����:��������� +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ����seq:01 +2019-03-14 11:19:51,481 [11964] INFO TelecomServer - ��������������ϴ�TAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:19:51,484 [10844] INFO TelecomServer - Session: 23a74cbb-c647-4247-8c58-91de32a47913/192.168.8.107:54103 +This session was closed for ServerClosing! +2019-03-14 11:23:30,757 [7220] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:23:30,936 [6140] INFO TelecomServer - Session: 43adbb6d-d355-4c96-a248-4ff96b292340/192.168.8.107:54204 +A new session connected! +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - �豸����:��������� +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ����seq:01 +2019-03-14 11:23:49,444 [8624] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:23:49,447 [8624] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:23:49,456 [5464] INFO TelecomServer - Session: 43adbb6d-d355-4c96-a248-4ff96b292340/192.168.8.107:54204 +This session was closed for ServerClosing! +2019-03-14 11:24:40,942 [6140] INFO TelecomServer - Session: 6bff6253-4133-4fa8-bf06-f6f58f89bf95/192.168.8.107:54251 +A new session connected! +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - �豸����:��������� +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ����seq:01 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:24:41,500 [8440] INFO TelecomServer - Session: 6bff6253-4133-4fa8-bf06-f6f58f89bf95/192.168.8.107:54251 +This session was closed for ServerClosing! +2019-03-14 11:25:29,770 [8440] INFO TelecomServer - Session: bf7d9f60-7538-48c1-884a-a176fafe35c0/192.168.8.107:54268 +A new session connected! +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - Session: bf7d9f60-7538-48c1-884a-a176fafe35c0/192.168.8.107:54268 +This session was closed for ServerClosing! +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - �豸����:��������� +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ����seq:01 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:48:01,744 [5404] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:52:30,595 [6648] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:52:30,717 [6060] INFO TelecomServer - Session: 089558ed-5059-4137-a7a4-d33f9fb1c0f9/192.168.8.107:55015 +A new session connected! +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - �豸����:��������� +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ����seq:01 +2019-03-14 11:52:35,873 [8756] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 11:52:35,893 [10336] INFO TelecomServer - Session: 089558ed-5059-4137-a7a4-d33f9fb1c0f9/192.168.8.107:55015 +This session was closed for ServerClosing! +2019-03-14 11:52:57,912 [10336] INFO TelecomServer - Session: b453cd97-e00b-41d9-b3bc-33d26dc46999/192.168.8.107:55050 +A new session connected! +2019-03-14 11:52:58,542 [8756] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:52:58,542 [8756] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - �豸����:��������� +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - ����seq:01 +2019-03-14 11:52:58,545 [11640] INFO TelecomServer - Session: b453cd97-e00b-41d9-b3bc-33d26dc46999/192.168.8.107:55050 +This session was closed for ServerClosing! +2019-03-14 11:55:55,378 [8756] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 11:55:59,241 [12184] INFO TelecomServer - Session: 9fe29086-3fb8-4040-8872-1582388389a2/192.168.8.107:55126 +A new session connected! +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:55:59,818 [11640] INFO TelecomServer - Session: 9fe29086-3fb8-4040-8872-1582388389a2/192.168.8.107:55126 +This session was closed for ServerClosing! +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - �豸����:��������� +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:55:59,819 [6112] INFO TelecomServer - ����seq:01 +2019-03-14 11:57:38,077 [6112] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 12:03:07,054 [6784] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:03:07,336 [8328] INFO TelecomServer - Session: 4b7960c8-b918-4d85-ab45-7c94926b1488/192.168.8.107:55292 +A new session connected! +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - �豸����:��������� +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ����seq:01 +2019-03-14 12:03:24,616 [7976] INFO TelecomServer - Session: 4b7960c8-b918-4d85-ab45-7c94926b1488/192.168.8.107:55292 +This session was closed for ServerClosing! +2019-03-14 12:18:19,566 [6008] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:18:26,781 [11724] INFO TelecomServer - Session: cb6dc683-e58d-4091-90ff-3eb10428453e/192.168.8.107:55696 +A new session connected! +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - �豸����:��������� +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ����seq:01 +2019-03-14 12:18:36,731 [10844] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:18:36,749 [2444] INFO TelecomServer - Session: cb6dc683-e58d-4091-90ff-3eb10428453e/192.168.8.107:55696 +This session was closed for ServerClosing! +2019-03-14 12:21:40,398 [9316] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:21:40,562 [9828] INFO TelecomServer - Session: 408cbb6b-e6d6-4cea-9f0a-6c8863c7b774/192.168.8.107:55792 +A new session connected! +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - �豸����:��������� +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ����seq:01 +2019-03-14 12:21:43,430 [11964] INFO TelecomServer - Session: 408cbb6b-e6d6-4cea-9f0a-6c8863c7b774/192.168.8.107:55792 +This session was closed for ServerClosing! +2019-03-14 12:21:43,432 [8728] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:22:56,060 [8452] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:22:57,428 [5404] INFO TelecomServer - Session: 3b80d27c-364f-4332-91f8-64bad25052d8/192.168.8.107:55826 +A new session connected! +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - �豸����:��������� +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ����seq:01 +2019-03-14 12:23:06,628 [4896] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:23:06,664 [9296] INFO TelecomServer - Session: 3b80d27c-364f-4332-91f8-64bad25052d8/192.168.8.107:55826 +This session was closed for ServerClosing! +2019-03-14 12:23:17,609 [5404] INFO TelecomServer - Session: 8cd0979c-7513-40fa-8127-86cf9e013b3e/192.168.8.107:55833 +A new session connected! +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - �豸����:��������� +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ����seq:01 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:23:20,478 [9296] INFO TelecomServer - Session: 8cd0979c-7513-40fa-8127-86cf9e013b3e/192.168.8.107:55833 +This session was closed for ServerClosing! diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.vshost.exe.manifest b/bin/BRServerTest.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/BRServerTest.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Logs/debug.log b/bin/Logs/debug.log index 6257246..2f3a156 100644 --- a/bin/Logs/debug.log +++ b/bin/Logs/debug.log @@ -1,7 +1,70 @@ -2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! -2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered -2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! -2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started -2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:08:45,557 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:08:45,602 [8252] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:08:45,617 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:08:48,250 [8252] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:08:48,255 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:16:58,302 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:16:58,340 [12228] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:16:58,353 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:17:01,040 [12228] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:17:01,045 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:19:42,735 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:19:42,776 [8260] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:19:42,789 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:19:45,571 [8260] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:19:45,575 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:23:28,089 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:23:28,135 [7220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:23:28,147 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:23:30,756 [7220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:23:30,763 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:47:58,915 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:47:58,964 [5404] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:47:58,981 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:48:01,743 [5404] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:48:01,747 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:52:27,821 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:52:27,864 [6648] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:52:27,879 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:52:30,594 [6648] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:52:30,599 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:03:04,186 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:03:04,242 [6784] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:03:04,258 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:03:07,053 [6784] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:03:07,058 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:18:16,795 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:18:16,843 [6008] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:18:16,859 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:18:19,566 [6008] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:18:19,571 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:21:37,702 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:21:37,742 [9316] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:21:37,756 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:21:40,397 [9316] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:21:40,406 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:22:53,293 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:22:53,346 [8452] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:22:53,363 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:22:56,059 [8452] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:22:56,066 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/debug.log20190312 b/bin/Logs/debug.log20190312 new file mode 100644 index 0000000..6257246 --- /dev/null +++ b/bin/Logs/debug.log20190312 @@ -0,0 +1,7 @@ +2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/err.log b/bin/Logs/err.log index af8a711..bdd985b 100644 --- a/bin/Logs/err.log +++ b/bin/Logs/err.log @@ -1,34 +1,48 @@ -2019-03-12 09:26:55,597 [8684] ERROR DefaultBootstrap - Failed to create server instance TelecomServer! -System.IO.FileNotFoundException: δ�ܼ����ļ�����򼯡�BRServer��������ijһ�������ϵͳ�Ҳ���ָ�����ļ��� -�ļ���:��BRServer�� - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) - �� System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) - �� System.Type.GetType(String typeName, Boolean throwOnError) - �� SuperSocket.SocketEngine.DefaultBootstrap.CreateWorkItemInstance(String serviceTypeName, StatusInfoAttribute[] serverStatusMetadata) - �� SuperSocket.SocketEngine.DefaultBootstrap.InitializeAndSetupWorkItem(WorkItemFactoryInfo factoryInfo) - -=== Ԥ��״̬��Ϣ === -��־: DisplayName = BRServer - (Partial) -����: Ϊ�����ṩ�˲��ְ���Ϣ: -����: ��������: BRServer | �� ID: 1 -����: �����ṩ������ʾ���Ƶ�һ����ʱ�����������ְ󶨡� -����: ����ܵ������������ش���ij��򼯡� -����: ����Ϊ�����ṩ��ȫָ�������ֱ�ʶ�� -����: ���ɼ����ơ��汾�������Ժ͹�Կ�����ɡ� -����: �йش��������ϸ��Ϣ�ͳ��������������μ���Ƥ�� http://go.microsoft.com/fwlink/?LinkId=109270�� -��־: Appbase = file:///E:/gwq/BRServer/bin/ -��־: ��ʼ PrivatePath = NULL -���ó���: SuperSocket.SocketEngine, Version=1.6.2.0, Culture=neutral, PublicKeyToken=6c80000676988ebb�� -=== -��־: �˰󶨴� default ���������Ŀ�ʼ�� -��־: ����ʹ��Ӧ�ó��������ļ�: E:\gwq\BRServer\bin\BRCJServerTest.vshost.exe.Config -��־: ʹ�����������ļ�: -��־: ʹ�� C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config �ļ���������ļ��� -��־: ��ʱû��Ϊ����Ӧ�ò���(˽�С��Զ��塢�ֲ������λ�õij��򼯰�)�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.EXE�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.EXE�� - +2019-03-14 11:19:55,014 [11964] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 66 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:37,328 [8624] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:57,890 [11700] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:25:44,997 [5460] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:52:39,160 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:55:57,449 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:57:38,760 [6112] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:18:39,687 [10844] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:08,846 [4896] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:36,057 [8500] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 diff --git a/bin/Logs/info.log b/bin/Logs/info.log index c43e11c..7663110 100644 --- a/bin/Logs/info.log +++ b/bin/Logs/info.log @@ -1 +1,168 @@ -2019-03-12 09:28:51,437 [8220] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:08:48,251 [8252] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:17:01,040 [12228] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:19:45,572 [8260] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:19:49,320 [10844] INFO TelecomServer - Session: 23a74cbb-c647-4247-8c58-91de32a47913/192.168.8.107:54103 +A new session connected! +2019-03-14 11:19:51,476 [11964] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - �豸����:��������� +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ����seq:01 +2019-03-14 11:19:51,481 [11964] INFO TelecomServer - ��������������ϴ�TAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:19:51,484 [10844] INFO TelecomServer - Session: 23a74cbb-c647-4247-8c58-91de32a47913/192.168.8.107:54103 +This session was closed for ServerClosing! +2019-03-14 11:23:30,757 [7220] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:23:30,936 [6140] INFO TelecomServer - Session: 43adbb6d-d355-4c96-a248-4ff96b292340/192.168.8.107:54204 +A new session connected! +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - �豸����:��������� +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ����seq:01 +2019-03-14 11:23:49,444 [8624] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:23:49,447 [8624] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:23:49,456 [5464] INFO TelecomServer - Session: 43adbb6d-d355-4c96-a248-4ff96b292340/192.168.8.107:54204 +This session was closed for ServerClosing! +2019-03-14 11:24:40,942 [6140] INFO TelecomServer - Session: 6bff6253-4133-4fa8-bf06-f6f58f89bf95/192.168.8.107:54251 +A new session connected! +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - �豸����:��������� +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ����seq:01 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:24:41,500 [8440] INFO TelecomServer - Session: 6bff6253-4133-4fa8-bf06-f6f58f89bf95/192.168.8.107:54251 +This session was closed for ServerClosing! +2019-03-14 11:25:29,770 [8440] INFO TelecomServer - Session: bf7d9f60-7538-48c1-884a-a176fafe35c0/192.168.8.107:54268 +A new session connected! +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - Session: bf7d9f60-7538-48c1-884a-a176fafe35c0/192.168.8.107:54268 +This session was closed for ServerClosing! +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - �豸����:��������� +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ����seq:01 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:48:01,744 [5404] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:52:30,595 [6648] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:52:30,717 [6060] INFO TelecomServer - Session: 089558ed-5059-4137-a7a4-d33f9fb1c0f9/192.168.8.107:55015 +A new session connected! +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - �豸����:��������� +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ����seq:01 +2019-03-14 11:52:35,873 [8756] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 11:52:35,893 [10336] INFO TelecomServer - Session: 089558ed-5059-4137-a7a4-d33f9fb1c0f9/192.168.8.107:55015 +This session was closed for ServerClosing! +2019-03-14 11:52:57,912 [10336] INFO TelecomServer - Session: b453cd97-e00b-41d9-b3bc-33d26dc46999/192.168.8.107:55050 +A new session connected! +2019-03-14 11:52:58,542 [8756] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:52:58,542 [8756] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - �豸����:��������� +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - ����seq:01 +2019-03-14 11:52:58,545 [11640] INFO TelecomServer - Session: b453cd97-e00b-41d9-b3bc-33d26dc46999/192.168.8.107:55050 +This session was closed for ServerClosing! +2019-03-14 11:55:55,378 [8756] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 11:55:59,241 [12184] INFO TelecomServer - Session: 9fe29086-3fb8-4040-8872-1582388389a2/192.168.8.107:55126 +A new session connected! +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:55:59,818 [11640] INFO TelecomServer - Session: 9fe29086-3fb8-4040-8872-1582388389a2/192.168.8.107:55126 +This session was closed for ServerClosing! +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - �豸����:��������� +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:55:59,819 [6112] INFO TelecomServer - ����seq:01 +2019-03-14 11:57:38,077 [6112] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 12:03:07,054 [6784] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:03:07,336 [8328] INFO TelecomServer - Session: 4b7960c8-b918-4d85-ab45-7c94926b1488/192.168.8.107:55292 +A new session connected! +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - �豸����:��������� +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ����seq:01 +2019-03-14 12:03:24,616 [7976] INFO TelecomServer - Session: 4b7960c8-b918-4d85-ab45-7c94926b1488/192.168.8.107:55292 +This session was closed for ServerClosing! +2019-03-14 12:18:19,566 [6008] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:18:26,781 [11724] INFO TelecomServer - Session: cb6dc683-e58d-4091-90ff-3eb10428453e/192.168.8.107:55696 +A new session connected! +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - �豸����:��������� +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ����seq:01 +2019-03-14 12:18:36,731 [10844] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:18:36,749 [2444] INFO TelecomServer - Session: cb6dc683-e58d-4091-90ff-3eb10428453e/192.168.8.107:55696 +This session was closed for ServerClosing! +2019-03-14 12:21:40,398 [9316] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:21:40,562 [9828] INFO TelecomServer - Session: 408cbb6b-e6d6-4cea-9f0a-6c8863c7b774/192.168.8.107:55792 +A new session connected! +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - �豸����:��������� +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ����seq:01 +2019-03-14 12:21:43,430 [11964] INFO TelecomServer - Session: 408cbb6b-e6d6-4cea-9f0a-6c8863c7b774/192.168.8.107:55792 +This session was closed for ServerClosing! +2019-03-14 12:21:43,432 [8728] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:22:56,060 [8452] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:22:57,428 [5404] INFO TelecomServer - Session: 3b80d27c-364f-4332-91f8-64bad25052d8/192.168.8.107:55826 +A new session connected! +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - �豸����:��������� +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ����seq:01 +2019-03-14 12:23:06,628 [4896] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:23:06,664 [9296] INFO TelecomServer - Session: 3b80d27c-364f-4332-91f8-64bad25052d8/192.168.8.107:55826 +This session was closed for ServerClosing! +2019-03-14 12:23:17,609 [5404] INFO TelecomServer - Session: 8cd0979c-7513-40fa-8127-86cf9e013b3e/192.168.8.107:55833 +A new session connected! +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - �豸����:��������� +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ����seq:01 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:23:20,478 [9296] INFO TelecomServer - Session: 8cd0979c-7513-40fa-8127-86cf9e013b3e/192.168.8.107:55833 +This session was closed for ServerClosing! diff --git a/bin/Logs/info.log20190312 b/bin/Logs/info.log20190312 new file mode 100644 index 0000000..c43e11c --- /dev/null +++ b/bin/Logs/info.log20190312 @@ -0,0 +1 @@ +2019-03-12 09:28:51,437 [8220] INFO TelecomServer - The server instance TelecomServer has been started! diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.vshost.exe.manifest b/bin/BRServerTest.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/BRServerTest.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Logs/debug.log b/bin/Logs/debug.log index 6257246..2f3a156 100644 --- a/bin/Logs/debug.log +++ b/bin/Logs/debug.log @@ -1,7 +1,70 @@ -2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! -2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered -2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! -2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started -2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:08:45,557 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:08:45,602 [8252] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:08:45,617 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:08:48,250 [8252] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:08:48,255 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:16:58,302 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:16:58,340 [12228] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:16:58,353 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:17:01,040 [12228] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:17:01,045 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:19:42,735 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:19:42,776 [8260] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:19:42,789 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:19:45,571 [8260] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:19:45,575 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:23:28,089 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:23:28,135 [7220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:23:28,147 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:23:30,756 [7220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:23:30,763 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:47:58,915 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:47:58,964 [5404] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:47:58,981 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:48:01,743 [5404] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:48:01,747 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:52:27,821 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:52:27,864 [6648] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:52:27,879 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:52:30,594 [6648] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:52:30,599 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:03:04,186 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:03:04,242 [6784] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:03:04,258 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:03:07,053 [6784] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:03:07,058 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:18:16,795 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:18:16,843 [6008] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:18:16,859 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:18:19,566 [6008] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:18:19,571 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:21:37,702 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:21:37,742 [9316] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:21:37,756 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:21:40,397 [9316] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:21:40,406 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:22:53,293 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:22:53,346 [8452] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:22:53,363 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:22:56,059 [8452] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:22:56,066 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/debug.log20190312 b/bin/Logs/debug.log20190312 new file mode 100644 index 0000000..6257246 --- /dev/null +++ b/bin/Logs/debug.log20190312 @@ -0,0 +1,7 @@ +2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/err.log b/bin/Logs/err.log index af8a711..bdd985b 100644 --- a/bin/Logs/err.log +++ b/bin/Logs/err.log @@ -1,34 +1,48 @@ -2019-03-12 09:26:55,597 [8684] ERROR DefaultBootstrap - Failed to create server instance TelecomServer! -System.IO.FileNotFoundException: δ�ܼ����ļ�����򼯡�BRServer��������ijһ�������ϵͳ�Ҳ���ָ�����ļ��� -�ļ���:��BRServer�� - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) - �� System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) - �� System.Type.GetType(String typeName, Boolean throwOnError) - �� SuperSocket.SocketEngine.DefaultBootstrap.CreateWorkItemInstance(String serviceTypeName, StatusInfoAttribute[] serverStatusMetadata) - �� SuperSocket.SocketEngine.DefaultBootstrap.InitializeAndSetupWorkItem(WorkItemFactoryInfo factoryInfo) - -=== Ԥ��״̬��Ϣ === -��־: DisplayName = BRServer - (Partial) -����: Ϊ�����ṩ�˲��ְ���Ϣ: -����: ��������: BRServer | �� ID: 1 -����: �����ṩ������ʾ���Ƶ�һ����ʱ�����������ְ󶨡� -����: ����ܵ������������ش���ij��򼯡� -����: ����Ϊ�����ṩ��ȫָ�������ֱ�ʶ�� -����: ���ɼ����ơ��汾�������Ժ͹�Կ�����ɡ� -����: �йش��������ϸ��Ϣ�ͳ��������������μ���Ƥ�� http://go.microsoft.com/fwlink/?LinkId=109270�� -��־: Appbase = file:///E:/gwq/BRServer/bin/ -��־: ��ʼ PrivatePath = NULL -���ó���: SuperSocket.SocketEngine, Version=1.6.2.0, Culture=neutral, PublicKeyToken=6c80000676988ebb�� -=== -��־: �˰󶨴� default ���������Ŀ�ʼ�� -��־: ����ʹ��Ӧ�ó��������ļ�: E:\gwq\BRServer\bin\BRCJServerTest.vshost.exe.Config -��־: ʹ�����������ļ�: -��־: ʹ�� C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config �ļ���������ļ��� -��־: ��ʱû��Ϊ����Ӧ�ò���(˽�С��Զ��塢�ֲ������λ�õij��򼯰�)�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.EXE�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.EXE�� - +2019-03-14 11:19:55,014 [11964] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 66 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:37,328 [8624] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:57,890 [11700] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:25:44,997 [5460] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:52:39,160 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:55:57,449 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:57:38,760 [6112] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:18:39,687 [10844] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:08,846 [4896] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:36,057 [8500] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 diff --git a/bin/Logs/info.log b/bin/Logs/info.log index c43e11c..7663110 100644 --- a/bin/Logs/info.log +++ b/bin/Logs/info.log @@ -1 +1,168 @@ -2019-03-12 09:28:51,437 [8220] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:08:48,251 [8252] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:17:01,040 [12228] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:19:45,572 [8260] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:19:49,320 [10844] INFO TelecomServer - Session: 23a74cbb-c647-4247-8c58-91de32a47913/192.168.8.107:54103 +A new session connected! +2019-03-14 11:19:51,476 [11964] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - �豸����:��������� +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ����seq:01 +2019-03-14 11:19:51,481 [11964] INFO TelecomServer - ��������������ϴ�TAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:19:51,484 [10844] INFO TelecomServer - Session: 23a74cbb-c647-4247-8c58-91de32a47913/192.168.8.107:54103 +This session was closed for ServerClosing! +2019-03-14 11:23:30,757 [7220] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:23:30,936 [6140] INFO TelecomServer - Session: 43adbb6d-d355-4c96-a248-4ff96b292340/192.168.8.107:54204 +A new session connected! +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - �豸����:��������� +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ����seq:01 +2019-03-14 11:23:49,444 [8624] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:23:49,447 [8624] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:23:49,456 [5464] INFO TelecomServer - Session: 43adbb6d-d355-4c96-a248-4ff96b292340/192.168.8.107:54204 +This session was closed for ServerClosing! +2019-03-14 11:24:40,942 [6140] INFO TelecomServer - Session: 6bff6253-4133-4fa8-bf06-f6f58f89bf95/192.168.8.107:54251 +A new session connected! +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - �豸����:��������� +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ����seq:01 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:24:41,500 [8440] INFO TelecomServer - Session: 6bff6253-4133-4fa8-bf06-f6f58f89bf95/192.168.8.107:54251 +This session was closed for ServerClosing! +2019-03-14 11:25:29,770 [8440] INFO TelecomServer - Session: bf7d9f60-7538-48c1-884a-a176fafe35c0/192.168.8.107:54268 +A new session connected! +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - Session: bf7d9f60-7538-48c1-884a-a176fafe35c0/192.168.8.107:54268 +This session was closed for ServerClosing! +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - �豸����:��������� +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ����seq:01 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:48:01,744 [5404] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:52:30,595 [6648] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:52:30,717 [6060] INFO TelecomServer - Session: 089558ed-5059-4137-a7a4-d33f9fb1c0f9/192.168.8.107:55015 +A new session connected! +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - �豸����:��������� +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ����seq:01 +2019-03-14 11:52:35,873 [8756] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 11:52:35,893 [10336] INFO TelecomServer - Session: 089558ed-5059-4137-a7a4-d33f9fb1c0f9/192.168.8.107:55015 +This session was closed for ServerClosing! +2019-03-14 11:52:57,912 [10336] INFO TelecomServer - Session: b453cd97-e00b-41d9-b3bc-33d26dc46999/192.168.8.107:55050 +A new session connected! +2019-03-14 11:52:58,542 [8756] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:52:58,542 [8756] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - �豸����:��������� +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - ����seq:01 +2019-03-14 11:52:58,545 [11640] INFO TelecomServer - Session: b453cd97-e00b-41d9-b3bc-33d26dc46999/192.168.8.107:55050 +This session was closed for ServerClosing! +2019-03-14 11:55:55,378 [8756] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 11:55:59,241 [12184] INFO TelecomServer - Session: 9fe29086-3fb8-4040-8872-1582388389a2/192.168.8.107:55126 +A new session connected! +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:55:59,818 [11640] INFO TelecomServer - Session: 9fe29086-3fb8-4040-8872-1582388389a2/192.168.8.107:55126 +This session was closed for ServerClosing! +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - �豸����:��������� +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:55:59,819 [6112] INFO TelecomServer - ����seq:01 +2019-03-14 11:57:38,077 [6112] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 12:03:07,054 [6784] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:03:07,336 [8328] INFO TelecomServer - Session: 4b7960c8-b918-4d85-ab45-7c94926b1488/192.168.8.107:55292 +A new session connected! +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - �豸����:��������� +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ����seq:01 +2019-03-14 12:03:24,616 [7976] INFO TelecomServer - Session: 4b7960c8-b918-4d85-ab45-7c94926b1488/192.168.8.107:55292 +This session was closed for ServerClosing! +2019-03-14 12:18:19,566 [6008] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:18:26,781 [11724] INFO TelecomServer - Session: cb6dc683-e58d-4091-90ff-3eb10428453e/192.168.8.107:55696 +A new session connected! +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - �豸����:��������� +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ����seq:01 +2019-03-14 12:18:36,731 [10844] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:18:36,749 [2444] INFO TelecomServer - Session: cb6dc683-e58d-4091-90ff-3eb10428453e/192.168.8.107:55696 +This session was closed for ServerClosing! +2019-03-14 12:21:40,398 [9316] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:21:40,562 [9828] INFO TelecomServer - Session: 408cbb6b-e6d6-4cea-9f0a-6c8863c7b774/192.168.8.107:55792 +A new session connected! +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - �豸����:��������� +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ����seq:01 +2019-03-14 12:21:43,430 [11964] INFO TelecomServer - Session: 408cbb6b-e6d6-4cea-9f0a-6c8863c7b774/192.168.8.107:55792 +This session was closed for ServerClosing! +2019-03-14 12:21:43,432 [8728] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:22:56,060 [8452] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:22:57,428 [5404] INFO TelecomServer - Session: 3b80d27c-364f-4332-91f8-64bad25052d8/192.168.8.107:55826 +A new session connected! +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - �豸����:��������� +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ����seq:01 +2019-03-14 12:23:06,628 [4896] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:23:06,664 [9296] INFO TelecomServer - Session: 3b80d27c-364f-4332-91f8-64bad25052d8/192.168.8.107:55826 +This session was closed for ServerClosing! +2019-03-14 12:23:17,609 [5404] INFO TelecomServer - Session: 8cd0979c-7513-40fa-8127-86cf9e013b3e/192.168.8.107:55833 +A new session connected! +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - �豸����:��������� +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ����seq:01 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:23:20,478 [9296] INFO TelecomServer - Session: 8cd0979c-7513-40fa-8127-86cf9e013b3e/192.168.8.107:55833 +This session was closed for ServerClosing! diff --git a/bin/Logs/info.log20190312 b/bin/Logs/info.log20190312 new file mode 100644 index 0000000..c43e11c --- /dev/null +++ b/bin/Logs/info.log20190312 @@ -0,0 +1 @@ +2019-03-12 09:28:51,437 [8220] INFO TelecomServer - The server instance TelecomServer has been started! diff --git a/bin/Logs/perf.log b/bin/Logs/perf.log index 3b645ed..e9e303c 100644 --- a/bin/Logs/perf.log +++ b/bin/Logs/perf.log @@ -1,9 +1,205 @@ -2019-03-12 09:28:51,537 Performance - --------------------------------------------------- -CPU Usage: 0.00%, Physical Memory Usage: 47,816,704.00, Total Thread Count: 27 +2019-03-14 11:08:48,335 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 48,250,880.00, Total Thread Count: 25 AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 TelecomServer ---------------------------------- -Started Time: 2019/3/12 9:28:51 +Started Time: 2019/3/14 11:08:48 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:17:01,134 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,206,976.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:17:01 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:19:45,632 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,120,960.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:19:45 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:20:45,597 Performance - --------------------------------------------------- +CPU Usage: 0.21%, Physical Memory Usage: 54,157,312.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:19:45 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 1 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:23:30,842 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 45,735,936.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:23:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:24:37,325 Performance - --------------------------------------------------- +CPU Usage: 0.30%, Physical Memory Usage: 54,284,288.00, Total Thread Count: 27 +AvailableWorkingThreads: 1020, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:23:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:25:35,239 Performance - --------------------------------------------------- +CPU Usage: 0.04%, Physical Memory Usage: 55,504,896.00, Total Thread Count: 27 +AvailableWorkingThreads: 1020, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:23:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 2 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:48:01,808 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 44,470,272.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:48:01 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:52:30,681 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 43,999,232.00, Total Thread Count: 26 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:52:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:55:55,412 Performance - --------------------------------------------------- +CPU Usage: 0.09%, Physical Memory Usage: 53,174,272.00, Total Thread Count: 28 +AvailableWorkingThreads: 1021, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:52:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 1 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:57:38,094 Performance - --------------------------------------------------- +CPU Usage: 0.04%, Physical Memory Usage: 54,317,056.00, Total Thread Count: 28 +AvailableWorkingThreads: 1020, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:52:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 2 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 12:03:07,120 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 44,183,552.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 12:03:07 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 12:18:19,634 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,956,544.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 12:18:19 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 12:21:40,488 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,616,576.00, Total Thread Count: 26 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 12:21:40 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 12:22:56,138 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,481,408.00, Total Thread Count: 26 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 12:22:56 Is Running: True Total Connections: 0 Maximum Allowed Connection Number: 100 diff --git a/BRServer.BLL/Alarm.cs b/BRServer.BLL/Alarm.cs new file mode 100644 index 0000000..31c6bfc --- /dev/null +++ b/BRServer.BLL/Alarm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class Alarm + { + private static Alarm alarm; + + private Alarm() + { + } + + public static Alarm getInstance() + { + if (alarm == null) + { + alarm = new Alarm(); + } + return alarm; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.Alarm alarm) + { + if (alarm == null || alarm.MESSAGE == null || alarm.MESSAGE == "") + { + return; + } + + IAlarm dal = DALFactory.Alarm.Create(); + dal.insert(alarm); + } + + ///** + // *sequeceName:需要更新的序列名称 + // *key:主键字段名称 + // *tableName:表名称 + // */ + //public void updateSequence(String sequeceName) + //{ + // IBRCJ dal = DALFactory.BR.Create(); + // dal.updateSequence(sequeceName); + //} + + } +} diff --git a/BRServer.BLL/BRCJ.cs b/BRServer.BLL/BRCJ.cs new file mode 100644 index 0000000..c90b49e --- /dev/null +++ b/BRServer.BLL/BRCJ.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.IDAL; + +namespace BRServer.BLL +{ + public class BRCJ + { + private static BRCJ br; + + private BRCJ() + { + } + + public static BRCJ getInstance() + { + if (br == null) + { + br = new BRCJ(); + } + return br; + } + + /// + /// A method to insert a new Adapter + /// + /// An adapter entity with information about the new adapter + public void insert(Model.BRCJ cj) + { + if (cj == null || (cj.SEDIMENTATION == 0.0 && cj.TEMPERATURE == 0.0)) + { + return; + } + + IBRCJ dal = DALFactory.BRCJ.Create(); + dal.insert(cj); + } + } +} diff --git a/BRServer.BLL/BRServer.BLL.csproj b/BRServer.BLL/BRServer.BLL.csproj index 3d489f9..c8b2a14 100644 --- a/BRServer.BLL/BRServer.BLL.csproj +++ b/BRServer.BLL/BRServer.BLL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache index 64bafec..b7f9bce 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.dll b/BRServer.BLL/obj/Debug/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.dll +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.dll Binary files differ diff --git a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/BRServer.BLL/obj/Debug/BRServer.BLL.pdb +++ b/BRServer.BLL/obj/Debug/BRServer.BLL.pdb Binary files differ diff --git a/BRServer.DAL/Alarm.cs b/BRServer.DAL/Alarm.cs new file mode 100644 index 0000000..c9ad5ca --- /dev/null +++ b/BRServer.DAL/Alarm.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class Alarm : IDAL.IAlarm + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_ALARM"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_MESSAGE = "MESSAGE"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_MESSAGE = "@MESSAGE"; + + private const string SQL_INSERT_ALARM = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_MESSAGE + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_MESSAGE + ")"; + + + public void insert(Model.Alarm alarm) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(alarm.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, alarm); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_ALARM, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null; + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_MESSAGE, MySqlDbType.VarChar,255) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.Alarm alarm) + { + parms[0].Value = alarm.DEVCODE; + + if (null != alarm.LOGTIME) + { + parms[1].Value = alarm.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != alarm.MESSAGE) + { + parms[2].Value = alarm.MESSAGE; + } + else + { + parms[2].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRCJ.cs b/BRServer.DAL/BRCJ.cs new file mode 100644 index 0000000..7326b2a --- /dev/null +++ b/BRServer.DAL/BRCJ.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; + +namespace BRServer.DAL +{ + public class BRCJ : IDAL.IBRCJ + { + public static readonly string ConnectionStringOrderDistributedTransaction = + System.Configuration.ConfigurationManager.AppSettings["MySqlConnString"]; + + // Static constants + private const string TABLE_NAME = "BRCJ_DATA"; + + private const string COLUMN_DEVCODE = "DEVCODE"; + private const string COLUMN_LOGTIME = "LOGTIME"; + private const string COLUMN_CELL = "CELL"; + private const string COLUMN_VALUE = "SEDIMENTATION"; + private const string COLUMN_VALUE2 = "TEMPERATURE"; + private const string COLUMN_UPTIME = "UPTIME"; + + private const string PARM_DEVCODE = "@DEVCODE"; + private const string PARM_LOGTIME = "@LOGTIME"; + private const string PARM_CELL = "@CELL"; + private const string PARM_VALUE = "@SEDIMENTATION"; + private const string PARM_VALUE2 = "@TEMPERATURE"; + private const string PARM_UPTIME = "@UPTIME"; + + private const string SQL_INSERT_CJ = "INSERT INTO " + TABLE_NAME + + " (" + COLUMN_DEVCODE + "," + + " " + COLUMN_LOGTIME + "," + + " " + COLUMN_CELL + "," + + " " + COLUMN_VALUE + "," + + " " + COLUMN_VALUE2 + "," + + " " + COLUMN_UPTIME + ")" + + " VALUES " + + " (" + PARM_DEVCODE + "," + + " " + PARM_LOGTIME + "," + + " " + PARM_CELL + "," + + " " + PARM_VALUE + "," + + " " + PARM_VALUE2 + "," + + " " + PARM_UPTIME + ")"; + + + public void insert(Model.BRCJ cj) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + if (string.IsNullOrEmpty(cj.DEVCODE)) + { + throw new Exception("设备ID为空!"); + } + + MySqlParameter[] parms = GetAdapterParameters(); + SetAdapterParameters(parms, cj); + + MySqlCommand cmd = new MySqlCommand(SQL_INSERT_CJ, conn); + foreach (MySqlParameter pram in parms) + cmd.Parameters.Add(pram); + cmd.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + /** + *sequeceName:需要更新的序列名称 + *key:主键字段名称 + *tableName:表名称 + */ + public void updateSequence(String sequeceName) + { + MySqlTransaction tran = null; + using (MySqlConnection conn = new MySqlConnection(ConnectionStringOrderDistributedTransaction)) + { + try + { + conn.Open(); + tran = conn.BeginTransaction(); + + String SQL_DROP_SEQUENCE = "ALTER TABLE " + TABLE_NAME +" DROP "+ sequeceName; + MySqlCommand cmd1 = new MySqlCommand(SQL_DROP_SEQUENCE, conn); + cmd1.ExecuteNonQuery(); + + String SQL_ADD_SEQUENC = "ALTER TABLE " + TABLE_NAME + " ADD " + sequeceName + + " INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (" + sequeceName + ")"; + + MySqlCommand cmd2 = new MySqlCommand(SQL_ADD_SEQUENC, conn); + cmd2.ExecuteNonQuery(); + + tran.Commit(); + } + catch (Exception e) + { + if (null != tran) + { + tran.Rollback(); + } + throw (e); + } + } + } + + + /// + /// An internal function to get the database parameters + /// + /// Parameter array + private static MySqlParameter[] GetAdapterParameters() + { + MySqlParameter[] parms = null;//OracleHelperParameterCache.GetCachedParameterSet(SQL_INSERT_WS, "INSERT:UPDATE"); + + if (parms == null) + { + parms = new MySqlParameter[]{ + new MySqlParameter(PARM_DEVCODE, MySqlDbType.VarChar, 255), + new MySqlParameter(PARM_LOGTIME, MySqlDbType.DateTime), + new MySqlParameter(PARM_CELL, MySqlDbType.VarChar,255), + new MySqlParameter(PARM_VALUE, MySqlDbType.Float,20), + new MySqlParameter(PARM_VALUE2, MySqlDbType.Float,20), + new MySqlParameter(PARM_UPTIME, MySqlDbType.DateTime) + }; + } + + return parms; + } + + + /// + /// An internal function to bind values parameters for insert + /// + /// Database parameters + /// Values to bind to parameters + private void SetAdapterParameters(MySqlParameter[] parms, Model.BRCJ cj) + { + parms[0].Value = cj.DEVCODE; + + if (null != cj.LOGTIME) + { + parms[1].Value = cj.LOGTIME; + } + else + { + parms[1].Value = DBNull.Value; + } + + if (null != cj.CELL) + { + parms[2].Value = cj.CELL; + } + else + { + parms[2].Value = DBNull.Value; + } + + if (null != cj.SEDIMENTATION) + { + parms[3].Value = cj.SEDIMENTATION; + } + else + { + parms[3].Value = DBNull.Value; + } + + if (null != cj.TEMPERATURE) + { + parms[4].Value = cj.TEMPERATURE; + } + else + { + parms[4].Value = DBNull.Value; + } + + if (null != cj.UPTIME) + { + parms[5].Value = cj.UPTIME; + } + else + { + parms[5].Value = DBNull.Value; + } + } + } +} diff --git a/BRServer.DAL/BRServer.DAL.csproj b/BRServer.DAL/BRServer.DAL.csproj index aa29460..3580c8e 100644 --- a/BRServer.DAL/BRServer.DAL.csproj +++ b/BRServer.DAL/BRServer.DAL.csproj @@ -45,7 +45,8 @@ - + + diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache index 4a9e055..9c6f3ca 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.dll b/BRServer.DAL/obj/Debug/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.dll +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.dll Binary files differ diff --git a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/BRServer.DAL/obj/Debug/BRServer.DAL.pdb +++ b/BRServer.DAL/obj/Debug/BRServer.DAL.pdb Binary files differ diff --git a/BRServer.DALFactory/Alarm.cs b/BRServer.DALFactory/Alarm.cs new file mode 100644 index 0000000..9fe1f50 --- /dev/null +++ b/BRServer.DALFactory/Alarm.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class Alarm + { + public static BRServer.IDAL.IAlarm Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".Alarm"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IAlarm)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRCJ.cs b/BRServer.DALFactory/BRCJ.cs new file mode 100644 index 0000000..56bfa0f --- /dev/null +++ b/BRServer.DALFactory/BRCJ.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace BRServer.DALFactory +{ + public class BRCJ + { + public static BRServer.IDAL.IBRCJ Create() + { + // Look up the DAL implementation we should be using + string path = System.Configuration.ConfigurationManager.AppSettings["mysqlDAL"]; + string className = path + ".BRCJ"; + + // Using the evidence given in the config file load the appropriate assembly and class + return (BRServer.IDAL.IBRCJ)Assembly.Load(path).CreateInstance(className); + } + } +} diff --git a/BRServer.DALFactory/BRServer.DALFactory.csproj b/BRServer.DALFactory/BRServer.DALFactory.csproj index 3799033..0a82d65 100644 --- a/BRServer.DALFactory/BRServer.DALFactory.csproj +++ b/BRServer.DALFactory/BRServer.DALFactory.csproj @@ -41,7 +41,8 @@ - + + diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache index 716d0c1..1fb7c62 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.dll Binary files differ diff --git a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb +++ b/BRServer.DALFactory/obj/Debug/BRServer.DALFactory.pdb Binary files differ diff --git a/BRServer.IDAL/BRServer.IDAL.csproj b/BRServer.IDAL/BRServer.IDAL.csproj index 4ff7d1b..129f852 100644 --- a/BRServer.IDAL/BRServer.IDAL.csproj +++ b/BRServer.IDAL/BRServer.IDAL.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.IDAL/IAlarm.cs b/BRServer.IDAL/IAlarm.cs new file mode 100644 index 0000000..72dffcc --- /dev/null +++ b/BRServer.IDAL/IAlarm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IBRCJ + { + void insert(Model.BRCJ cj); + void updateSequence(String sequeceName); + //int queryCountByDevAndUpTime(String devCode, DateTime upTime); + + //float getLastData(Model.BRKKJ tempInfo); + } +} diff --git a/BRServer.IDAL/IBRCJ.cs b/BRServer.IDAL/IBRCJ.cs new file mode 100644 index 0000000..b187d2e --- /dev/null +++ b/BRServer.IDAL/IBRCJ.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace BRServer.IDAL +{ + public interface IAlarm + { + void insert(Model.Alarm alarm); + //void updateSequence(String sequeceName); + } +} diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache index 77a9cd8..2846259 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.dll Binary files differ diff --git a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb +++ b/BRServer.IDAL/obj/Debug/BRServer.IDAL.pdb Binary files differ diff --git a/BRServer.Model/Alarm.cs b/BRServer.Model/Alarm.cs new file mode 100644 index 0000000..477c734 --- /dev/null +++ b/BRServer.Model/Alarm.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class Alarm + { + private long dbId; + private string devCode; + private string message; + private DateTime logTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public string MESSAGE + { + get { return message; } + set { message = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + } +} diff --git a/BRServer.Model/BRCJ.cs b/BRServer.Model/BRCJ.cs new file mode 100644 index 0000000..8f1f519 --- /dev/null +++ b/BRServer.Model/BRCJ.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer.Model +{ + public class BRCJ + { + private long dbId; + private string devCode; + private DateTime logTime; + private int cell; + private float sedimentation; + private float temperature; + private DateTime upTime; + + public long DBID + { + get { return dbId; } + set { dbId = value; } + } + + public string DEVCODE + { + get { return devCode; } + set { devCode = value; } + } + + public DateTime LOGTIME + { + get { return logTime; } + set { logTime = value; } + } + + public int CELL + { + get { return cell; } + set { cell = value; } + } + + public float SEDIMENTATION + { + get { return sedimentation; } + set { sedimentation = value; } + } + + public float TEMPERATURE + { + get { return temperature; } + set { temperature = value; } + } + + public DateTime UPTIME + { + get { return upTime; } + set { upTime = value; } + } + } +} diff --git a/BRServer.Model/BRServer.Model.csproj b/BRServer.Model/BRServer.Model.csproj index 282cd2c..4b6463d 100644 --- a/BRServer.Model/BRServer.Model.csproj +++ b/BRServer.Model/BRServer.Model.csproj @@ -40,7 +40,8 @@ - + + diff --git a/BRServer.Model/obj/Debug/BRServer.Model.dll b/BRServer.Model/obj/Debug/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.dll +++ b/BRServer.Model/obj/Debug/BRServer.Model.dll Binary files differ diff --git a/BRServer.Model/obj/Debug/BRServer.Model.pdb b/BRServer.Model/obj/Debug/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/BRServer.Model/obj/Debug/BRServer.Model.pdb +++ b/BRServer.Model/obj/Debug/BRServer.Model.pdb Binary files differ diff --git a/BRServer.suo b/BRServer.suo index 72bf124..a70401f 100644 --- a/BRServer.suo +++ b/BRServer.suo Binary files differ diff --git a/BRServer/BRCJTagHandler.cs b/BRServer/BRCJTagHandler.cs new file mode 100644 index 0000000..c2935ec --- /dev/null +++ b/BRServer/BRCJTagHandler.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +namespace BRServer +{ + public class BRCJTagHandler:TagHandler + { + public override void resolve(Tag tag,CasicSession session) + { + //TODO LIST:解析数据,保存数据 + UploadTag BRTag = tag as UploadTag; + Interval = BRTag.CollectInter; + CollecTime = BRTag.CollectTime; + int len = BRTag.Len; + String dataValue = BRTag.DataValue; + + DataList = new List(); + + float sedimentation = strHexToSingle(dataValue.Substring(0, 8)); + DataList.Add(sedimentation); + + session.Logger.Info("沉降监测仪数据上传,沉降值TAG:oid:" + BRTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + + } + + //网络序列转float + private float strHexToSingle(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + }; + return BitConverter.ToSingle(lBt, 0); + } + } +} diff --git a/BRServer/BRServer.csproj b/BRServer/BRServer.csproj index cbdd2ae..828f0a5 100644 --- a/BRServer/BRServer.csproj +++ b/BRServer/BRServer.csproj @@ -61,12 +61,11 @@ - + - @@ -75,6 +74,7 @@ + @@ -86,6 +86,7 @@ + diff --git a/BRServer/CasicCmd.cs b/BRServer/CasicCmd.cs index 46c321e..bf99eee 100644 --- a/BRServer/CasicCmd.cs +++ b/BRServer/CasicCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SuperSocket.SocketBase.Command; using SuperSocket.SocketBase.Protocol; +using BRServer.Model; namespace BRServer { @@ -27,7 +28,7 @@ devType = "未知设备"; break; case 21: - devType = "北燃沉降监测仪"; + devType = "沉降监测仪"; break; default: devType = "undefiend"; @@ -41,11 +42,11 @@ Int16 btpduType = Int16.Parse(pduType, System.Globalization.NumberStyles.HexNumber); int opearType = (btpduType >> 8) & 0xFF; - String result=""; - switch (opearType) + String result = ""; + switch (opearType) { case 1: - result = "GetRequest"; + result = "GetRequest"; break; case 2: result = "GetResponse"; @@ -90,7 +91,7 @@ return result; } - private List getTags(String strTags,CasicSession session) + private List getTags(String strTags, CasicSession session) { List tags = new List(); try @@ -156,7 +157,7 @@ String preamble = requestInfo.Parameters[0]; String version = requestInfo.Parameters[1]; String leng = requestInfo.Parameters[2]; - String deviceId = requestInfo.Parameters[3]; + String devCode = requestInfo.Parameters[3]; String routeFlag = requestInfo.Parameters[4]; String dstNodeAddr = requestInfo.Parameters[5]; String pduType = requestInfo.Parameters[6]; @@ -169,43 +170,101 @@ String operType = getOpeTypeByPdu(pduType); session.Logger.Info("AD接收数据:" + requestInfo.Body); session.Logger.Info("当前版本:" + version); - session.Logger.Info("设备编号:" + deviceId); + session.Logger.Info("设备编号:" + devCode); session.Logger.Info("路由标志:" + routeFlag); session.Logger.Info("目标节点地址:" + dstNodeAddr); session.Logger.Info("设备类型:" + devType); session.Logger.Info("操作类型:" + operType); session.Logger.Info("序列seq:" + seq); - if (devType != "北燃沉降监测仪") - { - session.Logger.Error("数据不是由北燃沉降监测仪上传,不作处理!"); - return; - } - + String collectDate = ""; List tags = this.getTags(settings, session); - CellTag cellTag = this.getCellTag(tags, session); - SystemDateTag systemDateTag = this.getSystemDateTag(tags); + Model.BRCJ cj = new Model.BRCJ(); + cj.DEVCODE = devCode; + cj.LOGTIME = DateTime.Now; + + Model.Alarm alarm = new Model.Alarm(); + try { - //TODO LIST:处理主动上报的数据、参数查、询参数设置 - TagHandler systemDateHandler = new SystemDateTagHandler(); - TagHandler cellTagHandler = new CellTagHandler(); - TagHandler BRTagHandler = new BRTagHandler(); - - systemDateHandler.NextHandler = cellTagHandler; - cellTagHandler.NextHandler = BRTagHandler; - foreach (Tag tag in tags) { - //采用责任链的方式来处理各个tag - systemDateHandler.handleTag(tag, deviceId, cellTag, - systemDateTag, session); + if (!(tag is UploadTag)) + { + //非业务处理 + if (tag != null && tag is SystemDateTag) + { + SystemDateTag systemDateTag = tag as SystemDateTag; + collectDate = systemDateTag.CollectDate; + continue; + } + else if (tag != null && tag is CellTag) + { + CellTag cellTag = tag as CellTag; + cj.CELL = cellTag.Cell; + continue; + } + else if (tag != null && tag is SensorException0Tag) + { + SensorException0Tag sensorException0 = tag as SensorException0Tag; + int state = sensorException0.state; + + if (state == 1) + { + alarm.MESSAGE = "采集失败"; + } + else + { + continue; + } + + alarm.DEVCODE = devCode; + alarm.LOGTIME = DateTime.Now; + + session.Logger.Info("沉降监测仪发送通道一容错信息:oid:" + tag.Oid + ";value:" + state); + continue; + } + else + { + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + continue; + } + } + else + { + //业务处理 + UploadTag uploadTag = tag as UploadTag; + switch (uploadTag.BizType) + { + case 18: + //沉降值 + TagHandler cjHandler = new BRCJTagHandler(); + cjHandler.resolve(tag, session); + cj.SEDIMENTATION = (float)cjHandler.DataList[0]; + cj.UPTIME = Convert.ToDateTime(collectDate + " " + cjHandler.CollecTime); + break; + case 8: + //温度 + TagHandler tempHandler = new TempTagHandler(); + tempHandler.resolve(tag, session); + cj.TEMPERATURE = (float)tempHandler.DataList[0]; + break; + default: + DefaultTagHandler defaultHandler = new DefaultTagHandler(); + defaultHandler.resolve(tag, session); + break; + } + } } + BLL.BRCJ.getInstance().insert(cj); + BLL.Alarm.getInstance().insert(alarm); + //回复校时信息 CasicSender sender = new CasicSender(null); - sender.doSendTimeConfig(deviceId, version, devType, session, "3", deviceId_Telecom); + sender.doSendTimeConfig(devCode, version, devType, session, "3", deviceId_Telecom); } catch (Exception e) { diff --git a/BRServer/CasicSender.cs b/BRServer/CasicSender.cs index cf73793..b982f0b 100644 --- a/BRServer/CasicSender.cs +++ b/BRServer/CasicSender.cs @@ -54,7 +54,7 @@ switch (typeName) { - case "北燃沉降监测仪": + case "沉降监测仪": btPdu[0] = 0x05; btPdu[1] = 0x95; tag = this.getTimeTag(); @@ -117,7 +117,7 @@ return false; } - session.Logger.Info("回复校时信息成功 设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + strBase64Value); + session.Logger.Info("回复校时信息成功,设备类型:" + typeName + " 设备编号:" + devCode + " 回复校时信息:" + afcrc.ToString().Replace("-","")); return true; } diff --git a/BRServer/CellTag.cs b/BRServer/CellTag.cs index b934c6d..3272c88 100644 --- a/BRServer/CellTag.cs +++ b/BRServer/CellTag.cs @@ -5,10 +5,9 @@ namespace BRServer { - public class CellTag:Tag + public class CellTag : Tag { - - private string cell; + private int cell; public static String CELL_TAG_OID = "60000020"; @@ -20,11 +19,10 @@ public CellTag(String oid, int len, String dataValue) : base(oid, len, dataValue) { - byte btCell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); - cell = btCell + ""; + cell = byte.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); } - public string Cell + public int Cell { get { return cell; } set { cell = value; } diff --git a/BRServer/DefaultTagHandler.cs b/BRServer/DefaultTagHandler.cs index be13008..c34b3b1 100644 --- a/BRServer/DefaultTagHandler.cs +++ b/BRServer/DefaultTagHandler.cs @@ -7,14 +7,8 @@ { public class DefaultTagHandler: TagHandler { - public override bool isThisTag(Tag tag) - { - return true; - } - //TODO LIST:默认打印出来未处理的tag信息 - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session) + public override void resolve(Tag tag, CasicSession session) { switch(tag.Oid) { diff --git a/BRServer/SensorException0Tag.cs b/BRServer/SensorException0Tag.cs new file mode 100644 index 0000000..1fc1c78 --- /dev/null +++ b/BRServer/SensorException0Tag.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BRServer +{ + public class SensorException0Tag : Tag + { + public static String SENSOR_EXCEP0_TAG_OID = "60000009"; + + public int state; + + public SensorException0Tag() + { + + } + + public SensorException0Tag(String oid, int len, String dataValue) + : base(oid, len, dataValue) + { + int intState = Int32.Parse(dataValue, System.Globalization.NumberStyles.HexNumber); + state = intState; + } + } +} diff --git a/BRServer/SystemDateTagHandler.cs b/BRServer/SystemDateTagHandler.cs index 9e87ad3..013df8b 100644 --- a/BRServer/SystemDateTagHandler.cs +++ b/BRServer/SystemDateTagHandler.cs @@ -7,13 +7,7 @@ { public class SystemDateTagHandler : TagHandler { - public override bool isThisTag(Tag tag) - { - return tag is SystemDateTag ? true : false; - } - - public override void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag0,CasicSession session) + public override void resolve(Tag tag,CasicSession session) { //更新系统日期 SystemDateTag systemDateTag = tag as SystemDateTag; diff --git a/BRServer/TagFactory.cs b/BRServer/TagFactory.cs index 56fed87..a176f05 100644 --- a/BRServer/TagFactory.cs +++ b/BRServer/TagFactory.cs @@ -22,6 +22,10 @@ { tag = new CellTag(oid, len, value); } + else if (oid == SensorException0Tag.SENSOR_EXCEP0_TAG_OID) + { + tag = new SensorException0Tag(oid, len, value); + } else { tag = new NormalTag(oid, len, value); diff --git a/BRServer/TagHandler.cs b/BRServer/TagHandler.cs index 87b0090..88cdc19 100644 --- a/BRServer/TagHandler.cs +++ b/BRServer/TagHandler.cs @@ -7,42 +7,12 @@ { public abstract class TagHandler { - private TagHandler nextHandler; + public String CollecTime { get; set; } - public TagHandler NextHandler - { - get { return nextHandler; } - set { nextHandler = value; } - } + public int Interval { get; set; } - public void handleTag(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag,CasicSession session) - { - if (this.isThisTag(tag)) - { - //处理当前逻辑 - this.execute(tag, devCode, cellTag, systemDateTag, session); - } - else - { - if (nextHandler != null) - { - nextHandler.handleTag(tag, devCode, cellTag, systemDateTag, - session); - } - else - { - //TODO LIST:用默认的TagHandler来处理 - nextHandler = new DefaultTagHandler(); - nextHandler.execute(tag, devCode, cellTag, systemDateTag, - session); - } - } - } + public List DataList { get; set; } - public abstract bool isThisTag(Tag tag); - - public abstract void execute(Tag tag, String devCode, CellTag cellTag, - SystemDateTag systemDateTag, CasicSession session); + public abstract void resolve(Tag tag, CasicSession session); } } diff --git a/BRServer/TempTagHandler.cs b/BRServer/TempTagHandler.cs new file mode 100644 index 0000000..5da6098 --- /dev/null +++ b/BRServer/TempTagHandler.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BRServer.Model; +using System.Collections; + +namespace BRServer +{ + public class TempTagHandler : TagHandler + { + public override void resolve(Tag tag, CasicSession session) + { + //TODO LIST:解析数据 + UploadTag tempTag = tag as UploadTag; + Interval = tempTag.CollectInter; + CollecTime = tempTag.CollectTime; + int len = tempTag.Len; + DataList = new List(); + + String dataValue = tempTag.DataValue; + + float temp = strHexToFloat(dataValue.Substring(0, 8)); + DataList.Add(temp); + + session.Logger.Info("沉降监测仪数据上传,温度TAG:oid:" + tempTag.Oid + " 采集间隔: " + + Interval + " 采集时间:" + CollecTime + " 上传数值:" + dataValue); + } + + //网络序列转float + private float strHexToFloat(String src) + { + if (src.Length != 8) + return 0; + + byte[] lBt ={ + byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber), + byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber) + + }; + float ss = BitConverter.ToSingle(lBt, 0); + return ss; + } + + } +} diff --git a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache index a12034b..87fb0d2 100644 --- a/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache +++ b/BRServer/obj/Debug/BRServer.csprojResolveAssemblyReference.cache Binary files differ diff --git a/BRServer/obj/Debug/BRServer.dll b/BRServer/obj/Debug/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/BRServer/obj/Debug/BRServer.dll +++ b/BRServer/obj/Debug/BRServer.dll Binary files differ diff --git a/BRServer/obj/Debug/BRServer.pdb b/BRServer/obj/Debug/BRServer.pdb index 999158c..af02ee6 100644 --- a/BRServer/obj/Debug/BRServer.pdb +++ b/BRServer/obj/Debug/BRServer.pdb Binary files differ diff --git a/BRServerTest/App.config b/BRServerTest/App.config index fe3c554..9b2ff63 100644 --- a/BRServerTest/App.config +++ b/BRServerTest/App.config @@ -17,7 +17,7 @@ - + diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.exe b/BRServerTest/obj/x86/Debug/BRServerTest.exe index c969846..64eb447 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.exe +++ b/BRServerTest/obj/x86/Debug/BRServerTest.exe Binary files differ diff --git a/BRServerTest/obj/x86/Debug/BRServerTest.pdb b/BRServerTest/obj/x86/Debug/BRServerTest.pdb index 3e417af..504c665 100644 --- a/BRServerTest/obj/x86/Debug/BRServerTest.pdb +++ b/BRServerTest/obj/x86/Debug/BRServerTest.pdb Binary files differ diff --git a/bin/BRServer.BLL.dll b/bin/BRServer.BLL.dll index 273337f..4123df3 100644 --- a/bin/BRServer.BLL.dll +++ b/bin/BRServer.BLL.dll Binary files differ diff --git a/bin/BRServer.BLL.pdb b/bin/BRServer.BLL.pdb index ac68f3f..3737785 100644 --- a/bin/BRServer.BLL.pdb +++ b/bin/BRServer.BLL.pdb Binary files differ diff --git a/bin/BRServer.DAL.dll b/bin/BRServer.DAL.dll index 59819df..b4d9f97 100644 --- a/bin/BRServer.DAL.dll +++ b/bin/BRServer.DAL.dll Binary files differ diff --git a/bin/BRServer.DAL.pdb b/bin/BRServer.DAL.pdb index f5a2f12..3c487bc 100644 --- a/bin/BRServer.DAL.pdb +++ b/bin/BRServer.DAL.pdb Binary files differ diff --git a/bin/BRServer.DALFactory.dll b/bin/BRServer.DALFactory.dll index b32b907..f2b0556 100644 --- a/bin/BRServer.DALFactory.dll +++ b/bin/BRServer.DALFactory.dll Binary files differ diff --git a/bin/BRServer.DALFactory.pdb b/bin/BRServer.DALFactory.pdb index d3f668a..f610993 100644 --- a/bin/BRServer.DALFactory.pdb +++ b/bin/BRServer.DALFactory.pdb Binary files differ diff --git a/bin/BRServer.IDAL.dll b/bin/BRServer.IDAL.dll index 095ed2b..f669ec3 100644 --- a/bin/BRServer.IDAL.dll +++ b/bin/BRServer.IDAL.dll Binary files differ diff --git a/bin/BRServer.IDAL.pdb b/bin/BRServer.IDAL.pdb index f13b477..a892aa5 100644 --- a/bin/BRServer.IDAL.pdb +++ b/bin/BRServer.IDAL.pdb Binary files differ diff --git a/bin/BRServer.Model.dll b/bin/BRServer.Model.dll index 973712c..a5ad8db 100644 --- a/bin/BRServer.Model.dll +++ b/bin/BRServer.Model.dll Binary files differ diff --git a/bin/BRServer.Model.pdb b/bin/BRServer.Model.pdb index dcf82a9..7eddac9 100644 --- a/bin/BRServer.Model.pdb +++ b/bin/BRServer.Model.pdb Binary files differ diff --git a/bin/BRServer.dll b/bin/BRServer.dll index d1eb51b..c9f91c3 100644 --- a/bin/BRServer.dll +++ b/bin/BRServer.dll Binary files differ diff --git a/bin/BRServer.pdb b/bin/BRServer.pdb index 999158c..af02ee6 100644 --- a/bin/BRServer.pdb +++ b/bin/BRServer.pdb Binary files differ diff --git a/bin/BRServerTest.exe b/bin/BRServerTest.exe index c969846..64eb447 100644 --- a/bin/BRServerTest.exe +++ b/bin/BRServerTest.exe Binary files differ diff --git a/bin/BRServerTest.exe.config b/bin/BRServerTest.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.exe.config +++ b/bin/BRServerTest.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.pdb b/bin/BRServerTest.pdb index 3e417af..504c665 100644 --- a/bin/BRServerTest.pdb +++ b/bin/BRServerTest.pdb Binary files differ diff --git a/bin/BRServerTest.vshost.exe.config b/bin/BRServerTest.vshost.exe.config index fe3c554..9b2ff63 100644 --- a/bin/BRServerTest.vshost.exe.config +++ b/bin/BRServerTest.vshost.exe.config @@ -17,7 +17,7 @@ - + diff --git a/bin/BRServerTest.vshost.exe.manifest b/bin/BRServerTest.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/BRServerTest.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Logs/debug.log b/bin/Logs/debug.log index 6257246..2f3a156 100644 --- a/bin/Logs/debug.log +++ b/bin/Logs/debug.log @@ -1,7 +1,70 @@ -2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! -2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered -2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! -2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! -2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started -2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:08:45,557 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:08:45,602 [8252] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:08:45,617 [8252] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:08:48,221 [8252] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:08:48,250 [8252] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:08:48,255 [8252] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:16:58,302 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:16:58,340 [12228] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:16:58,353 [12228] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:17:00,998 [12228] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:17:01,040 [12228] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:17:01,045 [12228] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:19:42,735 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:19:42,776 [8260] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:19:42,789 [8260] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:19:45,536 [8260] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:19:45,571 [8260] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:19:45,575 [8260] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:23:28,089 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:23:28,135 [7220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:23:28,147 [7220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:23:30,723 [7220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:23:30,756 [7220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:23:30,763 [7220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:47:58,915 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:47:58,964 [5404] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:47:58,981 [5404] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:48:01,710 [5404] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:48:01,743 [5404] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:48:01,747 [5404] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 11:52:27,821 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 11:52:27,864 [6648] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 11:52:27,879 [6648] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 11:52:30,558 [6648] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 11:52:30,594 [6648] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 11:52:30,599 [6648] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:03:04,186 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:03:04,242 [6784] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:03:04,258 [6784] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:03:07,018 [6784] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:03:07,053 [6784] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:03:07,058 [6784] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:18:16,795 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:18:16,843 [6008] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:18:16,859 [6008] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:18:19,533 [6008] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:18:19,566 [6008] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:18:19,571 [6008] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:21:37,702 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:21:37,742 [9316] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:21:37,756 [9316] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:21:40,365 [9316] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:21:40,397 [9316] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:21:40,406 [9316] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! +2019-03-14 12:22:53,293 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-14 12:22:53,346 [8452] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-14 12:22:53,363 [8452] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-14 12:22:56,022 [8452] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-14 12:22:56,059 [8452] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-14 12:22:56,066 [8452] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/debug.log20190312 b/bin/Logs/debug.log20190312 new file mode 100644 index 0000000..6257246 --- /dev/null +++ b/bin/Logs/debug.log20190312 @@ -0,0 +1,7 @@ +2019-03-12 09:28:48,534 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been created! +2019-03-12 09:28:48,570 [8220] DEBUG TelecomServer - The command Casic(BRServer.CasicCmd, BRServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) has been discovered +2019-03-12 09:28:48,582 [8220] DEBUG DefaultBootstrap - The server instance TelecomServer has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been initialized! +2019-03-12 09:28:51,404 [8220] DEBUG DefaultBootstrap - The Bootstrap has been initialized! +2019-03-12 09:28:51,436 [8220] DEBUG TelecomServer - Listener (0.0.0.0:50000) was started +2019-03-12 09:28:51,441 [8220] DEBUG DefaultBootstrap - The PerformanceMonitor has been started! diff --git a/bin/Logs/err.log b/bin/Logs/err.log index af8a711..bdd985b 100644 --- a/bin/Logs/err.log +++ b/bin/Logs/err.log @@ -1,34 +1,48 @@ -2019-03-12 09:26:55,597 [8684] ERROR DefaultBootstrap - Failed to create server instance TelecomServer! -System.IO.FileNotFoundException: δ�ܼ����ļ�����򼯡�BRServer��������ijһ�������ϵͳ�Ҳ���ָ�����ļ��� -�ļ���:��BRServer�� - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) - �� System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) - �� System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) - �� System.Type.GetType(String typeName, Boolean throwOnError) - �� SuperSocket.SocketEngine.DefaultBootstrap.CreateWorkItemInstance(String serviceTypeName, StatusInfoAttribute[] serverStatusMetadata) - �� SuperSocket.SocketEngine.DefaultBootstrap.InitializeAndSetupWorkItem(WorkItemFactoryInfo factoryInfo) - -=== Ԥ��״̬��Ϣ === -��־: DisplayName = BRServer - (Partial) -����: Ϊ�����ṩ�˲��ְ���Ϣ: -����: ��������: BRServer | �� ID: 1 -����: �����ṩ������ʾ���Ƶ�һ����ʱ�����������ְ󶨡� -����: ����ܵ������������ش���ij��򼯡� -����: ����Ϊ�����ṩ��ȫָ�������ֱ�ʶ�� -����: ���ɼ����ơ��汾�������Ժ͹�Կ�����ɡ� -����: �йش��������ϸ��Ϣ�ͳ��������������μ���Ƥ�� http://go.microsoft.com/fwlink/?LinkId=109270�� -��־: Appbase = file:///E:/gwq/BRServer/bin/ -��־: ��ʼ PrivatePath = NULL -���ó���: SuperSocket.SocketEngine, Version=1.6.2.0, Culture=neutral, PublicKeyToken=6c80000676988ebb�� -=== -��־: �˰󶨴� default ���������Ŀ�ʼ�� -��־: ����ʹ��Ӧ�ó��������ļ�: E:\gwq\BRServer\bin\BRCJServerTest.vshost.exe.Config -��־: ʹ�����������ļ�: -��־: ʹ�� C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config �ļ���������ļ��� -��־: ��ʱû��Ϊ����Ӧ�ò���(˽�С��Զ��塢�ֲ������λ�õij��򼯰�)�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.DLL�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer.EXE�� -��־: ���������µ� URL file:///E:/gwq/BRServer/bin/BRServer/BRServer.EXE�� - +2019-03-14 11:19:55,014 [11964] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 66 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:37,328 [8624] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:24:57,890 [11700] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:25:44,997 [5460] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:52:39,160 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:55:57,449 [8756] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 11:57:38,760 [6112] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:18:39,687 [10844] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:08,846 [4896] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 +2019-03-14 12:23:36,057 [8500] ERROR TelecomServer - System.NullReferenceException: δ�������������õ������ʵ���� + �� BRServer.CasicSender.GetWindowsServiceInstallPath(String ServiceName) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 169 + �� BRServer.CasicSender.SendNACommand(String deviceId_Telecom, String strValue, CasicSession session) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 139 + �� BRServer.CasicSender.doSendTimeConfig(String devCode, String ver, String typeName, CasicSession session, String flag, String deviceId_Telecom) λ�� E:\gwq\BRServer\BRServer\CasicSender.cs:�к� 113 + �� BRServer.CasicCmd.ExecuteCommand(CasicSession session, StringRequestInfo requestInfo) λ�� E:\gwq\BRServer\BRServer\CasicCmd.cs:�к� 267 diff --git a/bin/Logs/info.log b/bin/Logs/info.log index c43e11c..7663110 100644 --- a/bin/Logs/info.log +++ b/bin/Logs/info.log @@ -1 +1,168 @@ -2019-03-12 09:28:51,437 [8220] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:08:48,251 [8252] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:17:01,040 [12228] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:19:45,572 [8260] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:19:49,320 [10844] INFO TelecomServer - Session: 23a74cbb-c647-4247-8c58-91de32a47913/192.168.8.107:54103 +A new session connected! +2019-03-14 11:19:51,476 [11964] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - �豸����:��������� +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:19:51,477 [11964] INFO TelecomServer - ����seq:01 +2019-03-14 11:19:51,481 [11964] INFO TelecomServer - ��������������ϴ�TAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:19:51,484 [10844] INFO TelecomServer - Session: 23a74cbb-c647-4247-8c58-91de32a47913/192.168.8.107:54103 +This session was closed for ServerClosing! +2019-03-14 11:23:30,757 [7220] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:23:30,936 [6140] INFO TelecomServer - Session: 43adbb6d-d355-4c96-a248-4ff96b292340/192.168.8.107:54204 +A new session connected! +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - �豸����:��������� +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:23:49,440 [8624] INFO TelecomServer - ����seq:01 +2019-03-14 11:23:49,444 [8624] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:23:49,447 [8624] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:23:49,456 [5464] INFO TelecomServer - Session: 43adbb6d-d355-4c96-a248-4ff96b292340/192.168.8.107:54204 +This session was closed for ServerClosing! +2019-03-14 11:24:40,942 [6140] INFO TelecomServer - Session: 6bff6253-4133-4fa8-bf06-f6f58f89bf95/192.168.8.107:54251 +A new session connected! +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - �豸����:��������� +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ����seq:01 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:24:41,498 [11700] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:24:41,500 [8440] INFO TelecomServer - Session: 6bff6253-4133-4fa8-bf06-f6f58f89bf95/192.168.8.107:54251 +This session was closed for ServerClosing! +2019-03-14 11:25:29,770 [8440] INFO TelecomServer - Session: bf7d9f60-7538-48c1-884a-a176fafe35c0/192.168.8.107:54268 +A new session connected! +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - Session: bf7d9f60-7538-48c1-884a-a176fafe35c0/192.168.8.107:54268 +This session was closed for ServerClosing! +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - AD��������:A3,20,0030,132019010001,03,0001,0495,01,10000050000312060160000020000163C26D0194000400004843C82D019400040000C041,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - �豸����:��������� +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ����seq:01 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������������ϴ�����ֵTAG��oid��C26D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��00004843 +2019-03-14 11:25:30,329 [5460] INFO TelecomServer - ��������������ϴ��¶�TAG��oid��C82D0194 �ɼ����: 1440 �ɼ�ʱ�䣺6:44:00 �ϴ���ֵ��0000C041 +2019-03-14 11:48:01,744 [5404] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:52:30,595 [6648] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 11:52:30,717 [6060] INFO TelecomServer - Session: 089558ed-5059-4137-a7a4-d33f9fb1c0f9/192.168.8.107:55015 +A new session connected! +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - �豸����:��������� +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:52:35,871 [8756] INFO TelecomServer - ����seq:01 +2019-03-14 11:52:35,873 [8756] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 11:52:35,893 [10336] INFO TelecomServer - Session: 089558ed-5059-4137-a7a4-d33f9fb1c0f9/192.168.8.107:55015 +This session was closed for ServerClosing! +2019-03-14 11:52:57,912 [10336] INFO TelecomServer - Session: b453cd97-e00b-41d9-b3bc-33d26dc46999/192.168.8.107:55050 +A new session connected! +2019-03-14 11:52:58,542 [8756] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:52:58,542 [8756] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:52:58,543 [8756] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - �豸����:��������� +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:52:58,544 [8756] INFO TelecomServer - ����seq:01 +2019-03-14 11:52:58,545 [11640] INFO TelecomServer - Session: b453cd97-e00b-41d9-b3bc-33d26dc46999/192.168.8.107:55050 +This session was closed for ServerClosing! +2019-03-14 11:55:55,378 [8756] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 11:55:59,241 [12184] INFO TelecomServer - Session: 9fe29086-3fb8-4040-8872-1582388389a2/192.168.8.107:55126 +A new session connected! +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - �豸���:132019010001 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 11:55:59,818 [11640] INFO TelecomServer - Session: 9fe29086-3fb8-4040-8872-1582388389a2/192.168.8.107:55126 +This session was closed for ServerClosing! +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - �豸����:��������� +2019-03-14 11:55:59,818 [6112] INFO TelecomServer - ��������:TrapRequest +2019-03-14 11:55:59,819 [6112] INFO TelecomServer - ����seq:01 +2019-03-14 11:57:38,077 [6112] INFO TelecomServer - δ����TAG oid:60000009 len:1 value:01 +2019-03-14 12:03:07,054 [6784] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:03:07,336 [8328] INFO TelecomServer - Session: 4b7960c8-b918-4d85-ab45-7c94926b1488/192.168.8.107:55292 +A new session connected! +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - �豸����:��������� +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:03:22,184 [4800] INFO TelecomServer - ����seq:01 +2019-03-14 12:03:24,616 [7976] INFO TelecomServer - Session: 4b7960c8-b918-4d85-ab45-7c94926b1488/192.168.8.107:55292 +This session was closed for ServerClosing! +2019-03-14 12:18:19,566 [6008] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:18:26,781 [11724] INFO TelecomServer - Session: cb6dc683-e58d-4091-90ff-3eb10428453e/192.168.8.107:55696 +A new session connected! +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - �豸����:��������� +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:18:36,728 [10844] INFO TelecomServer - ����seq:01 +2019-03-14 12:18:36,731 [10844] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:18:36,749 [2444] INFO TelecomServer - Session: cb6dc683-e58d-4091-90ff-3eb10428453e/192.168.8.107:55696 +This session was closed for ServerClosing! +2019-03-14 12:21:40,398 [9316] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:21:40,562 [9828] INFO TelecomServer - Session: 408cbb6b-e6d6-4cea-9f0a-6c8863c7b774/192.168.8.107:55792 +A new session connected! +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - �豸����:��������� +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:21:43,428 [8728] INFO TelecomServer - ����seq:01 +2019-03-14 12:21:43,430 [11964] INFO TelecomServer - Session: 408cbb6b-e6d6-4cea-9f0a-6c8863c7b774/192.168.8.107:55792 +This session was closed for ServerClosing! +2019-03-14 12:21:43,432 [8728] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:22:56,060 [8452] INFO TelecomServer - The server instance TelecomServer has been started! +2019-03-14 12:22:57,428 [5404] INFO TelecomServer - Session: 3b80d27c-364f-4332-91f8-64bad25052d8/192.168.8.107:55826 +A new session connected! +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - �豸����:��������� +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:23:06,626 [4896] INFO TelecomServer - ����seq:01 +2019-03-14 12:23:06,628 [4896] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:23:06,664 [9296] INFO TelecomServer - Session: 3b80d27c-364f-4332-91f8-64bad25052d8/192.168.8.107:55826 +This session was closed for ServerClosing! +2019-03-14 12:23:17,609 [5404] INFO TelecomServer - Session: 8cd0979c-7513-40fa-8127-86cf9e013b3e/192.168.8.107:55833 +A new session connected! +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - AD��������:A3,20,0023,132019010001,03,0001,0495,01,10000050000313030E6000002000016360000009000101,9f28040b-2c26-414f-9c7f-83426a47201b +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - ��ǰ�汾:20 +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - �豸���:132019010001 +2019-03-14 12:23:18,178 [8500] INFO TelecomServer - ·�ɱ�־:03 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - Ŀ��ڵ��ַ:0001 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - �豸����:��������� +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ��������:TrapRequest +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ����seq:01 +2019-03-14 12:23:18,179 [8500] INFO TelecomServer - ��������Ƿ���ͨ��һ�ݴ���Ϣ��oid��60000009;value:1 +2019-03-14 12:23:20,478 [9296] INFO TelecomServer - Session: 8cd0979c-7513-40fa-8127-86cf9e013b3e/192.168.8.107:55833 +This session was closed for ServerClosing! diff --git a/bin/Logs/info.log20190312 b/bin/Logs/info.log20190312 new file mode 100644 index 0000000..c43e11c --- /dev/null +++ b/bin/Logs/info.log20190312 @@ -0,0 +1 @@ +2019-03-12 09:28:51,437 [8220] INFO TelecomServer - The server instance TelecomServer has been started! diff --git a/bin/Logs/perf.log b/bin/Logs/perf.log index 3b645ed..e9e303c 100644 --- a/bin/Logs/perf.log +++ b/bin/Logs/perf.log @@ -1,9 +1,205 @@ -2019-03-12 09:28:51,537 Performance - --------------------------------------------------- -CPU Usage: 0.00%, Physical Memory Usage: 47,816,704.00, Total Thread Count: 27 +2019-03-14 11:08:48,335 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 48,250,880.00, Total Thread Count: 25 AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 TelecomServer ---------------------------------- -Started Time: 2019/3/12 9:28:51 +Started Time: 2019/3/14 11:08:48 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:17:01,134 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,206,976.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:17:01 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:19:45,632 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,120,960.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:19:45 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:20:45,597 Performance - --------------------------------------------------- +CPU Usage: 0.21%, Physical Memory Usage: 54,157,312.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:19:45 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 1 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:23:30,842 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 45,735,936.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:23:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:24:37,325 Performance - --------------------------------------------------- +CPU Usage: 0.30%, Physical Memory Usage: 54,284,288.00, Total Thread Count: 27 +AvailableWorkingThreads: 1020, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:23:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:25:35,239 Performance - --------------------------------------------------- +CPU Usage: 0.04%, Physical Memory Usage: 55,504,896.00, Total Thread Count: 27 +AvailableWorkingThreads: 1020, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:23:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 2 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:48:01,808 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 44,470,272.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:48:01 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:52:30,681 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 43,999,232.00, Total Thread Count: 26 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:52:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:55:55,412 Performance - --------------------------------------------------- +CPU Usage: 0.09%, Physical Memory Usage: 53,174,272.00, Total Thread Count: 28 +AvailableWorkingThreads: 1021, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:52:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 1 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 11:57:38,094 Performance - --------------------------------------------------- +CPU Usage: 0.04%, Physical Memory Usage: 54,317,056.00, Total Thread Count: 28 +AvailableWorkingThreads: 1020, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 11:52:30 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 2 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 12:03:07,120 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 44,183,552.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 12:03:07 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 12:18:19,634 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,956,544.00, Total Thread Count: 25 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 12:18:19 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 12:21:40,488 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,616,576.00, Total Thread Count: 26 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 12:21:40 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 + +2019-03-14 12:22:56,138 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 46,481,408.00, Total Thread Count: 26 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/14 12:22:56 Is Running: True Total Connections: 0 Maximum Allowed Connection Number: 100 diff --git a/bin/Logs/perf.log20190312 b/bin/Logs/perf.log20190312 new file mode 100644 index 0000000..3b645ed --- /dev/null +++ b/bin/Logs/perf.log20190312 @@ -0,0 +1,14 @@ +2019-03-12 09:28:51,537 Performance - --------------------------------------------------- +CPU Usage: 0.00%, Physical Memory Usage: 47,816,704.00, Total Thread Count: 27 +AvailableWorkingThreads: 1022, AvailableCompletionPortThreads: 1000 +MaxWorkingThreads: 1023, MaxCompletionPortThreads: 1000 +TelecomServer ---------------------------------- +Started Time: 2019/3/12 9:28:51 +Is Running: True +Total Connections: 0 +Maximum Allowed Connection Number: 100 +Total Handled Requests: 0 +Request Handling Speed (#/second): 0 +Avialable Sending Queue Items: 256 +Total Sending Queue Items: 256 +