/// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        /// <exception cref="AggregateException"></exception>
        public Task<ApiLogOnResponseDTO> LoginAsync(string username, string password)
        {
            var dto = new ApiLogOnRequestDTO
                {
                    UserName = username,
                    Password = password
                };


            Task<ApiLogOnResponseDTO> getResponseTextTask = Authentication.LogOnAsync(dto);

            Task<ApiLogOnResponseDTO> deserializeTask = getResponseTextTask.ContinueWith(task =>
            {
                switch (task.Status)
                {

                    case TaskStatus.Faulted:
                        throw task.Exception;
                    default:

                        SessionId = task.Result.Session;
                        Username = username;
                        return task.Result;
                }
            });

            Task<ApiLogOnResponseDTO> accountInfoTask = deserializeTask.ContinueWith(task =>
                {
                    var t = AccountInformation.GetClientAndTradingAccountAsync();
                    t.Wait();
                    CurrentAccountInformation = t.Result;
                    return task.Result;
                });

            return accountInfoTask.ContinueWith(task => task.Result);
        }
Example #2
0
        // ***********************************
        // LogOn
        // ***********************************


        /// <summary>
        /// Create a new session. This is how you "log on" to the CIAPI.
        /// </summary>
        /// <param name="apiLogOnRequest">The request to create a session *(log on)*.</param>
        internal virtual Task<ApiLogOnResponseDTO> LogOnAsync(ApiLogOnRequestDTO apiLogOnRequest)
        {
            var entry = new Entry
            {
                Request = new Request
                {
                    Method = "POST",
                    Url = _client.ApiBaseUrl + "/session/",
                    PostData = new PostData{
                       MimeType = "application/json",
                       Params = new Parameters(new NameValuePair("", apiLogOnRequest))
                    }
                }
            };


            Task<Entry> getResponseTextTask = _client.EnqueueRequestAsync(entry);

            Task<ApiLogOnResponseDTO> deserializeTask =
                getResponseTextTask.ContinueWith(task =>
                {
                    var data =
                        JsonConvert.DeserializeObject<ApiLogOnResponseDTO>(task.Result.Response.Content.Text);
                    return data;
                });

            return deserializeTask.ContinueWith(task => task.Result);
        }