当前位置: 首页>>代码示例>>C#>>正文


C# PwEntry.MaintainBackups方法代码示例

本文整理汇总了C#中PwEntry.MaintainBackups方法的典型用法代码示例。如果您正苦于以下问题:C# PwEntry.MaintainBackups方法的具体用法?C# PwEntry.MaintainBackups怎么用?C# PwEntry.MaintainBackups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PwEntry的用法示例。


在下文中一共展示了PwEntry.MaintainBackups方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportEntry

		private static void ImportEntry(XmlNode xmlNode, PwDatabase pwStorage,
			string strLineBreak)
		{
			Debug.Assert(xmlNode != null); if(xmlNode == null) return;

			PwEntry pe = new PwEntry(true, true);
			string strGroupName = string.Empty;

			List<DatePasswordPair> listHistory = null;

			foreach(XmlNode xmlChild in xmlNode.ChildNodes)
			{
				if(xmlChild.Name == ElemGroup)
					strGroupName = XmlUtil.SafeInnerText(xmlChild);
				else if(xmlChild.Name == ElemTitle)
					pe.Strings.Set(PwDefs.TitleField,
						new ProtectedString(pwStorage.MemoryProtection.ProtectTitle,
						XmlUtil.SafeInnerText(xmlChild)));
				else if(xmlChild.Name == ElemUserName)
					pe.Strings.Set(PwDefs.UserNameField,
						new ProtectedString(pwStorage.MemoryProtection.ProtectUserName,
						XmlUtil.SafeInnerText(xmlChild)));
				else if(xmlChild.Name == ElemPassword)
					pe.Strings.Set(PwDefs.PasswordField,
						new ProtectedString(pwStorage.MemoryProtection.ProtectPassword,
						XmlUtil.SafeInnerText(xmlChild)));
				else if(xmlChild.Name == ElemURL)
					pe.Strings.Set(PwDefs.UrlField,
						new ProtectedString(pwStorage.MemoryProtection.ProtectUrl,
						XmlUtil.SafeInnerText(xmlChild)));
				else if(xmlChild.Name == ElemNotes)
					pe.Strings.Set(PwDefs.NotesField,
						new ProtectedString(pwStorage.MemoryProtection.ProtectNotes,
						XmlUtil.SafeInnerText(xmlChild, strLineBreak)));
				else if(xmlChild.Name == ElemEMail)
					pe.Strings.Set("E-Mail", new ProtectedString(false,
						XmlUtil.SafeInnerText(xmlChild)));
				else if(xmlChild.Name == ElemCreationTime)
					pe.CreationTime = ReadDateTime(xmlChild);
				else if(xmlChild.Name == ElemLastAccessTime)
					pe.LastAccessTime = ReadDateTime(xmlChild);
				else if(xmlChild.Name == ElemExpireTime)
				{
					pe.ExpiryTime = ReadDateTime(xmlChild);
					pe.Expires = true;
				}
				else if(xmlChild.Name == ElemLastModTime) // = last mod
					pe.LastModificationTime = ReadDateTime(xmlChild);
				else if(xmlChild.Name == ElemRecordModTime) // = last mod
					pe.LastModificationTime = ReadDateTime(xmlChild);
				else if(xmlChild.Name == ElemCreationTimeX)
					pe.CreationTime = ReadDateTimeX(xmlChild);
				else if(xmlChild.Name == ElemLastAccessTimeX)
					pe.LastAccessTime = ReadDateTimeX(xmlChild);
				else if(xmlChild.Name == ElemExpireTimeX)
				{
					pe.ExpiryTime = ReadDateTimeX(xmlChild);
					pe.Expires = true;
				}
				else if(xmlChild.Name == ElemLastModTimeX) // = last mod
					pe.LastModificationTime = ReadDateTimeX(xmlChild);
				else if(xmlChild.Name == ElemRecordModTimeX) // = last mod
					pe.LastModificationTime = ReadDateTimeX(xmlChild);
				else if(xmlChild.Name == ElemAutoType)
					pe.AutoType.DefaultSequence = XmlUtil.SafeInnerText(xmlChild);
				else if(xmlChild.Name == ElemRunCommand)
					pe.OverrideUrl = XmlUtil.SafeInnerText(xmlChild);
				else if(xmlChild.Name == ElemEntryHistory)
					listHistory = ReadEntryHistory(xmlChild);
			}

			if(listHistory != null)
			{
				string strPassword = pe.Strings.ReadSafe(PwDefs.PasswordField);
				DateTime dtLastMod = pe.LastModificationTime;

				foreach(DatePasswordPair dpp in listHistory)
				{
					pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
						pwStorage.MemoryProtection.ProtectPassword,
						dpp.Password));
					pe.LastModificationTime = dpp.Time;

					pe.CreateBackup(null);
				}
				// Maintain backups manually now (backups from the imported file
				// might have been out of order)
				pe.MaintainBackups(pwStorage);

				pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
					pwStorage.MemoryProtection.ProtectPassword,
					strPassword));
				pe.LastModificationTime = dtLastMod;
			}

			PwGroup pgContainer = pwStorage.RootGroup;
			if(strGroupName.Length != 0)
				pgContainer = pwStorage.RootGroup.FindCreateSubTree(strGroupName,
					new string[1]{ "." }, true);
			pgContainer.AddEntry(pe, true);
//.........这里部分代码省略.........
开发者ID:riking,项目名称:go-keepass2,代码行数:101,代码来源:PwSafeXml302.cs

示例2: 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;
        }
开发者ID:rdealexb,项目名称:keepass,代码行数:80,代码来源:PwEntryForm.cs


注:本文中的PwEntry.MaintainBackups方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。