コード例 #1
0
        public int Compare(object x, object y)
        {
            ListViewItemBase sx = (ListViewItemBase)x;
            ListViewItemBase sy = (ListViewItemBase)y;

            int col = Math.Min(_control.SortingColumn, _control.Columns.Count - 1);

            ListViewItem.ListViewSubItem a = sx.SubItems[col];
            ListViewItem.ListViewSubItem b = sy.SubItems[col];

            int c = 0;

            if ((a.Tag != null) && (b.Tag != null))
            {
                // Compare DateTime
                if ((a.Tag is DateTime?) && (b.Tag is DateTime?) && (a.Tag as DateTime?).HasValue && (b.Tag as DateTime?).HasValue)
                {
                    var adt = (a.Tag as DateTime?).Value;
                    var bdt = (b.Tag as DateTime?).Value;
                    c = DateTime.Compare(adt, bdt);
                }
                // Compare TimeSpan
                if ((a.Tag is TimeSpan?) && (b.Tag is TimeSpan?) && (a.Tag as TimeSpan?).HasValue && (b.Tag as TimeSpan?).HasValue)
                {
                    var ats = (a.Tag as TimeSpan?).Value;
                    var bts = (b.Tag as TimeSpan?).Value;
                    c = TimeSpan.Compare(ats, bts);
                }
            }
            else
            {
                c = string.Compare(a.Text, b.Text);
            }
            return((_control.Sorting == SortOrder.Descending) ? -c : c);
        }
コード例 #2
0
 public Exception FindItemsWithText(string regexPattern)
 {
     try
     {
         ListViewItemBase selectItem = null;
         BeginUpdate();
         Regex regex = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
         foreach (ListViewItemBase lvib in Items)
         {
             bool contains = lvib.Contains(regex);
             lvib.SearchResult = contains;
             if ((selectItem == null) && contains)
             {
                 selectItem = lvib;
             }
         }
         Sort();
         selectItem?.RefreshAndSelect();
         RefreshGroupsHeader();
         return(null);
     }
     catch (Exception e)
     {
         return(e);
     }
     finally
     {
         EndUpdate();
     }
 }
コード例 #3
0
 public void AddOrReplaceItem(ListViewItemBase item)
 {
     if (null == item)
     {
         return;
     }
     if (Items.ContainsKey(item.Name)) // Overwrite flow
     {
         var lvi = Items[item.Name] as ListViewItemBase;
         RemoveTags(lvi.Tags);
         Items.RemoveByKey(item.Name);
     }
     Items.Add(item);
     AddTags(item.Tags);
 }
コード例 #4
0
        private async void uxButtonToggle_Click(object sender, EventArgs e)
        {
            var item = uxListViewSecrets.FirstSelectedItem;

            if (null != item)
            {
                string action = item.Enabled ? "disable" : "enable";
                if (MessageBox.Show($"Are you sure you want to {action} {item.Kind} '{item.Name}'?", Utils.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    using (var op = NewUxOperationWithProgress(uxButtonToggle, uxMenuItemToggle))
                    {
                        ListViewItemBase lvib = null;
                        await op.Invoke($"update {item.Kind} in", async() => lvib = await item.ToggleAsync(op.CancellationToken));

                        AddOrReplaceItemInListView(lvib, item);
                    }
                }
            }
        }
コード例 #5
0
 private void AddOrReplaceItemInListView(ListViewItemBase newItem, ListViewItemBase oldItem = null)
 {
     try
     {
         uxListViewSecrets.BeginUpdate();
         if (null != oldItem)
         {
             uxListViewSecrets.Items.Remove(oldItem);                  // Rename flow
         }
         uxListViewSecrets.AddOrReplaceItem(newItem);                  // Overwrite flow
         uxTimerSearchTextTypingCompleted_Tick(null, EventArgs.Empty); // Refresh search
         newItem?.RefreshAndSelect();
         uxListViewSecrets.RefreshGroupsHeader();
         RefreshItemsCount();
     }
     finally
     {
         uxListViewSecrets.EndUpdate();
     }
 }
コード例 #6
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);
                    };
                }
            }
        }
コード例 #7
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);
                    }
                }
            }
        }