| | |
| | | {
|
| | | private const string DbConfigFilename = "DBConfig.xml";
|
| | |
|
| | | private static Logger _logger = LogManager.GetCurrentClassLogger();
|
| | | private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
| | | private static CcsMain _instance;
|
| | |
|
| | | public static ArrayList ProcessCases = new ArrayList();
|
| | |
| | |
|
| | | private int _connectionCount = 1;
|
| | | private OracleConnection _mainConn = null;
|
| | | private SEventLog _mainLog = null;
|
| | |
|
| | | private SmartThreadPool _mainjobThreadPool = null;
|
| | | private readonly object _syncDbQueue = new object();
|
| | |
| | |
|
| | | public void Startup()
|
| | | {
|
| | | _mainLog = new SEventLog();
|
| | | Logger.Info("CCSMain Startup.");
|
| | |
|
| | | try
|
| | | {
|
| | | ReadXml();
|
| | | Logger.Info("CCSMain ReadXml Complete.");
|
| | |
|
| | | if (_mainConn == null)
|
| | | _mainConn = CreateConnection();
|
| | | //MainConn = CreateMainConnection();
|
| | | Logger.Info("CCSMain has been connected database.");
|
| | |
|
| | | GlobalVariable.CcsCodelist = new CcsCodelist(_mainConn);
|
| | | GlobalVariable.EosCodelist = new EosCodelist(_mainConn);
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | Console.WriteLine(e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | _mainLog.Error(e.Message);
|
| | |
|
| | | if (GlobalVariable.ShowError)
|
| | | _mainLog.Error(e.StackTrace);
|
| | |
|
| | | Logger.Error(e, e.Message);
|
| | | throw;
|
| | | }
|
| | | finally
|
| | | {
|
| | | _mainLog.Close();
|
| | | }
|
| | |
|
| | | CcsRecord mRecord = GetWaitRecord(_mainConn);
|
| | |
| | | stpStartInfo.MaxWorkerThreads = GlobalVariable.MaxThreadSize;
|
| | | stpStartInfo.MinWorkerThreads = GlobalVariable.MinThreadSize;
|
| | | _mainjobThreadPool = new SmartThreadPool(stpStartInfo);
|
| | | Logger.Info("Create Thread Pool.");
|
| | | }
|
| | |
|
| | | public void Shutdown()
|
| | |
| | | GC.Collect();
|
| | | GC.WaitForPendingFinalizers();
|
| | | }
|
| | |
|
| | | public void AcceptEvent(CcsRecord record)
|
| | | {
|
| | | /*
|
| | | WorkItemCallback workItemCallback = new WorkItemCallback(this.DoWork);
|
| | | _mainjobThreadPool.QueueWorkItem(workItemCallback, record);
|
| | | */
|
| | |
|
| | | int i = 0;
|
| | | int reConnectCount = 1;
|
| | |
|
| | |
| | |
|
| | | if (mRecord != null)
|
| | | {
|
| | | OracleConnection conn = _dbQueue.Dequeue();
|
| | | OracleConnection conn = null;
|
| | | lock (_syncDbQueue) conn = _dbQueue.Dequeue();
|
| | | ProcessCase(mRecord, conn);
|
| | | }
|
| | | }
|
| | |
| | | break;
|
| | | }
|
| | | }
|
| | | catch (Exception)
|
| | | catch (Exception e)
|
| | | {
|
| | | Logger.Error(e, e.Message);
|
| | | if (_mainConn.State == ConnectionState.Closed)
|
| | | {
|
| | | i++;
|
| | |
| | | }
|
| | | catch (XmlException xe)
|
| | | {
|
| | | Console.WriteLine(xe.StackTrace);
|
| | | Logger.Error(xe, xe.Message);
|
| | | reader?.Close();
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | try
|
| | | {
|
| | | _mainLog = new SEventLog();
|
| | |
|
| | | if (conn.State.ToString().Equals("Closed"))
|
| | | if (conn.State == ConnectionState.Closed)
|
| | | conn.Open();
|
| | |
|
| | | transaction = conn.BeginTransaction();
|
| | |
|
| | | if (record.InsertDb(conn, transaction, _mainLog))
|
| | | if (record.InsertDb(conn, transaction))
|
| | | {
|
| | | var eventQuery = new EventQuery
|
| | | {
|
| | |
| | | };
|
| | |
|
| | |
|
| | | if (eventQuery.Insert(_mainLog, conn, transaction))
|
| | | if (eventQuery.Insert(conn, transaction))
|
| | | transaction.Commit();
|
| | | else
|
| | | {
|
| | | if (transaction.Connection.State.ToString().Equals("Open"))
|
| | | if (transaction.Connection.State == ConnectionState.Open)
|
| | | transaction.Rollback();
|
| | |
|
| | | throw new Exception("案件未受理成功。");
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | if (transaction.Connection.State.ToString().Equals("Open"))
|
| | | if (transaction.Connection.State == ConnectionState.Open)
|
| | | transaction.Rollback();
|
| | |
|
| | | throw new Exception("案件未受理成功。");
|
| | |
| | | }
|
| | | catch (OracleException e)
|
| | | {
|
| | | Console.WriteLine(e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | _mainLog.Error(e.Message);
|
| | | Logger.Error(e, e.Message);
|
| | |
|
| | | if (GlobalVariable.ShowError)
|
| | | _mainLog.Error(e.StackTrace);
|
| | |
|
| | | if (transaction != null && transaction.Connection.State.ToString().Equals("Open"))
|
| | | if (transaction != null && (transaction.Connection.State == ConnectionState.Open))
|
| | | transaction.Rollback();
|
| | |
|
| | | throw;
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | Console.WriteLine(ex.Message);
|
| | | Console.WriteLine(ex.StackTrace);
|
| | | _mainLog.Error(ex.Message);
|
| | | Logger.Error(ex, ex.Message);
|
| | |
|
| | | if (GlobalVariable.ShowError)
|
| | | _mainLog.Error(ex.StackTrace);
|
| | |
|
| | | if (transaction != null && transaction.Connection.State.ToString().Equals("Open"))
|
| | | if (transaction != null && (transaction.Connection.State == ConnectionState.Open))
|
| | | transaction.Rollback();
|
| | |
|
| | | throw;
|
| | | }
|
| | | finally
|
| | | {
|
| | | _mainLog.Close();
|
| | | }
|
| | |
|
| | | return true;
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | Log(e.Message);
|
| | | _mainLog.Error("無法取得等候處理CCS案件資料。錯誤訊息 = " + e.Message);
|
| | |
|
| | | if (GlobalVariable.ShowError)
|
| | | _mainLog.Error(e.StackTrace);
|
| | | Logger.Error(e, e.Message);
|
| | | }
|
| | | finally
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | if (ccsid.Length != 0)
|
| | | record = new CcsRecord(ccsid, conn, _mainLog);
|
| | | record = new CcsRecord(ccsid, conn);
|
| | |
|
| | | if (record != null)
|
| | | {
|
| | |
| | |
|
| | | try
|
| | | {
|
| | | if (eventQuery.UpdateCaseStatus(_mainLog, conn, transaction))
|
| | | if (eventQuery.UpdateCaseStatus(conn, transaction))
|
| | | {
|
| | | _mainLog.Info("更新EVENTQUERY的案件狀態為處理中.(CCSID = " + record.CcsId + ")");
|
| | | Logger.Info("更新EVENTQUERY的案件狀態為處理中.(CCSID = " + record.CcsId + ")");
|
| | | transaction.Commit();
|
| | | ProcessCases.Add(record.CcsId);
|
| | | }
|
| | | else
|
| | | {
|
| | | _mainLog.Error("無法更新EVENTQUERY的案件狀態.(CCSID = " + record.CcsId + ")");
|
| | | Logger.Error("無法更新EVENTQUERY的案件狀態.(CCSID = " + record.CcsId + ")");
|
| | |
|
| | | if (transaction.Connection.State.ToString().Equals("Open"))
|
| | | transaction.Rollback();
|
| | |
| | | if (transaction.Connection.State.ToString().Equals("Open"))
|
| | | transaction.Rollback();
|
| | |
|
| | | Log(e.Message);
|
| | | Logger.Error(e, e.Message);
|
| | | record = null;
|
| | | }
|
| | | }
|
| | |
|
| | | return record;
|
| | | }
|
| | |
|
| | | private void Log(string message)
|
| | | {
|
| | | RecordLog pLog = null;
|
| | | try
|
| | | {
|
| | | pLog = new RecordLog(GlobalVariable.CcsListPath + "MAIN.txt");
|
| | | pLog.Error(message);
|
| | | }
|
| | | finally
|
| | | {
|
| | | if (pLog != null)
|
| | | {
|
| | | pLog.Close();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | } |