本文整理汇总了C#中KeePassLib.PwDatabase.MergeIn方法的典型用法代码示例。如果您正苦于以下问题:C# PwDatabase.MergeIn方法的具体用法?C# PwDatabase.MergeIn怎么用?C# PwDatabase.MergeIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeePassLib.PwDatabase
的用法示例。
在下文中一共展示了PwDatabase.MergeIn方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Import
//.........这里部分代码省略.........
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)
{
PwMergeMethod mm;
if(!fmtImp.SupportsUuids) mm = PwMergeMethod.CreateNewUuids;
else if(bSynchronize) mm = PwMergeMethod.Synchronize;
else
{
ImportMethodForm imf = new ImportMethodForm();
if(UIUtil.ShowDialogNotValue(imf, DialogResult.OK)) continue;
mm = imf.MergeMethod;
UIUtil.DestroyForm(imf);
}
// slf.SetText(KPRes.MergingData, LogStatusType.Info);
try { pwDatabase.MergeIn(pwImp, mm, dlgStatus); }
catch(Exception exMerge)
{
MessageService.ShowWarning(iocIn.GetDisplayName(),
KPRes.ImportFailed, exMerge);
bAllSuccess = false;
continue;
}
}
}
dlgStatus.EndLogging();
if(bSynchronize && bAllSuccess)
{
Debug.Assert(uiOps != null);
if(uiOps == null) throw new ArgumentNullException("uiOps");
if(uiOps.UIFileSave(bForceSave))
{
foreach(IOConnectionInfo ioc in vConnections)
{
try
{
if(ioc.Path != pwDatabase.IOConnectionInfo.Path)
{
if(pwDatabase.IOConnectionInfo.IsLocalFile() &&
ioc.IsLocalFile())
{
File.Copy(pwDatabase.IOConnectionInfo.Path,
ioc.Path, true);
}
else pwDatabase.SaveAs(ioc, false, null);
}
else { } // No assert (sync on save)
Program.MainForm.FileMruList.AddItem(ioc.GetDisplayName(),
ioc.CloneDeep(), true);
}
catch(Exception exSync)
{
MessageService.ShowWarning(KPRes.SyncFailed,
pwDatabase.IOConnectionInfo.GetDisplayName() +
MessageService.NewLine + ioc.GetDisplayName(), exSync);
bAllSuccess = false;
continue;
}
}
}
else
{
MessageService.ShowWarning(KPRes.SyncFailed,
pwDatabase.IOConnectionInfo.GetDisplayName());
bAllSuccess = false;
}
}
return bAllSuccess;
}
示例2: 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;
}
示例3: PerformXmlReplace
private static void PerformXmlReplace(PwDatabase pd, XmlReplaceOptions opt,
IStatusLogger sl)
{
if(opt.SelectNodesXPath.Length == 0) return;
if(opt.Operation == XmlReplaceOp.None) return;
bool bRemove = (opt.Operation == XmlReplaceOp.RemoveNodes);
bool bReplace = (opt.Operation == XmlReplaceOp.ReplaceData);
bool bMatchCase = ((opt.Flags & XmlReplaceFlags.CaseSensitive) != XmlReplaceFlags.None);
bool bRegex = ((opt.Flags & XmlReplaceFlags.Regex) != XmlReplaceFlags.None);
Regex rxFind = null;
if(bReplace && bRegex)
rxFind = new Regex(opt.FindText, (bMatchCase ? RegexOptions.None :
RegexOptions.IgnoreCase));
EnsureStandardFieldsExist(pd);
KdbxFile kdbxOrg = new KdbxFile(pd);
MemoryStream msOrg = new MemoryStream();
kdbxOrg.Save(msOrg, null, KdbxFormat.PlainXml, sl);
byte[] pbXml = msOrg.ToArray();
msOrg.Close();
string strXml = StrUtil.Utf8.GetString(pbXml);
XmlDocument xd = new XmlDocument();
xd.LoadXml(strXml);
XPathNavigator xpNavRoot = xd.CreateNavigator();
XPathNodeIterator xpIt = xpNavRoot.Select(opt.SelectNodesXPath);
// XPathNavigators must be cloned to make them independent
List<XPathNavigator> lNodes = new List<XPathNavigator>();
while(xpIt.MoveNext()) lNodes.Add(xpIt.Current.Clone());
if(lNodes.Count == 0) return;
for(int i = lNodes.Count - 1; i >= 0; --i)
{
if((sl != null) && !sl.ContinueWork()) return;
XPathNavigator xpNav = lNodes[i];
if(bRemove) xpNav.DeleteSelf();
else if(bReplace) ApplyReplace(xpNav, opt, rxFind);
else { Debug.Assert(false); } // Unknown action
}
MemoryStream msMod = new MemoryStream();
XmlWriterSettings xws = new XmlWriterSettings();
xws.Encoding = StrUtil.Utf8;
xws.Indent = true;
xws.IndentChars = "\t";
XmlWriter xw = XmlWriter.Create(msMod, xws);
xd.Save(xw);
byte[] pbMod = msMod.ToArray();
msMod.Close();
PwDatabase pdMod = new PwDatabase();
msMod = new MemoryStream(pbMod, false);
try
{
KdbxFile kdbxMod = new KdbxFile(pdMod);
kdbxMod.Load(msMod, KdbxFormat.PlainXml, sl);
}
catch(Exception)
{
throw new Exception(KPRes.XmlModInvalid + MessageService.NewParagraph +
KPRes.OpAborted + MessageService.NewParagraph +
KPRes.DbNoModBy.Replace(@"{PARAM}", @"'" + KPRes.XmlReplace + @"'"));
}
finally { msMod.Close(); }
PrepareModDbForMerge(pdMod, pd);
pd.Modified = true;
pd.UINeedsIconUpdate = true;
pd.MergeIn(pdMod, PwMergeMethod.Synchronize, sl);
}
示例4: MergeIn
protected void MergeIn(PwDatabase target, PwDatabase source)
{
//remember stats of destDB to guess if we merged in something
//maybe we only look for the lastChanged entry
var clone = source.CloneDeep(target.RootGroup);
clone.Register(KeeShare.TemporaryDatabaseId, KeeShare.TemporaryDatabaseTag);
var cyclicEntries = new List<PwEntry>();
foreach (var cloneEntry in clone.RootGroup.GetEntries(true).ToList())
{
if(cloneEntry.HasExportSource(target.RootGroup.Uuid.ToHexString()))
{
cloneEntry.DeleteFrom(cloneEntry.ParentGroup);
cyclicEntries.Add(cloneEntry);
}
}
Console.WriteLine("Prevent import of nodes which are exported from here: " + String.Join(",", cyclicEntries.Select(e => e.GetTitle()).ToArray()));
DateTime lastChange = DateTime.MinValue;
foreach (var entry in target.RootGroup.GetEntries(true))
{
if (entry.LastModificationTime.Ticks > lastChange.Ticks)
{
lastChange = entry.LastModificationTime;
}
}
target.MergeIn(clone, PwMergeMethod.Synchronize);
foreach (var entry in source.RootGroup.GetEntries(true))
{
if (entry.LastModificationTime.Ticks > lastChange.Ticks)
{
//set the modified flag of the database true, so the uiUpdate knows which tab should be marked as changed
target.Modified = true;
}
}
if (Imported != null) Imported.Invoke(this, target.RootGroup);
}
示例5: PerformImport
//.........这里部分代码省略.........
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;
mm = imf.MergeMethod;
}
slf.SetText(KPRes.MergingData, LogStatusType.Info);
try { pwDatabase.MergeIn(pwImp, mm); }
catch(Exception exMerge)
{
MessageService.ShowWarning(iocIn.GetDisplayName(),
KPRes.ImportFailed, exMerge);
bAllSuccess = false;
continue;
}
}
}
slf.EndLogging(); slf.Close();
if(bSynchronize && bAllSuccess)
{
Debug.Assert(uiOps != null);
if(uiOps == null) throw new ArgumentNullException("uiOps");
if(uiOps.UIFileSave(bForceSave))
{
foreach(IOConnectionInfo ioc in vConnections)
{
try
{
if(pwDatabase.IOConnectionInfo.IsLocalFile())
{
if((pwDatabase.IOConnectionInfo.Path != ioc.Path) &&
ioc.IsLocalFile())
{
File.Copy(pwDatabase.IOConnectionInfo.Path,
ioc.Path, true);
}
}
else pwDatabase.SaveAs(ioc, false, null);
}
catch(Exception exSync)
{
MessageService.ShowWarning(KPRes.SyncFailed,
pwDatabase.IOConnectionInfo.GetDisplayName() +
MessageService.NewLine + ioc.GetDisplayName(), exSync);
bAllSuccess = false;
continue;
}
}
}
else
{
MessageService.ShowWarning(KPRes.SyncFailed,
pwDatabase.IOConnectionInfo.GetDisplayName());
bAllSuccess = false;
}
}
else if(bSynchronize) // Synchronized but not successfully imported
{
MessageService.ShowWarning(KPRes.SyncFailed,
pwDatabase.IOConnectionInfo.GetDisplayName());
bAllSuccess = false;
}
return bAllSuccess;
}
示例6: Import
//.........这里部分代码省略.........
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)
{
PwMergeMethod mm;
if(!fmtImp.SupportsUuids) mm = PwMergeMethod.CreateNewUuids;
else if(bSynchronize) mm = PwMergeMethod.Synchronize;
else
{
ImportMethodForm imf = new ImportMethodForm();
if(UIUtil.ShowDialogNotValue(imf, DialogResult.OK)) continue;
mm = imf.MergeMethod;
UIUtil.DestroyForm(imf);
}
try { pwDatabase.MergeIn(pwImp, mm, dlgStatus); }
catch(Exception exMerge)
{
MessageService.ShowWarning(iocIn.GetDisplayName(),
KPRes.ImportFailed, exMerge);
bAllSuccess = false;
continue;
}
}
}
if(bSynchronize && bAllSuccess)
{
Debug.Assert(uiOps != null);
if(uiOps == null) throw new ArgumentNullException("uiOps");
dlgStatus.SetText(KPRes.Synchronizing + " (" +
KPRes.SavingDatabase + ")", LogStatusType.Info);
MainForm mf = Program.MainForm; // Null for KPScript
if(mf != null)
{
try { mf.DocumentManager.ActiveDatabase = pwDatabase; }
catch(Exception) { Debug.Assert(false); }
}
if(uiOps.UIFileSave(bForceSave))
{
foreach(IOConnectionInfo ioc in vConnections)
{
try
{