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


C# QueryType.HasFlag方法代码示例

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


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

示例1: QueryAsync

		public async Task<QuerySummary> QueryAsync(string sourcePath, bool recursive, QueryType queries, params MetaType[] types)
		{
			if (String.IsNullOrEmpty(sourcePath))
				throw new ArgumentNullException(nameof(sourcePath));
			if (!Directory.Exists(sourcePath))
				throw new DirectoryNotFoundException(sourcePath);
			if (queries == QueryType.None)
				throw new ArgumentException("No queries given.");

			Dictionary<string, IEnumerable<Tuple<string, QueryType>>> duplicates = new Dictionary<string, IEnumerable<Tuple<string, QueryType>>>();
			Dictionary<string, string> md5sums = new Dictionary<string, string>();
			Dictionary<string, string> sha1sums = new Dictionary<string, string>();
			IEnumerable<MetaData> data = await GetMetaData(sourcePath, recursive, types);
			foreach (MetaData item in data.Where(x => x.Type != MetaType.Directory && x.Type != MetaType.File))
			{
				List<Tuple<string, QueryType>> matches = new List<Tuple<string, QueryType>>();
				foreach (MetaData other in data.Where(x => x.Type != MetaType.Directory && x.Type != MetaType.File && !x.Equals(item)))
				{
					QueryType match = QueryType.None;

					bool equalFilename = Path.GetFileName(item.Path).Equals(Path.GetFileName(other.Path), StringComparison.Ordinal /* TODO: which type? */);
					if (queries.HasFlag(QueryType.EqualFileName) && equalFilename)
							match |= QueryType.EqualFileName;

					if (queries.HasFlag(QueryType.EqualFileNameDifferentFileSize) && equalFilename)
					{
							if (item.Data[MetaKey.Size] != other.Data[MetaKey.Size])
								match |= QueryType.EqualFileNameDifferentFileSize;
					}

					if (queries.HasFlag(QueryType.EqualChecksumMD5) || queries.HasFlag(QueryType.EqualFileNameDifferentChecksumMD5))
					{
							string md5item;
							if (!md5sums.TryGetValue(item.Path, out md5item))
							{
								md5item = GetMD5(item.Path);
								md5sums[item.Path] = md5item;
							}

							string md5other;
							if (!md5sums.TryGetValue(other.Path, out md5other))
							{
								md5other = GetMD5(other.Path);
								md5sums[other.Path] = md5other;
							}

						bool md5match = md5item.Equals(md5other, StringComparison.Ordinal);
						if (queries.HasFlag(QueryType.EqualChecksumMD5) && md5match)
							match |= QueryType.EqualChecksumMD5;
						if (queries.HasFlag(QueryType.EqualFileNameDifferentChecksumMD5) && equalFilename && !md5match)
							match |= QueryType.EqualFileNameDifferentChecksumMD5;
					}

					if (queries.HasFlag(QueryType.EqualChecksumSHA1) || queries.HasFlag(QueryType.EqualFileNameDifferentChecksumSHA1))
					{
						string sha1item;
						if (!sha1sums.TryGetValue(item.Path, out sha1item))
						{
							sha1item = GetSHA1(item.Path);
							sha1sums[item.Path] = sha1item;
						}

						string sha1other;
						if (!sha1sums.TryGetValue(other.Path, out sha1other))
						{
							sha1other = GetSHA1(other.Path);
							sha1sums[other.Path] = sha1other;
						}

						bool sha1match = sha1item.Equals(sha1other, StringComparison.Ordinal);
						if (queries.HasFlag(QueryType.EqualChecksumSHA1) && sha1match)
							match |= QueryType.EqualChecksumSHA1;
						if (queries.HasFlag(QueryType.EqualFileNameDifferentChecksumSHA1) && equalFilename && !sha1match)
							match |= QueryType.EqualFileNameDifferentChecksumSHA1;
					}

					if ((queries.HasFlag(QueryType.LowResolution) || queries.HasFlag(QueryType.EqualFileNameDifferentResolution)) && item.Data.ContainsKey(MetaKey.Resolution))
					{
						//const int limit = 960 * 1280;
						const int resolutionLimit = 1024 * 768;

						int resolutionItem = (int)item.Data[MetaKey.Width] * (int)item.Data[MetaKey.Height];
						if (resolutionItem <= resolutionLimit)
							match |= QueryType.LowResolution;

						if (queries.HasFlag(QueryType.EqualFileNameDifferentResolution) && other.Data.ContainsKey(MetaKey.Resolution) && equalFilename)
						{
							int resolutionOther = (int)other.Data[MetaKey.Width] * (int)other.Data[MetaKey.Height];
							if (resolutionItem != resolutionOther)
								match |= QueryType.EqualFileNameDifferentResolution;
						}
					}

					if (match != QueryType.None)
						matches.Add(Tuple.Create(other.Path, match));
				}

				if (matches.Count > 0)
					duplicates[item.Path] = matches;
			}
//.........这里部分代码省略.........
开发者ID:RiJo,项目名称:ExifOrganizer,代码行数:101,代码来源:MediaQuerier.cs


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