private bool Connect(string server, string username, string password)
		{
			bool ret = true;
			serverContext = new ServerContext();
			serverContext.Server = server;
			serverContext.Username = username;
			serverContext.Password = password;

			ES.InitializeServices(serverContext);
			int status = -1;
			try
			{
				status = ES.Services.Authentication.AuthenticateUser(serverContext.Username, serverContext.Password, null);
			}
			catch (Exception ex)
			{
				Log.WriteError("Authentication error", ex);
				return false;
			}

			string errorMessage = "Check your internet connection or server URL.";
			if (status != 0)
			{
				switch (status)
				{
					case ERROR_USER_WRONG_USERNAME:
						errorMessage = "Wrong username.";
						break;
					case ERROR_USER_WRONG_PASSWORD:
						errorMessage = "Wrong password.";
						break;
					case ERROR_USER_ACCOUNT_CANCELLED:
						errorMessage = "Account cancelled.";
						break;
					case ERROR_USER_ACCOUNT_PENDING:
						errorMessage = "Account pending.";
						break;
				}
				Log.WriteError(
					string.Format("Cannot connect to the remote server. {0}", errorMessage));
				ret = false;
			}
			return ret;
		}
Example #2
0
 public static void InitializeServices(ServerContext context)
 {
     serverContext = context;
 }