Example #1
0
        // 获得记录
        // 本函数每次调用前,最好调用一次 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
            });
        }
Example #2
0
        // 解释包
        void menuItem_explainContent_Click(object sender,
                                           EventArgs e)
        {
            TreeNode node = this.treeView_ber.SelectedNode;

            if (node == null)
            {
                MessageBox.Show(this, "尚未选定节点");
                return;
            }

            BerNode bernode = (BerNode)node.Tag;

            if (TreeNodeLevel(node) != 1)
            {
                MessageBox.Show(this, "必须是Ber包根节点");
                return;
            }

            BerNode root         = bernode;
            int     nRet         = 0;
            string  strError     = "";
            string  strDebugInfo = "OK";

            if (root.m_uTag == BerTree.z3950_initRequest)
            {
                // 观察Initial请求包
                nRet = BerTree.GetInfo_InitRequest(
                    root,
                    out strDebugInfo,
                    out strError);
            }
            else if (root.m_uTag == BerTree.z3950_searchRequest)
            {
                nRet = BerTree.GetInfo_SearchRequest(
                    root,
                    out strDebugInfo,
                    out strError);
            }
            else if (root.m_uTag == BerTree.z3950_presentRequest)
            {
                nRet = BerTree.GetInfo_PresentRequest(
                    root,
                    out strDebugInfo,
                    out strError);
            }
            else if (root.m_uTag == BerTree.z3950_initResponse)
            {
                nRet = BerTree.GetInfo_InitResponse(root,
                                                    out strDebugInfo,
                                                    out strError);
            }
            else if (root.m_uTag == BerTree.z3950_searchResponse)
            {
                nRet = BerTree.GetInfo_SearchResponse(root,
                                                      out strDebugInfo,
                                                      out strError);
            }
            else if (root.m_uTag == BerTree.z3950_presentResponse)
            {
                RecordCollection records         = null;
                SEARCH_RESPONSE  search_response = new SEARCH_RESPONSE();
                nRet = BerTree.GetInfo_PresentResponse(root,
                                                       ref search_response,
                                                       out records,
                                                       true,
                                                       out strError);
            }

            if (nRet == -1)
            {
                MessageBox.Show(this, strError);
            }
            else
            {
                MessageBox.Show(this, strDebugInfo);
            }
        }