当前位置: 首页>>代码示例>>C#>>正文


C# PwDatabase.Open方法代码示例

本文整理汇总了C#中KeePassLib.PwDatabase.Open方法的典型用法代码示例。如果您正苦于以下问题:C# PwDatabase.Open方法的具体用法?C# PwDatabase.Open怎么用?C# PwDatabase.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KeePassLib.PwDatabase的用法示例。


在下文中一共展示了PwDatabase.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateAndSaveLocal

        public void CreateAndSaveLocal()
        {
            IKp2aApp app = new TestKp2aApp();
            IOConnectionInfo ioc = new IOConnectionInfo {Path = DefaultFilename};

            File outputDir = new File(DefaultDirectory);
            outputDir.Mkdirs();
            File targetFile = new File(ioc.Path);
            if (targetFile.Exists())
                targetFile.Delete();

            bool createSuccesful = false;
            //create the task:
            CreateDb createDb = new CreateDb(app, Application.Context, ioc, new ActionOnFinish((success, message) =>
                { createSuccesful = success;
                    if (!success)
                        Android.Util.Log.Debug("KP2A_Test", message);
                }), false);
            //run it:

            createDb.Run();
            //check expectations:
            Assert.IsTrue(createSuccesful);
            Assert.IsNotNull(app.GetDb());
            Assert.IsNotNull(app.GetDb().KpDatabase);
            //the create task should create two groups:
            Assert.AreEqual(2, app.GetDb().KpDatabase.RootGroup.Groups.Count());

            //ensure the the database can be loaded from file:
            PwDatabase loadedDb = new PwDatabase();
            loadedDb.Open(ioc, new CompositeKey(), null, new KdbxDatabaseFormat(KdbxFormat.Default));

            //Check whether the databases are equal
            AssertDatabasesAreEqual(loadedDb, app.GetDb().KpDatabase);
        }
开发者ID:pythe,项目名称:wristpass,代码行数:35,代码来源:TestCreateDb.cs

示例2: 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();
 }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:34,代码来源:SyncImporter.cs

示例3: PostSavingEx

		private void PostSavingEx(bool bPrimary, PwDatabase pwDatabase,
			IOConnectionInfo ioc, IStatusLogger sl)
		{
			if(ioc == null) { Debug.Assert(false); return; }

			byte[] pbIO = null;
			if(Program.Config.Application.VerifyWrittenFileAfterSaving)
			{
				pbIO = WinUtil.HashFile(ioc);
				Debug.Assert((pbIO != null) && (pwDatabase.HashOfLastIO != null));
				if(!MemUtil.ArraysEqual(pbIO, pwDatabase.HashOfLastIO))
					MessageService.ShowWarning(ioc.GetDisplayName(),
						KPRes.FileVerifyHashFail, KPRes.FileVerifyHashFailRec);
			}

			if(bPrimary)
			{
#if DEBUG
				Debug.Assert(MemUtil.ArraysEqual(pbIO, pwDatabase.HashOfFileOnDisk));

				try
				{
					PwDatabase pwCheck = new PwDatabase();
					pwCheck.Open(ioc.CloneDeep(), pwDatabase.MasterKey, null);

					Debug.Assert(MemUtil.ArraysEqual(pwDatabase.HashOfLastIO,
						pwCheck.HashOfLastIO));

					uint uGroups1, uGroups2, uEntries1, uEntries2;
					pwDatabase.RootGroup.GetCounts(true, out uGroups1, out uEntries1);
					pwCheck.RootGroup.GetCounts(true, out uGroups2, out uEntries2);
					Debug.Assert((uGroups1 == uGroups2) && (uEntries1 == uEntries2));
				}
				catch(Exception exVerify) { Debug.Assert(false, exVerify.Message); }
#endif

				m_mruList.AddItem(ioc.GetDisplayName(), ioc.CloneDeep());

				// SetLastUsedFile(ioc);

				// if(Program.Config.Application.CreateBackupFileAfterSaving && bHashValid)
				// {
				//	try { pwDatabase.CreateBackupFile(sl); }
				//	catch(Exception exBackup)
				//	{
				//		MessageService.ShowWarning(KPRes.FileBackupFailed, exBackup);
				//	}
				// }

				// ulong uTotalBinSize = 0;
				// EntryHandler ehCnt = delegate(PwEntry pe)
				// {
				//	foreach(KeyValuePair<string, ProtectedBinary> kvpCnt in pe.Binaries)
				//	{
				//		uTotalBinSize += kvpCnt.Value.Length;
				//	}
				//
				//	return true;
				// };
				// pwDatabase.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, ehCnt);
			}

			RememberKeySources(pwDatabase);
			WinUtil.FlushStorageBuffers(ioc.Path, true);
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:65,代码来源:MainForm_Functions.cs

示例4: Synchronize

        /// <summary>
        /// Synchronize current database with another one.
        /// </summary>
        /// <param name="strFile">Source file.</param>
        public void Synchronize(string strFile)
        {
            PwDatabase pwSource = new PwDatabase();

            IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
            pwSource.Open(ioc, this.m_pwUserKey, null);

            MergeIn(pwSource, PwMergeMethod.Synchronize);
        }
开发者ID:jonbws,项目名称:strengthreport,代码行数:13,代码来源:PwDatabase.cs

示例5: OpenDatabaseInternal

        private PwDatabase OpenDatabaseInternal(IOConnectionInfo ioc, CompositeKey cmpKey)
        {
            PerformSelfTest ();

             //string strPathNrm = ioc.Path.Trim().ToLower();

             PwDatabase pwDb = new PwDatabase ();

             try {
            pwDb.Open (ioc, cmpKey, null);
             }
             catch (Exception ex) {
            //MessageService.ShowLoadWarning(ioc.GetDisplayName(), ex,
            //   (Program.CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null));
            pwDb = null;
            throw;
             }

             return pwDb;
        }
开发者ID:enecciari,项目名称:mackeepass,代码行数:20,代码来源:DatabaseCommands.cs

示例6: 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();
        }
