Example #1
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxAccountName.Text))
            {
                MessageBox.Show("The account name cannot be empty.");
                return;
            }

            CredentialsEntry myCredentials = new CredentialsEntry(textBoxAccountName.Text, textBoxAccountKey.Text, textBoxBlobKey.Text, textBoxAccountID.Text, textBoxDescription.Text, radioButtonPartner.Checked, radioButtonOther.Checked, textBoxAPIServer.Text, textBoxScope.Text, textBoxACSBaseAddress.Text, textBoxAzureEndpoint.Text, textBoxManagementPortal.Text);

            var entryWithSameName = CredentialList.MediaServicesAccounts.Where(c => c.AccountName.ToLower().Trim() == textBoxAccountName.Text.ToLower().Trim()).FirstOrDefault();

            // if found the same name
            if (entryWithSameName == null)  // not found
            {
                //CredentialList.MediaServicesAccounts[CredentialList.MediaServicesAccounts.IndexOf(entryWithSameName)] = myCredentials;
                var result = MessageBox.Show(string.Format("Do you want to save the credentials for {0} ?", textBoxAccountName.Text), "Save credentials", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes) // ok to save
                {
                    CredentialList.MediaServicesAccounts.Add(myCredentials);
                    Properties.Settings.Default.LoginListJSON = JsonConvert.SerializeObject(CredentialList);
                    Program.SaveAndProtectUserConfig();

                    listBoxAcounts.Items.Add(myCredentials.AccountName);
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            else // found
            {
                if (!myCredentials.Equals(entryWithSameName)) // changed ?
                {
                    var result = MessageBox.Show(string.Format("Do you want to update the credentials for {0} ?", myCredentials.AccountName), "Update credentials", 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;
                    }
                }
            }

            this.DialogResult = DialogResult.OK;  // form will close with OK result
                                                  // else --> form won't close...
        }
        private void listViewAccounts_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoginCredentials = GenerateLoginCredentials;

            buttonDeleteAccountEntry.Enabled = (listViewAccounts.SelectedIndices.Count > 0); // no selected item, so login button not active
            buttonExport.Enabled             = (listViewAccounts.Items.Count > 0);
            if (listViewAccounts.SelectedIndices.Count > 0)                                  // one selected
            {
                if (LoginCredentials != null)
                {
                    var entryWithSameName = CredentialList.MediaServicesAccounts.Where(c => c.ReturnAccountName().ToLower().Trim() == LoginCredentials.ReturnAccountName().ToLower().Trim()).FirstOrDefault();

                    if (entryWithSameName != null && !LoginCredentials.Equals(entryWithSameName))
                    {
                        var result = MessageBox.Show(string.Format(AMSExplorer.Properties.Resources.AMSLogin_buttonLogin_Click_DoYouWantToUpdateTheCredentialsFor0, LoginCredentials.ReturnAccountName()), 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();
                        }
                    }
                }

                var entry = CredentialList.MediaServicesAccounts[listViewAccounts.SelectedIndices[0]];

                radioButtonAADAut.Checked = entry.UseAADInteract || entry.UseAADServicePrincipal;
                radioButtonAADServicePrincipal.Checked = entry.UseAADServicePrincipal;
                radioButtonAADInteractive.Checked      = !radioButtonAADServicePrincipal.Checked;

                if (entry.ADCustomSettings != null)  // custom settings
                {
                    radioButtonAADOther.Checked          = true;
                    comboBoxAADMappingList.SelectedIndex = comboBoxAADMappingList.Items.Count - 1; // last one

                    textBoxAADAMSResource.Text      = entry.ADCustomSettings.MediaServicesResource;
                    textBoxAADClienid.Text          = entry.ADCustomSettings.MediaServicesSdkClientId;
                    textBoxAADRedirect.Text         = entry.ADCustomSettings.MediaServicesSdkRedirectUri.ToString();
                    textBoxAADAzureEndpoint.Text    = entry.ADCustomSettings.ActiveDirectoryEndpoint.ToString();
                    textBoxAADManagementPortal.Text = entry.OtherManagementPortal;
                }
                else if (entry.ADDeploymentName != null)
                {
                    radioButtonAADOther.Checked = true;
                    int index = 0;
                    foreach (var it in comboBoxAADMappingList.Items)
                    {
                        if (((Item)it).Value == entry.ADDeploymentName)
                        {
                            break;
                        }
                        index++;
                    }
                    comboBoxAADMappingList.SelectedIndex = index;
                }
                else
                {
                    radioButtonAADProd.Checked = true;
                }

                textBoxAccountName.Text      = entry.AccountName;
                textBoxAccountKey.Text       = entry.AccountKey;
                textBoxAADtenant.Text        = entry.ADTenantDomain;
                textBoxRestAPIEndpoint.Text  = entry.ADRestAPIEndpoint;
                textBoxBlobKey.Text          = entry.DefaultStorageKey;
                textBoxDescription.Text      = entry.Description;
                radioButtonACSAut.Checked    = !entry.UseAADInteract && !entry.UseAADServicePrincipal;;
                radioButtonAADAut.Checked    = entry.UseAADInteract || entry.UseAADServicePrincipal;
                radioButtonPartner.Checked   = entry.UsePartnerAPI;
                radioButtonOther.Checked     = entry.UseOtherAPI;
                textBoxAPIServer.Text        = entry.OtherAPIServer;
                textBoxScope.Text            = entry.OtherScope;
                textBoxACSBaseAddress.Text   = entry.OtherACSBaseAddress;
                textBoxAzureEndpoint.Text    = entry.OtherAzureEndpoint;
                textBoxManagementPortal.Text = entry.OtherManagementPortal;

                // if not partner or other, then defaut
                if (!radioButtonPartner.Checked && !radioButtonOther.Checked)
                {
                    radioButtonProd.Checked = true;
                }

                // to clear or set the error
                CheckTextBox((object)textBoxAccountName);
                CheckTextBox((object)textBoxAccountKey);
                CheckTextBox((object)textBoxAADtenant);
                CheckTextBox((object)textBoxRestAPIEndpoint);

                UpdateTexboxUI();
            }
        }
        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...
        }
Example #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...
        }