private static void Zserver_InitializeLogin(object sender, InitializeLoginEventArgs e) { ZServerChannel zserver_channel = (ZServerChannel)sender; string strInstanceName = zserver_channel.SetProperty().GetKeyValue("i_n"); if (strInstanceName == null) { string strErrorText = "通道中 实例名 '" + strInstanceName + "' 尚未初始化"; ZManager.Log?.Error(strErrorText); e.Result = new Result { Value = -1, ErrorInfo = strErrorText }; return; } Instance instance = FindInstance(strInstanceName); if (instance == null) { e.Result = new Result { Value = -1, ErrorInfo = "实例名 '" + strInstanceName + "' 不存在" }; return; } // result.Value: // -1 登录出错 // 0 登录未成功 // 1 登录成功 string strUserName = zserver_channel.SetProperty().GetKeyValue("i_u"); string strPassword = zserver_channel.SetProperty().GetKeyValue("i_p"); LoginInfo login_info = new LoginInfo { UserName = strUserName, Password = strPassword }; LibraryChannel library_channel = instance.MessageConnection.GetChannel(login_info); try { string strParameters = ""; if (login_info.UserType == "patron") { strParameters += ",type=reader"; } strParameters += ",client=dp2capo|" + "0.01"; long lRet = library_channel.Login(strUserName, strPassword, strParameters, out string strError); e.Result.Value = (int)lRet; e.Result.ErrorInfo = strError; } finally { instance.MessageConnection.ReturnChannel(library_channel); } }
private static void Zserver_InitializeLogin(object sender, InitializeLoginEventArgs e) { ZServerChannel zserver_channel = (ZServerChannel)sender; if (zserver_channel == null) { throw new ArgumentException("zserver_channel 为空"); } string strInstanceName = zserver_channel.EnsureProperty().GetKeyValue("i_n"); if (strInstanceName == null) { string strErrorText = "通道中 实例名 'i_n' 尚未初始化"; // ?? bug LibraryManager.Log?.Error(strErrorText); e.Result = new Result { Value = -1, ErrorCode = "2", ErrorInfo = strErrorText }; return; } Instance instance = FindZ3950Instance(strInstanceName, out string strError); if (instance == null) { if (string.IsNullOrEmpty(strError)) { strError = "实例名 '" + strInstanceName + "' 不存在(或实例没有启用 Z39.50 服务)"; } e.Result = new Result { Value = -1, ErrorCode = "", ErrorInfo = strError }; return; } if (instance.Running == false) { e.Result = new Result { Value = -1, ErrorCode = "1019", // Init/AC: System not available due to maintenance ErrorInfo = "实例 '" + instance.Name + "' 正在维护中,暂时不能访问" }; return; } // TODO: TcpClient 可能为 null, 表示通道已经被切断 string strClientIP = ZServer.GetClientIP(zserver_channel.TcpClient); // testing // strClientIP = "127.0.0.2"; string strUserName = zserver_channel.EnsureProperty().GetKeyValue("i_u"); string strPassword = zserver_channel.EnsureProperty().GetKeyValue("i_p"); LoginInfo login_info = BuildLoginInfo(strUserName, strPassword); LibraryChannel library_channel = instance.MessageConnection.GetChannel(login_info); try { string strParameters = ""; if (login_info.UserType == "patron") { strParameters += ",type=reader"; } strParameters += ",client=dp2capo|" + "0.01" + ",clientip=" + strClientIP; // result.Value: // -1 登录出错 // 0 登录未成功 // 1 登录成功 long lRet = library_channel.Login(login_info.UserName, login_info.Password, // strPassword, strParameters, out strError); e.Result.Value = (int)lRet; if (lRet != 1) { e.Result.ErrorCode = "101"; } e.Result.ErrorInfo = strError; } finally { instance.MessageConnection.ReturnChannel(library_channel); } }