本文整理汇总了C#中PwEntry.AddTag方法的典型用法代码示例。如果您正苦于以下问题:C# PwEntry.AddTag方法的具体用法?C# PwEntry.AddTag怎么用?C# PwEntry.AddTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PwEntry
的用法示例。
在下文中一共展示了PwEntry.AddTag方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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); }
}
}
示例2: UpdateKeePassEntry
public static void UpdateKeePassEntry(PwEntry entry,
string username = "",
string title = "",
string url = "",
string notes = "",
string password = "",
string[] attachments = null,
string[] tags = null)
{
UpdateValue(entry, "UserName", username);
UpdateValue(entry, "Title", title);
UpdateValue(entry, "URL", url);
UpdateValue(entry, "Notes", notes);
UpdateValue(entry, "Password", password);
if(tags != null)
{
var tagsCopy = entry.Tags.ToArray();
foreach(var tag in tagsCopy)
entry.RemoveTag(tag);
foreach (var tag in tags)
entry.AddTag(tag);
}
if (attachments != null)
{
var fileNames = attachments.Select(o => Path.GetFileName(o)).ToList();
var binaries = entry.Binaries.CloneDeep();
var filesToAdd = new List<string>();
foreach(var binary in binaries)
{
entry.Binaries.Remove(binary.Key);
}
foreach(var attachment in attachments)
{
var fileName = Path.GetFileName(attachment);
var bytes = File.ReadAllBytes(attachment);
if(bytes != null)
{
var protectedBytes = new ProtectedBinary(true, bytes);
entry.Binaries.Set(fileName, protectedBytes);
}
}
}
}
示例3: PerformImport
private void PerformImport(PwGroup pgStorage, bool bCreatePreview)
{
List<CsvFieldInfo> lFields = GetCsvFieldInfos();
if(bCreatePreview)
{
int dx = m_lvImportPreview.ClientRectangle.Width; // Before clearing
m_lvImportPreview.Items.Clear();
m_lvImportPreview.Columns.Clear();
foreach(CsvFieldInfo cfi in lFields)
{
string strCol = CsvFieldToString(cfi.Type);
if(cfi.Type == CsvFieldType.CustomString)
strCol = (cfi.Name ?? string.Empty);
m_lvImportPreview.Columns.Add(strCol, dx / lFields.Count);
}
}
CsvOptions opt = GetCsvOptions();
if(opt == null) { Debug.Assert(bCreatePreview); return; }
string strData = GetDecodedText();
CsvStreamReaderEx csr = new CsvStreamReaderEx(strData, opt);
Dictionary<string, PwGroup> dGroups = new Dictionary<string, PwGroup>();
dGroups[string.Empty] = pgStorage;
if(bCreatePreview) m_lvImportPreview.BeginUpdate();
DateTime dtNow = DateTime.Now;
DateTime dtNoExpire = KdbTime.NeverExpireTime.ToDateTime();
bool bIgnoreFirstRow = m_cbIgnoreFirst.Checked;
bool bIsFirstRow = true;
bool bMergeGroups = m_cbMergeGroups.Checked;
while(true)
{
string[] v = csr.ReadLine();
if(v == null) break;
if(v.Length == 0) continue;
if((v.Length == 1) && (v[0].Length == 0)) continue;
if(bIsFirstRow && bIgnoreFirstRow)
{
bIsFirstRow = false;
continue;
}
bIsFirstRow = false;
PwGroup pg = pgStorage;
PwEntry pe = new PwEntry(true, true);
ListViewItem lvi = null;
for(int i = 0; i < Math.Min(v.Length, lFields.Count); ++i)
{
string strField = v[i];
CsvFieldInfo cfi = lFields[i];
if(cfi.Type == CsvFieldType.Ignore) { }
else if(cfi.Type == CsvFieldType.Group)
pg = FindCreateGroup(strField, pgStorage, dGroups,
cfi.Format, opt, bMergeGroups);
else if(cfi.Type == CsvFieldType.Title)
ImportUtil.AppendToField(pe, PwDefs.TitleField,
strField, m_pwDatabase);
else if(cfi.Type == CsvFieldType.UserName)
ImportUtil.AppendToField(pe, PwDefs.UserNameField,
strField, m_pwDatabase);
else if(cfi.Type == CsvFieldType.Password)
ImportUtil.AppendToField(pe, PwDefs.PasswordField,
strField, m_pwDatabase);
else if(cfi.Type == CsvFieldType.Url)
ImportUtil.AppendToField(pe, PwDefs.UrlField,
strField, m_pwDatabase);
else if(cfi.Type == CsvFieldType.Notes)
ImportUtil.AppendToField(pe, PwDefs.NotesField,
strField, m_pwDatabase);
else if(cfi.Type == CsvFieldType.CustomString)
ImportUtil.AppendToField(pe, (string.IsNullOrEmpty(cfi.Name) ?
PwDefs.NotesField : cfi.Name), strField, m_pwDatabase);
else if(cfi.Type == CsvFieldType.CreationTime)
pe.CreationTime = ParseDateTime(ref strField, cfi, dtNow);
// else if(cfi.Type == CsvFieldType.LastAccessTime)
// pe.LastAccessTime = ParseDateTime(ref strField, cfi, dtNow);
else if(cfi.Type == CsvFieldType.LastModTime)
pe.LastModificationTime = ParseDateTime(ref strField, cfi, dtNow);
else if(cfi.Type == CsvFieldType.ExpiryTime)
{
bool bParseSuccess;
pe.ExpiryTime = ParseDateTime(ref strField, cfi, dtNow,
out bParseSuccess);
pe.Expires = (bParseSuccess && (pe.ExpiryTime != dtNoExpire));
}
else if(cfi.Type == CsvFieldType.Tags)
{
List<string> lTags = StrUtil.StringToTags(strField);
foreach(string strTag in lTags)
pe.AddTag(strTag);
//.........这里部分代码省略.........
示例4: AddEntry
private static void AddEntry(string[] vLine, PwDatabase pd)
{
Debug.Assert((vLine.Length == 0) || (vLine.Length == 7));
if(vLine.Length < 5) return;
// Skip header line
if((vLine[1] == "username") && (vLine[2] == "password") &&
(vLine[3] == "extra") && (vLine[4] == "name"))
return;
PwEntry pe = new PwEntry(true, true);
PwGroup pg = pd.RootGroup;
if(vLine.Length >= 6)
{
string strGroup = vLine[5];
if(strGroup.Length > 0)
pg = pg.FindCreateSubTree(strGroup, new string[1]{ "\\" }, true);
}
pg.AddEntry(pe, true);
ImportUtil.AppendToField(pe, PwDefs.TitleField, vLine[4], pd);
ImportUtil.AppendToField(pe, PwDefs.UserNameField, vLine[1], pd);
ImportUtil.AppendToField(pe, PwDefs.PasswordField, vLine[2], pd);
string strNotes = vLine[3];
bool bIsSecNote = vLine[0].Equals("http://sn", StrUtil.CaseIgnoreCmp);
if(bIsSecNote)
{
if(strNotes.StartsWith("NoteType:", StrUtil.CaseIgnoreCmp))
AddNoteFields(pe, strNotes, pd);
else ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
}
else // Standard entry, no secure note
{
ImportUtil.AppendToField(pe, PwDefs.UrlField, vLine[0], pd);
Debug.Assert(!strNotes.StartsWith("NoteType:"));
ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
}
if(vLine.Length >= 7)
{
if(StrUtil.StringToBool(vLine[6]))
pe.AddTag("Favorite");
}
}
示例5: SaveEntry
private bool SaveEntry(PwEntry peTarget, bool bValidate)
{
if(m_pwEditMode == PwEditMode.ViewReadOnlyEntry) return true;
if(bValidate && !m_icgPassword.ValidateData(true)) return false;
if(this.EntrySaving != null)
{
CancellableOperationEventArgs eaCancel = new CancellableOperationEventArgs();
this.EntrySaving(this, eaCancel);
if(eaCancel.Cancel) return false;
}
peTarget.History = m_vHistory; // Must be called before CreateBackup()
bool bCreateBackup = (m_pwEditMode != PwEditMode.AddNewEntry);
if(bCreateBackup) peTarget.CreateBackup(null);
peTarget.IconId = m_pwEntryIcon;
peTarget.CustomIconUuid = m_pwCustomIconID;
if(m_cbCustomForegroundColor.Checked)
peTarget.ForegroundColor = m_clrForeground;
else peTarget.ForegroundColor = Color.Empty;
if(m_cbCustomBackgroundColor.Checked)
peTarget.BackgroundColor = m_clrBackground;
else peTarget.BackgroundColor = Color.Empty;
peTarget.OverrideUrl = m_cmbOverrideUrl.Text;
List<string> vNewTags = StrUtil.StringToTags(m_tbTags.Text);
peTarget.Tags.Clear();
foreach(string strTag in vNewTags) peTarget.AddTag(strTag);
peTarget.Expires = m_cgExpiry.Checked;
if(peTarget.Expires) peTarget.ExpiryTime = m_cgExpiry.Value;
UpdateEntryStrings(true, false, false);
peTarget.Strings = m_vStrings;
peTarget.Binaries = m_vBinaries;
m_atConfig.Enabled = m_cbAutoTypeEnabled.Checked;
m_atConfig.ObfuscationOptions = (m_cbAutoTypeObfuscation.Checked ?
AutoTypeObfuscationOptions.UseClipboard :
AutoTypeObfuscationOptions.None);
SaveDefaultSeq();
peTarget.AutoType = m_atConfig;
peTarget.Touch(true, false); // Touch *after* backup
if(object.ReferenceEquals(peTarget, m_pwEntry)) m_bTouchedOnce = true;
StrUtil.NormalizeNewLines(peTarget.Strings, true);
bool bUndoBackup = false;
PwCompareOptions cmpOpt = m_cmpOpt;
if(bCreateBackup) cmpOpt |= PwCompareOptions.IgnoreLastBackup;
if(peTarget.EqualsEntry(m_pwInitialEntry, cmpOpt, MemProtCmpMode.CustomOnly))
{
// No modifications at all => restore last mod time and undo backup
peTarget.LastModificationTime = m_pwInitialEntry.LastModificationTime;
bUndoBackup = bCreateBackup;
}
else if(bCreateBackup)
{
// If only history items have been modified (deleted) => undo
// backup, but without restoring the last mod time
PwCompareOptions cmpOptNH = (m_cmpOpt | PwCompareOptions.IgnoreHistory);
if(peTarget.EqualsEntry(m_pwInitialEntry, cmpOptNH, MemProtCmpMode.CustomOnly))
bUndoBackup = true;
}
if(bUndoBackup) peTarget.History.RemoveAt(peTarget.History.UCount - 1);
peTarget.MaintainBackups(m_pwDatabase);
if(this.EntrySaved != null) this.EntrySaved(this, EventArgs.Empty);
return true;
}
示例6: AddEntry
private static void AddEntry(string[] vLine, PwDatabase pd,
IDictionary<string, PwGroup> dGroups)
{
Debug.Assert((vLine.Length == 0) || (vLine.Length == 7));
if(vLine.Length < 5) return;
// Skip header line
if((vLine[1] == "username") && (vLine[2] == "password") &&
(vLine[3] == "extra") && (vLine[4] == "name"))
return;
PwEntry pe = new PwEntry(true, true);
PwGroup pg = dGroups[string.Empty];
if(vLine.Length >= 6)
{
string strGroup = vLine[5];
if(!dGroups.TryGetValue(strGroup, out pg))
{
pg = new PwGroup(true, true, strGroup, PwIcon.Folder);
pd.RootGroup.AddGroup(pg, true, true);
dGroups[strGroup] = pg;
}
}
pg.AddEntry(pe, true, true);
ImportUtil.AppendToField(pe, PwDefs.TitleField, vLine[4], pd);
ImportUtil.AppendToField(pe, PwDefs.UserNameField, vLine[1], pd);
ImportUtil.AppendToField(pe, PwDefs.PasswordField, vLine[2], pd);
string strNotes = vLine[3];
bool bIsSecNote = vLine[0].Equals("http://sn", StrUtil.CaseIgnoreCmp);
if(bIsSecNote)
{
if(strNotes.StartsWith("NoteType:", StrUtil.CaseIgnoreCmp))
AddNoteFields(pe, strNotes, pd);
else ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
}
else // Standard entry, no secure note
{
ImportUtil.AppendToField(pe, PwDefs.UrlField, vLine[0], pd);
Debug.Assert(!strNotes.StartsWith("NoteType:"));
ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
}
if(vLine.Length >= 7)
{
if(StrUtil.StringToBool(vLine[6]))
pe.AddTag("Favorite");
}
}
示例7: ReadEntry
private static void ReadEntry(XmlNode xmlNode, PwGroup pgParent, PwDatabase pwStorage)
{
PwEntry pe = new PwEntry(true, true);
pgParent.AddEntry(pe, true);
DateTime? odtExpiry = null;
foreach(XmlNode xmlChild in xmlNode)
{
string strValue = XmlUtil.SafeInnerText(xmlChild);
if(xmlChild.NodeType == XmlNodeType.Text)
ImportUtil.AppendToField(pe, PwDefs.TitleField, (xmlChild.Value ??
string.Empty).Trim(), pwStorage, " ", false);
else if(xmlChild.Name == ElemEntryUser)
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUserName, strValue));
else if(xmlChild.Name == ElemEntryPassword)
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
pwStorage.MemoryProtection.ProtectPassword, strValue));
else if(xmlChild.Name == ElemEntryPassword2)
{
if(strValue.Length > 0) // Prevent empty item
pe.Strings.Set(Password2Key, new ProtectedString(
pwStorage.MemoryProtection.ProtectPassword, strValue));
}
else if(xmlChild.Name == ElemEntryUrl)
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUrl, strValue));
else if(xmlChild.Name == ElemEntryNotes)
pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
pwStorage.MemoryProtection.ProtectNotes, strValue));
else if(xmlChild.Name == ElemTags)
{
string strTags = strValue.Replace(' ', ';');
List<string> vTags = StrUtil.StringToTags(strTags);
foreach(string strTag in vTags) { pe.AddTag(strTag); }
}
else if(xmlChild.Name == ElemEntryExpires)
pe.Expires = StrUtil.StringToBool(strValue);
else if(xmlChild.Name == ElemEntryExpiryTime)
{
DateTime dt = TimeUtil.FromDisplayString(strValue);
if(dt != DateTime.Now) odtExpiry = dt;
else { Debug.Assert(false); }
}
else if(xmlChild.Name == ElemAutoType)
ReadAutoType(xmlChild, pe);
else if(xmlChild.Name == ElemEntryUnsupp0) { }
else if(xmlChild.Name == ElemEntryUnsupp1) { }
else { Debug.Assert(false); }
}
if(odtExpiry.HasValue) pe.ExpiryTime = odtExpiry.Value;
else pe.Expires = false;
}
示例8: setTags
private void setTags(PwEntry pwe, string url = null)
{
pwe.AddTag("keebook_bookmark");
if (!string.IsNullOrEmpty(url))
{
if (url.Contains("https://"))
{
pwe.AddTag("keebook_secure_url");
}
}
if (pwe.IconId != PwIcon.Star)
{
pwe.AddTag("keebook_custom_icon");
}
}
示例9: ProcessCsvLine
private static void ProcessCsvLine(string[] vLine, PwDatabase pwStorage,
SortedDictionary<string, PwGroup> dictGroups)
{
string strType = ParseCsvWord(vLine[0]);
string strGroupName = ParseCsvWord(vLine[12]); // + " - " + strType;
if(strGroupName.Length == 0) strGroupName = strType;
SplashIdMapping mp = null;
foreach(SplashIdMapping mpFind in SplashIdCsv402.SplashIdMappings)
{
if(mpFind.TypeName == strType)
{
mp = mpFind;
break;
}
}
PwIcon pwIcon = ((mp != null) ? mp.Icon : PwIcon.Key);
PwGroup pg = null;
if(dictGroups.ContainsKey(strGroupName))
pg = dictGroups[strGroupName];
else
{
// PwIcon pwGroupIcon = ((pwIcon == PwIcon.Key) ?
// PwIcon.FolderOpen : pwIcon);
// pg = new PwGroup(true, true, strGroupName, pwGroupIcon);
pg = new PwGroup(true, true);
pg.Name = strGroupName;
pwStorage.RootGroup.AddGroup(pg, true);
dictGroups[strGroupName] = pg;
}
PwEntry pe = new PwEntry(true, true);
pg.AddEntry(pe, true);
pe.IconId = pwIcon;
List<string> vTags = StrUtil.StringToTags(strType);
foreach(string strTag in vTags) { pe.AddTag(strTag); }
for(int iField = 0; iField < 9; ++iField)
{
string strData = ParseCsvWord(vLine[iField + 1]);
if(strData.Length == 0) continue;
string strLookup = ((mp != null) ? mp.FieldNames[iField] :
null);
string strField = (strLookup ?? ("Field " + (iField + 1).ToString()));
string strSep = ((strField != PwDefs.NotesField) ? ", " : "\r\n");
ImportUtil.AppendToField(pe, strField, strData, pwStorage, strSep, false);
}
ImportUtil.AppendToField(pe, PwDefs.NotesField, ParseCsvWord(vLine[11]),
pwStorage, "\r\n", false);
DateTime? odt = TimeUtil.ParseUSTextDate(ParseCsvWord(vLine[10]),
DateTimeKind.Local);
if(odt.HasValue)
{
DateTime dt = TimeUtil.ToUtc(odt.Value, false);
pe.LastAccessTime = dt;
pe.LastModificationTime = dt;
}
}
示例10: UpdateEntryFromUi
void UpdateEntryFromUi(PwEntry entry)
{
Database db = App.Kp2a.GetDb();
EntryEditActivity act = this;
entry.Strings.Set(PwDefs.TitleField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectTitle,
Util.GetEditText(act, Resource.Id.entry_title)));
entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUserName,
Util.GetEditText(act, Resource.Id.entry_user_name)));
String pass = Util.GetEditText(act, Resource.Id.entry_password);
byte[] password = StrUtil.Utf8.GetBytes(pass);
entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectPassword,
password));
MemUtil.ZeroByteArray(password);
entry.Strings.Set(PwDefs.UrlField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUrl,
Util.GetEditText(act, Resource.Id.entry_url)));
entry.Strings.Set(PwDefs.NotesField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectNotes,
Util.GetEditText(act, Resource.Id.entry_comment)));
// Validate expiry date
DateTime newExpiry = new DateTime();
if ((State.Entry.Expires) && (!DateTime.TryParse( Util.GetEditText(this,Resource.Id.entry_expires), out newExpiry)))
{
//ignore here
}
else
{
State.Entry.ExpiryTime = newExpiry;
}
// Delete all non standard strings
var keys = entry.Strings.GetKeys();
foreach (String key in keys)
if (PwDefs.IsStandardField(key) == false)
entry.Strings.Remove(key);
LinearLayout container = (LinearLayout) FindViewById(Resource.Id.advanced_container);
for (int index = 0; index < container.ChildCount; index++) {
View view = container.GetChildAt(index);
TextView keyView = (TextView)view.FindViewById(Resource.Id.title);
String key = keyView.Text;
if (String.IsNullOrEmpty(key))
continue;
TextView valueView = (TextView)view.FindViewById(Resource.Id.value);
String value = valueView.Text;
bool protect = ((CheckBox) view.FindViewById(Resource.Id.protection)).Checked;
entry.Strings.Set(key, new ProtectedString(protect, value));
}
entry.OverrideUrl = Util.GetEditText(this,Resource.Id.entry_override_url);
List<string> vNewTags = StrUtil.StringToTags(Util.GetEditText(this,Resource.Id.entry_tags));
entry.Tags.Clear();
foreach(string strTag in vNewTags) entry.AddTag(strTag);
/*KPDesktop
m_atConfig.Enabled = m_cbAutoTypeEnabled.Checked;
m_atConfig.ObfuscationOptions = (m_cbAutoTypeObfuscation.Checked ?
AutoTypeObfuscationOptions.UseClipboard :
AutoTypeObfuscationOptions.None);
SaveDefaultSeq();
newEntry.AutoType = m_atConfig;
*/
}