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


C# PwGroup.GetCounts方法代码示例

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


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

示例1: WriteDocument

		private void WriteDocument(PwGroup pgRoot)
		{
			Debug.Assert(m_xmlWriter != null);
			if(m_xmlWriter == null) throw new InvalidOperationException();

			uint uNumGroups, uNumEntries, uCurEntry = 0;
			pgRoot.GetCounts(true, out uNumGroups, out uNumEntries);

			m_xmlWriter.WriteStartDocument(true);
			m_xmlWriter.WriteStartElement(ElemDocNode);

			WriteMeta();

			m_xmlWriter.WriteStartElement(ElemRoot);
			StartGroup(pgRoot);

			Stack<PwGroup> groupStack = new Stack<PwGroup>();
			groupStack.Push(pgRoot);

			GroupHandler gh = delegate(PwGroup pg)
			{
				Debug.Assert(pg != null);
				if(pg == null) throw new ArgumentNullException("pg");

				while(true)
				{
					if(pg.ParentGroup == groupStack.Peek())
					{
						groupStack.Push(pg);
						StartGroup(pg);
						break;
					}
					else
					{
						groupStack.Pop();
						if(groupStack.Count <= 0) return false;

						EndGroup();
					}
				}

				return true;
			};

			EntryHandler eh = delegate(PwEntry pe)
			{
				Debug.Assert(pe != null);
				WriteEntry(pe, false);

				++uCurEntry;
				if(m_slLogger != null)
					if(!m_slLogger.SetProgress((100 * uCurEntry) / uNumEntries))
						return false;

				return true;
			};

			if(!pgRoot.TraverseTree(TraversalMethod.PreOrder, gh, eh))
				throw new InvalidOperationException();

			while(groupStack.Count > 1)
			{
				m_xmlWriter.WriteEndElement();
				groupStack.Pop();
			}

			EndGroup();

			WriteList(ElemDeletedObjects, m_pwDatabase.DeletedObjects);
			m_xmlWriter.WriteEndElement(); // Root

			m_xmlWriter.WriteEndElement(); // ElemDocNode
			m_xmlWriter.WriteEndDocument();
		}
开发者ID:joshuadugie,项目名称:KeePass-2.x,代码行数:74,代码来源:KdbxFile.Write.cs

