private void addToListButton_Click(object sender, EventArgs e)
 {
     try
     {
         _webSites.ChangeWebSiteList("toRebuild", _webSites.Current);
         statusLabel.Text = @"The domain " + _webSites.Current.DomainName + @" was added to the rebuild list!";
     }
     catch (Exception) { statusLabel.Text = @"The domain " + _webSites.Current.DomainName + @" was not added to the rebuild list!"; }
 }
        private async void rebuildButton_Click(object sender, EventArgs e)
        {
            var btn = sender as Button;

            if (btn == null)
            {
                return;
            }
            if (btn.Text.Equals("Cancel"))
            {
                _cancellationTokenSource.Cancel();
                rebuildButton.Text = @"ReBuild!";
                statusLabel.Text   = @"ReBuild was canceled!";
            }
            else
            {
                _cancellationTokenSource.Dispose();
                _cancellationTokenSource = new CancellationTokenSource();
                rebuildButton.Text       = @"Cancel";

                var count = _webSites.Lists.ContainsKey("toRebuild") ? _webSites.Lists["toRebuild"].Count : 0;
                statusLabel.Text = @"ReBuild " + count + (count == 1 ? @" domain." : @" domains.");

                await _webSites.RebuildList(_progressIndicator, _cancellationTokenSource.Token, _webSites.AsrSettings.OverwriteMode);

                if (_cancellationTokenSource.Token.IsCancellationRequested)
                {
                    _isRebuildFinished = false;
                    rebuildButton.Text = @"ReBuild!";
                    statusLabel.Text   = @"ReBuild was canceled!";
                    return;
                }

                try
                {
                    await Task.Run(() =>
                    {
                        for (var i = count - 1; i >= 0; i--)
                        {
                            _webSites.ChangeWebSiteList("rebuilt", _webSites.Lists["toRebuild"][i]);
                        }
                    });
                }
                catch (Exception) { }

                previewButton.Enabled        = true;
                previewBrowserButton.Enabled = true;
                _isRebuildFinished           = true;
                rebuildButton.Text           = @"ReBuild!";
                statusLabel.Text             = count + (count == 1 ? @" domain was " : @" domains were ") + @"rebuilt.";
            }
        }