本文整理汇总了C#中PwObjectList类的典型用法代码示例。如果您正苦于以下问题:C# PwObjectList类的具体用法?C# PwObjectList怎么用?C# PwObjectList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PwObjectList类属于命名空间,在下文中一共展示了PwObjectList类的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: FindMatchingEntries
private IEnumerable<PwEntry> FindMatchingEntries(Request r, Aes aes)
{
string submithost = null;
string realm = null;
var list = new PwObjectList<PwEntry>();
string formhost, searchHost;
formhost = searchHost = GetHost(CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT));
if (r.SubmitUrl != null) {
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
}
if (r.Realm != null)
realm = CryptoTransform(r.Realm, true, false, aes, CMode.DECRYPT);
var origSearchHost = searchHost;
var parms = MakeSearchParameters();
var root = host.Database.RootGroup;
while (list.UCount == 0 && (origSearchHost == searchHost || searchHost.IndexOf(".") != -1))
{
parms.SearchString = String.Format("^{0}$|/{0}/?", searchHost);
root.SearchEntries(parms, list);
searchHost = searchHost.Substring(searchHost.IndexOf(".") + 1);
if (searchHost == origSearchHost)
break;
}
Func<PwEntry, bool> filter = delegate(PwEntry e)
{
var title = e.Strings.ReadSafe(PwDefs.TitleField);
var entryUrl = e.Strings.ReadSafe(PwDefs.UrlField);
var c = GetEntryConfig(e);
if (c != null)
{
if (c.Allow.Contains(formhost) && (submithost == null || c.Allow.Contains(submithost)))
return true;
if (c.Deny.Contains(formhost) || (submithost != null && c.Deny.Contains(submithost)))
return false;
if (realm != null && c.Realm != realm)
return false;
}
if (title.StartsWith("http://") || title.StartsWith("https://"))
{
var u = new Uri(title);
if (formhost.Contains(u.Host))
return true;
}
if (entryUrl != null && entryUrl.StartsWith("http://") || entryUrl.StartsWith("https://"))
{
var u = new Uri(entryUrl);
if (formhost.Contains(u.Host))
return true;
}
return formhost.Contains(title) || (entryUrl != null && formhost.Contains(entryUrl));
};
return from e in list where filter(e) select e;
}
示例3: InitEx
public void InitEx(string strTitle, string strDescShort,
string strDescLong, Image imgIcon, ImageList ilIcons,
PwObjectList<PwEntry> vEntries)
{
m_strTitle = strTitle;
m_strDescShort = strDescShort;
m_strDescLong = strDescLong;
m_imgIcon = imgIcon;
m_ilIcons = UIUtil.CloneImageList(ilIcons, true);
m_vEntries = vEntries;
}
示例4: FindMatchingEntries
private IEnumerable<PwEntryDatabase> FindMatchingEntries(Request r, Aes aes)
{
string submithost = null;
string realm = null;
var listResult = new List<PwEntryDatabase>();
string formhost, searchHost;
formhost = searchHost = GetHost(CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT));
if (r.SubmitUrl != null) {
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
}
if (r.Realm != null)
realm = CryptoTransform(r.Realm, true, false, aes, CMode.DECRYPT);
var origSearchHost = searchHost;
var parms = MakeSearchParameters();
List<PwDatabase> listDatabases = new List<PwDatabase>();
var configOpt = new ConfigOpt(this.host.CustomConfig);
if (configOpt.SearchInAllOpenedDatabases)
{
foreach (PwDocument doc in host.MainWindow.DocumentManager.Documents)
{
if (doc.Database.IsOpen)
{
listDatabases.Add(doc.Database);
}
}
}
else
{
listDatabases.Add(host.Database);
}
int listCount = 0;
foreach (PwDatabase db in listDatabases)
{
searchHost = origSearchHost;
//get all possible entries for given host-name
while (listResult.Count == listCount && (origSearchHost == searchHost || searchHost.IndexOf(".") != -1))
{
parms.SearchString = String.Format("^{0}$|/{0}/?", searchHost);
var listEntries = new PwObjectList<PwEntry>();
db.RootGroup.SearchEntries(parms, listEntries);
foreach (var le in listEntries)
{
listResult.Add(new PwEntryDatabase(le, db));
}
searchHost = searchHost.Substring(searchHost.IndexOf(".") + 1);
//searchHost contains no dot --> prevent possible infinite loop
if (searchHost == origSearchHost)
break;
}
listCount = listResult.Count;
}
Func<PwEntry, bool> filter = delegate(PwEntry e)
{
var title = e.Strings.ReadSafe(PwDefs.TitleField);
var entryUrl = e.Strings.ReadSafe(PwDefs.UrlField);
var c = GetEntryConfig(e);
if (c != null)
{
if (c.Allow.Contains(formhost) && (submithost == null || c.Allow.Contains(submithost)))
return true;
if (c.Deny.Contains(formhost) || (submithost != null && c.Deny.Contains(submithost)))
return false;
if (realm != null && c.Realm != realm)
return false;
}
if (title.StartsWith("http://") || title.StartsWith("https://"))
{
var u = new Uri(title);
if (formhost.Contains(u.Host))
return true;
}
if (entryUrl != null && entryUrl.StartsWith("http://") || entryUrl.StartsWith("https://"))
{
var u = new Uri(entryUrl);
if (formhost.Contains(u.Host))
return true;
}
return formhost.Contains(title) || (entryUrl != null && formhost.Contains(entryUrl));
};
return from e in listResult where filter(e.entry) select e;
}
示例5: 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);
}
示例6: FindRefTarget
public static PwEntry FindRefTarget(string strFullRef, SprContext ctx,
out char chScan, out char chWanted)
{
chScan = char.MinValue;
chWanted = char.MinValue;
if(strFullRef == null) { Debug.Assert(false); return null; }
if(!strFullRef.StartsWith(StrRefStart, SprEngine.ScMethod) ||
!strFullRef.EndsWith(StrRefEnd, SprEngine.ScMethod))
return null;
if((ctx == null) || (ctx.Database == null)) { Debug.Assert(false); return null; }
string strRef = strFullRef.Substring(StrRefStart.Length,
strFullRef.Length - StrRefStart.Length - StrRefEnd.Length);
if(strRef.Length <= 4) return null;
if(strRef[1] != '@') return null;
if(strRef[3] != ':') return null;
chScan = char.ToUpper(strRef[2]);
chWanted = char.ToUpper(strRef[0]);
SearchParameters sp = SearchParameters.None;
sp.SearchString = strRef.Substring(4);
sp.RespectEntrySearchingDisabled = false;
if(chScan == 'T') sp.SearchInTitles = true;
else if(chScan == 'U') sp.SearchInUserNames = true;
else if(chScan == 'A') sp.SearchInUrls = true;
else if(chScan == 'P') sp.SearchInPasswords = true;
else if(chScan == 'N') sp.SearchInNotes = true;
else if(chScan == 'I') sp.SearchInUuids = true;
else if(chScan == 'O') sp.SearchInOther = true;
else return null;
PwObjectList<PwEntry> lFound = new PwObjectList<PwEntry>();
ctx.Database.RootGroup.SearchEntries(sp, lFound);
return ((lFound.UCount > 0) ? lFound.GetAt(0) : null);
}
示例7: 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);
}
示例8: 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);
}
}
示例9: EntriesHaveSameParent
public static bool EntriesHaveSameParent(PwObjectList<PwEntry> v)
{
if(v == null) { Debug.Assert(false); return true; }
if(v.UCount == 0) return true;
PwGroup pg = v.GetAt(0).ParentGroup;
foreach(PwEntry pe in v)
{
if(pe.ParentGroup != pg) return false;
}
return true;
}
示例10: SelectEntries
internal void SelectEntries(PwObjectList<PwEntry> lEntries,
bool bDeselectOthers, bool bFocusFirst)
{
++m_uBlockEntrySelectionEvent;
bool bFirst = true;
for(int i = 0; i < m_lvEntries.Items.Count; ++i)
{
PwEntry pe = ((PwListItem)m_lvEntries.Items[i].Tag).Entry;
if(pe == null) { Debug.Assert(false); continue; }
bool bFound = false;
foreach(PwEntry peFocus in lEntries)
{
if(pe == peFocus)
{
m_lvEntries.Items[i].Selected = true;
if(bFirst && bFocusFirst)
{
UIUtil.SetFocusedItem(m_lvEntries,
m_lvEntries.Items[i], false);
bFirst = false;
}
bFound = true;
break;
}
}
if(bDeselectOthers && !bFound)
m_lvEntries.Items[i].Selected = false;
}
--m_uBlockEntrySelectionEvent;
}
示例11: ShowEntriesByTag
internal void ShowEntriesByTag(string strTag)
{
if(strTag == null) { Debug.Assert(false); return; }
if(strTag.Length == 0) return; // No assert
PwDatabase pd = m_docMgr.ActiveDatabase;
if((pd == null) || !pd.IsOpen) return; // No assert (call from trigger)
PwObjectList<PwEntry> vEntries = new PwObjectList<PwEntry>();
pd.RootGroup.FindEntriesByTag(strTag, vEntries, true);
PwGroup pgResults = new PwGroup(true, true);
pgResults.IsVirtual = true;
foreach(PwEntry pe in vEntries) pgResults.AddEntry(pe, false);
UpdateUI(false, null, false, null, true, pgResults, false);
}
示例12: Clear
private void Clear()
{
m_pgRootGroup = null;
m_vDeletedObjects = new PwObjectList<PwDeletedObject>();
m_uuidDataCipher = StandardAesEngine.AesUuid;
m_caCompression = PwCompressionAlgorithm.GZip;
m_uKeyEncryptionRounds = PwDefs.DefaultKeyEncryptionRounds;
m_pwUserKey = null;
m_memProtConfig = new MemoryProtectionConfig();
m_vCustomIcons = new List<PwCustomIcon>();
m_strName = string.Empty;
m_strDesc = string.Empty;
m_strDefaultUserName = string.Empty;
m_bUINeedsIconUpdate = true;
m_ioSource = new IOConnectionInfo();
m_bDatabaseOpened = false;
m_bModified = false;
m_pwLastSelectedGroup = PwUuid.Zero;
m_pwLastTopVisibleGroup = PwUuid.Zero;
m_pbHashOfFileOnDisk = null;
m_pbHashOfLastIO = null;
}
示例13: 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);
}
示例14: ApplyDeletions
/// <summary>
/// Apply a list of deleted objects.
/// </summary>
/// <param name="listDelObjects">List of deleted objects.</param>
private void ApplyDeletions(PwObjectList<PwDeletedObject> listDelObjects,
bool bCopyDeletionInfoToLocal)
{
Debug.Assert(listDelObjects != null); if(listDelObjects == null) throw new ArgumentNullException("listDelObjects");
LinkedList<PwGroup> listGroupsToDelete = new LinkedList<PwGroup>();
LinkedList<PwEntry> listEntriesToDelete = new LinkedList<PwEntry>();
GroupHandler gh = delegate(PwGroup pg)
{
if(pg == m_pgRootGroup) return true;
foreach(PwDeletedObject pdo in listDelObjects)
{
if(pg.Uuid.EqualsValue(pdo.Uuid))
if(pg.LastModificationTime < pdo.DeletionTime)
listGroupsToDelete.AddLast(pg);
}
return true;
};
EntryHandler eh = delegate(PwEntry pe)
{
foreach(PwDeletedObject pdo in listDelObjects)
{
if(pe.Uuid.EqualsValue(pdo.Uuid))
if(pe.LastModificationTime < pdo.DeletionTime)
listEntriesToDelete.AddLast(pe);
}
return true;
};
m_pgRootGroup.TraverseTree(TraversalMethod.PreOrder, gh, eh);
foreach(PwGroup pg in listGroupsToDelete)
pg.ParentGroup.Groups.Remove(pg);
foreach(PwEntry pe in listEntriesToDelete)
pe.ParentGroup.Entries.Remove(pe);
if(bCopyDeletionInfoToLocal)
{
foreach(PwDeletedObject pdoNew in listDelObjects)
{
bool bCopy = true;
foreach(PwDeletedObject pdoLocal in m_vDeletedObjects)
{
if(pdoNew.Uuid.EqualsValue(pdoLocal.Uuid))
{
bCopy = false;
if(pdoNew.DeletionTime > pdoLocal.DeletionTime)
pdoLocal.DeletionTime = pdoNew.DeletionTime;
break;
}
}
if(bCopy) m_vDeletedObjects.Add(pdoNew);
}
}
}
示例15: OnFilterKeyDown
private void OnFilterKeyDown(object sender, KeyEventArgs e)
{
if((e.KeyCode == Keys.Return) || (e.KeyCode == Keys.Enter))
{
e.SuppressKeyPress = true;
SearchParameters sp = new SearchParameters();
sp.SearchString = m_tbFilter.Text;
sp.SearchInPasswords = true;
PwObjectList<PwEntry> lResults = new PwObjectList<PwEntry>();
m_pgEntrySource.SearchEntries(sp, lResults);
UIUtil.CreateEntryList(m_lvEntries, lResults, m_vColumns, m_ilIcons);
}
}