/// <summary> /// Asynchronously log into the server -- meaning, this function returns immediately /// while it attempts to login to the server. When it finishes, it calls the /// 'callback' function handed in. /// </summary> /// <param name="user">Username to login with.</param> /// <param name="password">Password for the user.</param> /// <param name="version">Version of the client.</param> /// <param name="callback">Callback, called when the login finishes.</param> /// <exception cref="Network.Exceptions.UnknownException"> /// Thrown if any error occurs. It's unusual.</exception> public void LoginAsync(string user, string password, VTankObject.Version version, ActionFinished callback) { try { remoteCallback = callback; factory.VTankLogin_async(new Login_Callback(LoginCallback), user, password, version); } // Unknown exceptions are escalated because it's unusual for an error to happen here. catch (Ice.Exception e) { logger.Error("LoginAsync() Ice.Exception: {0}", e); throw new UnknownException("Unable to establish a connection for logging in."); } catch (NullReferenceException e) { logger.Error("LoginAsync() System.NullReferenceException: {0}", e); throw new UnknownException("Unable to establish a connection for logging in."); } catch (System.Exception e) { logger.Error("LoginAsync() System.Exception: {0}", e); throw new UnknownException("Unable to establish a connection for logging in."); } }
/// <summary> /// Log into the server synchronously, which means it will block until it receives /// a response. /// </summary> /// <param name="user">Username to login with.</param> /// <param name="password">Password for the user.</param> /// <param name="version">Version of the client.</param> /// <param name="callback">Callback, called when the login finishes.</param> /// <exception cref="Network.Exceptions.LoginFailedException"> /// Thrown if the login failed.</exception> public void Login(string user, string password, VTankObject.Version version) { try { session = MainSessionPrxHelper.uncheckedCast( factory.VTankLogin(user, password, version)); pinger = new Pinger(session); if (KeepAlive) { keepAliveTimer = new Timer(new TimerCallback(OnKeepAlive), null, KeepAliveInterval, KeepAliveInterval); } } catch (Exceptions.PermissionDeniedException e) { logger.Info("Login() PermissionDeniedException: {0}", e.reason); throw new LoginFailedException(e.reason); } catch (Ice.Exception e) { logger.Error("Login() Ice.Exception: {0}", e); throw new UnknownException("Cannot connect to the server."); } catch (System.Exception e) { logger.Error("Login() System.Exception: {0}", e); throw new UnknownException("Cannot connect to the server."); } }