예제 #1
0
        public void Connect()
        {
            if (IsConnected)
            {
                _client.AddWarningLog("Connect: already connected");
                return;
            }

            do
            {
                if (!_client.VerificationCode.IsEmpty() && _reqToken != null)
                {
                    try
                    {
                        _client.AddDebugLog("getting access token with code {0}", _client.VerificationCode);
                        AccessToken = Api.GetAccessToken(_reqToken, _client.VerificationCode);
                        SetConnectionState(true);
                        return;
                    }
                    catch (ETradeException)
                    {
                        _client.VerificationCode = null;
                        throw;
                    }
                }

                if (AccessToken != null)
                {
                    try
                    {
                        AccessToken = Api.RenewAccessToken(AccessToken);
                        _client.AddDebugLog("renew of access token successful");
                        SetConnectionState(true);
                        return;
                    }
                    catch (Exception e)
                    {
                        _client.AddWarningLog("unable to renew access token: {0}", e);
                        AccessToken = null;
                    }
                }

                _client.AddDebugLog("getting request token");
                _reqToken = Api.GetRequestToken();

                _client.VerificationCode = null;

                _client.AddDebugLog("starting authorization");
                AuthorizationAction(Api.GetAuthorizeUrl(_reqToken));
            }while (!_client.VerificationCode.IsEmpty());
        }
예제 #2
0
        public ETradeResponse ExecuteNextPart(ETradeClient client)
        {
            IsDone = false;
            var response = ExecuteNextPartInternal(client.Api);

            IsDone = GetIsDone() || response.Exception != null;

            if (response.Exception != null)
            {
                client.AddWarningLog("Request '{0}' completed with exception: {1}", GetType().Name, response.Exception);
            }

            return(response);
        }