BattlelogMobile.Client.ViewModel.MainViewModel.LogIn C# (CSharp) Method

LogIn() private method

private LogIn ( SupportedGame game ) : void
game SupportedGame
return void
        private async void LogIn(SupportedGame game)
        {
            UserInterfaceEnabled = false;
            StatusInformation = Common.StatusInformationVerifyingCredential;
            SaveCredentials();

            Uri requestUri = game == SupportedGame.Battlefield3 ? ViewModelLocator.Bf3LogInUri : ViewModelLocator.Bf4LogInUri;
            Uri responseUri = game == SupportedGame.Battlefield3 ? ViewModelLocator.Bf3LogInResponseUri : ViewModelLocator.Bf4LogInResponseUri;

            var request = WebRequest.Create(requestUri) as HttpWebRequest;
            if (request == null)
                throw new ArgumentNullException();

            request.Credentials = new NetworkCredential(Email, Password);
            request.Method = Common.HttpPostMethod;
            request.Accept = Common.HttpAccept;
            request.UserAgent = Common.HttpUserAgent;
            request.ContentType = Common.HttpContentType;
            request.CookieContainer = ViewModelLocator.CookieJar;

            _timedOut = false;
            var dispatchTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(Common.TimeOutInSeconds) };
            dispatchTimer.Tick += TimerTicked;
            dispatchTimer.Start();

            var streamTask = request.GetRequestStreamAsync();

            var requestStream = await streamTask.ConfigureAwait(false);
            using (var writer = new StreamWriter(requestStream))
            {
                await writer.WriteAsync(ConstructPostData(Email, Password, Game)).ConfigureAwait(false);
                writer.Close();
            }

            if (_timedOut)
            {
                ResetControls();
                DispatcherHelper.CheckBeginInvokeOnUI(() => LogInFailedReason = Common.LogInFailedReasonTimedOut);
                return;
            }

            // Got response
            var responseTask = request.GetResponseAsync();
            try
            {
                var response = await responseTask.ConfigureAwait(false);
                if (response.ResponseUri.Equals(responseUri))
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                        {
                            ViewModelLocator.Soldier.Game = game;
                            ViewModelLocator.Soldier.UpdateData(false);
                        });
                }
                else
                {
                    ResetControls();
                    DispatcherHelper.CheckBeginInvokeOnUI(() => LogInFailedReason = Common.LogInFailedReasonInvalidCredentials);
                }
            }
            catch (WebException we)
            {
                ResetControls();
                DispatcherHelper.CheckBeginInvokeOnUI(() => LogInFailedReason = we.Message);
            }
        }