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


C# PwDatabase.New方法代码示例

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


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

示例1: SetEntry

                public void SetEntry(PwEntry e)
                {
                    KpDatabase = new PwDatabase();
                    KpDatabase.New(new IOConnectionInfo(), new CompositeKey());

                    KpDatabase.RootGroup.AddEntry(e, true);
                }
开发者ID:pythe,项目名称:wristpass,代码行数:7,代码来源:App.cs

示例2: TestCreateSaveAndLoad_TestIdenticalFiles_kdb

        public void TestCreateSaveAndLoad_TestIdenticalFiles_kdb()
        {
            string filename = DefaultDirectory + "createsaveandload.kdb";
            IKp2aApp app = SetupAppWithDatabase(filename);
            string kdbxXml = DatabaseToXml(app);
            //save it and reload it
            Android.Util.Log.Debug("KP2A", "-- Save DB -- ");
            SaveDatabase(app);
            Android.Util.Log.Debug("KP2A", "-- Load DB -- ");

            PwDatabase pwImp = new PwDatabase();
            PwDatabase pwDatabase = app.GetDb().KpDatabase;
            pwImp.New(new IOConnectionInfo(), pwDatabase.MasterKey);
            pwImp.MemoryProtection = pwDatabase.MemoryProtection.CloneDeep();
            pwImp.MasterKey = pwDatabase.MasterKey;

            IOConnectionInfo ioc = new IOConnectionInfo() {Path = filename};
            using (Stream s = app.GetFileStorage(ioc).OpenFileForRead(ioc))
            {
                app.GetDb().DatabaseFormat.PopulateDatabaseFromStream(pwImp, s, null);
            }
            string kdbxReloadedXml = DatabaseToXml(app);

            RemoveKdbLines(ref kdbxReloadedXml);
            RemoveKdbLines(ref kdbxXml);

            Assert.AreEqual(kdbxXml, kdbxReloadedXml);
        }
开发者ID:pythe,项目名称:wristpass,代码行数:28,代码来源:TestSaveDb.cs

示例3: CreateKeePassDatabase

        public static PwDatabase CreateKeePassDatabase(string databasePath, CompositeKey compositeKey)
        {
            if (!databasePath.EndsWith(".kdbx"))
                throw new FileNotFoundException("The database file must end with .kdbx");

            var directoryName = Path.GetDirectoryName(databasePath);
            var fileName = Path.GetFileName(databasePath);

            if (!Directory.Exists(directoryName))
                Directory.CreateDirectory(directoryName);

            var ioc = new IOConnectionInfo();
            ioc.Path = fileName;
            ioc.CredSaveMode = IOCredSaveMode.NoSave;

            var database = new PwDatabase();
            database.New(ioc, compositeKey);
            database.Save(null);

            return database;
        }
开发者ID:badmishkallc,项目名称:jolt9-devops,代码行数:21,代码来源:Util.cs

