Beispiel #1
0
        /// <summary>
        ///		Asynchronously log into the CaaS API.
        /// </summary>
        /// <param name="accountCredentials">
        ///		The CaaS account credentials used to authenticate against the CaaS API.
        /// </param>
        /// <returns>
        ///		An <see cref="IAccount"/> implementation representing the CaaS account that the client is logged into.
        /// </returns>
        public async Task <IAccount> LoginAsync(ICredentials accountCredentials)
        {
            if (accountCredentials == null)
            {
                throw new ArgumentNullException("accountCredentials");
            }

            CheckDisposed();

            if (IsLoggedIn)
            {
                throw ComputeApiClientException.AlreadyLoggedIn();
            }

            _clientMessageHandler.Credentials     = accountCredentials;
            _clientMessageHandler.PreAuthenticate = true;

            try
            {
                Account = await ApiGetAsync <Account>(ApiUris.MyAccount);
            }
            catch (HttpRequestException eRequestFailure)
            {
                Debug.WriteLine(eRequestFailure.GetBaseException(), "BASE EXCEPTION");

                throw;
            }

            return(Account);
        }
Beispiel #2
0
        /// <summary>
        ///		Log out of the CaaS API.
        /// </summary>
        public void Logout()
        {
            CheckDisposed();

            if (!IsLoggedIn)
            {
                throw ComputeApiClientException.NotLoggedIn();
            }

            _account = null;
            _clientMessageHandler.Credentials     = null;
            _clientMessageHandler.PreAuthenticate = false;
        }