Пример #1
0
        internal bool AddCertificate(X509Certificate2 oCert, string sIdentifier)
        {
            using (CryptureEntities oContent = new CryptureEntities())
            {
                if (oContent.Users.Where(u => u.Certificate == oCert.RawData).Count() > 0)
                {
                    MessageBox.Show(this,
                                    "The selected certificate is already in the database.",
                                    "Certificate In Database", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return(false);
                }

                bool bAmOwner = MessageBox.Show(this,
                                                "Are you the owner of the selected certificate?",
                                                "Ownership Confirmation",
                                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;

                User oUser = new User()
                {
                    Certificate = oCert.GetRawCertData(),
                    Sid         = (bAmOwner) ? sIdentifier : null
                };
                oContent.Users.Add(oUser);
                oContent.SaveChanges();
                oRefreshItemButton_Click();
            }

            return(true);
        }
Пример #2
0
        private void oCompactDatabaseButton_Click(object sender, RoutedEventArgs e)
        {
            using (CryptureEntities oContent = new CryptureEntities())
            {
                oContent.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, "VACUUM;");
            }

            MessageBox.Show(this, "Compact operation complete.",
                            "Operation Complete", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Пример #3
0
        private void oRefreshItemButton_Click(object sender = null, RoutedEventArgs e = null)
        {
            using (CryptureEntities oContent = new CryptureEntities())
            {
                oItemDataGrid.ItemsSource = oContent.Items.ToList <Item>().OrderBy(i => i.Label);
                oCertDataGrid.ItemsSource = oContent.Users.ToList <User>().OrderBy(u => u.Name);

                // if the option to only show my items is enable, then downselect the list to only
                // include items that have an instance for this currently logged in user
                if (oHideAccessible.IsChecked.Value)
                {
                    oItemDataGrid.ItemsSource = oContent.Items.ToList <Item>().OrderBy(i => i.Label).
                                                Where(i => i.Instances.ToList().Where(u => u.User.IsOwnedByCurrentUser).Count() > 0);
                }
            }
        }
Пример #4
0
        private void oRemoveItemUser_Click(object sender, RoutedEventArgs e)
        {
            // get the selected object based on what button was pressed
            object oObject = (sender == oRemoveCertButton) ?
                             oCertDataGrid.SelectedItem : oItemDataGrid.SelectedItem;

            // prevent removal of automatic certificate
            if (oObject is User)
            {
                if (CertificateOperations.GetAutomaticCertificates().Where(u =>
                                                                           StructuralComparisons.StructuralEqualityComparer.Equals(u, ((User)oObject).Certificate)).Count() > 0)
                {
                    MessageBox.Show(this, "Removal of automatic certificate is prohibited.",
                                    "Removal Prohibited", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
            }

            // confirm removal
            if (oObject == null || MessageBox.Show(this,
                                                   "Are you sure you want to remove '" + ((oObject is User) ?
                                                                                          ((User)oObject).Name : ((Item)oObject).Label) + "'?",
                                                   "Removal Confirmation",
                                                   MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return;
            }

            // remove select item or user
            using (CryptureEntities oContent = new CryptureEntities())
            {
                oContent.Entry(oObject).State = EntityState.Deleted;
                oContent.SaveChanges();
                oRefreshItemButton_Click();
            }
        }