コード例 #1
0
        private async void uxButtonEdit_Click(object sender, EventArgs e)
        {
            var item = uxListViewSecrets.FirstSelectedItem;

            if (item == null)
            {
                return;
            }
            if (!item.Active && MessageBox.Show($"'{item.Name}' {item.Kind} is not active or expired. In order to view or edit {item.Kind}, {Utils.AppName} must change the expiration times of '{item.Name}'. Are you sure you want to change Valid from time (UTC): '{Utils.NullableDateTimeToString(item.NotBefore)}' and Valid until time (UTC): '{Utils.NullableDateTimeToString(item.Expires)}' to one year from now?\n\nNote: You will be able to change back the expiration times in the Edit dialog if needed.",
                                                Utils.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                using (var op = NewUxOperationWithProgress(uxButtonEdit, uxMenuItemEdit))
                {
                    ListViewItemBase newItem = null;
                    await op.Invoke($"update {item.Kind} in", async() => newItem = await item.ResetExpirationAsync(op.CancellationToken));

                    AddOrReplaceItemInListView(newItem, item);
                    item = newItem;
                };
            }
            if (item.Enabled && item.Active)
            {
                IEnumerable <object> versions = null;
                using (var op = NewUxOperationWithProgress(uxButtonEdit, uxMenuItemEdit)) await op.Invoke($"get {item.Kind} from", async() =>
                    {
                        versions = await item.GetVersionsAsync(op.CancellationToken);
                    });
                dynamic editDlg = item.GetEditDialog(item.Name, versions);
                // If OK was clicked, check for duplication by Name and Md5
                if ((editDlg.ShowDialog() == DialogResult.OK) && ListViewItemBase.VerifyDuplication(this, item.Name, editDlg.PropertyObject))
                {
                    using (var op = NewUxOperationWithProgress(uxButtonEdit, uxMenuItemEdit))
                    {
                        ListViewItemBase newItem = null;
                        await op.Invoke($"update {item.Kind} in", async() => newItem = await item.UpdateAsync(editDlg.OriginalObject, editDlg.PropertyObject, op.CancellationToken));

                        AddOrReplaceItemInListView(newItem, item);
                    };
                }
            }
        }
コード例 #2
0
        private async void uxMenuItemAddKVCertificate_Click(object sender, EventArgs e)
        {
            CertificateDialog certDlg = null;

            // Add certificate
            using (var dtf = new DeleteTempFileInfo())
            {
                // Add certificate from file
                if ((sender == uxAddKVCertFromFile) || (sender == uxAddKVCertFromFile2))
                {
                    dtf.FileInfoObject = GetFileInfo(sender, e);
                    if (dtf.FileInfoObject == null)
                    {
                        return;
                    }
                    certDlg = new CertificateDialog(this, dtf.FileInfoObject);
                }
                // Add certificate from store
                if ((sender == uxAddKVCertFromUserStore) || (sender == uxAddKVCertFromMachineStore) || (sender == uxAddKVCertFromUserStore2) || (sender == uxAddKVCertFromMachineStore2))
                {
                    var cert = Utils.SelectCertFromStore(StoreName.My, (sender == uxAddKVCertFromUserStore) || (sender == uxAddKVCertFromUserStore2) ? StoreLocation.CurrentUser : StoreLocation.LocalMachine, CurrentVaultAlias.Alias, Handle);
                    if (cert == null)
                    {
                        return;
                    }
                    certDlg = new CertificateDialog(this, cert);
                }
                // DialogResult.Cancel is when user clicked cancel during password prompt from the ctor(), if OK was clicked, check for duplication by Name and Md5
                if ((certDlg != null) && (certDlg.DialogResult != DialogResult.Cancel) && (certDlg.ShowDialog() == DialogResult.OK) && ListViewItemBase.VerifyDuplication(this, null, certDlg.PropertyObject))
                {
                    using (var op = NewUxOperationWithProgress(uxButtonAdd, uxMenuItemAdd))
                    {
                        ListViewItemCertificate lvic = null;
                        await op.Invoke("add certificate to", async() => lvic = await ListViewItemCertificate.NewAsync(this, certDlg.PropertyObject, op.CancellationToken));

                        AddOrReplaceItemInListView(lvic);
                    }
                }
            }
        }