示例4: Import

        public static bool? Import(PwDatabase pwDatabase, FileFormatProvider fmtImp,
            IOConnectionInfo[] vConnections, bool bSynchronize, IUIOperations uiOps,
            bool bForceSave, Form fParent)
        {
            if(pwDatabase == null) throw new ArgumentNullException("pwDatabase");
            if(!pwDatabase.IsOpen) return null;
            if(fmtImp == null) throw new ArgumentNullException("fmtImp");
            if(vConnections == null) throw new ArgumentNullException("vConnections");

            if(!AppPolicy.Try(AppPolicyId.Import)) return false;
            if(!fmtImp.TryBeginImport()) return false;

            bool bUseTempDb = (fmtImp.SupportsUuids || fmtImp.RequiresKey);
            bool bAllSuccess = true;

            // if(bSynchronize) { Debug.Assert(vFiles.Length == 1); }

            IStatusLogger dlgStatus;
            if(Program.Config.UI.ShowImportStatusDialog)
                dlgStatus = new OnDemandStatusDialog(false, fParent);
            else dlgStatus = new UIBlockerStatusLogger(fParent);

            dlgStatus.StartLogging(PwDefs.ShortProductName + " - " + (bSynchronize ?
                KPRes.Synchronizing : KPRes.ImportingStatusMsg), false);
            dlgStatus.SetText(bSynchronize ? KPRes.Synchronizing :
                KPRes.ImportingStatusMsg, LogStatusType.Info);

            if(vConnections.Length == 0)
            {
                try { fmtImp.Import(pwDatabase, null, dlgStatus); }
                catch(Exception exSingular)
                {
                    if((exSingular.Message != null) && (exSingular.Message.Length > 0))
                    {
                        // slf.SetText(exSingular.Message, LogStatusType.Warning);
                        MessageService.ShowWarning(exSingular);
                    }
                }

                dlgStatus.EndLogging();
                return true;
            }

            foreach(IOConnectionInfo iocIn in vConnections)
            {
                Stream s = null;

                try { s = IOConnection.OpenRead(iocIn); }
                catch(Exception exFile)
                {
                    MessageService.ShowWarning(iocIn.GetDisplayName(), exFile);
                    bAllSuccess = false;
                    continue;
                }
                if(s == null) { Debug.Assert(false); bAllSuccess = false; continue; }

                PwDatabase pwImp;
                if(bUseTempDb)
                {
                    pwImp = new PwDatabase();
                    pwImp.New(new IOConnectionInfo(), pwDatabase.MasterKey);
                    pwImp.MemoryProtection = pwDatabase.MemoryProtection.CloneDeep();
                }
                else pwImp = pwDatabase;

                if(fmtImp.RequiresKey && !bSynchronize)
                {
                    KeyPromptForm kpf = new KeyPromptForm();
                    kpf.InitEx(iocIn, false, true);

                    if(UIUtil.ShowDialogNotValue(kpf, DialogResult.OK)) { s.Close(); continue; }

                    pwImp.MasterKey = kpf.CompositeKey;
                    UIUtil.DestroyForm(kpf);
                }
                else if(bSynchronize) pwImp.MasterKey = pwDatabase.MasterKey;

                dlgStatus.SetText((bSynchronize ? KPRes.Synchronizing :
                    KPRes.ImportingStatusMsg) + " (" + iocIn.GetDisplayName() +
                    ")", LogStatusType.Info);

                try { fmtImp.Import(pwImp, s, dlgStatus); }
                catch(Exception excpFmt)
                {
                    string strMsgEx = excpFmt.Message;
                    if(bSynchronize && (excpFmt is InvalidCompositeKeyException))
                        strMsgEx = KLRes.InvalidCompositeKey + MessageService.NewParagraph +
                            KPRes.SynchronizingHint;

                    MessageService.ShowWarning(strMsgEx);

                    s.Close();
                    bAllSuccess = false;
                    continue;
                }

                s.Close();

                if(bUseTempDb)
                {
//.........这里部分代码省略.........
开发者ID:elitak,项目名称:keepass,代码行数:101,代码来源:ImportUtil.cs

示例5: Import

		public static bool? Import(PwDatabase pd, FileFormatProvider fmtImp,
			IOConnectionInfo iocImp, PwMergeMethod mm, CompositeKey cmpKey)
		{
			if(pd == null) { Debug.Assert(false); return false; }
			if(fmtImp == null) { Debug.Assert(false); return false; }
			if(iocImp == null) { Debug.Assert(false); return false; }
			if(cmpKey == null) cmpKey = new CompositeKey();

			if(!AppPolicy.Try(AppPolicyId.Import)) return false;
			if(!fmtImp.TryBeginImport()) return false;

			PwDatabase pdImp = new PwDatabase();
			pdImp.New(new IOConnectionInfo(), cmpKey);
			pdImp.MemoryProtection = pd.MemoryProtection.CloneDeep();

			Stream s = IOConnection.OpenRead(iocImp);
			if(s == null)
				throw new FileNotFoundException(iocImp.GetDisplayName() +
					MessageService.NewLine + KPRes.FileNotFoundError);

			try { fmtImp.Import(pdImp, s, null); }
			finally { s.Close(); }

			pd.MergeIn(pdImp, mm);
			return true;
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:26,代码来源:ImportUtil.cs

示例6: PerformImport

        private static bool PerformImport(PwDatabase pwDatabase, FileFormatProvider fmtImp,
            IOConnectionInfo[] vConnections, bool bSynchronize, IUIOperations uiOps,
            bool bForceSave)
        {
            if(fmtImp.TryBeginImport() == false) return false;

            bool bUseTempDb = (fmtImp.SupportsUuids || fmtImp.RequiresKey);
            bool bAllSuccess = true;

            // if(bSynchronize) { Debug.Assert(vFiles.Length == 1); }

            StatusLoggerForm slf = new StatusLoggerForm();
            slf.InitEx(false);
            slf.Show();

            if(bSynchronize) slf.StartLogging(KPRes.Synchronize, false);
            else slf.StartLogging(KPRes.ImportingStatusMsg, false);

            if(vConnections.Length == 0)
            {
                try { fmtImp.Import(pwDatabase, null, slf); }
                catch(Exception exSingular)
                {
                    if((exSingular.Message != null) && (exSingular.Message.Length > 0))
                    {
                        slf.SetText(exSingular.Message, LogStatusType.Warning);
                        MessageService.ShowWarning(exSingular);
                    }
                }

                slf.EndLogging(); slf.Close();
                return true;
            }

            foreach(IOConnectionInfo iocIn in vConnections)
            {
                Stream s = null;

                try { s = IOConnection.OpenRead(iocIn); }
                catch(Exception exFile)
                {
                    MessageService.ShowWarning(iocIn.GetDisplayName(), exFile);
                    bAllSuccess = false;
                    continue;
                }

                if(s == null) { Debug.Assert(false); bAllSuccess = false; continue; }

                PwDatabase pwImp;
                if(bUseTempDb)
                {
                    pwImp = new PwDatabase();
                    pwImp.New(new IOConnectionInfo(), pwDatabase.MasterKey);
                    pwImp.MemoryProtection = pwDatabase.MemoryProtection.CloneDeep();
                }
                else pwImp = pwDatabase;

                if(fmtImp.RequiresKey && !bSynchronize)
                {
                    KeyPromptForm kpf = new KeyPromptForm();
                    kpf.InitEx(iocIn.GetDisplayName(), false);

                    if(kpf.ShowDialog() != DialogResult.OK) { s.Close(); continue; }

                    pwImp.MasterKey = kpf.CompositeKey;
                }
                else if(bSynchronize) pwImp.MasterKey = pwDatabase.MasterKey;

                slf.SetText((bSynchronize ? KPRes.Synchronizing : KPRes.ImportingStatusMsg) +
                    " " + iocIn.GetDisplayName(), LogStatusType.Info);

                try { fmtImp.Import(pwImp, s, slf); }
                catch(Exception excpFmt)
                {
                    string strMsgEx = excpFmt.Message;
                    if(bSynchronize)
                    {
                        strMsgEx += MessageService.NewParagraph +
                            KPRes.SynchronizingHint;
                    }

                    MessageService.ShowWarning(strMsgEx);

                    s.Close();
                    bAllSuccess = false;
                    continue;
                }

                s.Close();

                if(bUseTempDb)
                {
                    PwMergeMethod mm;
                    if(!fmtImp.SupportsUuids) mm = PwMergeMethod.CreateNewUuids;
                    else if(bSynchronize) mm = PwMergeMethod.Synchronize;
                    else
                    {
                        ImportMethodForm imf = new ImportMethodForm();
                        if(imf.ShowDialog() != DialogResult.OK)
                            continue;
//.........这里部分代码省略.........
开发者ID:jonbws,项目名称:strengthreport,代码行数:101,代码来源:ImportUtil.cs

示例7: MergeIn

        private void MergeIn(IFileStorage fileStorage, IOConnectionInfo ioc)
        {
            StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.SynchronizingDatabase));

            PwDatabase pwImp = new PwDatabase();
            PwDatabase pwDatabase = _app.GetDb().KpDatabase;
            pwImp.New(new IOConnectionInfo(), pwDatabase.MasterKey);
            pwImp.MemoryProtection = pwDatabase.MemoryProtection.CloneDeep();
            pwImp.MasterKey = pwDatabase.MasterKey;
            var stream = GetStreamForBaseFile(fileStorage, ioc);

            _app.GetDb().DatabaseFormat.PopulateDatabaseFromStream(pwImp, stream, null);

            pwDatabase.MergeIn(pwImp, PwMergeMethod.Synchronize, null);
        }
开发者ID:pythe,项目名称:wristpass,代码行数:15,代码来源:SaveDB.cs

示例8: Import

        public static bool? Import(PwDatabase pwDatabase, FileFormatProvider fmtImp,
			IOConnectionInfo[] vConnections, bool bSynchronize, IUIOperations uiOps,
			bool bForceSave, Form fParent)
        {
            if(pwDatabase == null) throw new ArgumentNullException("pwDatabase");
            if(!pwDatabase.IsOpen) return null;
            if(fmtImp == null) throw new ArgumentNullException("fmtImp");
            if(vConnections == null) throw new ArgumentNullException("vConnections");

            if(!AppPolicy.Try(AppPolicyId.Import)) return false;
            if(!fmtImp.TryBeginImport()) return false;

            bool bUseTempDb = (fmtImp.SupportsUuids || fmtImp.RequiresKey);
            bool bAllSuccess = true;

            // if(bSynchronize) { Debug.Assert(vFiles.Length == 1); }

            IStatusLogger dlgStatus;
            if(Program.Config.UI.ShowImportStatusDialog)
                dlgStatus = new OnDemandStatusDialog(false, fParent);
            else dlgStatus = new UIBlockerStatusLogger(fParent);

            dlgStatus.StartLogging(PwDefs.ShortProductName + " - " + (bSynchronize ?
                KPRes.Synchronizing : KPRes.ImportingStatusMsg), false);
            dlgStatus.SetText(bSynchronize ? KPRes.Synchronizing :
                KPRes.ImportingStatusMsg, LogStatusType.Info);

            if(vConnections.Length == 0)
            {
                try { fmtImp.Import(pwDatabase, null, dlgStatus); }
                catch(Exception exSingular)
                {
                    if((exSingular.Message != null) && (exSingular.Message.Length > 0))
                    {
                        // slf.SetText(exSingular.Message, LogStatusType.Warning);
                        MessageService.ShowWarning(exSingular);
                    }
                }

                dlgStatus.EndLogging();
                return true;
            }

            foreach(IOConnectionInfo iocIn in vConnections)
            {
                Stream s = null;

                try { s = IOConnection.OpenRead(iocIn); }
                catch(Exception exFile)
                {
                    // Transacted-file operations can leave behind intact *.kdbx.tmp files when
                    // the file rename doesn't get completed (can happen easily with slow/unreliable
                    // remote collections. We check if that's the case here and fix the situation if
                    // an kdbx file does *not* exist (to avoid possibly overwriting good data with bad
                    // data (i.e. an interrupted kdbx.tmp write).

                    // Make a copy of the IOC like FileTransactionEx.cs:Initialize does
                    IOConnectionInfo iocTemp = iocIn.CloneDeep();
                    iocTemp.Path += FileTransactionEx.StrTempSuffix;

                    if (IOConnection.FileExists(iocTemp) && !IOConnection.FileExists(iocIn))
                    {
                            // Try and rename iocTemp to ioc.Path, then retry file opening.
                            IOConnection.RenameFile(iocTemp, iocIn);
                            try { s = IOConnection.OpenRead(iocIn); }
                            catch(Exception nexFile)
                            {
                                    MessageService.ShowWarning(iocIn.GetDisplayName(), nexFile);
                                    bAllSuccess = false;
                                    continue;
                            }
                    }
                    else
                    {
                        MessageService.ShowWarning(iocIn.GetDisplayName(), exFile);
                        bAllSuccess = false;
                        continue;
                    }
                }
                if(s == null) { Debug.Assert(false); bAllSuccess = false; continue; }

                PwDatabase pwImp;
                if(bUseTempDb)
                {
                    pwImp = new PwDatabase();
                    pwImp.New(new IOConnectionInfo(), pwDatabase.MasterKey);
                    pwImp.MemoryProtection = pwDatabase.MemoryProtection.CloneDeep();
                }
                else pwImp = pwDatabase;

                if(fmtImp.RequiresKey && !bSynchronize)
                {
                    KeyPromptForm kpf = new KeyPromptForm();
                    kpf.InitEx(iocIn, false, true);

                    if(UIUtil.ShowDialogNotValue(kpf, DialogResult.OK)) { s.Close(); continue; }

                    pwImp.MasterKey = kpf.CompositeKey;
                    UIUtil.DestroyForm(kpf);
                }
//.........这里部分代码省略.........
开发者ID:rdealexb,项目名称:keepass,代码行数:101,代码来源:ImportUtil.cs


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