Ejemplo n.º 1
0
        private void CopyAsset_Load(object sender, EventArgs e)
        {
            labelWarning.Text        = "";
            labelWarningStorage.Text = "";

            CredentialList = (ListCredentials)JsonConvert.DeserializeObject(Properties.Settings.Default.LoginListJSON, typeof(ListCredentials));
            CredentialList.MediaServicesAccounts.ForEach(c => listBoxAccounts.Items.Add(c.AccountName));

            var entryWithSameName = CredentialList.MediaServicesAccounts.Where(c => c.AccountName.ToLower().Trim() == _context.Credentials.ClientId.ToLower().Trim()).FirstOrDefault();

            if (entryWithSameName != null)
            {
                listBoxAccounts.SelectedIndex = CredentialList.MediaServicesAccounts.IndexOf(entryWithSameName);
            }


            /*
             * if (CredentialList != null)
             * {
             *    for (int i = 0; i < (CredentialList.Count / CredentialsEntry.StringsCount); i++)
             *    {
             *        {
             *            int index = listBoxAccounts.Items.Add(CredentialList[i * CredentialsEntry.StringsCount]);
             *            if (CredentialList[i * CredentialsEntry.StringsCount] == _context.Credentials.ClientId)
             *            {
             *                listBoxAccounts.SelectedIndex = index;
             *            }
             *        }
             *    }
             * }
             * listBoxAccounts.SelectedItem = _context.DefaultStorageAccount.Name;
             */
        }
        private void buttonExport_Click(object sender, EventArgs e)
        {
            bool exportAll = true;

            if (CredentialList.MediaServicesAccounts.Count > 1 && listViewAccounts.SelectedIndices.Count > 0) // There are more than one entry and one has been selected. Let's ask if user want to export all or not
            {
                var diag = System.Windows.Forms.MessageBox.Show(AMSExplorer.Properties.Resources.AMSLogin_buttonExport_Click_DoYouWantToExportAllEntriesNNSelectYesToExportAllNoToExportTheSelection, AMSExplorer.Properties.Resources.AMSLogin_buttonExport_Click_ExportAllEntries, System.Windows.Forms.MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                switch (diag)
                {
                case DialogResult.Yes:
                    break;

                case DialogResult.No:
                    exportAll = false;
                    break;

                case DialogResult.Cancel:
                    return;
                }
            }

            DialogResult diares = saveFileDialog1.ShowDialog();

            if (diares == DialogResult.OK)
            {
                try
                {
                    JsonSerializerSettings settings = new JsonSerializerSettings();
                    settings.NullValueHandling = NullValueHandling.Ignore;
                    settings.Formatting        = Newtonsoft.Json.Formatting.Indented;

                    if (exportAll)
                    {
                        System.IO.File.WriteAllText(saveFileDialog1.FileName, JsonConvert.SerializeObject(CredentialList, settings));
                    }
                    else
                    {
                        var copyEntry = new ListCredentials();
                        copyEntry.MediaServicesAccounts.Add(CredentialList.MediaServicesAccounts[listViewAccounts.SelectedIndices[0]]);
                        System.IO.File.WriteAllText(saveFileDialog1.FileName, JsonConvert.SerializeObject(copyEntry, settings));
                    }
                }
                catch (Exception ex)

                {
                    MessageBox.Show(ex.Message, AMSExplorer.Properties.Resources.AMSLogin_buttonExport_Click_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void CopyAsset_Load(object sender, EventArgs e)
        {
            labelWarning.Text        = "";
            labelWarningStorage.Text = "";

            CredentialList = (ListCredentials)JsonConvert.DeserializeObject(Properties.Settings.Default.LoginListJSON, typeof(ListCredentials));
            CredentialList.MediaServicesAccounts.ForEach(c => listBoxAccounts.Items.Add(c.AccountName));

            var entryWithSameName = CredentialList.MediaServicesAccounts.Where(c => c.AccountName.ToLower().Trim() == _context.Credentials.ClientId.ToLower().Trim()).FirstOrDefault();

            if (entryWithSameName != null)
            {
                listBoxAccounts.SelectedIndex = CredentialList.MediaServicesAccounts.IndexOf(entryWithSameName);
            }
        }
        private void CopyAsset_Load(object sender, EventArgs e)
        {
            labelWarning.Text        = "";
            labelWarningStorage.Text = "";

            CredentialList     = (ListCredentials)JsonConvert.DeserializeObject(Properties.Settings.Default.LoginListJSON, typeof(ListCredentials));
            _listMediaAccounts = CredentialList.MediaServicesAccounts.Where(c => c.UseAADInteract || c.UseAADServicePrincipal).ToList();
            _listMediaAccounts.ForEach(c => listBoxAccounts.Items.Add(c.ReturnAccountName()));

            var entryWithSameName = _listMediaAccounts.Where(c => c.ReturnAccountName().ToLower().Trim() == _accountname.ToLower().Trim()).FirstOrDefault();

            if (entryWithSameName != null)
            {
                listBoxAccounts.SelectedIndex = _listMediaAccounts.IndexOf(entryWithSameName);
            }
        }
Ejemplo n.º 5
0
        public IEnumerable <ValidCredentialContract> Process(ListValidateCredentialsRequest input)
        {
            var parameter = new ListCredentials
            {
                Email    = input.Username,
                Password = input.Password
            };

            _query.BuildQuery(parameter);

            using (DapperUnitOfWork.Begin())
            {
                var credentials = _runner.Run(_query);

                return(credentials.Select(CredentialMapper.Map));
            }
        }
        private void AMSLogin_Load(object sender, EventArgs e)
        {
            labelEntry1 = labelE1.Text.Split('|');
            labelEntry2 = labelE2.Text.Split('|');

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.LoginListJSON))
            {
                // JSon deserialize
                CredentialList = (ListCredentials)JsonConvert.DeserializeObject(Properties.Settings.Default.LoginListJSON, typeof(ListCredentials));
                // Display accounts in the list
                CredentialList.MediaServicesAccounts.ForEach(c =>
                                                             AddItemToListviewAccounts(c)
                                                             );
            }
            buttonExport.Enabled = (listViewAccounts.Items.Count > 0);

            accountmgtlink.Links.Add(new LinkLabel.Link(0, accountmgtlink.Text.Length, Constants.LinkAMSCreateAccount));
            linkLabelAADAut.Links.Add(new LinkLabel.Link(0, linkLabelAADAut.Text.Length, Constants.LinkAMSAADAut));

            foreach (var map in CredentialsEntry.ACSMappings)
            {
                comboBoxMappingList.Items.Add(map.Name);
            }
            comboBoxMappingList.SelectedIndex = 0;

            comboBoxAADMappingList.Items.Add(new Item("Azure China", nameof(AzureEnvironments.AzureChinaCloudEnvironment)));
            comboBoxAADMappingList.Items.Add(new Item("Azure Germany", nameof(AzureEnvironments.AzureGermanCloudEnvironment)));
            comboBoxAADMappingList.Items.Add(new Item("Azure US Government", nameof(AzureEnvironments.AzureUsGovernmentEnvironment)));
            comboBoxAADMappingList.Items.Add(new Item(CustomString, CustomString));
            comboBoxAADMappingList.SelectedIndex = 0;

            // version
            labelVersion.Text = String.Format(labelVersion.Text, Assembly.GetExecutingAssembly().GetName().Version);

            UpdateTexboxUI();
            UpdateAADSettingsTextBoxes();
        }
Ejemplo n.º 7
0
        private void AMSLogin_Load(object sender, EventArgs e)
        {
            labelEntry1 = labelE1.Text.Split('|');
            labelEntry2 = labelE2.Text.Split('|');

            var CredentialsList = Properties.Settings.Default.LoginList;

            // let's purge the old list now.
            if (CredentialsList != null && CredentialsList.Count > 0)
            {
                Properties.Settings.Default.LoginList.Clear();
            }

            // OLD MODE. XML properties for account entries
            if (!Properties.Settings.Default.MigratedLoginListToJSON && CredentialsList != null && CredentialsList.Count > 0)
            {
                /*
                 * try
                 * {
                 *  if (CredentialsList != null && CredentialsList.Count > 0)
                 *  {
                 *      for (int i = 0; i < (CredentialsList.Count / CredentialsEntry.StringsCount); i++)
                 *          listBoxAcounts.Items.Add(CredentialsList[i * CredentialsEntry.StringsCount]);
                 *      buttonExport.Enabled = (listBoxAcounts.Items.Count > 0);
                 *  }
                 *  else
                 *  {
                 *      // if null or empty, let's create it
                 *      CredentialsList = new StringCollection();
                 *  }
                 * }
                 * catch // error, let's purge all
                 * {
                 *  MessageBox.Show(AMSExplorer.Properties.Resources.AMSLogin_AMSLogin_Load_ErrorReadingCredentialsSettingsHaveBeenDeleted);
                 *  Properties.Settings.Default.LoginList.Clear();
                 *  Program.SaveAndProtectUserConfig();
                 *  listBoxAcounts.Items.Clear();
                 * }
                 *
                 * // Migration to JSON
                 *
                 * for (int i = 0; i < (CredentialsList.Count / CredentialsEntry.StringsCount); i++)
                 * {
                 *
                 *  CredentialList.MediaServicesAccounts.Add(new CredentialsEntry(
                 *      CredentialsList[i * CredentialsEntry.StringsCount],
                 *      CredentialsList[i * CredentialsEntry.StringsCount + 1],
                 *      CredentialsList[i * CredentialsEntry.StringsCount + 2],
                 *      CredentialsList[i * CredentialsEntry.StringsCount + 3],
                 *      CredentialsList[i * CredentialsEntry.StringsCount + 4] == true.ToString() ? true : false,
                 *      CredentialsList[i * CredentialsEntry.StringsCount + 5] == true.ToString() ? true : false,
                 *      CredentialsList[i * CredentialsEntry.StringsCount + 6],
                 *      CredentialsList[i * CredentialsEntry.StringsCount + 7],
                 *      CredentialsList[i * CredentialsEntry.StringsCount + 8],
                 *      ReturnAzureEndpoint(CredentialsList[i * CredentialsEntry.StringsCount + 9]),
                 *      ReturnManagementPortal(CredentialsList[i * CredentialsEntry.StringsCount + 9])
                 *  ));
                 * }
                 *
                 * var NewCredentialListJSON = JsonConvert.SerializeObject(CredentialList);
                 * Properties.Settings.Default.LoginListJSON = NewCredentialListJSON;
                 * Properties.Settings.Default.MigratedLoginListToJSON = true;
                 * Program.SaveAndProtectUserConfig();
                 */
                MessageBox.Show("Please use an older version of AMSE to migrate your data");
                Environment.Exit(0);
            }
            else // Standard mode. New installation or migration already done
            {
                if (!Properties.Settings.Default.MigratedLoginListToJSON)
                {
                    Properties.Settings.Default.MigratedLoginListToJSON = true;
                    Program.SaveAndProtectUserConfig();
                }

                if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.LoginListJSON))
                {
                    CredentialList = (ListCredentials)JsonConvert.DeserializeObject(Properties.Settings.Default.LoginListJSON, typeof(ListCredentials));
                    CredentialList.MediaServicesAccounts.ForEach(c => listBoxAcounts.Items.Add(ReturnAccountName(c)));
                }
                buttonExport.Enabled = (listBoxAcounts.Items.Count > 0);
            }

            accountmgtlink.Links.Add(new LinkLabel.Link(0, accountmgtlink.Text.Length, Constants.LinkAMSCreateAccount));
            linkLabelAADAut.Links.Add(new LinkLabel.Link(0, linkLabelAADAut.Text.Length, Constants.LinkAMSAADAut));

            foreach (var map in CredentialsEntry.ACSMappings)
            {
                comboBoxMappingList.Items.Add(map.Name);
            }
            comboBoxMappingList.SelectedIndex = 0;


            //comboBoxAADMappingList.Items.Add(new Item("Azure Global", nameof(AzureEnvironments.AzureCloudEnvironment)));
            comboBoxAADMappingList.Items.Add(new Item("Azure China", nameof(AzureEnvironments.AzureChinaCloudEnvironment)));
            comboBoxAADMappingList.Items.Add(new Item("Azure Germany", nameof(AzureEnvironments.AzureGermanCloudEnvironment)));
            comboBoxAADMappingList.Items.Add(new Item("Azure US Government", nameof(AzureEnvironments.AzureUsGovernmentEnvironment)));
            comboBoxAADMappingList.Items.Add(new Item(CustomString, CustomString));
            comboBoxAADMappingList.SelectedIndex = 0;

            // version
            labelVersion.Text = String.Format("Version {0}", Assembly.GetExecutingAssembly().GetName().Version);

            UpdateTexboxUI();
            UpdateAADSettingsTextBoxes();
        }
        private void AMSLogin_Load(object sender, EventArgs e)
        {
            var CredentialsList = Properties.Settings.Default.LoginList;

            // let's purge the old list now.
            if (CredentialsList != null && CredentialsList.Count > 0)
            {
                Properties.Settings.Default.LoginList.Clear();
            }

            // OLD MODE. XML properties for account entries
            if (!Properties.Settings.Default.MigratedLoginListToJSON && CredentialsList != null && CredentialsList.Count > 0)
            {
                try
                {
                    if (CredentialsList != null && CredentialsList.Count > 0)
                    {
                        for (int i = 0; i < (CredentialsList.Count / CredentialsEntry.StringsCount); i++)
                        {
                            listBoxAcounts.Items.Add(CredentialsList[i * CredentialsEntry.StringsCount]);
                        }
                        buttonExport.Enabled = (listBoxAcounts.Items.Count > 0);
                    }
                    else
                    {
                        // if null or empty, let's create it
                        CredentialsList = new StringCollection();
                    }
                }
                catch // error, let's purge all
                {
                    MessageBox.Show(AMSExplorer.Properties.Resources.AMSLogin_AMSLogin_Load_ErrorReadingCredentialsSettingsHaveBeenDeleted);
                    Properties.Settings.Default.LoginList.Clear();
                    Program.SaveAndProtectUserConfig();
                    listBoxAcounts.Items.Clear();
                }

                // Migration to JSON

                for (int i = 0; i < (CredentialsList.Count / CredentialsEntry.StringsCount); i++)
                {
                    CredentialList.MediaServicesAccounts.Add(new CredentialsEntry(
                                                                 CredentialsList[i * CredentialsEntry.StringsCount],
                                                                 CredentialsList[i * CredentialsEntry.StringsCount + 1],
                                                                 CredentialsList[i * CredentialsEntry.StringsCount + 2],
                                                                 string.Empty,
                                                                 CredentialsList[i * CredentialsEntry.StringsCount + 3],
                                                                 CredentialsList[i * CredentialsEntry.StringsCount + 4] == true.ToString() ? true : false,
                                                                 CredentialsList[i * CredentialsEntry.StringsCount + 5] == true.ToString() ? true : false,
                                                                 CredentialsList[i * CredentialsEntry.StringsCount + 6],
                                                                 CredentialsList[i * CredentialsEntry.StringsCount + 7],
                                                                 CredentialsList[i * CredentialsEntry.StringsCount + 8],
                                                                 ReturnAzureEndpoint(CredentialsList[i * CredentialsEntry.StringsCount + 9]),
                                                                 ReturnManagementPortal(CredentialsList[i * CredentialsEntry.StringsCount + 9])
                                                                 ));
                }

                var NewCredentialListJSON = JsonConvert.SerializeObject(CredentialList);
                Properties.Settings.Default.LoginListJSON           = NewCredentialListJSON;
                Properties.Settings.Default.MigratedLoginListToJSON = true;
                Program.SaveAndProtectUserConfig();
            }
            else // Standard mode. New installation or migration already done
            {
                if (!Properties.Settings.Default.MigratedLoginListToJSON)
                {
                    Properties.Settings.Default.MigratedLoginListToJSON = true;
                    Program.SaveAndProtectUserConfig();
                }

                if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.LoginListJSON))
                {
                    CredentialList = (ListCredentials)JsonConvert.DeserializeObject(Properties.Settings.Default.LoginListJSON, typeof(ListCredentials));
                    CredentialList.MediaServicesAccounts.ForEach(c => listBoxAcounts.Items.Add(c.AccountName));
                }
                buttonExport.Enabled = (listBoxAcounts.Items.Count > 0);
            }

            accountmgtlink.Links.Add(new LinkLabel.Link(0, accountmgtlink.Text.Length, Constants.LinkAMSCreateAccount));
            foreach (var map in Mappings)
            {
                comboBoxMappingList.Items.Add(map.Name);
            }
            comboBoxMappingList.SelectedIndex = 0;

            // version
            labelVersion.Text = String.Format("Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
        }
