本文整理汇总了C#中PwGroup.TraverseTree方法的典型用法代码示例。如果您正苦于以下问题:C# PwGroup.TraverseTree方法的具体用法?C# PwGroup.TraverseTree怎么用?C# PwGroup.TraverseTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PwGroup
的用法示例。
在下文中一共展示了PwGroup.TraverseTree方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromGroupRecursive
public static PwObjectPool FromGroupRecursive(PwGroup pgRoot, bool bEntries)
{
if(pgRoot == null) throw new ArgumentNullException("pgRoot");
PwObjectPool p = new PwObjectPool();
if(!bEntries) p.m_dict[new PwUuidComparable(pgRoot.Uuid)] = pgRoot;
GroupHandler gh = delegate(PwGroup pg)
{
p.m_dict[new PwUuidComparable(pg.Uuid)] = pg;
return true;
};
EntryHandler eh = delegate(PwEntry pe)
{
p.m_dict[new PwUuidComparable(pe.Uuid)] = pe;
return true;
};
pgRoot.TraverseTree(TraversalMethod.PreOrder, bEntries ? null : gh,
bEntries ? eh : null);
return p;
}
示例2: BinPoolBuild
private void BinPoolBuild(PwGroup pgDataSource)
{
m_dictBinPool = new Dictionary<string, ProtectedBinary>();
if(pgDataSource == null) { Debug.Assert(false); return; }
EntryHandler eh = delegate(PwEntry pe)
{
foreach(PwEntry peHistory in pe.History)
{
BinPoolAdd(peHistory.Binaries);
}
BinPoolAdd(pe.Binaries);
return true;
};
pgDataSource.TraverseTree(TraversalMethod.PreOrder, null, eh);
}
示例3: WriteEntries
//.........这里部分代码省略.........
bool bWarnedOnce = false;
uint uGroupCount, uEntryCount, uEntriesSaved = 0;
pgRoot.GetCounts(true, out uGroupCount, out uEntryCount);
DateTime dtNeverExpire = KdbManager.GetNeverExpireTime();
EntryHandler eh = delegate(PwEntry pe)
{
KdbEntry e = new KdbEntry();
e.Uuid.Set(pe.Uuid.UuidBytes);
if(pe.ParentGroup != pgRoot)
e.GroupId = dictGroups[pe.ParentGroup];
else
{
e.GroupId = 1;
if((m_slLogger != null) && !bWarnedOnce)
{
m_slLogger.SetText(KdbPrefix +
KPRes.FormatNoRootEntries, LogStatusType.Warning);
bWarnedOnce = true;
}
if(dictGroups.Count == 0)
throw new Exception(KPRes.FormatNoSubGroupsInRoot);
}
e.ImageId = (uint)pe.IconId;
e.Title = pe.Strings.ReadSafe(PwDefs.TitleField);
e.UserName = pe.Strings.ReadSafe(PwDefs.UserNameField);
e.Password = pe.Strings.ReadSafe(PwDefs.PasswordField);
e.Url = pe.Strings.ReadSafe(PwDefs.UrlField);
string strNotes = pe.Strings.ReadSafe(PwDefs.NotesField);
ExportCustomStrings(pe, ref strNotes);
ExportAutoType(pe, ref strNotes);
ExportUrlOverride(pe, ref strNotes);
e.Additional = strNotes;
e.PasswordLength = (uint)e.Password.Length;
Debug.Assert(TimeUtil.PwTimeLength == 7);
e.CreationTime.Set(pe.CreationTime);
e.LastModificationTime.Set(pe.LastModificationTime);
e.LastAccessTime.Set(pe.LastAccessTime);
if(pe.Expires) e.ExpirationTime.Set(pe.ExpiryTime);
else e.ExpirationTime.Set(dtNeverExpire);
IntPtr hBinaryData = IntPtr.Zero;
if(pe.Binaries.UCount >= 1)
{
foreach(KeyValuePair<string, ProtectedBinary> kvp in pe.Binaries)
{
e.BinaryDescription = kvp.Key;
byte[] pbAttached = kvp.Value.ReadData();
e.BinaryDataLength = (uint)pbAttached.Length;
if(e.BinaryDataLength > 0)
{
hBinaryData = Marshal.AllocHGlobal((int)e.BinaryDataLength);
Marshal.Copy(pbAttached, 0, hBinaryData, (int)e.BinaryDataLength);
e.BinaryData = hBinaryData;
}
break;
}
if((pe.Binaries.UCount > 1) && (m_slLogger != null))
m_slLogger.SetText(KdbPrefix + KPRes.FormatOnlyOneAttachment + "\r\n\r\n" +
KPRes.Entry + ":\r\n" + KPRes.Title + ": " + e.Title + "\r\n" +
KPRes.UserName + ": " + e.UserName, LogStatusType.Warning);
}
bool bResult = mgr.AddEntry(ref e);
Marshal.FreeHGlobal(hBinaryData);
hBinaryData = IntPtr.Zero;
if(!bResult)
{
Debug.Assert(false);
throw new InvalidOperationException();
}
++uEntriesSaved;
if(m_slLogger != null)
if(!m_slLogger.SetProgress((100 * uEntriesSaved) / uEntryCount))
return false;
return true;
};
if(!pgRoot.TraverseTree(TraversalMethod.PreOrder, null, eh))
throw new InvalidOperationException();
}
示例4: EnsureParentGroupsExported
private static void EnsureParentGroupsExported(PwGroup pgRoot, ref uint uGroupIndex,
Dictionary<PwGroup, UInt32> dictGroups, DateTime dtNeverExpires,
KdbManager mgr)
{
bool bHasAtLeastOneGroup = (dictGroups.Count > 0);
uint uLocalIndex = uGroupIndex; // Local copy, can't use ref in delegate
EntryHandler eh = delegate(PwEntry pe)
{
PwGroup pg = pe.ParentGroup;
if(pg == null) { Debug.Assert(false); return true; }
if(bHasAtLeastOneGroup && (pg == pgRoot)) return true;
if(dictGroups.ContainsKey(pg)) return true;
WriteGroup(pg, pgRoot, ref uLocalIndex, dictGroups, dtNeverExpires,
mgr, true);
return true;
};
pgRoot.TraverseTree(TraversalMethod.PreOrder, null, eh);
uGroupIndex = uLocalIndex;
}
示例5: WriteGroups
private static Dictionary<PwGroup, UInt32> WriteGroups(KdbManager mgr,
PwGroup pgRoot)
{
Dictionary<PwGroup, UInt32> dictGroups = new Dictionary<PwGroup, uint>();
uint uGroupIndex = 1;
DateTime dtNeverExpire = KdbManager.GetNeverExpireTime();
GroupHandler gh = delegate(PwGroup pg)
{
WriteGroup(pg, pgRoot, ref uGroupIndex, dictGroups, dtNeverExpire,
mgr, false);
return true;
};
pgRoot.TraverseTree(TraversalMethod.PreOrder, gh, null);
Debug.Assert(dictGroups.Count == (int)(uGroupIndex - 1));
EnsureParentGroupsExported(pgRoot, ref uGroupIndex, dictGroups,
dtNeverExpire, mgr);
return dictGroups;
}
示例6: WriteGroups
private static Dictionary<PwGroup, UInt32> WriteGroups(Kdb3Manager mgr,
PwGroup pgRoot)
{
Dictionary<PwGroup, UInt32> dictGroups = new Dictionary<PwGroup, uint>();
uint uGroupIndex = 1;
DateTime dtNeverExpire = Kdb3Manager.GetNeverExpireTime();
GroupHandler gh = delegate(PwGroup pg)
{
if(pg == pgRoot) return true;
Kdb3Group grp = new Kdb3Group();
grp.GroupId = uGroupIndex;
dictGroups[pg] = grp.GroupId;
grp.ImageId = (uint)pg.IconId;
grp.Name = pg.Name;
grp.CreationTime.Set(pg.CreationTime);
grp.LastModificationTime.Set(pg.LastModificationTime);
grp.LastAccessTime.Set(pg.LastAccessTime);
if(pg.Expires)
grp.ExpirationTime.Set(pg.ExpiryTime);
else grp.ExpirationTime.Set(dtNeverExpire);
grp.Level = (ushort)(pg.GetLevel() - 1);
if(pg.IsExpanded) grp.Flags |= (uint)Kdb3GroupFlags.Expanded;
if(!mgr.AddGroup(ref grp))
{
Debug.Assert(false);
throw new InvalidOperationException();
}
++uGroupIndex;
return true;
};
pgRoot.TraverseTree(TraversalMethod.PreOrder, gh, null);
Debug.Assert(dictGroups.Count == (int)(uGroupIndex - 1));
return dictGroups;
}
示例7: WriteDocument
private void WriteDocument(PwGroup pgRoot)
{
Debug.Assert(m_xmlWriter != null);
if(m_xmlWriter == null) throw new InvalidOperationException();
uint uNumGroups, uNumEntries, uCurEntry = 0;
pgRoot.GetCounts(true, out uNumGroups, out uNumEntries);
m_xmlWriter.WriteStartDocument(true);
m_xmlWriter.WriteStartElement(ElemDocNode);
WriteMeta();
m_xmlWriter.WriteStartElement(ElemRoot);
StartGroup(pgRoot);
Stack<PwGroup> groupStack = new Stack<PwGroup>();
groupStack.Push(pgRoot);
GroupHandler gh = delegate(PwGroup pg)
{
Debug.Assert(pg != null);
if(pg == null) throw new ArgumentNullException("pg");
while(true)
{
if(pg.ParentGroup == groupStack.Peek())
{
groupStack.Push(pg);
StartGroup(pg);
break;
}
else
{
groupStack.Pop();
if(groupStack.Count <= 0) return false;
EndGroup();
}
}
return true;
};
EntryHandler eh = delegate(PwEntry pe)
{
Debug.Assert(pe != null);
WriteEntry(pe, false);
++uCurEntry;
if(m_slLogger != null)
if(!m_slLogger.SetProgress((100 * uCurEntry) / uNumEntries))
return false;
return true;
};
if(!pgRoot.TraverseTree(TraversalMethod.PreOrder, gh, eh))
throw new InvalidOperationException();
while(groupStack.Count > 1)
{
m_xmlWriter.WriteEndElement();
groupStack.Pop();
}
EndGroup();
WriteList(ElemDeletedObjects, m_pwDatabase.DeletedObjects);
m_xmlWriter.WriteEndElement(); // Root
m_xmlWriter.WriteEndElement(); // ElemDocNode
m_xmlWriter.WriteEndDocument();
}