开发者ID:grumpydev,项目名称:Keepass.AutoSync,代码行数:11,代码来源:AutoSyncExt.cs

示例7: PostSavingEx

        private void PostSavingEx(bool bPrimary, PwDatabase pwDatabase, IOConnectionInfo ioc)
        {
            if(ioc == null) { Debug.Assert(false); return; }

            byte[] pbIO = WinUtil.HashFile(ioc);
            Debug.Assert((pbIO != null) && (pwDatabase.HashOfLastIO != null));
            if(pwDatabase.HashOfLastIO != null)
            {
                if(!MemUtil.ArraysEqual(pbIO, pwDatabase.HashOfLastIO))
                {
                    MessageService.ShowWarning(ioc.GetDisplayName(), KPRes.FileVerifyHashFail,
                        KPRes.FileVerifyHashFailRec);
                }
            }

            if(bPrimary)
            {
            #if DEBUG
                Debug.Assert(MemUtil.ArraysEqual(pbIO, pwDatabase.HashOfFileOnDisk));

                try
                {
                    PwDatabase pwCheck = new PwDatabase();
                    pwCheck.Open(ioc.CloneDeep(), pwDatabase.MasterKey, null);

                    Debug.Assert(MemUtil.ArraysEqual(pwDatabase.HashOfLastIO,
                        pwCheck.HashOfLastIO));

                    uint uGroups1, uGroups2, uEntries1, uEntries2;
                    pwDatabase.RootGroup.GetCounts(true, out uGroups1, out uEntries1);
                    pwCheck.RootGroup.GetCounts(true, out uGroups2, out uEntries2);
                    Debug.Assert((uGroups1 == uGroups2) && (uEntries1 == uEntries2));
                }
                catch(Exception exVerify) { Debug.Assert(false, exVerify.Message); }
            #endif

                m_mruList.AddItem(ioc.GetDisplayName(), ioc.CloneDeep());

                Program.Config.Application.LastUsedFile = ioc.CloneDeep();
            }

            WinUtil.FlushStorageBuffers(ioc.Path, true);
        }
开发者ID:jonbws,项目名称:strengthreport,代码行数:43,代码来源:MainForm_Functions.cs

示例8: PopulateDatabaseFromStream

 protected virtual void PopulateDatabaseFromStream(PwDatabase pwDatabase, Stream s, IOConnectionInfo iocInfo, CompositeKey compositeKey, ProgressDialogStatusLogger status, IDatabaseFormat databaseFormat)
 {
     IFileStorage fileStorage = _app.GetFileStorage(iocInfo);
     var filename = fileStorage.GetFilenameWithoutPathAndExt(iocInfo);
     pwDatabase.Open(s, filename, iocInfo, compositeKey, status, databaseFormat);
 }
开发者ID:pythe,项目名称:wristpass,代码行数:6,代码来源:Database.cs

示例9: 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();
        }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:61,代码来源:SyncMasterUnitTest.cs

示例10: 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"));
        }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:37,代码来源:SyncMasterUnitTest.cs

示例11: ShouldNotExportKeeShareNodes

        public void ShouldNotExportKeeShareNodes()
        {
            m_treeManager.Initialize(m_database);
            var exportPath = GetTestPath();

            m_syncManager.AddExportPath(exportPath);
            var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");
            var userMrY = TestHelper.GetUserRootNodeByNameFor(m_database, "mrY");
            userMrY.SetPassword(STANDARD_PASSWORD);

            m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrY), true);

            m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrX), true);

            m_treeManager.CorrectStructure();

            m_database.GetUserHomeFor(userMrY).AddEntry(PwNode.CreateProxyNode(userMrX), true);
            m_database.GetUserHomeFor(userMrX).AddEntry(PwNode.CreateProxyNode(userMrY), true);

            string exportFile = exportPath + SyncSource.FileNameFor(userMrY) + SyncExporter.FileExtension;

            Assert.IsFalse(File.Exists(exportFile));

            m_syncManager.Export();

            TestHelper.DelayAction();

            Assert.IsTrue(File.Exists(exportFile));

            var deltaDBAdamReexport = new PwDatabase();
            deltaDBAdamReexport.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
            foreach( var entry in deltaDBAdamReexport.RootGroup.GetEntries( true ))
            {
                Assert.AreNotEqual(userMrX.GetTitle(), entry.GetTitle());
            }
            foreach( var group in deltaDBAdamReexport.RootGroup.GetGroups(true))
            {
                Assert.AreNotEqual(userMrX.GetTitle(), group.Name);
            }
        }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:40,代码来源:SyncMasterUnitTest.cs

示例12: 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"));
        }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:38,代码来源:SyncMasterUnitTest.cs

示例13: 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();
        }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:48,代码来源:SyncMasterUnitTest.cs

示例14: 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();
        }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:49,代码来源:SyncMasterUnitTest.cs

示例15: 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();
        }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:57,代码来源:SyncMasterUnitTest.cs


注:本文中的KeePassLib.PwDatabase.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。