private void listBoxAcounts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxAccounts.SelectedIndex > -1) // one selected
            {
                int index = listBoxAccounts.SelectedIndex;
                SelectedCredentials = _listMediaAccounts[index];

                if (Mode == CopyAssetBoxMode.CopyAsset)
                {
                    labelWarning.Text = (string.IsNullOrEmpty(SelectedCredentials.DefaultStorageKey)) ? AMSExplorer.Properties.Resources.CopyAsset_listBoxAcounts_SelectedIndexChanged_StorageKeyIsEmpty : string.Empty;
                }
                radioButtonDefaultStorage.Checked = true;
                listBoxStorage.Items.Clear();

                if (SelectedCredentials.UseAADServicePrincipal) // not supported for now
                {                                               /*
                                                                 * labelWarningStorage.Text = AMSExplorer.Properties.Resources.CopyAsset_listBoxAcounts_SelectedIndexChanged_ErrorWhenConnectingToAccount;
                                                                 * ErrorConnectingAMS = true;
                                                                 * return;
                                                                 */
                    var spcrendentialsform = new AMSLoginServicePrincipal();
                    if (spcrendentialsform.ShowDialog() == DialogResult.OK)
                    {
                        SelectedCredentials.ADSPClientId     = spcrendentialsform.ClientId;
                        SelectedCredentials.ADSPClientSecret = spcrendentialsform.ClientSecret;
                    }
                    else
                    {
                        labelWarningStorage.Text = AMSExplorer.Properties.Resources.CopyAsset_listBoxAcounts_SelectedIndexChanged_ErrorWhenConnectingToAccount;
                        ErrorConnectingAMS       = true;
                        return;
                    }
                }

                // let's check connection to account
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    CloudMediaContext newcontext = Program.ConnectAndGetNewContext(SelectedCredentials, true, false);
                    foreach (var storage in newcontext.StorageAccounts)
                    {
                        listBoxStorage.Items.Add(new Item(storage.Name + ((storage.Name == newcontext.DefaultStorageAccount.Name) ? AMSExplorer.Properties.Resources.CopyAsset_listBoxAcounts_SelectedIndexChanged_Default : string.Empty), storage.Name));
                    }
                    labelWarningStorage.Text = "";
                    ErrorConnectingAMS       = false;
                }
                catch
                {
                    labelWarningStorage.Text = AMSExplorer.Properties.Resources.CopyAsset_listBoxAcounts_SelectedIndexChanged_ErrorWhenConnectingToAccount;
                    ErrorConnectingAMS       = true;
                }
                finally
                {
                    this.Cursor = Cursors.Arrow;
                }
                UpdateStatusButtonOk();
            }
        }
