本文整理汇总了C#中Index.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Index.Remove方法的具体用法?C# Index.Remove怎么用?C# Index.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Index
的用法示例。
在下文中一共展示了Index.Remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunStatusTests
void RunStatusTests(StatusOperation oper)
{
//Due to the cumulative nature of these tests, rather than recreate the same
// conditions multiple times, all StatusResult testing has been rolled into one test.
var path = Path.Combine(trash.FullName, "test" + ++repCount);
if (Directory.Exists (path)) {
Directory.Delete (path, true);
Directory.CreateDirectory (path);
}
using (var repo = Repository.Init(path, false))
{
List<string> filesToCheck = new List<string> ();
//Verify the file has not already been created
filesToCheck.Clear ();
RepositoryStatus results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename);
AssertStatus (results, filesToCheck, filenameSubdir1);
AssertStatus (results, filesToCheck, filenameSubdir2);
//Create the files and verify the files are untracked
if (!Directory.Exists (repo.FromGitPath ("subdir1/subdir2")))
Directory.CreateDirectory (repo.FromGitPath ("subdir1/subdir2"));
File.WriteAllText(repo.FromGitPath (filename), "Just a simple test.");
File.WriteAllText(repo.FromGitPath (filenameSubdir1), "Just a simple test.");
File.WriteAllText(repo.FromGitPath (filenameSubdir2), "Just a simple test.");
filesToCheck.Clear ();
results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir1, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
// Modify a file
File.WriteAllText(repo.FromGitPath (filenameSubdir1), "Just a simple modified test.");
filesToCheck.Clear ();
results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir1, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
//Add an unmodified file to the index
File.WriteAllText(repo.FromGitPath (filenameSubdir1), "Just a simple test.");
Index index = new Index(repo);
index.Add(filenameSubdir1);
filesToCheck.Clear ();
results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir1, results.Added);
AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
//Modify file in the index
File.WriteAllText(repo.FromGitPath (filenameSubdir1), "Just a simple modified test.");
filesToCheck.Clear ();
results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir1, results.Modified, results.Added);
AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
// Commit the added file
repo.Commit ("test 1");
filesToCheck.Clear ();
results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir1, results.Modified);
AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
// Commit the modification
index.Add (filenameSubdir1);
repo.Commit ("test 2");
filesToCheck.Clear ();
results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir1);
AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
// Modify the committed file
File.WriteAllText(repo.FromGitPath (filenameSubdir1), "Modified after commit.");
filesToCheck.Clear ();
results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir1, results.Modified);
AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
// Remove the committed file
File.Delete (repo.FromGitPath (filenameSubdir1));
filesToCheck.Clear ();
results = oper (repo, filesToCheck);
AssertStatus (results, filesToCheck, filename, results.Untracked);
AssertStatus (results, filesToCheck, filenameSubdir1, results.Missing); // FIXME: should be Removed??
AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
//.........这里部分代码省略.........
示例2: Index_must_be_accessed_in_parallel
public void Index_must_be_accessed_in_parallel()
{
var index = new Index<int,int>();
var nrOfTasks = 10000;
var nrOfKeys = 10;
var nrOfValues = 10;
// Fill index
for(var key = 0; key < nrOfKeys; key++)
for (var value = 0; value < nrOfValues; value++)
index.Put(key, value);
// Tasks to be executed in parallel
Action putTask =
() => index.Put(ThreadLocalRandom.Current.Next(nrOfKeys), ThreadLocalRandom.Current.Next(nrOfValues));
Action removeTask1 = () => index.Remove(ThreadLocalRandom.Current.Next(nrOfKeys/2), ThreadLocalRandom.Current.Next(nrOfValues));
Action removeTask2 = () => index.Remove(ThreadLocalRandom.Current.Next(nrOfKeys / 2));
Action readTask = () =>
{
var key = ThreadLocalRandom.Current.Next(nrOfKeys);
var values = index[key];
if (key >= nrOfKeys/2)
{
values.Any().ShouldBeTrue();
}
};
Func<Action> randomTask = () =>
{
var next = ThreadLocalRandom.Current.Next(4);
switch (next)
{
case 0:
return putTask;
case 1:
return removeTask1;
case 2:
return removeTask2;
default:
return readTask;
}
};
var tasks = Enumerable.Repeat(randomTask(), nrOfTasks).Select(Task.Run);
Task.WaitAll(tasks.ToArray(), GetTimeoutOrDefault(null));
}