本文整理汇总了C#中KeePassLib.PwDatabase.Close方法的典型用法代码示例。如果您正苦于以下问题:C# PwDatabase.Close方法的具体用法?C# PwDatabase.Close怎么用?C# PwDatabase.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeePassLib.PwDatabase
的用法示例。
在下文中一共展示了PwDatabase.Close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseKeePassDatabase
public static void CloseKeePassDatabase(PwDatabase database)
{
database.Save(null);
database.Close();
}
示例2: SyncDatabase
private void SyncDatabase(string databaseFilename)
{
var db = new PwDatabase();
db.Open(IOConnectionInfo.FromPath(databaseFilename), this.host.Database.MasterKey, new NullStatusLogger());
this.host.Database.MergeIn(db, PwMergeMethod.Synchronize);
this.host.MainWindow.RefreshEntriesList();
db.Close();
}
示例3: Import
/// <summary>
/// The function tries to merge possible updates from the deltaDB into
/// the actual database. If there was made changes to the actualDB, then
/// the function fires a event, which cause the KeePass UI to update and
/// show the "save"-button.
/// </summary>
public void Import(object sender, SyncSource source)
{
Debug.Assert(source.DestinationDB != null && source.DestinationDB.RootGroup != null);
//merge all updates in
PwDatabase deltaDB = new PwDatabase();
try
{
deltaDB.Open(IOConnectionInfo.FromPath(source.Location), source.Key, null);
}
catch (InvalidCompositeKeyException e)
{
Debug.WriteLine("Wrong key! exception was: " + e.Message);
//brand this entry as a false one => red bg-color and "X" as group icon
ShowErrorHighlight(source.DestinationDB, source.Uuid);
if (Imported != null) Imported.Invoke(this, source.DestinationDB.RootGroup);
return;
}
catch (Exception e)
{
Debug.WriteLine("Standard exception was thrown during deltaDB.Open(): " + e.Message);
//maybe the process has not finished writing to our file, but the filewtcher fires our event
//sourceEntryUuid we have to ignore it and wait for the next one.
return;
}
HideErrorHighlight(source.DestinationDB, source.Uuid);
MergeIn(source.DestinationDB, deltaDB);
deltaDB.Close();
}
示例4: ShouldNotImportDatabasesWithDifferentUsers
public void ShouldNotImportDatabasesWithDifferentUsers()
{
var exportPath = GetTestPath();
m_syncManager.AddExportPath(exportPath);
var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");
var userMrY = TestHelper.GetUserRootNodeByNameFor(m_database, "mrY");
m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrY), true);
var existingEntry = new PwEntry(true, true);
existingEntry.SetTitle("Entry Version 1");
m_database.RootGroup.AddEntry(existingEntry, true);
m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrY), true);
m_treeManager.CorrectStructure();
string exportFile = exportPath + SyncSource.FileNameFor(userMrY) + SyncExporter.FileExtension;
Assert.IsFalse(File.Exists(exportFile));
m_syncManager.Export();
existingEntry.SetTitle("Entry Version 2");
var deltaDBInitial = new PwDatabase();
deltaDBInitial.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
Assert.AreEqual(0, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 2"));
Assert.AreEqual(1, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1"));
deltaDBInitial.Close();
m_syncManager.AddImportPath(exportFile);
m_database.GetImportGroup().Groups.GetAt(0).Entries.GetAt(0).SetPassword("InvalidPassword");
m_syncManager.RefeshSourcesList();
Assert.AreEqual(1, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 2"));
Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1"));
}
示例5: ShouldOnlyExportToCurrentSharedUsers
public void ShouldOnlyExportToCurrentSharedUsers()
{
m_treeManager.Initialize(m_database);
var exportPath = GetTestPath();
m_syncManager.AddExportPath(exportPath);
var exportGroup = m_database.GetExportGroup().Groups.GetAt( 0 ) ;
m_treeManager.CreateNewUser("Adam");
m_treeManager.CreateNewUser("Eva");
var userAdam = TestHelper.GetUserRootNodeByNameFor(m_database, "Adam");
var userEva = TestHelper.GetUserRootNodeByNameFor(m_database, "Eva");
userAdam.SetPassword(STANDARD_PASSWORD);
userEva.SetPassword(STANDARD_PASSWORD);
m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userAdam), true);
m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userEva), true);
exportGroup.AddEntry(PwNode.CreateProxyNode(userAdam), true);
exportGroup.AddEntry(PwNode.CreateProxyNode(userEva), true);
m_treeManager.CorrectStructure();
string exportFileAdam = exportPath + SyncSource.FileNameFor(userAdam) + SyncExporter.FileExtension;
string exportFileEva = exportPath + SyncSource.FileNameFor(userEva) + SyncExporter.FileExtension;
Assert.IsFalse(File.Exists(exportFileAdam));
Assert.IsFalse(File.Exists(exportFileEva));
m_syncManager.Export();
// TODO CK: At this point it may be possible that the files are not created - we need to wait for the filesystem to respond - maybe using a delay?
Assert.IsTrue(File.Exists(exportFileAdam));
Assert.IsTrue(File.Exists(exportFileEva));
var homeAdam = TestHelper.GetUserHomeNodeByNameFor(m_database, "Adam");
homeAdam.ParentGroup.Groups.Remove(homeAdam);
var trash = m_database.RootGroup.FindGroup(m_database.RecycleBinUuid, true);
trash.AddGroup(homeAdam, true);
trash.DeleteAllObjects(m_database);
//update should delete all references to the non existing user
m_treeManager.CorrectStructure();
var changedEntry = m_database.RootGroup.Entries.GetAt(0);
changedEntry.SetTitle("Changed");
TestHelper.SimulateTouch(changedEntry);
m_syncManager.Export();
TestHelper.DelayAction();
var deltaDBAdamReexport = new PwDatabase();
deltaDBAdamReexport.Open(IOConnectionInfo.FromPath(exportFileAdam), m_standardKey, null);
Assert.AreEqual(Uuid1, deltaDBAdamReexport.RootGroup.Entries.GetAt(0).Uuid);
Assert.AreNotEqual("Changed", deltaDBAdamReexport.RootGroup.Entries.GetAt(0).GetTitle());
deltaDBAdamReexport.Close();
var deltaDBEvaReexport = new PwDatabase();
deltaDBEvaReexport.Open(IOConnectionInfo.FromPath(exportFileEva), m_standardKey, null);
Assert.AreEqual(Uuid1, deltaDBEvaReexport.RootGroup.Entries.GetAt(0).Uuid);
Assert.AreEqual("Changed", deltaDBEvaReexport.RootGroup.Entries.GetAt(0).GetTitle());
deltaDBEvaReexport.Close();
}
示例6: ShouldHandleCyclesOfNodesInImportAndExport
public void ShouldHandleCyclesOfNodesInImportAndExport()
{
var exportPath = GetTestPath();
m_syncManager.AddExportPath(exportPath);
var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");
m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrX), true);
var existingEntry = new PwEntry(true, true);
existingEntry.SetTitle("Entry Version 1");
m_database.RootGroup.AddEntry(existingEntry, true);
m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrX), true);
m_treeManager.CorrectStructure();
string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension;
Assert.IsFalse(File.Exists(exportFile));
m_syncManager.Export();
var deltaDBInitial = new PwDatabase();
deltaDBInitial.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
Assert.AreEqual(1, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1"));
foreach(var entry in deltaDBInitial.RootGroup.GetEntries(true))
{
entry.SetTitle("Changed");
}
deltaDBInitial.Save(null);
deltaDBInitial.Close();
m_syncManager.AddImportPath(exportFile);
m_database.GetImportGroup().Groups.GetAt(0).Entries.GetAt(0).SetPassword(userMrX.Strings.ReadSafe(KeeShare.KeeShare.PasswordField));
m_syncManager.RefeshSourcesList();
// Node normalEntry6 is within the user home and is relocated on export which changes the parent node - during import, the parents of
// not "officially" relocated nodes is checked and an assertion is thrown
Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Changed"));
}
示例7: ShouldExportToTargets
public void ShouldExportToTargets()
{
//we change the password which is used to encrypt the delta container so we can later access the delta container
//more easily.
PwEntry mrX = TestHelper.GetUserRootNodeFor(m_database, 0);
//the first autoExport only checks if there is a delta container allready and if not it will export one
//in our case there should be no existing container so a new one will be created.
var exportFolder = m_database.GetExportGroup();
Assert.IsTrue(0 == exportFolder.Groups.UCount);
string exportPath = GetTestPath();
m_syncManager.AddExportPath(exportPath);
var exportGroup = exportFolder.Groups.GetAt(0);
exportGroup.AddEntry(PwNode.CreateProxyNode(mrX), true);
string exportFile = exportPath + SyncSource.FileNameFor(mrX) + SyncExporter.FileExtension;
Assert.IsFalse(File.Exists(exportFile));
m_syncManager.RefeshSourcesList();
m_syncManager.Export();
mrX = TestHelper.GetUserRootNodeFor(m_database, 0);
Assert.AreEqual("mrX", mrX.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
Assert.IsTrue(File.Exists(exportFile));
//now we open the creted delta container and verify the contend
PwDatabase deltaDB = new PwDatabase();
Assert.DoesNotThrow(delegate {
deltaDB.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
});
Assert.AreEqual(5, deltaDB.RootGroup.GetEntries(true).UCount);
Assert.AreEqual(3, deltaDB.RootGroup.Entries.UCount);
Assert.AreEqual("grp1", deltaDB.RootGroup.Groups.GetAt(0).Name);
Assert.AreEqual(2, deltaDB.RootGroup.Groups.GetAt(0).Entries.UCount);
//now we will test in detail if there are only the expected entries in the created delta container
Assert.AreEqual(Uuid1, deltaDB.RootGroup.Entries.GetAt(0).Uuid);
Assert.AreEqual(Uuid3, deltaDB.RootGroup.Entries.GetAt(2).Uuid);
Assert.AreEqual(Uuid6, deltaDB.RootGroup.Entries.GetAt(1).Uuid);
Assert.AreEqual(Uuid4, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(0).Uuid);
Assert.AreEqual(Uuid5, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(1).Uuid);
Assert.AreEqual("normalEntry1", deltaDB.RootGroup.Entries.GetAt(0).GetTitle());
deltaDB.Close();
}
示例8: ShouldExportImportedNodes
public void ShouldExportImportedNodes()
{
var importDatabase = TestHelper.CreateDatabase();
var importedEntry = new PwEntry(true, true);
importedEntry.SetTitle("ImportedEntry");
var importedGroup = new PwGroup(true, true);
importedGroup.Name = "ImportedGroup";
importedGroup.AddEntry(importedEntry, true);
importDatabase.RootGroup.AddGroup(importedGroup, true);
var exportPath = GetTestPath();
m_syncManager.AddExportPath(exportPath);
var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");
m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrX), true);
m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrX), true);
var existingEntry = new PwEntry(true, true);
existingEntry.SetTitle("ExistingEntry");
m_database.RootGroup.AddEntry(existingEntry, true);
m_treeManager.CorrectStructure();
string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension;
Assert.IsFalse(File.Exists(exportFile));
Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
Assert.AreEqual(0, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));
m_syncManager.Export();
Assert.IsTrue(File.Exists(exportFile));
var importer = new SyncImporterAccessor();
importer.MergeInAccessor(m_database, importDatabase);
Assert.AreEqual(1, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
Assert.AreEqual(1, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));
m_syncManager.Export();
Assert.IsTrue(File.Exists(exportFile));
var deltaDBUpdated = new PwDatabase();
deltaDBUpdated.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry"));
Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup"));
deltaDBUpdated.Close();
}
示例9: ShouldExportAfterChangedContent
public void ShouldExportAfterChangedContent()
{
PwEntry mrX = TestHelper.GetUserRootNodeFor(m_database, 0);
//the first autoExport only checks if there is a delta container allready and if not it will export one
//in our case there should be no existing container so a new one will be created.
string exportPath = GetTestPath();
PwGroup exportGroup = new PwGroup(true, true, exportPath, PwIcon.Apple);
m_database.GetExportGroup().AddGroup(exportGroup, true);
exportGroup.AddEntry(PwNode.CreateProxyNode(mrX), true);
string exportFile = exportPath + SyncSource.FileNameFor(mrX) + SyncExporter.FileExtension;
Assert.IsFalse(File.Exists(exportFile));
m_syncManager.RefeshSourcesList();
m_syncManager.Export();
mrX = TestHelper.GetUserRootNodeFor(m_database, 0);
Assert.AreEqual("mrX", mrX.GetTitle());
Assert.IsTrue(File.Exists(exportFile));
//now we will change a password that is shared to mrX and then trigger the AutoExport method
//like it will happen on any OnChangeEvent. After that again we validate the data in the export container.
PwEntry entry1 = m_database.RootGroup.FindEntry(Uuid1, true);
entry1.SetTitle("new title");
//due to the fact that the UnitTest is way faster than userIneraction we have to manipulate the lastModTimestamp
//because if we don't do that the um.Update() method will maybe use another value to update all references and
//then we will have the old title in the stringField
TestHelper.SimulateTouch(entry1);
//now we run the update methods that will be triggered on every UiChangeEvent
m_treeManager.CorrectStructure();
m_syncManager.RefeshSourcesList();
//the autoexport method was triggered by in import or OnSaveEvent only so we have to trigger it manually here
m_syncManager.Export();
PwDatabase deltaDB = new PwDatabase();
Assert.DoesNotThrow(delegate {
deltaDB.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
});
//as before we want to have the same content except that entry1 should now have a new title!
Assert.AreEqual(5, deltaDB.RootGroup.GetEntries(true).UCount);
Assert.AreEqual(3, deltaDB.RootGroup.Entries.UCount);
Assert.AreEqual("grp1", deltaDB.RootGroup.Groups.GetAt(0).Name);
Assert.AreEqual(2, deltaDB.RootGroup.Groups.GetAt(0).Entries.UCount);
//now we will test in detail if there are only the expected entries in the created delta container
Assert.AreEqual(Uuid1, deltaDB.RootGroup.Entries.GetAt(0).Uuid);
Assert.AreEqual(Uuid3, deltaDB.RootGroup.Entries.GetAt(2).Uuid);
Assert.AreEqual(Uuid6, deltaDB.RootGroup.Entries.GetAt(1).Uuid);
Assert.AreEqual(Uuid4, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(0).Uuid);
Assert.AreEqual(Uuid5, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(1).Uuid);
Assert.AreEqual("new title", deltaDB.RootGroup.Entries.GetAt(0).GetTitle());
deltaDB.Close();
}
示例10: loadMenu
private void loadMenu()
{
if (setDriveLetter()) {
dbPath = path + "passwords.kdbx"; // drive letter calculated
masterPath = path + "master";
// init local hashes
localPwdHash = new Dictionary<string, string>();
localURLHash = new Dictionary<string, string>();
string masterpw = File.ReadAllText(masterPath);
var ioConnInfo = new IOConnectionInfo { Path = dbPath };
var compKey = new CompositeKey();
compKey.AddUserKey(new KcpPassword(masterpw));
var db = new KeePassLib.PwDatabase();
db.Open(ioConnInfo, compKey, null);
foreach (var i in db.RootGroup.GetGroups(false)) {
var currMenu = new MenuItem(i.Name);
trayMenu.MenuItems.Add(currMenu);
loadSubMenuItems(i, currMenu);
}
db.Close();
if (watcher == null) {
watchForDbChanges();
}
} else {
const string DbFileNotFound = "Database file not found!";
trayMenu.MenuItems.Add(DbFileNotFound);
}
//trayMenu.MenuItems.Add(MenuSeparator);
//const string AddItem = "Add New Entry";
//trayMenu.MenuItems.Add(AddItem, onAddNewItem);
trayMenu.MenuItems.Add(MenuSeparator);
const string Exit = "Exit";
trayMenu.MenuItems.Add(Exit, OnExit);
}