Пример #1
0
        //Write the log message
        public void AddLog(int iDeviceIndex, int iLogType, string strFormat)
        {
            DeviceTree g_deviceTree = DeviceTree.Instance();
            DateTime   curTime      = DateTime.Now;
            string     strTime      = null;
            string     strlogType   = Properties.Resources.failLogType;
            string     strLogInfo   = null;
            string     strDevInfo   = null;
            string     strErrInfo   = null;
            string     strLog       = null;
            int        iErrorCode   = 0;

            strTime    = curTime.ToString();
            strLogInfo = strFormat;
            if (iDeviceIndex != -1 && iDeviceIndex < 512)
            {
                if (null == g_deviceTree.GetCurDeviceIp())
                {
                    strDevInfo = null;
                }
                else
                {
                    strDevInfo = string.Format("{0}-{1}", g_deviceTree.GetCurDeviceIp(), g_deviceTree.GetCurLocalNodeName());
                }
            }
            switch (iLogType)
            {
            case AcsDemoPublic.OPERATION_SUCC_T:
                strErrInfo = "";
                strlogType = Properties.Resources.successLogType;
                break;

            case AcsDemoPublic.PLAY_SUCC_T:
                strErrInfo = "";
                strlogType = Properties.Resources.successLogType;
                break;

            case AcsDemoPublic.PLAY_FAIL_T:
                //strErrInfo = "PLAY_M4 Error!!!";
                break;

            case AcsDemoPublic.OPERATION_FAIL_T:
                IntPtr ptrFail = CHCNetSDK.NET_DVR_GetErrorMsg(ref iErrorCode);
                string strFail = Marshal.PtrToStringAnsi(ptrFail);
                strErrInfo = string.Format("err{0}:{1}", CHCNetSDK.NET_DVR_GetLastError(), strFail);
                break;

            default:
                IntPtr ptrTemp = CHCNetSDK.NET_DVR_GetErrorMsg(ref iErrorCode);
                string strTemp = Marshal.PtrToStringAnsi(ptrTemp);
                strErrInfo = string.Format("err{0}:{1}", CHCNetSDK.NET_DVR_GetLastError(), strTemp);
                break;
            }

            if (iLogType == AcsDemoPublic.ALARM_INFO_T)
            {
                strLog = string.Format("{0}{1}\n", strTime, strLogInfo);
                //log file path undetermined, temporarily not implementation
            }
            else
            {
                strLog = string.Format("{0}{1}{2}{3}{4}", strTime, strlogType, strLogInfo, strDevInfo, strErrInfo);
            }

            m_struLogInfo.iLogType   = iLogType;
            m_struLogInfo.strTime    = strTime;
            m_struLogInfo.strLogInfo = strLogInfo;
            m_struLogInfo.strDevInfo = strDevInfo;
            m_struLogInfo.strErrInfo = strErrInfo;
            AddList(m_struLogInfo);
        }