/// <summary> Initializes a new instance of the <see cref="ReplayMonitorControl"/> class. </summary>
        /// <param name="api"> The api instance. </param>
        public ReplayMonitorControl(SettingsFile settings, TwitchApiV2 api)
            : this()
        {
            this.twitchApi = api;
            this.twitchApi.CommercialPlayed += this.TwitchApiCommercialPlayed;

            this.settings = settings;

            this.replayCountTimer.AutoReset = false;
            this.replayCountTimer.Elapsed += this.replayCountTimer_Elapsed;

            this.updateTimer.AutoReset = true;
            this.updateTimer.Elapsed += this.updateTimer_Elapsed;
            this.updateTimer.Start();

            this.VerifyWhetherSetupIsComplete();
        }
        private void AttemptToLogin()
        {
            var api = new TwitchTV.TwitchApiV2();
            string token = txtUsername.Text;

            try
            {
                if (api.HasUserAuthorized(token))
                {
                    var handler = this.LoginSuccessful;
                    if (handler != null)
                    {
                        handler(this, new LoginEventArgs(token));
                    }
                }
                else
                {
                    MessageBox.Show(
                        "Failed to log in. Your username or password may be incorrect.",
                        "Log in failed.",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
            catch (WebException ex)
            {
                string error = string.Format(
                    "Failed to log in. The request returned the following error:{0}{1}", Environment.NewLine, ex.Message);

                MessageBox.Show(
                    error,
                    "Log in failed.",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
        }