本文整理汇总了C#中PwObjectList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# PwObjectList.Add方法的具体用法?C# PwObjectList.Add怎么用?C# PwObjectList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PwObjectList
的用法示例。
在下文中一共展示了PwObjectList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformGlobal
public static bool PerformGlobal(List<PwDatabase> vSources,
ImageList ilIcons)
{
Debug.Assert(vSources != null); if(vSources == null) return false;
IntPtr hWnd;
string strWindow;
try
{
hWnd = NativeMethods.GetForegroundWindow();
strWindow = NativeMethods.GetWindowText(hWnd);
}
catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; }
if((strWindow == null) || (strWindow.Length == 0)) return false;
PwObjectList<PwEntry> m_vList = new PwObjectList<PwEntry>();
DateTime dtNow = DateTime.Now;
EntryHandler eh = delegate(PwEntry pe)
{
// Ignore expired entries
if(pe.Expires && (pe.ExpiryTime < dtNow)) return true;
if(GetSequenceForWindow(pe, strWindow, true) != null)
m_vList.Add(pe);
return true;
};
foreach(PwDatabase pwSource in vSources)
{
if(pwSource.IsOpen == false) continue;
pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);
}
if(m_vList.UCount == 1)
AutoType.PerformInternal(m_vList.GetAt(0), strWindow);
else if(m_vList.UCount > 1)
{
EntryListForm elf = new EntryListForm();
elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort,
KPRes.AutoTypeEntrySelectionDescLong,
Properties.Resources.B48x48_KGPG_Key2, ilIcons, m_vList);
elf.EnsureForeground = true;
if(elf.ShowDialog() == DialogResult.OK)
{
try { NativeMethods.EnsureForegroundWindow(hWnd); }
catch(Exception) { Debug.Assert(false); }
if(elf.SelectedEntry != null)
AutoType.PerformInternal(elf.SelectedEntry, strWindow);
}
}
return true;
}
示例2: CreateEntry
private static void CreateEntry(PwEntry peTemplate)
{
if(peTemplate == null) { Debug.Assert(false); return; }
PwDatabase pd = Program.MainForm.ActiveDatabase;
if(pd == null) { Debug.Assert(false); return; }
if(pd.IsOpen == false) { Debug.Assert(false); return; }
PwGroup pgContainer = Program.MainForm.GetSelectedGroup();
if(pgContainer == null) pgContainer = pd.RootGroup;
PwEntry pe = peTemplate.Duplicate();
if(EntryTemplates.EntryCreating != null)
EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
peTemplate.CloneDeep(), pe));
PwEntryForm pef = new PwEntryForm();
pef.InitEx(pe, PwEditMode.AddNewEntry, pd, Program.MainForm.ClientIcons,
false, true);
if(UIUtil.ShowDialogAndDestroy(pef) == DialogResult.OK)
{
pgContainer.AddEntry(pe, true, true);
MainForm mf = Program.MainForm;
if(mf != null)
{
mf.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
true, null, true);
PwObjectList<PwEntry> vSelect = new PwObjectList<PwEntry>();
vSelect.Add(pe);
mf.SelectEntries(vSelect, true, true);
mf.EnsureVisibleEntry(pe.Uuid);
mf.UpdateUI(false, null, false, null, false, null, false);
}
else { Debug.Assert(false); }
if(EntryTemplates.EntryCreated != null)
EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
peTemplate.CloneDeep(), pe));
}
else Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
pd.UINeedsIconUpdate, null, false);
}
示例3: ReorderEntriesAsInDatabase
public static void ReorderEntriesAsInDatabase(PwObjectList<PwEntry> v,
PwDatabase pd)
{
if((v == null) || (pd == null)) { Debug.Assert(false); return; }
if(pd.RootGroup == null) { Debug.Assert(false); return; } // DB must be open
PwObjectList<PwEntry> vRem = v.CloneShallow();
v.Clear();
EntryHandler eh = delegate(PwEntry pe)
{
int p = vRem.IndexOf(pe);
if(p >= 0)
{
v.Add(pe);
vRem.RemoveAt((uint)p);
}
return true;
};
pd.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);
foreach(PwEntry peRem in vRem) v.Add(peRem); // Entries not found
}
示例4: ReadDeletedObjects
/*
private void ReadDeletedObjects(XmlNode xmlNode, PwObjectList<PwDeletedObject> list)
{
ProcessNode(xmlNode);
foreach(XmlNode xmlChild in xmlNode.ChildNodes)
{
if(xmlChild.Name == ElemDeletedObject)
list.Add(ReadDeletedObject(xmlChild));
else ReadUnknown(xmlChild);
}
}
private PwDeletedObject ReadDeletedObject(XmlNode xmlNode)
{
ProcessNode(xmlNode);
PwDeletedObject pdo = new PwDeletedObject();
foreach(XmlNode xmlChild in xmlNode.ChildNodes)
{
if(xmlChild.Name == ElemUuid)
pdo.Uuid = ReadUuid(xmlChild);
else if(xmlChild.Name == ElemDeletionTime)
pdo.DeletionTime = ReadTime(xmlChild);
else ReadUnknown(xmlChild);
}
return pdo;
}
*/
private void ReadHistory(XmlNode xmlNode, PwObjectList<PwEntry> plStorage)
{
ProcessNode(xmlNode);
foreach(XmlNode xmlChild in xmlNode.ChildNodes)
{
if(xmlChild.Name == ElemEntry)
{
plStorage.Add(ReadEntry(xmlChild));
}
else ReadUnknown(xmlChild);
}
}
示例5: OnEntryViewLinkClicked
private void OnEntryViewLinkClicked(object sender, LinkClickedEventArgs e)
{
string strLink = e.LinkText;
if(string.IsNullOrEmpty(strLink)) { Debug.Assert(false); return; }
PwEntry pe = GetSelectedEntry(false);
ProtectedBinary pb = ((pe != null) ? pe.Binaries.Get(strLink) : null);
string strEntryUrl = string.Empty;
if(pe != null)
strEntryUrl = SprEngine.Compile(pe.Strings.ReadSafe(PwDefs.UrlField),
GetEntryListSprContext(pe, m_docMgr.SafeFindContainerOf(pe)));
if((pe != null) && (pe.ParentGroup != null) &&
(pe.ParentGroup.Name == strLink))
{
UpdateUI(false, null, true, pe.ParentGroup, true, null, false);
EnsureVisibleSelected(false);
ResetDefaultFocus(m_lvEntries);
}
else if(strEntryUrl == strLink)
PerformDefaultUrlAction(null, false);
else if(pb != null)
ExecuteBinaryEditView(strLink, pb);
else if(strLink.StartsWith(SprEngine.StrRefStart, StrUtil.CaseIgnoreCmp) &&
strLink.EndsWith(SprEngine.StrRefEnd, StrUtil.CaseIgnoreCmp))
{
// If multiple references are amalgamated, only use first one
string strFirstRef = strLink;
int iEnd = strLink.IndexOf(SprEngine.StrRefEnd, StrUtil.CaseIgnoreCmp);
if(iEnd != (strLink.Length - SprEngine.StrRefEnd.Length))
strFirstRef = strLink.Substring(0, iEnd + 1);
char chScan, chWanted;
PwEntry peRef = SprEngine.FindRefTarget(strFirstRef, GetEntryListSprContext(
pe, m_docMgr.SafeFindContainerOf(pe)), out chScan, out chWanted);
if(peRef != null)
{
UpdateUI(false, null, true, peRef.ParentGroup, true, null,
false, m_lvEntries);
PwObjectList<PwEntry> lSel = new PwObjectList<PwEntry>();
lSel.Add(peRef);
SelectEntries(lSel, true, true);
EnsureVisibleSelected(false);
ShowEntryDetails(peRef);
}
}
else WinUtil.OpenUrl(strLink, pe);
}
示例6: OnEntryDuplicate
private void OnEntryDuplicate(object sender, EventArgs e)
{
PwDatabase pd = m_docMgr.ActiveDatabase;
PwGroup pgSelected = GetSelectedGroup();
PwEntry[] vSelected = GetSelectedEntries();
if((vSelected == null) || (vSelected.Length == 0)) return;
DuplicationForm dlg = new DuplicationForm();
if(UIUtil.ShowDialogAndDestroy(dlg) != DialogResult.OK) return;
PwObjectList<PwEntry> vNewEntries = new PwObjectList<PwEntry>();
foreach(PwEntry pe in vSelected)
{
PwEntry peNew = pe.CloneDeep();
peNew.SetUuid(new PwUuid(true), true); // Create new UUID
if(dlg.AppendCopyToTitles && (pd != null))
{
string strTitle = peNew.Strings.ReadSafe(PwDefs.TitleField);
peNew.Strings.Set(PwDefs.TitleField, new ProtectedString(
pd.MemoryProtection.ProtectTitle, strTitle + " - " +
KPRes.CopyOfItem));
}
if(dlg.ReplaceDataByFieldRefs && (pd != null))
{
string strUser = @"{REF:[email protected]:" + pe.Uuid.ToHexString() + @"}";
peNew.Strings.Set(PwDefs.UserNameField, new ProtectedString(
pd.MemoryProtection.ProtectUserName, strUser));
string strPw = @"{REF:[email protected]:" + pe.Uuid.ToHexString() + @"}";
peNew.Strings.Set(PwDefs.PasswordField, new ProtectedString(
pd.MemoryProtection.ProtectPassword, strPw));
}
Debug.Assert(pe.ParentGroup == peNew.ParentGroup);
PwGroup pg = (pe.ParentGroup ?? pgSelected);
if((pg == null) && (pd != null)) pg = pd.RootGroup;
if(pg == null) continue;
pg.AddEntry(peNew, true, true);
vNewEntries.Add(peNew);
}
AddEntriesToList(vNewEntries);
SelectEntries(vNewEntries, true, false);
if(!m_lvEntries.ShowGroups && (m_lvEntries.Items.Count >= 1))
m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1);
else EnsureVisibleSelected(true);
UpdateUIState(true, m_lvEntries);
}
示例7: OnEntryAdd
private void OnEntryAdd(object sender, EventArgs e)
{
PwGroup pg = GetSelectedGroup();
Debug.Assert(pg != null); if(pg == null) return;
if(pg.IsVirtual)
{
MessageService.ShowWarning(KPRes.GroupCannotStoreEntries,
KPRes.SelectDifferentGroup);
return;
}
PwDatabase pwDb = m_docMgr.ActiveDatabase;
PwEntry pwe = new PwEntry(true, true);
pwe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
pwDb.MemoryProtection.ProtectUserName,
pwDb.DefaultUserName));
ProtectedString psAutoGen = new ProtectedString(
pwDb.MemoryProtection.ProtectPassword);
PwGenerator.Generate(psAutoGen, Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile,
null, Program.PwGeneratorPool);
pwe.Strings.Set(PwDefs.PasswordField, psAutoGen);
int nExpireDays = Program.Config.Defaults.NewEntryExpiresInDays;
if(nExpireDays >= 0)
{
pwe.Expires = true;
pwe.ExpiryTime = DateTime.Now.AddDays(nExpireDays);
}
if((pg.IconId != PwIcon.Folder) && (pg.IconId != PwIcon.FolderOpen) &&
(pg.IconId != PwIcon.FolderPackage))
{
pwe.IconId = pg.IconId; // Inherit icon from group
}
pwe.CustomIconUuid = pg.CustomIconUuid;
// Temporarily assume that the entry is in pg; required for retrieving
// the default auto-type sequence
pwe.ParentGroup = pg;
PwEntryForm pForm = new PwEntryForm();
pForm.InitEx(pwe, PwEditMode.AddNewEntry, pwDb, m_ilCurrentIcons,
false, false);
if(UIUtil.ShowDialogAndDestroy(pForm) == DialogResult.OK)
{
pg.AddEntry(pwe, true);
UpdateUI(false, null, pwDb.UINeedsIconUpdate, null, true,
null, true, m_lvEntries);
PwObjectList<PwEntry> vSelect = new PwObjectList<PwEntry>();
vSelect.Add(pwe);
SelectEntries(vSelect, true, true);
EnsureVisibleEntry(pwe.Uuid);
}
else UpdateUI(false, null, pwDb.UINeedsIconUpdate, null,
pwDb.UINeedsIconUpdate, null, false);
}
示例8: OnEntryDuplicate
private void OnEntryDuplicate(object sender, EventArgs e)
{
PwDatabase pd = m_docMgr.ActiveDatabase;
PwGroup pgSelected = GetSelectedGroup();
PwEntry[] vSelected = GetSelectedEntries();
if((vSelected == null) || (vSelected.Length == 0)) return;
DuplicationForm dlg = new DuplicationForm();
if(UIUtil.ShowDialogAndDestroy(dlg) != DialogResult.OK) return;
PwObjectList<PwEntry> vNewEntries = new PwObjectList<PwEntry>();
foreach(PwEntry pe in vSelected)
{
PwEntry peNew = pe.CloneDeep();
peNew.SetUuid(new PwUuid(true), true); // Create new UUID
dlg.ApplyTo(peNew, pe, pd);
Debug.Assert(pe.ParentGroup == peNew.ParentGroup);
PwGroup pg = (pe.ParentGroup ?? pgSelected);
if((pg == null) && (pd != null)) pg = pd.RootGroup;
if(pg == null) continue;
pg.AddEntry(peNew, true, true);
vNewEntries.Add(peNew);
}
AddEntriesToList(vNewEntries);
SelectEntries(vNewEntries, true, true);
// if(!m_lvEntries.ShowGroups && (m_lvEntries.Items.Count >= 1))
// m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1);
// else EnsureVisibleSelected(true);
EnsureVisibleSelected(true); // Show all copies if possible
EnsureVisibleSelected(false); // Ensure showing the first
UpdateUIState(true, m_lvEntries);
}
示例9: OnToolsPwGenerator
private void OnToolsPwGenerator(object sender, EventArgs e)
{
PwDatabase pwDb = m_docMgr.ActiveDatabase;
PwGeneratorForm pgf = new PwGeneratorForm();
pgf.InitEx(null, pwDb.IsOpen, IsTrayed());
if(pgf.ShowDialog() == DialogResult.OK)
{
if(pwDb.IsOpen)
{
PwGroup pg = GetSelectedGroup();
if(pg == null) pg = pwDb.RootGroup;
PwEntry pe = new PwEntry(true, true);
pg.AddEntry(pe, true);
byte[] pbAdditionalEntropy = EntropyForm.CollectEntropyIfEnabled(
pgf.SelectedProfile);
ProtectedString psNew;
PwGenerator.Generate(out psNew, pgf.SelectedProfile,
pbAdditionalEntropy, Program.PwGeneratorPool);
psNew = psNew.WithProtection(pwDb.MemoryProtection.ProtectPassword);
pe.Strings.Set(PwDefs.PasswordField, psNew);
UpdateUI(false, null, false, null, true, null, true, m_lvEntries);
PwObjectList<PwEntry> l = new PwObjectList<PwEntry>();
l.Add(pe);
SelectEntries(l, true, true);
EnsureVisibleSelected(false);
}
}
UIUtil.DestroyForm(pgf);
}
示例10: OnToolsGeneratePasswordList
private void OnToolsGeneratePasswordList(object sender, EventArgs e)
{
PwDatabase pwDb = m_docMgr.ActiveDatabase;
if(!pwDb.IsOpen) return;
PwGeneratorForm pgf = new PwGeneratorForm();
pgf.InitEx(null, true, IsTrayed());
if(pgf.ShowDialog() == DialogResult.OK)
{
PwGroup pg = GetSelectedGroup();
if(pg == null) pg = pwDb.RootGroup;
SingleLineEditForm dlgCount = new SingleLineEditForm();
dlgCount.InitEx(KPRes.GenerateCount, KPRes.GenerateCountDesc,
KPRes.GenerateCountLongDesc, Properties.Resources.B48x48_KGPG_Gen,
string.Empty, null);
if(dlgCount.ShowDialog() == DialogResult.OK)
{
uint uCount;
if(!uint.TryParse(dlgCount.ResultString, out uCount))
uCount = 1;
byte[] pbAdditionalEntropy = EntropyForm.CollectEntropyIfEnabled(
pgf.SelectedProfile);
PwObjectList<PwEntry> l = new PwObjectList<PwEntry>();
for(uint i = 0; i < uCount; ++i)
{
PwEntry pe = new PwEntry(true, true);
pg.AddEntry(pe, true);
ProtectedString psNew;
PwGenerator.Generate(out psNew, pgf.SelectedProfile,
pbAdditionalEntropy, Program.PwGeneratorPool);
psNew = psNew.WithProtection(pwDb.MemoryProtection.ProtectPassword);
pe.Strings.Set(PwDefs.PasswordField, psNew);
l.Add(pe);
}
UpdateUI(false, null, false, null, true, null, true, m_lvEntries);
SelectEntries(l, true, true);
EnsureVisibleSelected(false);
}
UIUtil.DestroyForm(dlgCount);
}
UIUtil.DestroyForm(pgf);
}
示例11: GetPossibleTemplates
public static PwObjectList<PwEntry> GetPossibleTemplates(IPluginHost m_host)
{
PwObjectList<PwEntry> entries = new PwObjectList<PwEntry>();
PwGroup group = template_group(m_host);
if (group == null)
return entries;
PwObjectList<PwEntry> all_entries = group.GetEntries(true);
foreach (PwEntry entry in all_entries) {
if (entry.Strings.Exists("_etm_template"))
entries.Add(entry);
}
return entries;
}
示例12: OnEntryDuplicate
private void OnEntryDuplicate(object sender, EventArgs e)
{
PwGroup pgSelected = GetSelectedGroup();
PwEntry[] vSelected = GetSelectedEntries();
if((vSelected == null) || (vSelected.Length == 0)) return;
PwObjectList<PwEntry> vNewEntries = new PwObjectList<PwEntry>();
foreach(PwEntry pe in vSelected)
{
PwEntry peNew = pe.CloneDeep();
peNew.Uuid = new PwUuid(true); // Create new UUID
ProtectedString psTitle = peNew.Strings.Get(PwDefs.TitleField);
if(psTitle != null)
peNew.Strings.Set(PwDefs.TitleField, new ProtectedString(
psTitle.IsProtected, psTitle.ReadString() + " - " +
KPRes.CopyOfItem));
Debug.Assert(pe.ParentGroup == peNew.ParentGroup);
PwGroup pg = (pe.ParentGroup ?? pgSelected);
if((pg == null) && (m_docMgr.ActiveDocument != null))
pg = m_docMgr.ActiveDatabase.RootGroup;
if(pg == null) continue;
pg.AddEntry(peNew, true, true);
vNewEntries.Add(peNew);
}
AddEntriesToList(vNewEntries);
SelectEntries(vNewEntries, true);
if((m_lvEntries.ShowGroups == false) && (m_lvEntries.Items.Count >= 1))
m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1);
else EnsureVisibleSelected(true);
UpdateUIState(true);
}
示例13: PerformGlobal
public static bool PerformGlobal(List<PwDatabase> vSources,
ImageList ilIcons)
{
Debug.Assert(vSources != null); if(vSources == null) return false;
if(KeePassLib.Native.NativeLib.IsUnix())
{
if(!NativeMethods.TryXDoTool(true))
{
MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequiredGlobalVer);
return false;
}
}
IntPtr hWnd;
string strWindow;
try
{
// hWnd = NativeMethods.GetForegroundWindowHandle();
// strWindow = NativeMethods.GetWindowText(hWnd);
NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true);
}
catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; }
if(string.IsNullOrEmpty(strWindow)) return false;
if(!IsValidAutoTypeWindow(hWnd, true)) return false;
PwObjectList<PwEntry> vList = new PwObjectList<PwEntry>();
DateTime dtNow = DateTime.Now;
EntryHandler eh = delegate(PwEntry pe)
{
// Ignore expired entries
if(pe.Expires && (pe.ExpiryTime < dtNow)) return true;
if(GetSequenceForWindow(pe, strWindow, true) != null)
vList.Add(pe);
return true;
};
foreach(PwDatabase pwSource in vSources)
{
if(pwSource.IsOpen == false) continue;
pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);
}
if(vList.UCount == 1)
AutoType.PerformInternal(vList.GetAt(0), strWindow);
else if(vList.UCount > 1)
{
EntryListForm elf = new EntryListForm();
elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort,
KPRes.AutoTypeEntrySelectionDescLong,
Properties.Resources.B48x48_KGPG_Key2, ilIcons, vList);
elf.EnsureForeground = true;
if(elf.ShowDialog() == DialogResult.OK)
{
try { NativeMethods.EnsureForegroundWindow(hWnd); }
catch(Exception) { Debug.Assert(false); }
if(elf.SelectedEntry != null)
AutoType.PerformInternal(elf.SelectedEntry, strWindow);
}
UIUtil.DestroyForm(elf);
}
return true;
}
示例14: GetAllUserNodes
/// <summary>
/// Finds all UserRootNodes, which means the returned list contains all users.
/// </summary>
/// <returns>A list which contains all UserRootNodes of the actual database.</returns>
public static PwObjectList<PwEntry> GetAllUserNodes(this PwDatabase database)
{
PwObjectList<PwEntry> allEntries = database.RootGroup.GetEntries(true);
PwObjectList<PwEntry> rootList = new PwObjectList<PwEntry>();
foreach (PwEntry pe in allEntries)
{
if (pe.IsUserRootNode())
{
rootList.Add(pe);
}
}
return rootList;
}
示例15: GetAllProxyNodes
/// <summary>
/// Finds all Proxynodes in the database. That means all PwEntries with a
/// StringFieldUidLink which points to another PwEntry
/// </summary>
/// <returns>A <c>PwObjectList<PwEntry></c> which contains all proxy nodes of the actual DB.</returns>
public static PwObjectList<PwEntry> GetAllProxyNodes(this PwDatabase database)
{
PwObjectList<PwEntry> allEntries = database.RootGroup.GetEntries(true);
PwObjectList<PwEntry> proxyList = new PwObjectList<PwEntry>();
foreach (PwEntry entry in allEntries)
{
if (entry.IsProxyNode())
{
proxyList.Add(entry);
}
}
return proxyList;
}