/// <summary> /// Executes the <see cref="SfRequest" /> asynchronously. /// </summary> /// <param name="source">The addressed request source, which should be an instance of type <see cref="SnFRequestSource" /> in usual cases.</param> /// <param name="sessionId">A valid session ID, with the length of 32. <see cref="Session.EmptySessionId" /> is used for logging in.</param> /// <param name="action">The action which shall be executed. See <see cref="SF" /> which start with "Act".</param> /// <param name="args">Additional arguments like e.g. the search string for searches or the user credentials for logging in.</param> /// <returns>A <see cref="SfResponse" /> containing the result information.</returns> /// <exception cref="ArgumentNullException">When source or sessionId is null.</exception> /// <exception cref="ArgumentException">When sessionId has not a length of 32.</exception> public async Task<ISfResponse> ExecuteAsync(IRequestSource source, string sessionId, SF action, IEnumerable<string> args = null) { if (source == null) throw new ArgumentNullException("source"); if (sessionId == null) throw new ArgumentNullException("sessionId"); if (sessionId.Length != 32) throw new ArgumentException("sessionId must have a length of 32.", "sessionId"); var id = Guid.NewGuid(); Log.Info("Request started: ID = {0}", id); var response = await source.RequestAsync(sessionId, action, args); Log.Info("Request finished: ID = {0}", id); return response; }
public static PaymentRequest <IRequestSource> CreateAlternativePaymentMethodRequest(IRequestSource alternativePaymentMethodRequestSource, string currency, long?amount = 100) { return(new PaymentRequest <IRequestSource>( alternativePaymentMethodRequestSource, currency, amount ) { Capture = false, Customer = new Checkout.Payments.CustomerRequest() { Email = TestHelper.GenerateRandomEmail() }, Reference = Guid.NewGuid().ToString() }); }
/// <summary> /// Logs the current session in. /// </summary> /// <param name="username">The username.</param> /// <param name="md5PasswordHash">The MD5 hash of the password.</param> /// <param name="serverUri">The <see cref="Uri"/> of the server to be logged on.</param> /// <returns>The success of the login process as <see cref="bool"/>.</returns> /// <exception cref="ArgumentException">When username or password hash have invalid formats.</exception> /// <exception cref="ArgumentNullException">When serverUri is null.</exception> public async Task<bool> LoginAsync(string username, string md5PasswordHash, Uri serverUri) { if (string.IsNullOrWhiteSpace(username)) throw new ArgumentException("Username must not be null or empty.", "username"); if (md5PasswordHash == null || md5PasswordHash.Length != 32) throw new ArgumentException("Password hash must not be null and have a length of 32.", "md5PasswordHash"); if (serverUri == null) throw new ArgumentNullException("serverUri"); _isLoggedIn = false; _username = username; _md5PasswordHash = md5PasswordHash; ServerUri = serverUri; _source = _sourceFactory(ServerUri); var result = await new SfRequest().ExecuteAsync(_source, EmptySessionId, SF.ActLogin, new[] { _username, _md5PasswordHash, "v1.70&random=%2" }); var hasErrors = HasErrors(result.Errors); var response = result.Response as LoginResponse; if (response == null || hasErrors) return _isLoggedIn; _sessionId = response.SessionId; Mushrooms = response.Mushrooms; Gold = response.Gold; Silver = response.Silver; _isLoggedIn = true; return _isLoggedIn; }