public async Task <byte[]> DefaultProcessPresent(ZServerChannel channel, BerTree request) { BerNode root = request.GetAPDuRoot(); // 解码Search请求包 int nRet = ZProcessor.Decode_PresentRequest( root, out PresentRequestInfo info, out string strError); if (nRet == -1) { goto ERROR1; } if (channel.EnsureProperty()._bInitialized == false) { return(null); } PresentGetRecordsEventArgs e = new PresentGetRecordsEventArgs(); if (this.PresentGetRecords == null) { // 模拟返回一条记录 e.Records = new List <RetrivalRecord>(); RetrivalRecord record = new RetrivalRecord(); // TODO: 准备数据 e.Records.Add(record); } else { e.Request = info; this.PresentGetRecords(channel, e); } // 编码Present响应包 nRet = ZProcessor.Encode_PresentResponse(info, e.Records, e.Diag, e.TotalCount, out byte[] baResponsePackage); if (nRet == -1) { goto ERROR1; } return(baResponsePackage); ERROR1: // TODO: 将错误原因写入日志 return(null); }
public async Task <byte[]> DefaultProcessSearch(ZServerChannel channel, BerTree request) { BerNode root = request.GetAPDuRoot(); // 解码Search请求包 int nRet = ZProcessor.Decode_SearchRequest( root, out SearchRequestInfo info, out string strError); if (nRet == -1) { goto ERROR1; } if (channel.EnsureProperty()._bInitialized == false) { return(null); } SearchSearchEventArgs e = new SearchSearchEventArgs(); e.Request = info; if (this.SearchSearch == null) { // 返回模拟的结果,假装命中了一条记录 e.Result = new ZClient.SearchResult { Value = 1 }; } else { this.SearchSearch(channel, e); } // 编码Search响应包 nRet = ZProcessor.Encode_SearchResponse(info, e.Result, e.Diag, out byte[] baResponsePackage, out strError); if (nRet == -1) { goto ERROR1; } return(baResponsePackage); ERROR1: // TODO: 将错误原因写入日志 return(null); }
public /*async*/ Task <byte[]> DefaultProcessInitialize(ZServerChannel channel, BerTree request) { BerNode root = request.GetAPDuRoot(); Encoding encoding = Encoding.GetEncoding(936); REDO: int nRet = ZProcessor.Decode_InitRequest( root, encoding, out InitRequestInfo info, out string strDebugInfo, out string strError); if (nRet == -1) { goto ERROR1; } // 可以用groupid来表示字符集信息 InitResponseInfo response_info = new InitResponseInfo(); if (info.m_charNego != null) { /* option * * search (0), * present (1), * delSet (2), * resourceReport (3), * triggerResourceCtrl (4), * resourceCtrl (5), * accessCtrl (6), * scan (7), * sort (8), * -- (9) (reserved) * extendedServices (10), * level-1Segmentation (11), * level-2Segmentation (12), * concurrentOperations (13), * namedResultSets (14) * 15 Encapsulation Z39.50-1995 Amendment 3: Z39.50 Encapsulation * 16 resultCount parameter in Sort Response See Note 8 Z39.50-1995 Amendment 1: Add resultCount parameter to Sort Response * 17 Negotiation Model See Note 9 Model for Z39.50 Negotiation During Initialization * 18 Duplicate Detection See Note 1 Z39.50 Duplicate Detection Service * 19 Query type 104 * } */ response_info.m_strOptions = "yynnnnnnnnnnnnn"; if (info.m_charNego.EncodingLevelOID == CharsetNeogatiation.Utf8OID) { BerTree.SetBit(ref response_info.m_strOptions, 17, true); response_info.m_charNego = info.m_charNego; // 2018/9/19 // 如果最初解码用的编码方式不是 UTF8,则需要重新解码 if (encoding != Encoding.UTF8) { encoding = Encoding.UTF8; goto REDO; } channel.EnsureProperty()._searchTermEncoding = Encoding.UTF8; if (info.m_charNego.RecordsInSelectedCharsets != -1) { response_info.m_charNego.RecordsInSelectedCharsets = info.m_charNego.RecordsInSelectedCharsets; // 依从前端的请求 if (response_info.m_charNego.RecordsInSelectedCharsets == 1) { channel.EnsureProperty()._marcRecordEncoding = Encoding.UTF8; } } } } else { response_info.m_strOptions = "yynnnnnnnnnnnnn"; } // 判断info中的信息,决定是否接受Init请求。 // ZServerChannel 初始化设置一些信息。这样它一直携带着伴随生命周期全程 Result result = AutoSetChannelProperty(channel, info); if (result.Value == -1) { response_info.m_nResult = 0; channel.EnsureProperty()._bInitialized = false; ZProcessor.SetInitResponseUserInfo(response_info, "1.2.840.10003.4.1", // string strOID, string.IsNullOrEmpty(result.ErrorCode) ? 100 : Convert.ToInt32(result.ErrorCode), // (unspecified) error result.ErrorInfo); goto DO_RESPONSE; } #if NO if (String.IsNullOrEmpty(info.m_strID) == true) { ZConfig config = AutoGetZConfig(channel, info, out strError); if (config == null) { ZProcessor.SetInitResponseUserInfo(response_info, "", // string strOID, 0, // long lErrorCode, strError); goto DO_RESPONSE; } // 如果定义了允许匿名登录 if (String.IsNullOrEmpty(config.AnonymousUserName) == false) { info.m_strID = config.AnonymousUserName; info.m_strPassword = config.AnonymousPassword; } else { response_info.m_nResult = 0; channel.SetProperty()._bInitialized = false; ZProcessor.SetInitResponseUserInfo(response_info, "", // string strOID, 0, // long lErrorCode, "不允许匿名登录"); goto DO_RESPONSE; } } #endif if (this.InitializeLogin != null) { InitializeLoginEventArgs e = new InitializeLoginEventArgs(); this.InitializeLogin(channel, e); if (e.Result.Value == -1 || e.Result.Value == 0) { response_info.m_nResult = 0; channel.EnsureProperty()._bInitialized = false; ZProcessor.SetInitResponseUserInfo(response_info, "1.2.840.10003.4.1", // string strOID, string.IsNullOrEmpty(e.Result.ErrorCode) ? 101 : Convert.ToInt32(e.Result.ErrorCode), // Access-control failure e.Result.ErrorInfo); } else { response_info.m_nResult = 1; channel.EnsureProperty()._bInitialized = true; } } else { response_info.m_nResult = 1; channel.EnsureProperty()._bInitialized = true; } #if NO // 进行登录 // return: // -1 error // 0 登录未成功 // 1 登录成功 nRet = DoLogin(info.m_strGroupID, info.m_strID, info.m_strPassword, out strError); if (nRet == -1 || nRet == 0) { response_info.m_nResult = 0; this._bInitialized = false; ZProcessor.SetInitResponseUserInfo(response_info, "", // string strOID, 0, // long lErrorCode, strError); } else { response_info.m_nResult = 1; channel._bInitialized = true; } #endif DO_RESPONSE: // 填充 response_info 的其它结构 response_info.m_strReferenceId = info.m_strReferenceId; //if (channel._property == null) // channel._property = new ChannelPropterty(); if (info.m_lPreferredMessageSize != 0) { channel.EnsureProperty().PreferredMessageSize = info.m_lPreferredMessageSize; } // 极限 if (channel.EnsureProperty().PreferredMessageSize > ZServerChannelProperty.MaxPreferredMessageSize) { channel.EnsureProperty().PreferredMessageSize = ZServerChannelProperty.MaxPreferredMessageSize; } response_info.m_lPreferredMessageSize = channel.EnsureProperty().PreferredMessageSize; if (info.m_lExceptionalRecordSize != 0) { channel.EnsureProperty().ExceptionalRecordSize = info.m_lExceptionalRecordSize; } // 极限 if (channel.EnsureProperty().ExceptionalRecordSize > ZServerChannelProperty.MaxExceptionalRecordSize) { channel.EnsureProperty().ExceptionalRecordSize = ZServerChannelProperty.MaxExceptionalRecordSize; } response_info.m_lExceptionalRecordSize = channel.EnsureProperty().ExceptionalRecordSize; response_info.m_strImplementationId = "Digital Platform"; response_info.m_strImplementationName = "dp2Capo"; response_info.m_strImplementationVersion = "1.0"; // BerTree tree = new BerTree(); ZProcessor.Encode_InitialResponse(response_info, out byte[] baResponsePackage); return(Task.FromResult(baResponsePackage)); ERROR1: // TODO: 将错误原因写入日志 LibraryManager.Log?.Error(strError); return(null); }