From 410dc2d04dbecf019129cd8cd65a3be2c62b4d0c Mon Sep 17 00:00:00 2001
From: ulysseskao <ulysseskao@gmail.com>
Date: Tue, 03 May 2016 18:36:41 +0800
Subject: [PATCH] refator code
---
CCSTrace/CCS/EventAI/TraceSubject.cs | 93 +++++++++++++++++++++-------------------------
1 files changed, 43 insertions(+), 50 deletions(-)
diff --git a/CCSTrace/CCS/EventAI/TraceSubject.cs b/CCSTrace/CCS/EventAI/TraceSubject.cs
index 701dcf3..3a89c5e 100644
--- a/CCSTrace/CCS/EventAI/TraceSubject.cs
+++ b/CCSTrace/CCS/EventAI/TraceSubject.cs
@@ -10,15 +10,15 @@
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
- private string _mDbConnectionString;
+ private string _dbConnectionString;
private static bool _isNewCase;
- private static ArrayList _mLinkList; // store the switch of the new case path
- private static TraceEngine _mTEngine;
- private static Hashtable _mTreeMap; // store the switch of the old case path
+ private static ArrayList _linkList; // store the switch of the new case path
+ private static TraceEngine _traceEngine;
+ private static Hashtable _treeMap; // store the switch of the old case path
private static int _sFsc;
private static int _sUfid;
- private readonly ArrayList _mTmp = new ArrayList();
- private NetworkContext _mPContext;
+ private readonly ArrayList _tmp = new ArrayList();
+ private NetworkContext _context;
private readonly OracleConnection _connectionTpc;
private readonly OracleTransaction _transaction;
@@ -27,35 +27,35 @@
{
_connectionTpc = conn;
_transaction = trx;
- _mDbConnectionString = traceConnectionString;
+ _dbConnectionString = traceConnectionString;
try
{
- if (_mTEngine == null)
+ if (_traceEngine == null)
{
- _mTEngine = new TraceEngine();
+ _traceEngine = new TraceEngine();
}
}
catch (Exception ex)
{
Logger.Error(ex, ex.Message);
- throw ex;
+ throw;
}
}
public void DiscardEngine()
{
- _mTEngine = null;
+ _traceEngine = null;
}
public ArrayList GetNewResult()
{
- return _mLinkList;
+ return _linkList;
}
public Hashtable GetOldResult()
{
- return _mTreeMap;
+ return _treeMap;
}
// for EOS(only get the reverse tree)
@@ -64,8 +64,8 @@
_sFsc = startFsc;
_sUfid = startUfid;
_isNewCase = mIsNew;
- _mTreeMap = new Hashtable();
- _mLinkList = new ArrayList();
+ _treeMap = new Hashtable();
+ _linkList = new ArrayList();
try
{
@@ -173,11 +173,11 @@
Equipment equip = new Equipment(node.ClassID, node.ObjectID);
if (_isNewCase)
- _mLinkList.Add(equip);
+ _linkList.Add(equip);
else
{
- _mTreeMap.Add(node.ObjectID, equip);
- _mTmp.Add(equip);
+ _treeMap.Add(node.ObjectID, equip);
+ _tmp.Add(equip);
}
i++;
@@ -188,7 +188,6 @@
*/
}
- Console.WriteLine(node.ClassID + "----->" + node.ObjectID);
Logger.Info(node.ClassID + "----->" + node.ObjectID);
iti.MoveDescent((short)0);
@@ -208,11 +207,11 @@
Equipment equip = new Equipment(node.ClassID, node.ObjectID);
if (_isNewCase)
- _mLinkList.Add(equip);
+ _linkList.Add(equip);
else
{
- _mTreeMap.Add(node.ObjectID, equip);
- _mTmp.Add(equip);
+ _treeMap.Add(node.ObjectID, equip);
+ _tmp.Add(equip);
}
i++; //後面直接就FINISH,所以就不用判斷tracecount
@@ -231,11 +230,11 @@
if (IsEndEquip(equip))
{
if (_isNewCase)
- _mLinkList.Add(equip);
+ _linkList.Add(equip);
else
{
- _mTreeMap.Add(node.ObjectID, equip);
- _mTmp.Add(equip);
+ _treeMap.Add(node.ObjectID, equip);
+ _tmp.Add(equip);
}
i++; //後面直接就FINISH,所以就不用判斷tracecount
@@ -294,11 +293,11 @@
{
case 108:
if (_isNewCase)
- _mLinkList.Add(equip);
+ _linkList.Add(equip);
else
{
- _mTreeMap.Add(node.ObjectID, equip);
- _mTmp.Add(equip);
+ _treeMap.Add(node.ObjectID, equip);
+ _tmp.Add(equip);
}
Logger.Info(node.ClassID + "----->" + node.ObjectID);
@@ -328,11 +327,11 @@
if (!ostatus)
{
if (_isNewCase)
- _mLinkList.Add(equip);
+ _linkList.Add(equip);
else
{
- _mTreeMap.Add(node.ObjectID, equip);
- _mTmp.Add(equip);
+ _treeMap.Add(node.ObjectID, equip);
+ _tmp.Add(equip);
}
Logger.Info(node.ClassID + "----->" + node.ObjectID);
@@ -380,9 +379,8 @@
}
catch (Exception e)
{
- Logger.Error(e.Message);
- Console.WriteLine(e.StackTrace);
- return tree;
+ Logger.Error(e, e.Message);
+ return null;
}
try
@@ -391,8 +389,7 @@
}
catch (Exception e)
{
- Logger.Error(e.Message);
- Console.WriteLine(e.StackTrace);
+ Logger.Error(e, e.Message);
}
return tree;
@@ -400,17 +397,17 @@
private void ConfigTrace()
{
- if (_mDbConnectionString == null)
+ if (_dbConnectionString == null)
{
- _mDbConnectionString = "basedb/basedb000@nntpc";
+ _dbConnectionString = "basedb/basedb000@nntpc";
}
try
{
- if (_mPContext == null) _mPContext = _mTEngine.teoCreateContext();
+ if (_context == null) _context = _traceEngine.teoCreateContext();
- if (_mPContext.IsConnected == 0)
+ if (_context.IsConnected == 0)
{
- _mPContext.Connect("", _mDbConnectionString);
+ _context.Connect("", _dbConnectionString);
}
}
catch (Exception ex)
@@ -445,10 +442,10 @@
tContext.addCriterion(sCriterion);
tContext.addCriterion(eCriterion);
- _mPContext.ResetContext();
+ _context.ResetContext();
Logger.Info("Set ModeTrace OK.");
- ResultTreeBuilder trBuilder = _mPContext.CreateTreeBuilder();
+ ResultTreeBuilder trBuilder = _context.CreateTreeBuilder();
if (!trBuilder.constructResultTree(tContext, TRAVELTHREADMODE.CONMODE_SYNCHRONOUS)) { return null; }
Logger.Info("ConstructResultTree OK.");
ResultTree result = trBuilder.ResultTree;
@@ -460,12 +457,11 @@
//判斷是否為最終設備(逆向追到已經無child的設備時,檢查該設備是否為最終設備(查驗該設備的同層設備,是否仍有可繼續逆向追蹤的設備,若無,則該設備為最終設備
private bool IsEndEquip(Equipment selfEquip)
{
- string sqlStmt;
OracleCommand command = null;
OracleDataReader reader = null;
long nValue = 0;
- sqlStmt = "SELECT DIR,OSTATUS,N1,N2 FROM BASEDB.CONNECTIVITY WHERE FSC = " + selfEquip.Fsc+ " AND UFID = " + selfEquip.Ufid;
+ var sqlStmt = "SELECT DIR,OSTATUS,N1,N2 FROM BASEDB.CONNECTIVITY WHERE FSC = " + selfEquip.Fsc+ " AND UFID = " + selfEquip.Ufid;
try
{
@@ -539,11 +535,8 @@
}
finally
{
- if (command != null)
- command.Dispose();
-
- if (reader != null)
- reader.Close();
+ command?.Dispose();
+ reader?.Close();
}
return true;
--
Gitblit v0.0.0-SNAPSHOT