// 获得记录 // 本函数每次调用前,最好调用一次 TryInitialize() // 不确保一定可以获得nCount个 // parameters: // nStart 获取记录的开始位置(从0开始计数) public async Task <PresentResult> OncePresent( string strResultSetName, int nStart, int nCount, string strElementSetName, string strPreferredRecordSyntax) { if (nCount == 0) { return new PresentResult { Value = 0, ErrorInfo = "nCount 参数为 0,本次没有真正请求服务器获取记录" } } ; BerTree tree = new BerTree(); PRESENT_REQUEST struPresent_request = new PRESENT_REQUEST(); //byte[] baPackage = null; //int nRet; struPresent_request.m_strReferenceId = this._currentRefID; struPresent_request.m_strResultSetName = strResultSetName; // "default"; struPresent_request.m_lResultSetStartPoint = nStart + 1; struPresent_request.m_lNumberOfRecordsRequested = nCount; struPresent_request.m_strElementSetNames = strElementSetName; struPresent_request.m_strPreferredRecordSyntax = strPreferredRecordSyntax; int nRet = tree.PresentRequest(struPresent_request, out byte[] baPackage); if (nRet == -1) { return new PresentResult { Value = -1, ErrorInfo = "CBERTree::PresentRequest() fail!" } } ; if (this._channel.Connected == false) { this.CloseConnection(); return(new PresentResult { Value = -1, ErrorInfo = "socket尚未连接或者已经被关闭" }); } #if DUMPTOFILE DeleteFile("presentrequest.bin"); DumpPackage("presentrequest.bin", (char *)baPackage.GetData(), baPackage.GetSize()); DeleteFile("presentrequest.txt"); tree.m_RootNode.DumpToFile("presentrequest.txt"); #endif BerTree tree1 = new BerTree(); { RecvResult result = await this._channel.SendAndRecv( baPackage); if (result.Value == -1) { return(new PresentResult(result)); } #if DUMPTOFILE DeleteFile("presendresponse.bin"); DumpPackage("presentresponse.bin", (char *)baPackage.GetData(), baPackage.GetSize()); #endif tree1.m_RootNode.BuildPartTree(result.Package, 0, result.Package.Length, out int nTotalLen); } #if DUMPTOFILE DeleteFile("PresentResponse.txt"); tree1.m_RootNode.DumpDebugInfoToFile("PresentResponse.txt"); #endif SEARCH_RESPONSE search_response = new SEARCH_RESPONSE(); nRet = BerTree.GetInfo_PresentResponse(tree1.GetAPDuRoot(), ref search_response, out RecordCollection records, true, out string strError); if (nRet == -1) { return new PresentResult { Value = -1, ErrorInfo = strError } } ; SetElementSetName(records, strElementSetName); if (search_response.m_diagRecords.Count != 0) { return new PresentResult { Value = -1, ErrorInfo = "error diagRecords:\r\n\r\n---\r\n" + search_response.m_diagRecords.GetMessage() } } ; return(new PresentResult { Records = records }); }
// 获得记录 // 不确保一定可以获得nCount个 // parameters: // nStart 开始记录(从0计算) int DoOncePresent( ZConnection connection, string strResultSetName, int nStart, int nCount, string strElementSetName, string strPreferredRecordSyntax, out RecordCollection records, out string strError) { records = null; strError = ""; if (nCount == 0) { strError = "nCount为0"; return 0; } BerTree tree = new BerTree(); PRESENT_REQUEST struPresent_request = new PRESENT_REQUEST(); byte[] baPackage = null; int nRet; int nRecvLen; // --> BerTree tree1 = new BerTree(); int nTotlen = 0; struPresent_request.m_strReferenceId = this.CurrentRefID; struPresent_request.m_strResultSetName = strResultSetName; // "default"; struPresent_request.m_lResultSetStartPoint = nStart + 1; struPresent_request.m_lNumberOfRecordsRequested = nCount; struPresent_request.m_strElementSetNames = strElementSetName; struPresent_request.m_strPreferredRecordSyntax = strPreferredRecordSyntax; nRet = tree.PresentRequest(struPresent_request, out baPackage); if (nRet == -1) { strError = "CBERTree::PresentRequest() fail!"; return -1; } #if DUMPTOFILE DeleteFile("presentrequest.bin"); DumpPackage("presentrequest.bin", (char *)baPackage.GetData(), baPackage.GetSize()); DeleteFile ("presentrequest.txt"); tree.m_RootNode.DumpToFile("presentrequest.txt"); #endif nRet = CheckConnect( connection, out strError); if (nRet == -1) return -1; /* nRet = this.ZChannel.SendTcpPackage( baPackage, baPackage.Length, out strError); if (nRet == -1 || nRet == 1) { // CloseZAssociation(); return -1; } ////////////// baPackage = null; nRet = this.ZChannel.RecvTcpPackage( out baPackage, out nRecvLen, out strError); if (nRet == -1) { // CloseZAssociation(); goto ERROR1; } * */ byte [] baOutPackage = null; nRet = connection.ZChannel.SendAndRecv( baPackage, out baOutPackage, out nRecvLen, out strError); if (nRet == -1) return -1; #if DUMPTOFILE DeleteFile("presendresponse.bin"); DumpPackage("presentresponse.bin", (char *)baPackage.GetData(), baPackage.GetSize()); #endif tree1.m_RootNode.BuildPartTree(baOutPackage, 0, baOutPackage.Length, out nTotlen); #if DUMPTOFILE DeleteFile("PresentResponse.txt"); tree1.m_RootNode.DumpDebugInfoToFile("PresentResponse.txt"); #endif SEARCH_RESPONSE search_response = new SEARCH_RESPONSE(); nRet = BerTree.GetInfo_PresentResponse(tree1.GetAPDuRoot(), ref search_response, out records, true, out strError); if (nRet == -1) goto ERROR1; /* nRet = FitDebugInfo_PresentResponse(&tree1, strError); if (nRet == -1) { goto ERROR1; } DeleteFile("PresentResponse.txt"); tree1.m_RootNode.DumpDebugInfoToFile("PresentResponse.txt"); */ if (search_response.m_diagRecords.Count != 0) { /* string strDiagText; string strAddInfo; nRet = GetDiagTextByNumber("bib1diag.txt", m_search_response.m_nDiagCondition, strDiagText, strAddInfo, strError); if (nRet == -1) { if (this->m_bAllowMessageBox) AfxMessageBox(strError); return -1; } if (strDiagText.GetLength()) strError = strDiagText; else strError.Format("diag condition[%d] diag set id[%s]", m_search_response.m_nDiagCondition, m_search_response.m_strDiagSetID); * */ strError = "error diagRecords:\r\n\r\n---\r\n" + search_response.m_diagRecords.GetMessage(); return -1; } return 0; ERROR1: return -1; }