示例2: WriteEntries

		private void WriteEntries(KdbManager mgr, Dictionary<PwGroup, uint> dictGroups,
			PwGroup pgRoot)
		{
			bool bWarnedOnce = false;
			uint uGroupCount, uEntryCount, uEntriesSaved = 0;
			pgRoot.GetCounts(true, out uGroupCount, out uEntryCount);

			DateTime dtNeverExpire = KdbManager.GetNeverExpireTime();

			EntryHandler eh = delegate(PwEntry pe)
			{
				KdbEntry e = new KdbEntry();

				e.Uuid.Set(pe.Uuid.UuidBytes);

				if(pe.ParentGroup != pgRoot)
					e.GroupId = dictGroups[pe.ParentGroup];
				else
				{
					e.GroupId = 1;
					if((m_slLogger != null) && !bWarnedOnce)
					{
						m_slLogger.SetText(KdbPrefix +
							KPRes.FormatNoRootEntries, LogStatusType.Warning);
						bWarnedOnce = true;
					}

					if(dictGroups.Count == 0)
						throw new Exception(KPRes.FormatNoSubGroupsInRoot);
				}

				e.ImageId = (uint)pe.IconId;

				e.Title = pe.Strings.ReadSafe(PwDefs.TitleField);
				e.UserName = pe.Strings.ReadSafe(PwDefs.UserNameField);
				e.Password = pe.Strings.ReadSafe(PwDefs.PasswordField);
				e.Url = pe.Strings.ReadSafe(PwDefs.UrlField);

				string strNotes = pe.Strings.ReadSafe(PwDefs.NotesField);
				ExportCustomStrings(pe, ref strNotes);
				ExportAutoType(pe, ref strNotes);
				ExportUrlOverride(pe, ref strNotes);
				e.Additional = strNotes;

				e.PasswordLength = (uint)e.Password.Length;

				Debug.Assert(TimeUtil.PwTimeLength == 7);
				e.CreationTime.Set(pe.CreationTime);
				e.LastModificationTime.Set(pe.LastModificationTime);
				e.LastAccessTime.Set(pe.LastAccessTime);

				if(pe.Expires) e.ExpirationTime.Set(pe.ExpiryTime);
				else e.ExpirationTime.Set(dtNeverExpire);

				IntPtr hBinaryData = IntPtr.Zero;
				if(pe.Binaries.UCount >= 1)
				{
					foreach(KeyValuePair<string, ProtectedBinary> kvp in pe.Binaries)
					{
						e.BinaryDescription = kvp.Key;

						byte[] pbAttached = kvp.Value.ReadData();
						e.BinaryDataLength = (uint)pbAttached.Length;

						if(e.BinaryDataLength > 0)
						{
							hBinaryData = Marshal.AllocHGlobal((int)e.BinaryDataLength);
							Marshal.Copy(pbAttached, 0, hBinaryData, (int)e.BinaryDataLength);

							e.BinaryData = hBinaryData;
						}

						break;
					}

					if((pe.Binaries.UCount > 1) && (m_slLogger != null))
						m_slLogger.SetText(KdbPrefix + KPRes.FormatOnlyOneAttachment + "\r\n\r\n" +
							KPRes.Entry + ":\r\n" + KPRes.Title + ": " + e.Title + "\r\n" +
							KPRes.UserName + ": " + e.UserName, LogStatusType.Warning);
				}

				bool bResult = mgr.AddEntry(ref e);

				Marshal.FreeHGlobal(hBinaryData);
				hBinaryData = IntPtr.Zero;

				if(!bResult)
				{
					Debug.Assert(false);
					throw new InvalidOperationException();
				}

				++uEntriesSaved;
				if(m_slLogger != null)
					if(!m_slLogger.SetProgress((100 * uEntriesSaved) / uEntryCount))
						return false;

				return true;
			};

//.........这里部分代码省略.........
开发者ID:kusuriya,项目名称:PasswordKeeper,代码行数:101,代码来源:KdbFile.cs

示例3: loadSubMenuItems

        private void loadSubMenuItems(PwGroup group, MenuItem currMenu)
        {
            const string UserName = "UserName";
            const string Title = "Title";
            const string URL = "URL";
            const string Password = "Password";
            const string CopyPwdCaption = "Copy Password";
            const string CopyUrlPwdCaption = "Launch URL && Copy Password";
            const string EditItemCaption = "Edit this item";

            uint grpCount = 0, entryCount = 0;
            group.GetCounts(false, out grpCount, out entryCount);
            if (entryCount > 0) {
                foreach (var j in group.GetEntries(false)) {

                    var titleMenu = new MenuItem(j.Strings.ReadSafe(Title));
                    currMenu.MenuItems.Add(titleMenu);

                    titleMenu.MenuItems.Add(new MenuItem(j.Strings.ReadSafe(UserName)));
                    var name = j.ParentGroup.Name + MenuSeparator + j.Strings.ReadSafe(Title) + MenuSeparator + j.Strings.ReadSafe(UserName);
                    var pwMnu = new MenuItem(CopyPwdCaption, onPwdMenuClick);
                    pwMnu.Name = name;
                    titleMenu.MenuItems.Add(pwMnu);
                    var pwlMnu = new MenuItem(CopyUrlPwdCaption, onUrlPwdMenuClick);
                    pwlMnu.Name = name;
                    titleMenu.MenuItems.Add(pwlMnu);

                    currMenu.MenuItems.Add(new MenuItem(MenuSeparator));

                    var editMnu = new MenuItem(EditItemCaption, OnEditItemClick);
                    editMnu.Name = name;
                    titleMenu.MenuItems.Add(editMnu);

                    try {
                        localPwdHash.Add(name, j.Strings.ReadSafe(Password));
                        localURLHash.Add(name, j.Strings.ReadSafe(URL));
                    } catch (Exception e) {
                        MessageBox.Show("Dupe found: " + name + MenuSeparator + j.Strings.ReadSafe(URL));
                    }

                }
            }
            // are there any group children
            if (grpCount > 0) {
                foreach (var j in group.Groups) {
                    var newGroupMenu = new MenuItem(j.Name);
                    currMenu.MenuItems.Add(newGroupMenu);
                    loadSubMenuItems(j, newGroupMenu);
                }
            }
        }
开发者ID:subatta,项目名称:KeePassMenu,代码行数:51,代码来源:Program.cs


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