private async void ButtonLogin_Click(object sender, EventArgs e) { if (listViewAccounts.SelectedIndices.Count != 1) { return; } // code when used from pick-up LoginInfo = CredentialList.MediaServicesAccounts[listViewAccounts.SelectedIndices[0]]; if (LoginInfo == null) { MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //MessageBox.Show(string.Format("The {0} cannot be empty.", labelE1.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } AmsClient = new AMSClientV3(LoginInfo.Environment, LoginInfo.AzureSubscriptionId, LoginInfo); AzureMediaServicesClient response = null; try { response = await AmsClient.ConnectAndGetNewClientV3Async(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (response == null) { return; } // let's save the credentials (SP) They may be updated by the user when connecting CredentialList.MediaServicesAccounts[listViewAccounts.SelectedIndices[0]] = AmsClient.credentialsEntry; SaveCredentialsToSettings(); try { // let's refresh storage accounts AmsClient.credentialsEntry.MediaService.StorageAccounts = (await AmsClient.AMSclient.Mediaservices.GetAsync(AmsClient.credentialsEntry.ResourceGroup, AmsClient.credentialsEntry.AccountName)).StorageAccounts; Cursor = Cursors.Default; } catch (Exception ex) { MessageBox.Show(Program.GetErrorMessage(ex), "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; return; } DialogResult = DialogResult.OK; // form will close with OK result // else --> form won't close... }
private async void listViewAccounts_SelectedIndexChanged(object sender, EventArgs e) { ErrorConnectingAMS = false; ErrorConnectingStorage = false; listBoxStorage.Items.Clear(); if (listViewAccounts.SelectedIndices.Count != 1) { return; } // code when used from pick-up DestinationLoginInfo = CredentialList.MediaServicesAccounts[listViewAccounts.SelectedIndices[0]]; if (DestinationLoginInfo == null) { MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //MessageBox.Show(string.Format("The {0} cannot be empty.", labelE1.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } this.Cursor = Cursors.WaitCursor; DestinationAmsClient = new AMSClientV3(DestinationLoginInfo.Environment, DestinationLoginInfo.AzureSubscriptionId, DestinationLoginInfo); AzureMediaServicesClient response = null; try { response = await DestinationAmsClient.ConnectAndGetNewClientV3Async(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; ErrorConnectingAMS = true; return; } if (response == null) { Cursor = Cursors.Default; ErrorConnectingAMS = true; return; } // let's save the credentials (SP) They may be updated by the user when connecting CredentialList.MediaServicesAccounts[listViewAccounts.SelectedIndices[0]] = DestinationAmsClient.credentialsEntry; //SaveCredentialsToSettings(); try { // let's refresh storage accounts DestinationAmsClient.credentialsEntry.MediaService.StorageAccounts = (await DestinationAmsClient.AMSclient.Mediaservices.GetAsync(DestinationAmsClient.credentialsEntry.ResourceGroup, DestinationAmsClient.credentialsEntry.AccountName)).StorageAccounts; foreach (var storage in DestinationAmsClient.credentialsEntry.MediaService.StorageAccounts) { string storageName = AMSClientV3.GetStorageName(storage.Id); int index = listBoxStorage.Items.Add(new Item(storageName + ((storage.Type == StorageAccountType.Primary) ? AMSExplorer.Properties.Resources.CopyAsset_listBoxAcounts_SelectedIndexChanged_Default : string.Empty), storageName)); if (storage.Type == StorageAccountType.Primary) { listBoxStorage.SelectedIndex = index; } } Cursor = Cursors.Default; } catch (Exception ex) { MessageBox.Show(Program.GetErrorMessage(ex), "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; ErrorConnectingAMS = true; return; } // DialogResult = DialogResult.OK; // form will close with OK result // else --> form won't close... UpdateStatusButtonOk(); }