private async void HandleTabSelecting(object sender, TabControlCancelEventArgs e)
        {
            LogMethodEntry();
            if (e.TabPage == null)
            {
                return;
            }

            if (e.Action == TabControlAction.Selecting && e.TabPage.Text == "+")
            {
                var deploy = new DeployControl(this, TabCounter.ToString());
                deploy.Dock    = DockStyle.Fill;
                e.TabPage.Text = "#" + TabCounter++;
                e.TabPage.Controls.Add(deploy);
                if (IsAuthenticated)
                {
                    await deploy.UpdateSubscriptions(lblLoggedInUser.Text);
                }

                tabControl1.TabPages.Add(new TabPage("+"));
            }
            if (e.TabPage.Tag != null)
            {
                e.TabPage.Tag = null;
                tabControl1.Invalidate();
            }
        }
 private void HandleMainformShown(object sender, EventArgs e)
 {
     LogMethodEntry();
     AppVersion.CheckForUpdateAsync();
     tabControl1.TabPages.Clear();
     var deploy = new DeployControl(this, TabCounter.ToString());
     deploy.Dock = DockStyle.Fill;
     var page = new TabPage("#" + TabCounter++);
     page.Controls.Add(deploy);
     tabControl1.TabPages.Add(page);
     tabControl1.TabPages.Add(new TabPage("+"));
     UpdatePresetsMRU();
     HandleAuthenticateClicked(this, EventArgs.Empty);
 }
        private async void RestorePresetFromFile(string filepath)
        {
            LogMethodEntry();
            DeployControlState[] states = new DeployControlState[0];
            try
            {
                string statesJson = File.ReadAllText(filepath);
                states = JsonConvert.DeserializeObject <DeployControlState[]>(statesJson);
                UpdatePresetsMRU(filepath);
                if (states == null || states.Length == 0)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to restore state: " + ex.Message);
                return;
            }

            tabControl1.Visible = false;
            tabControl1.SuspendDraw();
            try
            {
                TabCounter = 1;
                tabControl1.TabPages.Clear();
                foreach (var state in states)
                {
                    var deploy = new DeployControl(this, TabCounter.ToString());
                    deploy.Dock = DockStyle.Fill;
                    var page = new TabPage("#" + TabCounter++);
                    page.Controls.Add(deploy);
                    if (IsAuthenticated)
                    {
                        await deploy.UpdateSubscriptions(lblLoggedInUser.Text);
                    }
                    await deploy.RestoreState(state);

                    tabControl1.TabPages.Add(page);
                }
                tabControl1.TabPages.Add(new TabPage("+"));
            }
            finally
            {
                tabControl1.ResumeDraw();
                tabControl1.Visible = true;
            }
        }
        private void HandleMainformShown(object sender, EventArgs e)
        {
            LogMethodEntry();
            AppVersion.CheckForUpdateAsync();
            tabControl1.TabPages.Clear();
            var deploy = new DeployControl(this, TabCounter.ToString());

            deploy.Dock = DockStyle.Fill;
            var page = new TabPage("#" + TabCounter++);

            page.Controls.Add(deploy);
            tabControl1.TabPages.Add(page);
            tabControl1.TabPages.Add(new TabPage("+"));
            UpdatePresetsMRU();
            HandleAuthenticateClicked(this, EventArgs.Empty);
        }
        private async void RestorePresetFromFile(string filepath)
        {
            LogMethodEntry();
            DeployControlState[] states = new DeployControlState[0];
            try
            {
                string statesJson = File.ReadAllText(filepath);
                states = JsonConvert.DeserializeObject<DeployControlState[]>(statesJson);
                UpdatePresetsMRU(filepath);
                if (states == null || states.Length == 0)
                    return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to restore state: " + ex.Message);
                return;
            }

            tabControl1.Visible = false;
            tabControl1.SuspendDraw();
            try
            {
                TabCounter = 1;
                tabControl1.TabPages.Clear();
                foreach (var state in states)
                {
                    var deploy = new DeployControl(this, TabCounter.ToString());
                    deploy.Dock = DockStyle.Fill;
                    var page = new TabPage("#" + TabCounter++);
                    page.Controls.Add(deploy);
                    if (IsAuthenticated)
                        await deploy.UpdateSubscriptions(lblLoggedInUser.Text);
                    await deploy.RestoreState(state);
                    tabControl1.TabPages.Add(page);
                }
                tabControl1.TabPages.Add(new TabPage("+"));
            }
            finally
            {
                tabControl1.ResumeDraw();
                tabControl1.Visible = true;
            }
        }
        private async void HandleTabSelecting(object sender, TabControlCancelEventArgs e)
        {
            LogMethodEntry();
            if (e.TabPage == null)
                return;

            if (e.Action == TabControlAction.Selecting && e.TabPage.Text == "+")
            {
                var deploy = new DeployControl(this, TabCounter.ToString());
                deploy.Dock = DockStyle.Fill;
                e.TabPage.Text = "#" + TabCounter++;
                e.TabPage.Controls.Add(deploy);
                if (IsAuthenticated)
                    await deploy.UpdateSubscriptions(lblLoggedInUser.Text);

                tabControl1.TabPages.Add(new TabPage("+"));
            }
            if (e.TabPage.Tag != null)
            {
                e.TabPage.Tag = null;
                tabControl1.Invalidate();
            }
        }