| | |
| | | using System.Data.OracleClient;
|
| | | using System.Net;
|
| | | using System.Net.Sockets;
|
| | | using NLog;
|
| | |
|
| | | namespace CCSTrace.CCS.Object
|
| | | {
|
| | | public class AlarmData
|
| | | {
|
| | | private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
| | | private Hashtable _mTotalData = new Hashtable();
|
| | | private RecordLog _pLog;
|
| | | private OracleConnection _connectionTpc;
|
| | | private OracleTransaction _transaction;
|
| | |
|
| | | public AlarmData(OracleConnection conn, OracleTransaction trx, RecordLog log)
|
| | | public AlarmData(OracleConnection conn, OracleTransaction trx)
|
| | | {
|
| | | _connectionTpc = conn;
|
| | | _transaction = trx;
|
| | | _pLog = log;
|
| | |
|
| | | string sqlStmt;
|
| | |
|
| | | sqlStmt = "SELECT DEPTID,IP1,IP2,IP_PATROL FROM CCS.ALARM_IP";
|
| | | var sqlStmt = "SELECT DEPTID,IP1,IP2,IP_PATROL FROM CCS.ALARM_IP";
|
| | | OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
|
| | | OracleDataReader reader = command.ExecuteReader();
|
| | |
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Error("Problems occur when fetch alarm data: (" + e.Message + ")");
|
| | | Logger.Error(e, "Problems occur when fetch alarm data: (" + e.Message + ")");
|
| | | Console.WriteLine(e.StackTrace);
|
| | | }
|
| | | finally
|
| | |
| | |
|
| | | public bool Alarm(string acceptNum, int dept)
|
| | | {
|
| | | _pLog.Info("開始Alarm...");
|
| | | Logger.Info("開始Alarm...");
|
| | | Socket mClient;
|
| | | ArrayList ipAddressSet = GetIpAddress(GetSscCode(dept, Convert.ToInt32(DateTime.Now.DayOfWeek)));
|
| | | string ip1;
|
| | |
| | |
|
| | | if (ipAddressSet != null)
|
| | | {
|
| | | _pLog.Info("已取得該部門所需通知的IP Address.");
|
| | | Logger.Info("已取得該部門所需通知的IP Address.");
|
| | | ip1 = ipAddressSet[1].ToString();
|
| | | ip2 = ipAddressSet[2].ToString();
|
| | | ipPatrol = ipAddressSet[3].ToString();
|
| | | }
|
| | | else
|
| | | {
|
| | | _pLog.Warn("無法取得該部門所需通知的IP Address!");
|
| | | Logger.Warn("無法取得該部門所需通知的IP Address!");
|
| | | return false;
|
| | | }
|
| | |
|
| | |
| | | mClient.Shutdown(SocketShutdown.Both);
|
| | | mClient.Close();
|
| | | RecordAlarmIp(acceptNum, ip1);
|
| | | _pLog.Info("已成功通知" + ip1 + " !");
|
| | | Logger.Info("已成功通知" + ip1 + " !");
|
| | | return true;
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Warn("無法通知" + ip1 + ": " + e.Message);
|
| | | Logger.Warn("無法通知" + ip1 + ": " + e.Message);
|
| | | }
|
| | |
|
| | | try
|
| | |
| | | mClient.Shutdown(SocketShutdown.Both);
|
| | | mClient.Close();
|
| | | RecordAlarmIp(acceptNum, ip2);
|
| | | _pLog.Info("已成功通知" + ip2 + " !");
|
| | | Logger.Info("已成功通知" + ip2 + " !");
|
| | | return true;
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Warn("無法通知" + ip2 + ": " + e.Message);
|
| | | Logger.Warn("無法通知" + ip2 + ": " + e.Message);
|
| | | }
|
| | |
|
| | | try
|
| | |
| | | mClient.Shutdown(SocketShutdown.Both);
|
| | | mClient.Close();
|
| | | RecordAlarmIp(acceptNum, ipPatrol);
|
| | | _pLog.Info("已成功通知" + ipPatrol + " !");
|
| | | Logger.Info("已成功通知" + ipPatrol + " !");
|
| | | return true;
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Warn("無法通知" + ipPatrol + ": " + e.Message);
|
| | | _pLog.Warn("三個IP均無法通知到!");
|
| | | Logger.Warn("無法通知" + ipPatrol + ": " + e.Message);
|
| | | Logger.Warn("三個IP均無法通知到!");
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
| | | try
|
| | | {
|
| | | if (command.ExecuteNonQuery() <= 0)
|
| | | _pLog.Warn("無法紀錄Alarm IP!");
|
| | | Logger.Warn("無法紀錄Alarm IP!");
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _pLog.Error("recordAlarmIP Error." + e.Message);
|
| | | Logger.Error("recordAlarmIP Error." + e.Message);
|
| | | return;
|
| | | }
|
| | | finally
|