/// <summary>
 /// Factory method for creating response when there is authentication
 /// failure.
 /// </summary>
 public static AuthenticationResponse CreateFailureResponse(
     AuthenticationResultKind authenticationResultKind,
     string url) {
   Debug.Assert(
       authenticationResultKind != AuthenticationResultKind.Authenticated &&
       authenticationResultKind !=
         AuthenticationResultKind.CAPTCHARequired &&
       authenticationResultKind !=
         AuthenticationResultKind.ConnectionFailure &&
       authenticationResultKind != AuthenticationResultKind.TimeOut &&
       authenticationResultKind !=
         AuthenticationResultKind.ResponseParseError);
   AuthenticationResponse authenticationResponse =
       new AuthenticationResponse();
   authenticationResponse.authenticationResult = authenticationResultKind;
   authenticationResponse.url = url;
   return authenticationResponse;
 }
 /// <summary>
 /// Factory method for creating response when there is error in parsing
 /// server response.
 /// </summary>
 public static AuthenticationResponse CreateParseErrorResponse() {
   AuthenticationResponse authenticationResponse =
       new AuthenticationResponse();
   authenticationResponse.authenticationResult =
       AuthenticationResultKind.ResponseParseError;
   return authenticationResponse;
 }
 /// <summary>
 /// Factory method for creating response when the connection timed out.
 /// </summary>
 public static AuthenticationResponse CreateTimeoutResponse() {
   AuthenticationResponse authenticationResponse =
       new AuthenticationResponse();
   authenticationResponse.authenticationResult =
       AuthenticationResultKind.TimeOut;
   return authenticationResponse;
 }
 /// <summary>
 /// Factory method for creating response when there is error connection.
 /// </summary>
 public static AuthenticationResponse CreateConnectionFailureResponse(
   HttpException httpException) {
   Debug.Assert(httpException != null);
   AuthenticationResponse authenticationResponse =
       new AuthenticationResponse();
   authenticationResponse.authenticationResult =
       AuthenticationResultKind.ConnectionFailure;
   authenticationResponse.httpException = httpException;
   return authenticationResponse;
 }
 /// <summary>
 /// Factory method for creating the response when autentication needs
 /// solution for captcha challenge.
 /// </summary>
 public static AuthenticationResponse CreateCAPTCHAResponse(
     string captchaUrl,
     string captchaToken,
     string url,
     Image captchaImage) {
   AuthenticationResponse authenticationResponse =
       new AuthenticationResponse();
   authenticationResponse.authenticationResult =
       AuthenticationResultKind.CAPTCHARequired;
   authenticationResponse.captchaUrl = captchaUrl;
   authenticationResponse.captchaToken = captchaToken;
   authenticationResponse.url = url;
   authenticationResponse.captchaImage = captchaImage;
   return authenticationResponse;
 }
 /// <summary>
 /// Factory method for creating the response when authentication succeeds.
 /// </summary>
 public static AuthenticationResponse CreateAuthenticatedResponse(
     string authToken,
     string sidToken,
     string lsidToken) {
   AuthenticationResponse authenticationResponse =
       new AuthenticationResponse();
   authenticationResponse.authenticationResult =
       AuthenticationResultKind.Authenticated;
   authenticationResponse.authToken = authToken;
   authenticationResponse.sidToken = sidToken;
   authenticationResponse.lsidToken = lsidToken;
   return authenticationResponse;
 }