本文整理汇总了C#中Array.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Array.Add方法的具体用法?C# Array.Add怎么用?C# Array.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Array
的用法示例。
在下文中一共展示了Array.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
Run()
{
Log.Detail("Running build");
// TODO: should the rank collections be sorted, so that modules with fewest dependencies are first?
var graph = Graph.Instance;
var metaDataType = graph.BuildModeMetaData.GetType();
var useEvaluation = CheckIfModulesNeedRebuilding(metaDataType);
var explainRebuild = CommandLineProcessor.Evaluate(new Options.ExplainBuildReason());
var immediateOutput = CommandLineProcessor.Evaluate(new Options.ImmediateOutput());
ExecutePreBuild(metaDataType);
if (!System.IO.Directory.Exists(graph.BuildRoot))
{
System.IO.Directory.CreateDirectory(graph.BuildRoot);
}
var threadCount = CommandLineProcessor.Evaluate(new Options.MultiThreaded());
if (0 == threadCount)
{
threadCount = System.Environment.ProcessorCount;
}
System.Exception abortException = null;
if (threadCount > 1)
{
var cancellationSource = new System.Threading.CancellationTokenSource();
var cancellationToken = cancellationSource.Token;
// LongRunning is absolutely necessary in order to achieve paralleism
var creationOpts = System.Threading.Tasks.TaskCreationOptions.LongRunning;
var continuationOpts = System.Threading.Tasks.TaskContinuationOptions.LongRunning;
var scheduler = new LimitedConcurrencyLevelTaskScheduler(threadCount);
var factory = new System.Threading.Tasks.TaskFactory(
cancellationToken,
creationOpts,
continuationOpts,
scheduler);
var tasks = new Array<System.Threading.Tasks.Task>();
foreach (var rank in graph.Reverse())
{
foreach (var module in rank)
{
var context = new ExecutionContext(useEvaluation, explainRebuild, immediateOutput);
var task = factory.StartNew(() =>
{
if (cancellationToken.IsCancellationRequested)
{
return;
}
var depTasks = new Array<System.Threading.Tasks.Task>();
foreach (var dep in module.Dependents)
{
if (null == dep.ExecutionTask)
{
continue;
}
depTasks.Add(dep.ExecutionTask);
}
foreach (var dep in module.Requirements)
{
if (null == dep.ExecutionTask)
{
continue;
}
depTasks.Add(dep.ExecutionTask);
}
System.Threading.Tasks.Task.WaitAll(depTasks.ToArray());
if (cancellationToken.IsCancellationRequested)
{
return;
}
try
{
(module as IModuleExecution).Execute(context);
}
catch (Exception ex)
{
abortException = ex;
cancellationSource.Cancel();
}
finally
{
if (context.OutputStringBuilder != null && context.OutputStringBuilder.Length > 0)
{
Log.Info(context.OutputStringBuilder.ToString());
}
if (context.ErrorStringBuilder != null && context.ErrorStringBuilder.Length > 0)
{
Log.Info(context.ErrorStringBuilder.ToString());
}
}
});
tasks.Add(task);
//.........这里部分代码省略.........
示例2: ResolveDependencies
/// <summary>
/// Based on the dependents lists in the XML file, resolve all dependents by reading more
/// package definition files.
/// </summary>
/// <param name="current">Current.</param>
/// <param name="authenticated">Authenticated.</param>
/// <param name="candidatePackageDefinitions">Candidate package definitions.</param>
public static void ResolveDependencies(
PackageDefinition current,
Array<PackageDefinition> authenticated,
Array<PackageDefinition> candidatePackageDefinitions)
{
var matchingPackages = authenticated.Where(item => item.Name == current.Name);
if (null != current.Version)
{
matchingPackages = matchingPackages.Where(item => item.Version == current.Version);
}
if (matchingPackages.FirstOrDefault() != null)
{
return;
}
if (!current.SupportedPlatforms.Includes(OSUtilities.CurrentOS))
{
throw new Exception("Package {0} is not supported on {1}", current.FullName, OSUtilities.CurrentOS.ToString());
}
authenticated.Add(current);
foreach (var dependent in current.Dependents)
{
var depName = dependent.Item1;
var depVersion = dependent.Item2;
var candidates = candidatePackageDefinitions.Where(item => item.Name == depName);
if (depVersion != null)
{
candidates = candidates.Where(item => item.Version == depVersion);
}
var candidateCount = candidates.Count();
if (0 == candidateCount)
{
var message = new System.Text.StringBuilder();
message.AppendFormat("Unable to find a candidate package with name '{0}'", depName);
if (null != depVersion)
{
message.AppendFormat(" and version {0}", depVersion);
}
message.AppendLine();
var packageRepos = new StringArray();
Graph.Instance.PackageRepositories.ToList().ForEach(item => packageRepos.AddUnique(item));
message.AppendLine("Searched in the package repositories:");
message.AppendLine(packageRepos.ToString("\n"));
throw new Exception(message.ToString());
}
if (candidateCount > 1)
{
var message = new System.Text.StringBuilder();
message.AppendFormat("There are {0} identical candidate packages with name '{1}'", candidateCount, depName);
if (null != depVersion)
{
message.AppendFormat(" and version {0}", depVersion);
}
message.AppendLine(" from the following package definition files:");
foreach (var candidate in candidates)
{
message.AppendFormat(candidate.XMLFilename);
message.AppendLine();
}
var packageRepos = new StringArray();
Graph.Instance.PackageRepositories.ToList().ForEach(item => packageRepos.AddUnique(item));
message.AppendLine("Found in the package repositories:");
message.AppendLine(packageRepos.ToString("\n"));
throw new Exception(message.ToString());
}
ResolveDependencies(candidates.First(), authenticated, candidatePackageDefinitions);
}
}
示例3: ShowDependencies
private void ShowDependencies(
int depth,
Array<PackageDefinition> visitedPackages,
string packageFormatting)
{
visitedPackages.Add(this);
foreach (var dependent in this.Dependents)
{
var dep = Graph.Instance.Packages.Where(item => item.Name == dependent.Item1 && item.Version == dependent.Item2).First();
if (visitedPackages.Contains(dep))
{
continue;
}
var formattedName = System.String.Format("{0}{1}{2}",
new string(' ', depth * 4),
dep.FullName,
dependent.Item3.GetValueOrDefault(false) ? "*" : System.String.Empty);
var repo = (dep.PackageRepositories.Count > 0) ? dep.PackageRepositories[0] : "Found in " + System.IO.Path.GetDirectoryName(dep.GetPackageDirectory());
Log.MessageAll(packageFormatting, formattedName, repo);
if (dep.Dependents.Count > 0)
{
dep.ShowDependencies(depth + 1, visitedPackages, packageFormatting);
}
}
}
示例4: get_constants_at
// non-recursive
internal Array get_constants_at () //author: Brian
{
Array result = new Array();
foreach (KeyValuePair<string, object> var in instance_vars)
{
if (Symbol.is_const_id(var.Key))
result.Add(new String(var.Key));
}
return result;
}
示例5: Evaluate
Evaluate(
IRegExCommandLineArgument realArg)
{
if (null != realArg.ShortName)
{
throw new Exception("The command line argument '{0}' does not support short names", realArg.GetType().ToString());
}
var reg = new System.Text.RegularExpressions.Regex(realArg.LongName);
var results = new Array<StringArray>();
foreach (var arg in Arguments)
{
var matches = reg.Match(arg);
if (!matches.Success)
{
continue;
}
var thisResult = new StringArray();
foreach (var group in matches.Groups)
{
if (group.ToString() == arg)
{
continue;
}
thisResult.Add(group.ToString());
}
results.Add(thisResult);
}
return results;
}
示例6: 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;
}
}
//.........这里部分代码省略.........