本文整理汇总了C#中PwGroup.AddEntry方法的典型用法代码示例。如果您正苦于以下问题:C# PwGroup.AddEntry方法的具体用法?C# PwGroup.AddEntry怎么用?C# PwGroup.AddEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PwGroup
的用法示例。
在下文中一共展示了PwGroup.AddEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddKey
private void AddKey(PwDatabase database, PwGroup group, Key key)
{
var entry = new PwEntry(true, true);
group.AddEntry(entry, true);
entry.Strings.Set(PwDefs.TitleField, new ProtectedString(database.MemoryProtection.ProtectTitle, key.Type));
entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(database.MemoryProtection.ProtectPassword, key.Value));
entry.Strings.Set(PwDefs.NotesField, new ProtectedString(database.MemoryProtection.ProtectNotes, key.Description));
}
开发者ID:jeff2001,项目名称:MicrosoftKeyImporterPlugin,代码行数:10,代码来源:MicrosoftKeysExportFileFormatProvider.cs
示例2: Import
public static void Import(PwGroup pgStorage, Stream s, GxiProfile p,
PwDatabase pdContext, IStatusLogger sl)
{
if(pgStorage == null) throw new ArgumentNullException("pgStorage");
if(s == null) throw new ArgumentNullException("s");
if(p == null) throw new ArgumentNullException("p");
if(pdContext == null) throw new ArgumentNullException("pdContext");
// sl may be null
// Import into virtual group first, in order to realize
// an all-or-nothing import
PwGroup pgVirt = new PwGroup(true, true);
try { ImportPriv(pgVirt, s, p, pdContext, sl); }
finally { s.Close(); }
foreach(PwGroup pg in pgVirt.Groups)
pgStorage.AddGroup(pg, true);
foreach(PwEntry pe in pgVirt.Entries)
pgStorage.AddEntry(pe, true);
}
示例3: IsParentTest
public void IsParentTest()
{
PwDatabase db = new PwDatabase();
db.RootGroup = new PwGroup();
TreeManager um = new TreeManager();
userManager.Initialize( db );
rootGroup = db.RootGroup;
//groups are named like g<# of group>_<level in tree> level 0 is the copyRootGroup
PwGroup g1_1 = new PwGroup( true, true, "g1_1", PwIcon.Apple );
PwGroup g2_1 = new PwGroup( true, true, "g2_1", PwIcon.Apple );
PwGroup g3_2 = new PwGroup( true, true, "g3_2", PwIcon.Apple );
PwGroup g4_3 = new PwGroup( true, true, "g4_3", PwIcon.Apple );
rootGroup.AddGroup( g1_1, true );
rootGroup.AddGroup( g2_1, true );
g2_1.AddGroup( g3_2, true );
g3_2.AddGroup( g4_3, true );
PwEntry pe1_0 = new PwEntry( true, true );
PwEntry pe2_1 = new PwEntry( true, true );
PwEntry pe3_2 = new PwEntry( true, true );
PwEntry pe4_3 = new PwEntry( true, true );
rootGroup.AddEntry( pe1_0, true );
g2_1.AddEntry( pe2_1, true );
g3_2.AddEntry( pe3_2, true );
g4_3.AddEntry( pe4_3, true );
Assert.IsTrue( pe1_0.IsInsideParent( rootGroup ) );
Assert.IsTrue( pe4_3.IsInsideParent( rootGroup ) );
Assert.IsTrue( pe4_3.IsInsideParent( g2_1 ) );
Assert.IsTrue( g4_3.IsInsideParent( g2_1 ) );
Assert.IsTrue( g4_3.IsInsideParent( rootGroup ) );
Assert.IsFalse( pe1_0.IsInsideParent( g2_1 ) );
Assert.IsFalse( pe4_3.IsInsideParent( g1_1 ) );
Assert.IsFalse( pe2_1.IsInsideParent( g3_2 ) );
Assert.IsFalse( g2_1.IsInsideParent( g4_3 ) );
}
示例4: PasteEntriesFromClipboardPriv
private static void PasteEntriesFromClipboardPriv(PwDatabase pwDatabase,
PwGroup pgStorage)
{
if(!ClipboardUtil.ContainsData(ClipFormatEntries)) return;
byte[] pbEnc = ClipboardUtil.GetEncodedData(ClipFormatEntries, IntPtr.Zero);
if(pbEnc == null) { Debug.Assert(false); return; }
byte[] pbPlain;
if(WinUtil.IsWindows9x) pbPlain = pbEnc;
else pbPlain = ProtectedData.Unprotect(pbEnc, AdditionalEntropy,
DataProtectionScope.CurrentUser);
MemoryStream ms = new MemoryStream(pbPlain, false);
GZipStream gz = new GZipStream(ms, CompressionMode.Decompress);
List<PwEntry> vEntries = KdbxFile.ReadEntries(gz);
// Adjust protection settings and add entries
foreach(PwEntry pe in vEntries)
{
pe.Strings.EnableProtection(PwDefs.TitleField,
pwDatabase.MemoryProtection.ProtectTitle);
pe.Strings.EnableProtection(PwDefs.UserNameField,
pwDatabase.MemoryProtection.ProtectUserName);
pe.Strings.EnableProtection(PwDefs.PasswordField,
pwDatabase.MemoryProtection.ProtectPassword);
pe.Strings.EnableProtection(PwDefs.UrlField,
pwDatabase.MemoryProtection.ProtectUrl);
pe.Strings.EnableProtection(PwDefs.NotesField,
pwDatabase.MemoryProtection.ProtectNotes);
pgStorage.AddEntry(pe, true, true);
}
gz.Close(); ms.Close();
}
示例5: ImportGroup
private static void ImportGroup(XmlNode xmlNode, PwDatabase pwStorage,
PwGroup pg)
{
PwGroup pgSub = pg;
PwEntry pe = null;
foreach(XmlNode xmlChild in xmlNode)
{
if(xmlChild.Name == "A")
{
pe = new PwEntry(true, true);
pg.AddEntry(pe, true);
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
pwStorage.MemoryProtection.ProtectTitle,
XmlUtil.SafeInnerText(xmlChild)));
XmlNode xnUrl = xmlChild.Attributes.GetNamedItem("HREF");
if((xnUrl != null) && (xnUrl.Value != null))
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUrl, xnUrl.Value));
else { Debug.Assert(false); }
// pe.Strings.Set("RDF_ID", new ProtectedString(
// false, xmlChild.Attributes.GetNamedItem("ID").Value));
ImportIcon(xmlChild, pe, pwStorage);
XmlNode xnTags = xmlChild.Attributes.GetNamedItem("TAGS");
if((xnTags != null) && (xnTags.Value != null))
{
string[] vTags = xnTags.Value.Split(',');
foreach(string strTag in vTags)
{
if(string.IsNullOrEmpty(strTag)) continue;
pe.AddTag(strTag);
}
}
}
else if(xmlChild.Name == "DD")
{
if(pe != null)
ImportUtil.AppendToField(pe, PwDefs.NotesField,
XmlUtil.SafeInnerText(xmlChild).Trim(), pwStorage,
"\r\n", false);
else { Debug.Assert(false); }
}
else if(xmlChild.Name == "H3")
{
string strGroup = XmlUtil.SafeInnerText(xmlChild);
if(strGroup.Length == 0) { Debug.Assert(false); pgSub = pg; }
else
{
pgSub = new PwGroup(true, true, strGroup, PwIcon.Folder);
pg.AddGroup(pgSub, true);
}
}
else if(xmlChild.Name == "DL")
ImportGroup(xmlChild, pwStorage, pgSub);
else { Debug.Assert(false); }
}
}
示例6: GetAllUserRootNodesReturnsOnlyValidRootNodes
public void GetAllUserRootNodesReturnsOnlyValidRootNodes()
{
m_treeManager.Initialize(m_database);
PwEntry root1 = new PwEntry( true, true );
PwEntry root2 = new PwEntry( true, true );
PwEntry root3 = new PwEntry( true, true );
PwEntry normalEntry1 = new PwEntry( true, true );
PwEntry normalEntry2 = new PwEntry( true, true );
PwGroup level1 = new PwGroup();
//initial data
root1.Strings.Set(KeeShare.KeeShare.UuidLinkField, new ProtectedString( false, root1.Uuid.ToHexString() ) );
root2.Strings.Set(KeeShare.KeeShare.UuidLinkField, new ProtectedString( false, root2.Uuid.ToHexString() ) );
root3.Strings.Set(KeeShare.KeeShare.UuidLinkField, new ProtectedString( false, root3.Uuid.ToHexString() ) );
m_database.RootGroup.AddEntry( root1, true );
m_database.RootGroup.AddEntry( root2, true );
m_database.RootGroup.AddEntry( normalEntry1, true );
m_database.RootGroup.AddGroup( level1, true );
level1.AddEntry( normalEntry2, true );
level1.AddEntry( root3, true );
PwObjectList<PwEntry> rootNodes = m_database.GetAllUserNodes();
Assert.AreEqual( 3, rootNodes.UCount );
Assert.AreEqual( root1, rootNodes.GetAt( 0 ) );
Assert.AreEqual( root2, rootNodes.GetAt( 1 ) );
Assert.AreEqual( root3, rootNodes.GetAt( 2 ) );
}
示例7: AddObject
private static void AddObject(PwGroup pgStorage, JsonObject jObject,
PwDatabase pwContext, bool bCreateSubGroups)
{
if(jObject.Items.ContainsKey(m_strGroup))
{
JsonArray jArray = jObject.Items[m_strGroup].Value as JsonArray;
if(jArray == null) { Debug.Assert(false); return; }
PwGroup pgNew;
if(bCreateSubGroups)
{
pgNew = new PwGroup(true, true);
pgStorage.AddGroup(pgNew, true);
if(jObject.Items.ContainsKey("title"))
pgNew.Name = ((jObject.Items["title"].Value != null) ?
jObject.Items["title"].Value.ToString() : string.Empty);
}
else pgNew = pgStorage;
foreach(JsonValue jValue in jArray.Values)
{
JsonObject objSub = jValue.Value as JsonObject;
if(objSub != null) AddObject(pgNew, objSub, pwContext, true);
else { Debug.Assert(false); }
}
return;
}
PwEntry pe = new PwEntry(true, true);
SetString(pe, "Index", false, jObject, "index");
SetString(pe, PwDefs.TitleField, pwContext.MemoryProtection.ProtectTitle,
jObject, "title");
SetString(pe, "ID", false, jObject, "id");
SetString(pe, PwDefs.UrlField, pwContext.MemoryProtection.ProtectUrl,
jObject, "uri");
SetString(pe, "CharSet", false, jObject, "charset");
if((pe.Strings.ReadSafe(PwDefs.TitleField).Length > 0) ||
(pe.Strings.ReadSafe(PwDefs.UrlField).Length > 0))
pgStorage.AddEntry(pe, true);
}
示例8: MoveOrCopySelectedEntries
private void MoveOrCopySelectedEntries(PwGroup pgTo, DragDropEffects e)
{
PwEntry[] vSelected = GetSelectedEntries();
if((vSelected == null) || (vSelected.Length == 0)) return;
PwGroup pgSafeView = (m_pgActiveAtDragStart ?? new PwGroup());
bool bFullUpdateView = false;
List<PwEntry> vNowInvisible = new List<PwEntry>();
if(e == DragDropEffects.Move)
{
foreach(PwEntry pe in vSelected)
{
PwGroup pgParent = pe.ParentGroup;
if(pgParent == pgTo) continue;
if(pgParent != null) // Remove from parent
{
if(!pgParent.Entries.Remove(pe)) { Debug.Assert(false); }
}
pgTo.AddEntry(pe, true, true);
if(pe.IsContainedIn(pgSafeView)) bFullUpdateView = true;
else vNowInvisible.Add(pe);
}
}
else if(e == DragDropEffects.Copy)
{
foreach(PwEntry pe in vSelected)
{
PwEntry peCopy = pe.Duplicate();
pgTo.AddEntry(peCopy, true, true);
if(peCopy.IsContainedIn(pgSafeView)) bFullUpdateView = true;
}
}
else { Debug.Assert(false); }
if(!bFullUpdateView)
{
RemoveEntriesFromList(vNowInvisible, true);
UpdateUI(false, null, true, m_pgActiveAtDragStart, false, null, true);
}
else UpdateUI(false, null, true, m_pgActiveAtDragStart, true, null, true);
m_pgActiveAtDragStart = null;
}
示例9: GetCurrentEntries
internal PwGroup GetCurrentEntries()
{
PwGroup pg = new PwGroup(true, true);
pg.IsVirtual = true;
if(!m_lvEntries.ShowGroups)
{
foreach(ListViewItem lvi in m_lvEntries.Items)
pg.AddEntry(((PwListItem)lvi.Tag).Entry, false);
}
else // Groups
{
foreach(ListViewGroup lvg in m_lvEntries.Groups)
{
foreach(ListViewItem lvi in lvg.Items)
pg.AddEntry(((PwListItem)lvi.Tag).Entry, false);
}
}
return pg;
}
示例10: SetGrouping
private void SetGrouping(AceListGrouping lgPrimary)
{
Debug.Assert(((int)lgPrimary & ~(int)AceListGrouping.Primary) == 0);
if((int)lgPrimary == (Program.Config.MainWindow.ListGrouping &
(int)AceListGrouping.Primary))
return;
Program.Config.MainWindow.ListGrouping &= ~(int)AceListGrouping.Primary;
Program.Config.MainWindow.ListGrouping |= (int)lgPrimary;
Debug.Assert((Program.Config.MainWindow.ListGrouping &
(int)AceListGrouping.Primary) == (int)lgPrimary);
UpdateUI();
if(m_mf == null) { Debug.Assert(false); return; }
PwDatabase pd = m_mf.ActiveDatabase;
PwGroup pg = m_mf.GetCurrentEntries();
if((pd == null) || !pd.IsOpen || (pg == null)) return; // No assert
PwObjectList<PwEntry> pwl = pg.GetEntries(true);
if((pwl.UCount > 0) && EntryUtil.EntriesHaveSameParent(pwl))
m_mf.UpdateUI(false, null, true, pwl.GetAt(0).ParentGroup,
true, null, false);
else
{
EntryUtil.ReorderEntriesAsInDatabase(pwl, pd); // Requires open DB
pg = new PwGroup(true, true);
pg.IsVirtual = true;
foreach(PwEntry pe in pwl) pg.AddEntry(pe, false);
m_mf.UpdateUI(false, null, false, null, true, pg, false);
}
}
示例11: ImportEntry
private static void ImportEntry(string strData, PwGroup pg, PwDatabase pd,
bool bForceNotes)
{
PwEntry pe = new PwEntry(true, true);
pg.AddEntry(pe, true);
string[] v = strData.Split('\n');
if(v.Length == 0) { Debug.Assert(false); return; }
ImportUtil.AppendToField(pe, PwDefs.TitleField, v[0].Trim(), pd);
int n = v.Length;
for(int j = n - 1; j >= 0; --j)
{
if(v[j].Length > 0) break;
--n;
}
bool bInNotes = bForceNotes;
for(int i = 1; i < n; ++i)
{
string str = v[i];
int iSep = str.IndexOf(':');
if(iSep <= 0) bInNotes = true;
if(bInNotes)
{
if(str.Length == 0)
ImportUtil.AppendToField(pe, PwDefs.NotesField,
Environment.NewLine, pd, string.Empty, false);
else
ImportUtil.AppendToField(pe, PwDefs.NotesField,
str, pd, Environment.NewLine, false);
}
else
{
string strRawKey = str.Substring(0, iSep);
string strValue = str.Substring(iSep + 1).Trim();
string strKey = ImportUtil.MapNameToStandardField(strRawKey, false);
if(string.IsNullOrEmpty(strKey)) strKey = strRawKey;
bool bMultiLine = ((strKey == PwDefs.NotesField) ||
!PwDefs.IsStandardField(strKey));
ImportUtil.AppendToField(pe, strKey, strValue, pd,
(bMultiLine ? Environment.NewLine : ", "), false);
}
}
}
示例12: AddEntry
private static void AddEntry(PwGroup pg, Dictionary<string, string> dItems,
ref bool bInNotes, ref DateTime? dtExpire)
{
if(dItems.Count > 0)
{
PwEntry pe = new PwEntry(true, true);
pg.AddEntry(pe, true);
foreach(KeyValuePair<string, string> kvp in dItems)
pe.Strings.Set(kvp.Key, new ProtectedString(false, kvp.Value));
if(dtExpire.HasValue)
{
pe.Expires = true;
pe.ExpiryTime = dtExpire.Value;
}
}
bInNotes = false;
dtExpire = null;
}
示例13: AddEntry
private static void AddEntry(PwGroup pg, Dictionary<string, string> dItems,
ref bool bInNotes)
{
if(dItems.Count == 0) return;
PwEntry pe = new PwEntry(true, true);
pg.AddEntry(pe, true);
foreach(KeyValuePair<string, string> kvp in dItems)
pe.Strings.Set(kvp.Key, new ProtectedString(false, kvp.Value));
bInNotes = false;
}
示例14: AddCard
private static void AddCard(PwGroup pgParent, HspCard hspCard)
{
if(hspCard == null) { Debug.Assert(false); return; }
PwEntry pe = new PwEntry(true, true);
pgParent.AddEntry(pe, true);
if(!string.IsNullOrEmpty(hspCard.Name))
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(false, hspCard.Name));
if(!string.IsNullOrEmpty(hspCard.Note))
pe.Strings.Set(PwDefs.NotesField, new ProtectedString(false, hspCard.Note));
if(hspCard.Fields == null) return;
foreach(HspField fld in hspCard.Fields)
{
if(fld == null) { Debug.Assert(false); continue; }
if(string.IsNullOrEmpty(fld.Name) || string.IsNullOrEmpty(fld.Value)) continue;
string strKey = ImportUtil.MapNameToStandardField(fld.Name, true);
if(string.IsNullOrEmpty(strKey)) strKey = fld.Name;
string strValue = pe.Strings.ReadSafe(strKey);
if(strValue.Length > 0) strValue += ", ";
strValue += fld.Value;
pe.Strings.Set(strKey, new ProtectedString(false, strValue));
}
}
示例15: OnFileNew
private void OnFileNew(object sender, EventArgs e)
{
if(!AppPolicy.Try(AppPolicyId.NewFile)) return;
if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;
SaveFileDialogEx sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter(
AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1,
AppDefs.FileExtension.FileExt, AppDefs.FileDialogContext.Database);
GlobalWindowManager.AddDialog(sfd.FileDialog);
DialogResult dr = sfd.ShowDialog();
GlobalWindowManager.RemoveDialog(sfd.FileDialog);
string strPath = sfd.FileName;
if(dr != DialogResult.OK) return;
KeyCreationForm kcf = new KeyCreationForm();
kcf.InitEx(IOConnectionInfo.FromPath(strPath), true);
dr = kcf.ShowDialog();
if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
{
UIUtil.DestroyForm(kcf);
return;
}
PwDocument dsPrevActive = m_docMgr.ActiveDocument;
PwDatabase pd = m_docMgr.CreateNewDocument(true).Database;
pd.New(IOConnectionInfo.FromPath(strPath), kcf.CompositeKey);
UIUtil.DestroyForm(kcf);
DatabaseSettingsForm dsf = new DatabaseSettingsForm();
dsf.InitEx(true, pd);
dr = dsf.ShowDialog();
if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
{
m_docMgr.CloseDatabase(pd);
try { m_docMgr.ActiveDocument = dsPrevActive; }
catch(Exception) { } // Fails if no database is open now
UpdateUI(false, null, true, null, true, null, false);
UIUtil.DestroyForm(dsf);
return;
}
UIUtil.DestroyForm(dsf);
// AutoEnableVisualHiding();
PwGroup pg = new PwGroup(true, true, KPRes.General, PwIcon.Folder);
// for(int i = 0; i < 30; ++i) pg.CustomData.Set("Test" + i.ToString("D2"), "12345");
pd.RootGroup.AddGroup(pg, true);
pg = new PwGroup(true, true, KPRes.WindowsOS, PwIcon.DriveWindows);
pd.RootGroup.AddGroup(pg, true);
pg = new PwGroup(true, true, KPRes.Network, PwIcon.NetworkServer);
pd.RootGroup.AddGroup(pg, true);
pg = new PwGroup(true, true, KPRes.Internet, PwIcon.World);
// pg.CustomData.Set("GroupTestItem", "TestValue");
pd.RootGroup.AddGroup(pg, true);
pg = new PwGroup(true, true, KPRes.EMail, PwIcon.EMail);
pd.RootGroup.AddGroup(pg, true);
pg = new PwGroup(true, true, KPRes.Homebanking, PwIcon.Homebanking);
pd.RootGroup.AddGroup(pg, true);
PwEntry pe = new PwEntry(true, true);
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
KPRes.SampleEntry));
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
KPRes.UserName));
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
PwDefs.HomepageUrl));
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
KPRes.Password));
pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
KPRes.Notes));
pe.AutoType.Add(new AutoTypeAssociation(KPRes.TargetWindow,
@"{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}"));
// for(int i = 0; i < 30; ++i) pe.CustomData.Set("Test" + i.ToString("D2"), "12345");
pd.RootGroup.AddEntry(pe, true);
pe = new PwEntry(true, true);
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
KPRes.SampleEntry + " #2"));
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
"Michael321"));
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
@"http://keepass.info/help/kb/testform.html"));
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
"12345"));
pe.AutoType.Add(new AutoTypeAssociation("*Test Form - KeePass*", string.Empty));
pd.RootGroup.AddEntry(pe, true);
#if DEBUG
Random r = Program.GlobalRandom;
long lTimeMin = (new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc)).ToBinary();
//.........这里部分代码省略.........