| | |
| | | using System;
|
| | |
|
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using System.Data.OracleClient;
|
| | | using System.Net;
|
| | | using System.Net.Sockets;
|
| | | using CCSTrace.TPower.DMMS.Model.CCS;
|
| | | using NLog;
|
| | |
|
| | | namespace CCSTrace.CCS.Object
|
| | |
| | | public class AlarmData
|
| | | {
|
| | | private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
| | | private Hashtable _mTotalData = new Hashtable();
|
| | | private OracleConnection _connectionTpc;
|
| | | private OracleTransaction _transaction;
|
| | |
|
| | | public AlarmData(OracleConnection conn, OracleTransaction trx)
|
| | | public static AlarmData Instance { get; } = new AlarmData();
|
| | |
|
| | | private readonly Dictionary<int, ALARMIP> _totalAddrData = new Dictionary<int, ALARMIP>();
|
| | |
|
| | | private AlarmData()
|
| | | {
|
| | | _connectionTpc = conn;
|
| | | _transaction = trx;
|
| | | }
|
| | |
|
| | | public void Initialize(OracleConnection conn)
|
| | | {
|
| | | var sqlStmt = "SELECT DEPTID,IP1,IP2,IP_PATROL FROM CCS.ALARM_IP";
|
| | | OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
|
| | | OracleCommand command = new OracleCommand(sqlStmt, conn);
|
| | | OracleDataReader reader = command.ExecuteReader();
|
| | |
|
| | | try
|
| | | {
|
| | | while (reader.Read())
|
| | | {
|
| | | ArrayList tmp = new ArrayList();
|
| | | tmp.Add(Convert.ToInt32(reader["DEPTID"].ToString()));
|
| | | tmp.Add(reader["IP1"].ToString());
|
| | | tmp.Add(reader["IP2"].ToString());
|
| | | tmp.Add(reader["IP_Patrol"].ToString());
|
| | | ALARMIP tmp = new ALARMIP
|
| | | {
|
| | | DEPTID = Convert.ToInt32(reader["DEPTID"].ToString()),
|
| | | IP1 = reader["IP1"].ToString(),
|
| | | IP2 = reader["IP2"].ToString(),
|
| | | IPPATROL = reader["IP_Patrol"].ToString()
|
| | | };
|
| | |
|
| | | _mTotalData.Add(Convert.ToInt32(reader["DeptID"].ToString()), tmp);
|
| | | _totalAddrData.Add(tmp.DEPTID, tmp);
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | |
| | | return ssccode;
|
| | | }
|
| | |
|
| | | private ArrayList GetIpAddress(int deptCode)
|
| | | private ALARMIP GetIpAddress(int deptCode)
|
| | | {
|
| | | return (ArrayList)_mTotalData[Convert.ToInt32(deptCode)];
|
| | | return _totalAddrData[deptCode];
|
| | | }
|
| | |
|
| | | public bool Alarm(string acceptNum, int dept)
|
| | | public bool Alarm(OracleConnection conn, OracleTransaction trx, string acceptNum, int dept)
|
| | | {
|
| | | Logger.Info("開始Alarm...");
|
| | | Socket mClient;
|
| | | ArrayList ipAddressSet = GetIpAddress(GetSscCode(dept, Convert.ToInt32(DateTime.Now.DayOfWeek)));
|
| | | Socket clientSocket;
|
| | | ALARMIP alarmip = GetIpAddress(GetSscCode(dept, Convert.ToInt32(DateTime.Now.DayOfWeek)));
|
| | | string ip1;
|
| | | string ip2;
|
| | | string ipPatrol;
|
| | | System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
| | |
|
| | | if (ipAddressSet != null)
|
| | | if (alarmip != null)
|
| | | {
|
| | | Logger.Info("已取得該部門所需通知的IP Address.");
|
| | | ip1 = ipAddressSet[1].ToString();
|
| | | ip2 = ipAddressSet[2].ToString();
|
| | | ipPatrol = ipAddressSet[3].ToString();
|
| | | ip1 = alarmip.IP1;
|
| | | ip2 = alarmip.IP2;
|
| | | ipPatrol = alarmip.IPPATROL;
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | try
|
| | | {
|
| | | IPAddress serverIp = IPAddress.Parse(ip1);
|
| | | int serverPort = Convert.ToInt32(GlobalVariable.AlermPort);
|
| | | var serverPort = Convert.ToInt32(GlobalVariable.AlermPort);
|
| | | IPEndPoint iep = new IPEndPoint(serverIp, serverPort);
|
| | |
|
| | | mClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| | | mClient.Connect(iep);
|
| | | clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| | | clientSocket.Connect(iep);
|
| | |
|
| | | byte[] byteMessage = encoding.GetBytes(acceptNum);
|
| | |
|
| | | mClient.Send(byteMessage);
|
| | | mClient.Shutdown(SocketShutdown.Both);
|
| | | mClient.Close();
|
| | | RecordAlarmIp(acceptNum, ip1);
|
| | | clientSocket.Send(byteMessage);
|
| | | clientSocket.Shutdown(SocketShutdown.Both);
|
| | | clientSocket.Close();
|
| | | RecordAlarmIp(conn, trx, acceptNum, ip1);
|
| | | Logger.Info("已成功通知" + ip1 + " !");
|
| | | return true;
|
| | | }
|
| | |
| | | try
|
| | | {
|
| | | IPAddress serverIp = IPAddress.Parse(ip2);
|
| | | int serverPort = Convert.ToInt32(GlobalVariable.AlermPort);
|
| | | var serverPort = Convert.ToInt32(GlobalVariable.AlermPort);
|
| | | IPEndPoint iep = new IPEndPoint(serverIp, serverPort);
|
| | |
|
| | | mClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| | | mClient.Connect(iep);
|
| | | clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| | | clientSocket.Connect(iep);
|
| | |
|
| | | byte[] byteMessage = encoding.GetBytes(acceptNum);
|
| | |
|
| | | mClient.Send(byteMessage);
|
| | | mClient.Shutdown(SocketShutdown.Both);
|
| | | mClient.Close();
|
| | | RecordAlarmIp(acceptNum, ip2);
|
| | | clientSocket.Send(byteMessage);
|
| | | clientSocket.Shutdown(SocketShutdown.Both);
|
| | | clientSocket.Close();
|
| | | RecordAlarmIp(conn, trx, acceptNum, ip2);
|
| | | Logger.Info("已成功通知" + ip2 + " !");
|
| | | return true;
|
| | | }
|
| | |
| | | int serverPort = Convert.ToInt32(GlobalVariable.AlermPort);
|
| | | IPEndPoint iep = new IPEndPoint(serverIp, serverPort);
|
| | |
|
| | | mClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| | | mClient.Connect(iep);
|
| | | clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
| | | clientSocket.Connect(iep);
|
| | |
|
| | | byte[] byteMessage = encoding.GetBytes(acceptNum);
|
| | |
|
| | | mClient.Send(byteMessage);
|
| | | mClient.Shutdown(SocketShutdown.Both);
|
| | | mClient.Close();
|
| | | RecordAlarmIp(acceptNum, ipPatrol);
|
| | | clientSocket.Send(byteMessage);
|
| | | clientSocket.Shutdown(SocketShutdown.Both);
|
| | | clientSocket.Close();
|
| | | RecordAlarmIp(conn, trx, acceptNum, ipPatrol);
|
| | | Logger.Info("已成功通知" + ipPatrol + " !");
|
| | | return true;
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private void RecordAlarmIp(string accNum, string ip)
|
| | | private void RecordAlarmIp(OracleConnection conn, OracleTransaction trx, string accNum, string ip)
|
| | | {
|
| | | string sqlStmt = "insert into eos.case_dispatch (acceptnum,alarmip) values('" + accNum + "','" + ip + "')";
|
| | | string sqlStmt = "INSERT INTO EOS.CASE_DISPATCH (ACCEPTNUM,ALARMIP) VALUES('" + accNum + "','" + ip + "')";
|
| | |
|
| | | OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
|
| | | OracleCommand command = new OracleCommand(sqlStmt, conn, trx);
|
| | |
|
| | | try
|
| | | {
|
| | |
| | | catch (Exception e)
|
| | | {
|
| | | Logger.Error("recordAlarmIP Error." + e.Message);
|
| | | return;
|
| | | }
|
| | | finally
|
| | | {
|