Пример #1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            CloudTable profileTable = null;

            if (!CreateTableIfNecessary(ref profileTable))
            {
                return;
            }

            // ensure that we don't have a duplicate name
            TableOperation retrieveOperation = TableOperation.Retrieve <ProfileEntity>(this.AADDomain.Text, this.profileName.Text);
            TableResult    retrievedResult   = profileTable.Execute(retrieveOperation);

            if (retrievedResult.Result != null)
            {
                // we have a duplicate name!
                string message = "Profile name " + this.profileName.Text + " already exists for domain " + this.AADDomain.Text;
                MessageBox.Show(message);
                return;
            }

            // add profile to table (no concurrency checks for now)
            ProfileEntity newProfile = new ProfileEntity
                                           (this.comboboxMode.SelectedItem.ToString(),
                                           this.profileName.Text,
                                           this.AADDomain.Text,
                                           this.AADClientID.Text,
                                           this.AADPassword.Text,
                                           this.ADDomain.Text,
                                           this.ADUsername.Text,
                                           this.ADPassword.Text);
            TableOperation insert = TableOperation.InsertOrReplace(newProfile);

            profileTable.Execute(insert);

            // retrieve all profiles and add to view
            RefreshProfileListview();

            // all entry fields disabled
            this.comboboxMode.Enabled = false;
            this.profileName.Enabled  = false;
            this.AADDomain.Enabled    = false;
            this.AADClientID.Enabled  = false;
            this.AADPassword.Enabled  = false;
            this.ADDomain.Enabled     = false;
            this.ADUsername.Enabled   = false;
            this.ADPassword.Enabled   = false;

            // now only new and edit enabled
            this.buttonNewProfile.Enabled = true;
            this.buttonSave.Enabled       = false;
            this.buttonCancel.Enabled     = false;
            this.buttonEdit.Enabled       = true;
        }
Пример #2
0
        private void listviewProfile_SelectedIndexChanged(object sender, EventArgs e)
        {
            ProfileEntity profile = null;

            ListView.SelectedListViewItemCollection sel = this.listviewProfile.SelectedItems;
            foreach (ListViewItem item in sel)
            {
                // domain is partition, profile is rowKey
                string AADDomain = item.SubItems[1].Text;

                // extract "profileName" from "mode[profileName]"
                string profileName = Regex.Match(item.Text, @"(?<=\[)(.*?)(?=\])").ToString();

                // retrieve table
                CloudTable profileTable = null;
                if (!CreateTableIfNecessary(ref profileTable))
                {
                    return;
                }

                // query table
                TableOperation retrieveOperation = TableOperation.Retrieve <ProfileEntity>(AADDomain, profileName);
                TableResult    retrievedResult   = profileTable.Execute(retrieveOperation);
                profile = (ProfileEntity)retrievedResult.Result;
            }

            // refresh text boxes based on selection (or lack of selection)
            if (profile != null)
            {
                this.comboboxMode.SelectedIndex = this.comboboxMode.FindStringExact(profile.Mode);
            }
            this.profileName.Text = (profile != null) ? profile.RowKey : "";
            this.AADDomain.Text   = (profile != null) ? profile.PartitionKey : "";
            this.AADClientID.Text = (profile != null) ? profile.AADUsername : "";
            this.AADPassword.Text = (profile != null) ? profile.AADPassword : "";
            this.ADDomain.Text    = (profile != null) ? profile.ADDomain : "";
            this.ADUsername.Text  = (profile != null) ? profile.ADUsername : "";
            this.ADPassword.Text  = (profile != null) ? profile.ADPassword : "";

            // allow editing if we have a selection
            this.buttonEdit.Enabled = (profile != null);
        }