Exemple #1
0
        static int Main(string[] args)
        {
            string message = string.Empty;

            _SystemConfig = new CSystemConfig();
            if (_SystemConfig.getErrorCode() != 0)
            {
                return(1);
            }

            E_ERROR_CODE errorCode = loadConfigData();

            if (errorCode != E_ERROR_CODE.OK)
            {
                return((int)errorCode);
            }

            _DbConnection = new CDbConnection(_DbConnectStr, _SystemLog);
            if (!_DbConnection.testConnect())
            {
                _SystemLog.disposeLogWriter();
                return((int)E_ERROR_CODE.ERROR_CONNECT_DB_FAILED);
            }

            initLocalVaribles();

            while (true)
            {
                _BeiDouDeviceManager.processBeiDevice();
                message = string.Format("Run cycle <{0}>, Next run time <{1}>....", _RequestCycle, CPublic.getDateTimeString(DateTime.Now.AddSeconds(_RequestCycle)));
                _SystemLog.writeLog(LOG_LEVEL.WARNING, message);
                Thread.Sleep(TimeSpan.FromSeconds(_RequestCycle));
            }
        }
        public void printSystemConfig(CSystemLog systemLog)
        {
            string message = string.Empty;

            foreach (KeyValuePair <string, object> kvp in _ConfigItemTable)
            {
                message = string.Format("{0}={1}", kvp.Key, kvp.Value.ToString());
                systemLog.writeLog(LOG_LEVEL.NOTICE, message);
            }
        }
        public bool testConnect()
        {
            string          message      = string.Empty;
            MySqlConnection dbConnection = null;

            try
            {
                dbConnection = getDbConnection();
                return(dbConnection.State == System.Data.ConnectionState.Open);
            }
            catch (Exception ex) {
                message = string.Format("Open db faild, error message<{0}>.", ex.Message);
                _SystemLog.writeLog(LOG_LEVEL.CRIT, message);
                return(false);
            }
            finally
            {
                if (dbConnection != null)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();
                    dbConnection = null;
                }
            }
        }
Exemple #4
0
 public int getIpAddress()
 {
     try
     {
         IPAddress ipAddress = IPAddress.Parse(IpAddress);
         Byte[]    bytes     = ipAddress.GetAddressBytes();
         return(Math.Abs(BitConverter.ToInt32(bytes, 0)));
     }
     catch (Exception ex)
     {
         _SystemLog.writeLog(LOG_LEVEL.ERR, string.Format("Address is not valid ip address<{0}>, error message<{1}>.", IpAddress, ex.Message));
         return(-1);
     }
 }
        public bool save2Db()
        {
            int addRecordCount = 0;
            List <List <CDbParameter> > recordTable     = new List <List <CDbParameter> >();
            List <CDbParameter>         recordParameter = convert2DbParameterList();

            if (recordParameter != null)
            {
                recordTable.Add(recordParameter);
            }
            else
            {
                message = string.Format("Conver device<{0}> to db parameter list faild.", Id);
                _SystemLog.writeLog(LOG_LEVEL.ERR, message);
                return(false);
            }

            return(_DbConnection.saveRecords(INSERT_RECORD_SQL, recordTable, getFieldNameList(), out addRecordCount));
        }
        public E_ERROR_CODE processBeiDevice()
        {
            string       message   = string.Empty;
            E_ERROR_CODE errorCode = E_ERROR_CODE.ERROR;

            errorCode = loadBeiDeviceFromDb();
            if (errorCode != E_ERROR_CODE.OK)
            {
                return(errorCode);
            }

            errorCode = queryBeiDouDeviceFromRemoteServer();
            if (errorCode != E_ERROR_CODE.OK)
            {
                return(errorCode);
            }

            findInsertDevice();
            findDeleteDevice();
            findUpdateDevice();
            errorCode = insertDeviceToDb();
            if (errorCode != E_ERROR_CODE.OK)
            {
                message = "Insert devices to db faild.";
                _SystemLog.writeLog(LOG_LEVEL.ERR, message);
            }

            errorCode = updateDeviceToDb();
            if (errorCode != E_ERROR_CODE.OK)
            {
                message = "Update devices to db faild.";
                _SystemLog.writeLog(LOG_LEVEL.ERR, message);
            }

            return(errorCode);
        }