示例#2
0
        private async Task <MediaServicesManagementClient> GetMediaClient()
        {
            ServiceClientCredentials serviceCreds;

            if (_credentials.UseAADServicePrincipal)
            {
                serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(_credentials.ADTenantDomain, _credentials.ADSPClientId, _credentials.ADSPClientSecret, _credentials.ReturnADSettings());
            }
            else
            {
                var formSP = new AMSLoginServicePrincipal();
                if (formSP.ShowDialog() == DialogResult.OK)
                {
                    serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(_credentials.ADTenantDomain, formSP.ClientId, formSP.ClientSecret, _credentials.ReturnADSettings());
                }
                else
                {
                    return(null);
                }
            }

            return(new MediaServicesManagementClient(serviceCreds));
        }
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            LoginCredentials = GenerateLoginCredentials;

            if (string.IsNullOrEmpty(LoginCredentials.ReturnAccountName()))
            {
                MessageBox.Show(string.Format("The {0} cannot be empty.", labelE1.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            var accName = LoginCredentials.ReturnAccountName();

            var entryWithSameName = CredentialList.MediaServicesAccounts.Where(c => c.ReturnAccountName().ToLower().Trim() == accName.ToLower().Trim()).FirstOrDefault();

            // if found the same name
            if (entryWithSameName == null)  // not found
            {
                var result = MessageBox.Show(string.Format(AMSExplorer.Properties.Resources.AMSLogin_buttonLogin_Click_DoYouWantToSaveTheCredentialsFor0, accName), AMSExplorer.Properties.Resources.AMSLogin_buttonLogin_Click_SaveCredentials, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes) // ok to save
                {
                    CredentialList.MediaServicesAccounts.Add(LoginCredentials);
                    Properties.Settings.Default.LoginListJSON = JsonConvert.SerializeObject(CredentialList);
                    Program.SaveAndProtectUserConfig();

                    AddItemToListviewAccounts(LoginCredentials);
                    //listViewAccounts.Items.Add(ReturnAccountName(LoginCredentials));
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            else // found
            {
                if (!LoginCredentials.Equals(entryWithSameName)) // changed ?
                {
                    var result = MessageBox.Show(string.Format(AMSExplorer.Properties.Resources.AMSLogin_buttonLogin_Click_DoYouWantToUpdateTheCredentialsFor0, accName), AMSExplorer.Properties.Resources.AMSLogin_listBoxAccounts_SelectedIndexChanged_UpdateCredentials, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes) // ok to update the credentials
                    {
                        CredentialList.MediaServicesAccounts[CredentialList.MediaServicesAccounts.IndexOf(entryWithSameName)] = LoginCredentials;
                        Properties.Settings.Default.LoginListJSON = JsonConvert.SerializeObject(CredentialList);
                        Program.SaveAndProtectUserConfig();
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }

            if (LoginCredentials.UseAADServicePrincipal)  // service principal mode
            {
                var spcrendentialsform = new AMSLoginServicePrincipal();
                if (spcrendentialsform.ShowDialog() == DialogResult.OK)
                {
                    LoginCredentials.ADSPClientId     = spcrendentialsform.ClientId;
                    LoginCredentials.ADSPClientSecret = spcrendentialsform.ClientSecret;
                }
                else
                {
                    return;
                }
            }

            // OLD ACS Mode - let's warm the user
            if (!LoginCredentials.UseAADServicePrincipal && !LoginCredentials.UseAADInteract)
            {
                var f = new DisplayBox("Warning", AMSExplorer.Properties.Resources.AMSLogin_buttonLogin_Click_ACSAuthenticationWarning, 10);
                f.ShowDialog();
            }

            // Context creation
            this.Cursor = Cursors.WaitCursor;

            context = Program.ConnectAndGetNewContext(LoginCredentials, false, true);

            accName = LoginCredentials.ReturnAccountName();

            try
            {
                var a = context.Assets.FirstOrDefault();
                this.Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBox.Show(Program.GetErrorMessage(ex), "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Cursor = Cursors.Default;
                return;
            }

            accountName       = accName;
            this.DialogResult = DialogResult.OK;  // form will close with OK result
                                                  // else --> form won't close...
        }
示例#4
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            LoginCredentials = GenerateLoginCredentials;

            if (string.IsNullOrEmpty(ReturnAccountName(LoginCredentials)))
            {
                MessageBox.Show("The account name cannot be empty.");
                return;
            }

            /*
             * CredentialsEntry myCredentials = new CredentialsEntry(
             *  textBoxAccountName.Text,
             *  textBoxAccountKey.Text,
             *  textBoxADTenantDomain.Text,
             * textBoxADRestAPIEndpoint.Text,
             * textBoxBlobKey.Text,
             * textBoxDescription.Text,
             * radioButtonAADInteract.Checked,
             * radioButtonPartner.Checked,
             * radioButtonOther.Checked,
             * textBoxAPIServer.Text,
             * textBoxScope.Text,
             * textBoxACSBaseAddress.Text,
             * textBoxAzureEndpoint.Text,
             * textBoxManagementPortal.Text
             *  );
             */

            var accName = ReturnAccountName(LoginCredentials);

            var entryWithSameName = CredentialList.MediaServicesAccounts.Where(c => ReturnAccountName(c).ToLower().Trim() == accName.ToLower().Trim()).FirstOrDefault();

            // if found the same name
            if (entryWithSameName == null)  // not found
            {
                var result = MessageBox.Show(string.Format(AMSExplorer.Properties.Resources.AMSLogin_buttonLogin_Click_DoYouWantToSaveTheCredentialsFor0, accName), AMSExplorer.Properties.Resources.AMSLogin_buttonLogin_Click_SaveCredentials, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes) // ok to save
                {
                    CredentialList.MediaServicesAccounts.Add(LoginCredentials);
                    Properties.Settings.Default.LoginListJSON = JsonConvert.SerializeObject(CredentialList);
                    Program.SaveAndProtectUserConfig();

                    listBoxAcounts.Items.Add(ReturnAccountName(LoginCredentials));
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            else // found
            {
                if (!LoginCredentials.Equals(entryWithSameName)) // changed ?
                {
                    var result = MessageBox.Show(string.Format(AMSExplorer.Properties.Resources.AMSLogin_buttonLogin_Click_DoYouWantToUpdateTheCredentialsFor0, accName), AMSExplorer.Properties.Resources.AMSLogin_listBoxAccounts_SelectedIndexChanged_UpdateCredentials, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes) // ok to update the credentials
                    {
                        CredentialList.MediaServicesAccounts[CredentialList.MediaServicesAccounts.IndexOf(entryWithSameName)] = LoginCredentials;
                        Properties.Settings.Default.LoginListJSON = JsonConvert.SerializeObject(CredentialList);
                        Program.SaveAndProtectUserConfig();
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }

            if (LoginCredentials.UseAADServicePrincipal)  // service principal mode
            {
                var spcrendentialsform = new AMSLoginServicePrincipal();
                if (spcrendentialsform.ShowDialog() == DialogResult.OK)
                {
                    LoginCredentials.ADSPClientId     = spcrendentialsform.ClientId;
                    LoginCredentials.ADSPClientSecret = spcrendentialsform.ClientSecret;
                }
                else
                {
                    return;
                }
            }

            // Context creation
            this.Cursor = Cursors.WaitCursor;

            context = Program.ConnectAndGetNewContext(LoginCredentials, false, true);

            accName = ReturnAccountName(LoginCredentials);

            try
            {
                var a = context.Assets.FirstOrDefault();
                this.Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBox.Show(Program.GetErrorMessage(ex), "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Cursor = Cursors.Default;
                return;
            }

            accountName       = accName;
            this.DialogResult = DialogResult.OK;  // form will close with OK result
                                                  // else --> form won't close...
        }