public async Task RestoreState(DeployControlState state) { LogMethodEntry(); cbSubscriptions.SelectedItem = cbSubscriptions.Items.OfType <SubscriptionListOperationResponse.Subscription>().Where(s => s.SubscriptionName == state.SubscriptionName).FirstOrDefault(); if (cbSubscriptions.SelectedItem == null) { Logger.Warn("[" + _id + "] " + "Cannot restore state as the subscription cannot be selected. Are you logged in with the correct user?"); } await HandleSubscriptionIndexChangedAsync(this, EventArgs.Empty); cbCloudservices.SelectedItem = cbCloudservices.Items.OfType <HostedServiceListResponse.HostedService>().Where(s => s.ServiceName == state.CloudServiceName).FirstOrDefault(); cbPackageStorage.SelectedItem = cbPackageStorage.Items.OfType <StorageAccount>().Where(s => s.Name == state.PackageStorageAccountName).FirstOrDefault(); cbSlot.SelectedItem = cbSlot.Items.OfType <DeploymentSlot>().Where(s => s.ToString() == state.DeploymentSlot).FirstOrDefault(); cbUpgradePreference.SelectedItem = cbUpgradePreference.Items.OfType <KeyValuePair <UpgradePreference, string> >().Where(s => s.Key.ToString() == state.DeploymentType).FirstOrDefault(); HandleDeploymentTypeChanged(this, EventArgs.Empty); cbDiagStorage.SelectedItem = cbDiagStorage.Items.OfType <StorageAccount>().Where(s => s.Name == state.DiagStorageAccountName).FirstOrDefault(); if (cbDiagStorage.SelectedItem == null && cbDiagStorage.Items.Count > 0) { cbDiagStorage.SelectedItem = cbDiagStorage.Items[0]; } cbForceUpgrade.Checked = state.ForceUpgrade; tbLabel.Text = state.Label; UpdateSelectedFiles(state.CloudPackage, state.CloudConfig, state.DiagConfig); lblLabelPreview.Text = GetRenderedLabel(); }
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; } }
public async Task RestoreState(DeployControlState state) { LogMethodEntry(); cbSubscriptions.SelectedItem = cbSubscriptions.Items.OfType<SubscriptionListOperationResponse.Subscription>().Where(s => s.SubscriptionName == state.SubscriptionName).FirstOrDefault(); if (cbSubscriptions.SelectedItem == null) Logger.Warn("[" + _id + "] " + "Cannot restore state as the subscription cannot be selected. Are you logged in with the correct user?"); await HandleSubscriptionIndexChangedAsync(this, EventArgs.Empty); cbCloudservices.SelectedItem = cbCloudservices.Items.OfType<HostedServiceListResponse.HostedService>().Where(s => s.ServiceName == state.CloudServiceName).FirstOrDefault(); cbPackageStorage.SelectedItem = cbPackageStorage.Items.OfType<StorageAccount>().Where(s => s.Name == state.PackageStorageAccountName).FirstOrDefault(); cbSlot.SelectedItem = cbSlot.Items.OfType<DeploymentSlot>().Where(s => s.ToString() == state.DeploymentSlot).FirstOrDefault(); cbUpgradePreference.SelectedItem = cbUpgradePreference.Items.OfType<KeyValuePair<UpgradePreference, string>>().Where(s => s.Key.ToString() == state.DeploymentType).FirstOrDefault(); HandleDeploymentTypeChanged(this, EventArgs.Empty); cbDiagStorage.SelectedItem = cbDiagStorage.Items.OfType<StorageAccount>().Where(s => s.Name == state.DiagStorageAccountName).FirstOrDefault(); if (cbDiagStorage.SelectedItem == null && cbDiagStorage.Items.Count > 0) cbDiagStorage.SelectedItem = cbDiagStorage.Items[0]; cbForceUpgrade.Checked = state.ForceUpgrade; tbLabel.Text = state.Label; UpdateSelectedFiles(state.CloudPackage, state.CloudConfig, state.DiagConfig); lblLabelPreview.Text = GetRenderedLabel(); }
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; } }