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


C# Index.Remove方法代码示例

本文整理汇总了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);

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

示例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));
        }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:49,代码来源:IndexSpec.cs


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