本文整理汇总了C#中Array.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GroupBy方法的具体用法?C# Array.GroupBy怎么用?C# Array.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Array
的用法示例。
在下文中一共展示了Array.GroupBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IdentifyAllPackages
IdentifyAllPackages(
bool allowDuplicates = false,
bool enforceBamAssemblyVersions = true)
{
var packageRepos = new System.Collections.Generic.Queue<string>();
foreach (var repo in Graph.Instance.PackageRepositories)
{
if (packageRepos.Contains(repo))
{
continue;
}
packageRepos.Enqueue(repo);
}
var masterDefinitionFile = GetMasterPackage(enforceBamAssemblyVersions: enforceBamAssemblyVersions);
foreach (var repo in masterDefinitionFile.PackageRepositories)
{
if (packageRepos.Contains(repo))
{
continue;
}
packageRepos.Enqueue(repo);
}
// read the definition files of any package found in the package roots
var candidatePackageDefinitions = new Array<PackageDefinition>();
candidatePackageDefinitions.Add(masterDefinitionFile);
while (packageRepos.Count > 0)
{
var repo = packageRepos.Dequeue();
if (!System.IO.Directory.Exists(repo))
{
throw new Exception("Package repository directory {0} does not exist", repo);
}
var candidatePackageDirs = System.IO.Directory.GetDirectories(repo, BamSubFolder, System.IO.SearchOption.AllDirectories);
Graph.Instance.PackageRepositories.Add(repo);
foreach (var bamDir in candidatePackageDirs)
{
var packageDir = System.IO.Path.GetDirectoryName(bamDir);
var packageDefinitionPath = GetPackageDefinitionPathname(packageDir);
// ignore any duplicates (can be found due to nested repositories)
if (null != candidatePackageDefinitions.Where(item => item.XMLFilename == packageDefinitionPath).FirstOrDefault())
{
continue;
}
var definitionFile = new PackageDefinition(packageDefinitionPath, !Graph.Instance.ForceDefinitionFileUpdate);
definitionFile.Read(true, enforceBamAssemblyVersions);
candidatePackageDefinitions.Add(definitionFile);
foreach (var newRepo in definitionFile.PackageRepositories)
{
if (Graph.Instance.PackageRepositories.Contains(newRepo))
{
continue;
}
packageRepos.Enqueue(newRepo);
}
}
}
// defaults come from
// - the master definition file
// - command line args (these trump the mdf)
// and only requires resolving when referenced
var packageDefinitions = new Array<PackageDefinition>();
PackageDefinition.ResolveDependencies(masterDefinitionFile, packageDefinitions, candidatePackageDefinitions);
// now resolve any duplicate names using defaults
// unless duplicates are allowed
var duplicatePackageNames = packageDefinitions.GroupBy(item => item.Name).Where(item => item.Count() > 1).Select(item => item.Key);
if ((duplicatePackageNames.Count() > 0) && !allowDuplicates)
{
var versionSpeciferArgs = new Options.PackageDefaultVersion();
var packageVersionSpecifiers = CommandLineProcessor.Evaluate(versionSpeciferArgs);
var toRemove = new Array<PackageDefinition>();
foreach (var dupName in duplicatePackageNames)
{
var duplicates = packageDefinitions.Where(item => item.Name == dupName);
PackageDefinition resolvedDuplicate = null;
// command line specifications take precedence to resolve a duplicate
foreach (var specifier in packageVersionSpecifiers)
{
if (!specifier.Contains(dupName))
{
continue;
}
foreach (var dupPackage in duplicates)
{
if (specifier[1] == dupPackage.Version)
{
resolvedDuplicate = dupPackage;
break;
}
}
//.........这里部分代码省略.........