Ejemplo n.º 9
0
        private void buttonExport_Click(object sender, EventArgs e)
        {
            /*     XDocument xmlexport = new XDocument();
             *   xmlexport.Add(new XComment("Created by Azure Media Services Explorer"));
             *   xmlexport.Add(new XElement("Credentials", new XAttribute("Version", "1.1")));
             *
             *   for (int i = 0; i < (CredentialsList.Count / CredentialsEntry.StringsCount); i++)
             *   {
             *       xmlexport.Descendants("Credentials").FirstOrDefault().Add(new XElement("Entry",
             *           new XAttribute("AccountName", CredentialsList[i * CredentialsEntry.StringsCount]),
             *             new XAttribute("AccountKey", CredentialsList[i * CredentialsEntry.StringsCount + 1]),
             *          new XAttribute("StorageKey", CredentialsList[i * CredentialsEntry.StringsCount + 2]),
             *          new XAttribute("Description", CredentialsList[i * CredentialsEntry.StringsCount + 3]),
             *         new XAttribute("UsePartnerAPI", CredentialsList[i * CredentialsEntry.StringsCount + 4]),
             *          new XAttribute("UseOtherAPI", CredentialsList[i * CredentialsEntry.StringsCount + 5]),
             *          new XAttribute("OtherAPIServer", CredentialsList[i * CredentialsEntry.StringsCount + 6]),
             *          new XAttribute("OtherScope", CredentialsList[i * CredentialsEntry.StringsCount + 7]),
             *          new XAttribute("OtherACSBaseAddress", CredentialsList[i * CredentialsEntry.StringsCount + 8]),
             *           new XAttribute("OtherAzureEndpoint", ReturnAzureEndpoint(CredentialsList[i * CredentialsEntry.StringsCount + 9])),
             *             new XAttribute("OtherManagementPortal", ReturnManagementPortal(CredentialsList[i * CredentialsEntry.StringsCount + 9]))
             *          ));
             *
             *   }
             */

            bool exportAll = true;

            if (CredentialList.MediaServicesAccounts.Count > 1 && listBoxAcounts.SelectedIndex > -1) // There are more than one entry and one has been selected. Let's ask if user want to export all or not
            {
                var diag = System.Windows.Forms.MessageBox.Show("Do you want to export all entries ? \n\nSelect 'Yes' to export all, 'No' to export the selection.", "Export all entries", System.Windows.Forms.MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                switch (diag)
                {
                case DialogResult.Yes:
                    break;

                case DialogResult.No:
                    exportAll = false;
                    break;

                case DialogResult.Cancel:
                    return;
                }
            }

            DialogResult diares = saveFileDialog1.ShowDialog();

            if (diares == DialogResult.OK)
            {
                try
                {
                    if (exportAll)
                    {
                        System.IO.File.WriteAllText(saveFileDialog1.FileName, JsonConvert.SerializeObject(CredentialList, Newtonsoft.Json.Formatting.Indented));
                    }
                    else
                    {
                        var copyEntry = new ListCredentials();
                        copyEntry.MediaServicesAccounts.Add(CredentialList.MediaServicesAccounts[listBoxAcounts.SelectedIndex]);
                        System.IO.File.WriteAllText(saveFileDialog1.FileName, JsonConvert.SerializeObject(copyEntry, Newtonsoft.Json.Formatting.Indented));
                    }
                }
                catch (Exception ex)

                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }