private void ProcessFaceDataRecordCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData)
        {
            if (pUserData == null)
            {
                return;
            }
            if (dwType == (uint)CHCNetSDK.NET_SDK_CALLBACK_TYPE.NET_SDK_CALLBACK_TYPE_STATUS)
            {
                uint dwStatus = (uint)Marshal.ReadInt32(lpBuffer);
                if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_FAILED)
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 1, 0);
                    //可以结束了,异常结束
                }
                else if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_EXCEPTION)
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 2, 0);
                    //可以结束了,异常结束
                }
                else if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_PROCESSING)
                {
                    ;
                }
                else if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_SUCCESS)
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 4, 0);
                    //可以结束了,正常(异常)结束
                }
                else
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 3, 0);
                    //可以结束了,异常结束
                }
            }
            else if (dwType == (uint)CHCNetSDK.NET_SDK_CALLBACK_TYPE.NET_SDK_CALLBACK_TYPE_DATA)
            {
                string          strResponseStatus  = Marshal.PtrToStringAnsi(lpBuffer);
                CResponseStatus JsonResponseStatus = new CResponseStatus();
                JsonResponseStatus = JsonConvert.DeserializeObject <CResponseStatus>(strResponseStatus);
                m_strFPID          = JsonResponseStatus.FPID;

                CHCNetSDK.PostMessage(pUserData, 1003, JsonResponseStatus.statusCode, 0);

                if ((m_iFaceDataRecordIndex >= m_iFaceDataRecordCount) || (JsonResponseStatus.statusCode != 1))
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 4, 0);
                    //可以结束了,正常(异常)结束
                    return;
                }
                CHCNetSDK.PostMessage(pUserData, 1002, 0, 0);
                //在主线程中发送下一个用户
            }
            return;
        }
Ejemplo n.º 2
0
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case 1001:
                int iErrorMsg = m.WParam.ToInt32();
                if (iErrorMsg == 1)
                {
                    ListViewItem listItem = new ListViewItem();
                    listItem.Text = "Fail";
                    string strTemp = string.Format("NET_SDK_CALLBACK_STATUS_FAILED");
                    listItem.SubItems.Add(strTemp);
                    this.AddList(listViewResponse, listItem);
                }
                else if (iErrorMsg == 2)
                {
                    ListViewItem listItem = new ListViewItem();
                    listItem.Text = "Fail";
                    string strTemp = string.Format("NET_SDK_CALLBACK_STATUS_EXCEPTION");
                    listItem.SubItems.Add(strTemp);
                    this.AddList(listViewResponse, listItem);
                }
                else if (iErrorMsg == 3)
                {
                    ListViewItem listItem = new ListViewItem();
                    listItem.Text = "Fail";
                    string strTemp = string.Format("NET_SDK_CALLBACK_OTHER_ERROR");
                    listItem.SubItems.Add(strTemp);
                    this.AddList(listViewResponse, listItem);
                }
                else if (iErrorMsg == 4)
                {
                    ListViewItem listItem = new ListViewItem();
                    listItem.Text = "Succ";
                    string strTemp = string.Format("NET_SDK_CALLBACK_FINISH");
                    listItem.SubItems.Add(strTemp);
                    this.AddList(listViewResponse, listItem);
                }
                m_bStart = false;
                m_bFirst = true;
                if (-1 != m_lInfoSynHandle)
                {
                    if (CHCNetSDK.NET_DVR_StopRemoteConfig(m_lInfoSynHandle))
                    {
                        m_lInfoSynHandle = -1;
                    }
                }
                break;

            case 1002:
                m_bGetResult = true;
                break;

            case 1003:
                IntPtr ptrResponse       = (IntPtr)m.WParam.ToInt32();
                string strResponseStatus = Marshal.PtrToStringAnsi(ptrResponse);

                string strResponse = null;

                if (m_bFirst)
                {
                    m_bFirst = false;
                    CResponseStatus JsonResponseStatus = new CResponseStatus();
                    strResponse    = strResponseStatus;
                    m_iCurProgress = 0;
                }
                else
                {
                    if (m_command == SynInfoCommand.USER_INFO_SYN)
                    {
                        CUserInfoSyn JsonResponseStatus = new CUserInfoSyn();
                        JsonResponseStatus.UserInfoSync = new CUserInfoSynContent();
                        if (JsonResponseStatus.UserInfoSync != null)
                        {
                            strResponse    = JsonConvert.SerializeObject(JsonResponseStatus.UserInfoSync.SyncInfo);
                            m_iCurProgress = JsonResponseStatus.UserInfoSync.progressValue;
                        }
                        else
                        {
                            strResponse = strResponseStatus;
                        }
                    }
                    else
                    {
                        CCardInfoSyn JsonResponseStatus = new CCardInfoSyn();
                        JsonResponseStatus = JsonConvert.DeserializeObject <CCardInfoSyn>(strResponseStatus);
                        if (JsonResponseStatus.CardInfoSync != null)
                        {
                            strResponse    = JsonConvert.SerializeObject(JsonResponseStatus.CardInfoSync.SyncInfo);
                            m_iCurProgress = JsonResponseStatus.CardInfoSync.progressValue;
                        }
                        else
                        {
                            strResponse = strResponseStatus;
                        }
                    }
                }

                ListViewItem lvItem = new ListViewItem();
                string       strTmp = null;
                lvItem.Text = "Succ";
                strTmp      = string.Format("Percent:{0}-{1}", m_iCurProgress, strResponse);
                lvItem.SubItems.Add(strTmp);
                this.AddList(listViewResponse, lvItem);
                Marshal.FreeHGlobal(ptrResponse);
                break;

            default:
                base.DefWndProc(ref m);
                break;
            }
        }
Ejemplo n.º 3
0
        private void ProcessInfoSynCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData)
        {
            if (pUserData == null)
            {
                return;
            }

            if (dwType == (uint)CHCNetSDK.NET_SDK_CALLBACK_TYPE.NET_SDK_CALLBACK_TYPE_STATUS)
            {
                uint dwStatus = (uint)Marshal.ReadInt32(lpBuffer);
                if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_FAILED)
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 1, 0);
                    //可以结束了,异常结束
                }
                else if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_EXCEPTION)
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 2, 0);
                    //可以结束了,异常结束
                }
                else if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_PROCESSING)
                {
                    ;
                }
                else
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 3, 0);
                    //可以结束了,异常结束
                }
            }
            else if (dwType == (uint)CHCNetSDK.NET_SDK_CALLBACK_TYPE.NET_SDK_CALLBACK_TYPE_DATA)
            {
                //输出上一包解析信息, 1003
                string strResponseStatus = Marshal.PtrToStringAnsi(lpBuffer);
                IntPtr response          = IntPtr.Zero;

                if (m_bFirst)
                {
                    m_bFirst = false;
                    CResponseStatus JsonResponseStatus = new CResponseStatus();
                    JsonResponseStatus = JsonConvert.DeserializeObject <CResponseStatus>(strResponseStatus);
                    response           = Marshal.StringToHGlobalAnsi(strResponseStatus);
                }
                else
                {
                    if (m_command == SynInfoCommand.USER_INFO_SYN)
                    {
                        CUserInfoSyn JsonResponseStatus = new CUserInfoSyn();
                        JsonResponseStatus = JsonConvert.DeserializeObject <CUserInfoSyn>(strResponseStatus);
                        m_iCurProgress     = JsonResponseStatus.UserInfoSync.progressValue;
                        response           = Marshal.StringToHGlobalAnsi(strResponseStatus);
                    }
                    else
                    {
                        CCardInfoSyn JsonResponseStatus = new CCardInfoSyn();
                        JsonResponseStatus = JsonConvert.DeserializeObject <CCardInfoSyn>(strResponseStatus);
                        m_iCurProgress     = JsonResponseStatus.CardInfoSync.progressValue;
                        response           = Marshal.StringToHGlobalAnsi(strResponseStatus);
                    }
                }

                CHCNetSDK.PostMessage(pUserData, 1003, (int)response, 0);

                if (m_iCurProgress >= 100)
                {
                    CHCNetSDK.PostMessage(pUserData, 1001, 4, 0);
                    //可以结束了,正常(异常)结束
                    return;
                }
                CHCNetSDK.PostMessage(pUserData, 1002, 0, 0);
                //在主线程中发送下一个用户
            }
            return;
        }
        public void ProcessResult(MessageData m)
        {
            if (m.searchMsg == SearchMsgType.RECV_DATA)
            {
                Debug.Assert(m.data != null);

                // 包含节点\"errorCode\",则按照responsestatus状态解析
                if (m.data.Contains("\"errorCode\""))
                {
                    CResponseStatus status  = JsonConvert.DeserializeObject <CResponseStatus>(m.data);
                    string          strTemp = string.Format("Search data device return failure status.errorcode[{0}] errormsg[{1}]", status.errorCode, status.errorMsg);
                    addLog(false, strTemp);
                    rConfig.stop();
                    return;
                }

                // 按照查询结果解析
                CSearchTaskResponse cSearchTaskResponse = null;
                try
                {
                    cSearchTaskResponse = JsonConvert.DeserializeObject <CSearchTaskResponse>(m.data);
                }
                catch (Exception e)
                {
                    addLog(false, "Data DeserializeObject failed " + e.Message);
                }

                if (cSearchTaskResponse == null)
                {
                    addLog(false, "Data return invalid");
                    // 查询下一条数据
                    SearchNextData();
                    return;
                }

                if (cSearchTaskResponse.SearchTaskResponse.responseStatusStrg.Equals("NO MATCH"))
                {
                    addLog(true, "Response NO MATCH data, search over");
                    rConfig.stop();
                    return;
                }

                if (cSearchTaskResponse.SearchTaskResponse.numOfMatches != 1)
                {
                    addLog(true, "Warning: numOfMatches!=1!!! carptureNo: " + cSearchTaskResponse.SearchTaskResponse.DataCollections[0].captureNo);
                }

                if (bFirst)
                {
                    totalMaches = cSearchTaskResponse.SearchTaskResponse.totalMatches;
                    bFirst      = false;
                }

                // 保存数据并且在UI上展现
                UpdateViewControls(ref cSearchTaskResponse);
                SavePcituresAndFP(ref cSearchTaskResponse, ref m);

                if (cSearchTaskResponse.SearchTaskResponse.responseStatusStrg.Equals("OK"))
                {
                    addLog(true, "Response OK data, search over");
                    rConfig.stop();
                    return;
                }

                if (iSearchPos >= totalMaches - 1)
                {
                    addLog(true, "search over");
                    rConfig.stop();
                    return;
                }

                // 查询下一条数据
                SearchNextData();
            }
            else if (m.searchMsg == SearchMsgType.RECV_FAILIURE)
            {
                addLog(false, "Receive failed status runtime error: " + m.errorcode);
                // 查询下一条数据
                SearchNextData();
            }
            else if (m.searchMsg == SearchMsgType.RECV_FINISH)
            {
                addLog(true, "Receive with long config status: " + m.status + " " + m.searchMsg);
                rConfig.stop();
            }

            return;
        }
        private void DeleteFaceRecord()
        {
            IntPtr ptrOutBuf       = Marshal.AllocHGlobal(1024);
            IntPtr ptrStatusBuffer = Marshal.AllocHGlobal(1024);

            for (int i = 0; i < 1024; i++)
            {
                Marshal.WriteByte(ptrOutBuf, i, 0);
                Marshal.WriteByte(ptrStatusBuffer, i, 0);
            }

            CHCNetSDK.NET_DVR_XML_CONFIG_INPUT  struInput = new CHCNetSDK.NET_DVR_XML_CONFIG_INPUT();
            CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struOuput = new CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();

            string libType = (comboBoxLibType.SelectedIndex == 0) ? "blackFD" : "infraredFD";
            string sUrl    = "PUT /ISAPI/Intelligent/FDLib/FDSearch/Delete?format=json&FDID=" + textBoxFDID2.Text + "&faceLibType=" + libType;
            IntPtr ptrURL  = Marshal.StringToHGlobalAnsi(sUrl);

            struInput.dwSize          = (uint)Marshal.SizeOf(struInput);
            struInput.lpRequestUrl    = ptrURL;
            struInput.dwRequestUrlLen = (uint)sUrl.Length;

            CFaceRecordDelete JsonFaceRecordDelete = new CFaceRecordDelete();

            JsonFaceRecordDelete.FPID = new List <CFPID>();

            if (!m_bDeleteAll)
            {
                foreach (ListViewItem item in this.listViewFPID.Items)
                {
                    if (item.SubItems[1].Text != "")
                    {
                        CFPID singleFPID = new CFPID();
                        singleFPID.value = item.SubItems[1].Text;
                        JsonFaceRecordDelete.FPID.Add(singleFPID);
                    }
                }
            }

            string strFaceRecordDelete = JsonConvert.SerializeObject(JsonFaceRecordDelete);

            IntPtr ptrInBuffer = Marshal.StringToHGlobalAnsi(strFaceRecordDelete);

            struInput.lpInBuffer     = ptrInBuffer;
            struInput.dwInBufferSize = (uint)strFaceRecordDelete.Length;

            struOuput.dwSize          = (uint)Marshal.SizeOf(struOuput);
            struOuput.lpOutBuffer     = ptrOutBuf;
            struOuput.dwOutBufferSize = 1024;
            struOuput.lpStatusBuffer  = ptrStatusBuffer;
            struOuput.dwStatusSize    = 1024;

            IntPtr ptrInput = Marshal.AllocHGlobal(Marshal.SizeOf(struInput));

            Marshal.StructureToPtr(struInput, ptrInput, false);
            IntPtr ptrOuput = Marshal.AllocHGlobal(Marshal.SizeOf(struOuput));

            Marshal.StructureToPtr(struOuput, ptrOuput, false);
            if (!CHCNetSDK.NET_DVR_STDXMLConfig(m_lUserID, ptrInput, ptrOuput))
            {
                ListViewItem listItem = new ListViewItem();
                listItem.Text = "Fail";
                string strTemp = string.Format("Delete Face Record Fail,Error Code={0}", CHCNetSDK.NET_DVR_GetLastError());
                listItem.SubItems.Add(strTemp);
                this.AddList(listViewMessage, listItem);
            }
            else
            {
                ListViewItem listItem = new ListViewItem();
                listItem.Text = "Succ";
                string strTemp = string.Format("Delete Face Record Success");
                listItem.SubItems.Add(strTemp);
                this.AddList(listViewMessage, listItem);

                string          strResponseStatus  = Marshal.PtrToStringAnsi(struOuput.lpOutBuffer);
                CResponseStatus JsonResponseStatus = new CResponseStatus();
                JsonResponseStatus = JsonConvert.DeserializeObject <CResponseStatus>(strResponseStatus);
            }

            Marshal.FreeHGlobal(ptrOutBuf);
            Marshal.FreeHGlobal(ptrStatusBuffer);
            Marshal.FreeHGlobal(ptrInBuffer);
            Marshal.FreeHGlobal(ptrInput);
            Marshal.FreeHGlobal(ptrOuput);
            Marshal.FreeHGlobal(ptrURL);
        }