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


C# Index.Add方法代码示例

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


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

示例1: CanAddDuplicatesIfInitializedWithAllowDuplicateFlag

 public void CanAddDuplicatesIfInitializedWithAllowDuplicateFlag()
 {
     SUT = new Index<string, double>(true);
     SUT.Add("hello", 40);
     SUT.Add("hello", 40);
     Assert.AreEqual(2, SUT["hello"].Count);
 }
开发者ID:iainsproat,项目名称:SharpFE,代码行数:7,代码来源:IndexTest.cs

示例2: TestOneElement

 public void TestOneElement()
 {
     using(var map = new MemoryMapStream())
     {
         var index = new Index<string>(map);
         var id = index.Add("Ben");
         Assert.AreEqual("Ben", index.Get(id));
     }
 }
开发者ID:cmberryau,项目名称:reminiscence,代码行数:9,代码来源:IndexTests.cs

示例3: ScriptNode

 static ScriptNode() {
    _subtypes = new Index<string, Type>(t => t.Name);
    _subtypes.Add(typeof(ConditionNode));
    _subtypes.Add(typeof(ExceptionNode));
    _subtypes.Add(typeof(InitializationNode));
    _subtypes.Add(typeof(IterationNode));
    _subtypes.Add(typeof(OperationNode));
    _subtypes.Add(typeof(ParallelNode));
    _subtypes.Add(typeof(SequenceNode));
    _subtypes.Add(typeof(TerminationNode));
 }
开发者ID:borkaborka,项目名称:gmit,代码行数:11,代码来源:ScripNode.cs

示例4: Filter

 public Index Filter(IndexBinding binding)
 {
     Index res = new Index();
     bool wasSorted = binding.IsSorted;
     ListSortDirection prevOrder = binding.Order;
     if (!wasSorted || prevOrder != settings.Direction)
         binding.Sort(settings.Direction);
     int lim = settings.Count > binding.Count ? binding.Count : settings.Count;
     int i = 0;
     foreach (KeyValuePair<string, int> pair in binding)
     {
         if (i >= lim)
             break;
         res.Add(pair.Key, pair.Value);
         i++;
     }
     if (!wasSorted)
         binding.Reset();
     else if (prevOrder != settings.Direction)
         binding.Sort(prevOrder);
     return res;
 }
开发者ID:trustmaster,项目名称:WordFreqAnalyzer,代码行数:22,代码来源:IndexFilter.cs

示例5: IndexAdd

		public void IndexAdd()
		{
			var workingDirectory = Path.Combine(trash.FullName, "test");
			using (var repo = Repository.Init(workingDirectory))
			{
				var index_path = Path.Combine(repo.Directory, "index");
				var old_index = Path.Combine(repo.Directory, "old_index");
				var index = repo.Index;
				index.Write(); // write empty index
				new FileInfo(index_path).CopyTo(old_index);
				string filepath = Path.Combine(workingDirectory, "for henon.txt");
				File.WriteAllText(filepath, "Weißbier");
				repo.Index.Add(filepath);
				// now verify
				Assert.IsTrue(new FileInfo(index_path).Exists);
				Assert.AreNotEqual(File.ReadAllBytes(old_index), File.ReadAllBytes(index_path));

				// make another addition
				var index_1 = Path.Combine(repo.Directory, "index_1");
				new FileInfo(index_path).CopyTo(index_1);
				string filepath1 = Path.Combine(workingDirectory, "for nulltoken.txt");
				File.WriteAllText(filepath1, "Rotwein");
				index = new Index(repo);
				index.Add(filepath1);
				Assert.AreNotEqual(File.ReadAllBytes(index_1), File.ReadAllBytes(index_path));
				Assert.DoesNotThrow(() => repo.Index.Read());

				var status = repo.Status;
				Assert.IsTrue(status.Added.Contains("for henon.txt"));
				Assert.IsTrue(status.Added.Contains("for nulltoken.txt"));
				Assert.AreEqual(2, status.Added.Count);
				Assert.AreEqual(0, status.Staged.Count);
				Assert.AreEqual(0, status.Missing.Count);
				Assert.AreEqual(0, status.Modified.Count);
				Assert.AreEqual(0, status.Removed.Count);
			}
		}
开发者ID:dev218,项目名称:GitSharp,代码行数:37,代码来源:IndexTest.cs

示例6: IsStatusResultAccurate

        public void IsStatusResultAccurate()
        {
            //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.
            bool bare = false;
            var path = Path.Combine(trash.FullName, "test");
            using (var repo = Repository.Init(path, bare))
            {
                StatusCommand cmd = new StatusCommand();
                Assert.IsNotNull(cmd);
                cmd.Repository = repo;
                Assert.IsNotNull(cmd.Repository);
                //Verify the file has not already been created
                string filename = "newfile.txt";
                StatusResults results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsFalse(results.Contains(filename, StatusState.Untracked));

                //Create the file and verify the file is untracked
                string filepath = Path.Combine(repo.WorkingDirectory, filename);
                File.WriteAllText(filepath, "Just a simple test.");
                //Re-populate the status results
                results.Clear();
                results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsFalse(results.Contains(filename, StatusState.Staged));
                Assert.IsFalse(results.Contains(filename, StatusState.Modified));
                Assert.IsTrue(results.Contains(filename, StatusState.Untracked));

                //Add the file to the index and verify the file is modified
                Index index = new Index(repo);
                index.Add(filepath);
                //Re-populate the status results
                results.Clear();
                results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsTrue(results.Contains(filename, StatusState.Staged));
                Assert.IsFalse(results.Contains(filename, StatusState.Modified));
                Assert.IsFalse(results.Contains(filename, StatusState.Untracked));

                //Change the modified file status to staged and verify the file is staged.
                index.Add(filepath);
                //Re-populate the status results
                results.Clear();
                results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsTrue(results.Contains(filename, StatusState.Staged));
                Assert.IsFalse(results.Contains(filename, StatusState.Modified));
                Assert.IsFalse(results.Contains(filename, StatusState.Untracked));

                // Modify the staged file and verify the file is both modified
                // and staged simultaneously.
                File.AppendAllText(filepath, "Appended a line.");
                //Re-populate the status results
                results.Clear();
                results = Git.Status(cmd);
                Assert.IsNotNull(results);
                Assert.IsTrue(results.Contains(filename, StatusState.Staged));
                Assert.IsTrue(results.Contains(filename, StatusState.Modified));
                Assert.IsFalse(results.Contains(filename, StatusState.Untracked));

            }
        }
开发者ID:mooffie,项目名称:GitSharp,代码行数:63,代码来源:StatusTests.cs

示例7: Load

      /// <summary>Loads the diagram with the given collection of classes and namespaces.</summary>
      public void Load(IEnumerable<BplClass> classes) {
         Children.Clear();
         var counter = 0;

         // blocks layer
         _blocks = new Index<long, BplNamespace, DiagramBlock>(block => block.Id, block => block.Namespace);
         Blocks = new ReadOnlyIndex<long, BplNamespace, DiagramBlock>(_blocks);
         BlocksLayer = new Canvas();
         Children.Add(BlocksLayer);
         foreach (var ns in classes.Select(c => c.Namespace).Distinct()) {
            var block = new DiagramBlock(this, counter++, ns);
            BlocksLayer.Children.Add(block);
            _blocks.Add(block);
         }

         // skeleton layer
         SkeletonLayer = new Canvas();
         Children.Add(SkeletonLayer);

         // edges layer
         Edges = new HashSet<DiagramEdge>();
         EdgesLayer = new Canvas();
         Children.Add(EdgesLayer);

         // nodes layer
         _nodes = new Index<long, BplClass, DiagramNode>(node => node.Id, node => node.Class);
         Nodes = new ReadOnlyIndex<long, BplClass, DiagramNode>(_nodes);
         NodesLayer = new Canvas();
         Children.Add(NodesLayer);
         foreach (var bplClass in classes) {
            var node = new DiagramNode(this, counter++, bplClass);
            NodesLayer.Children.Add(node);
            _nodes.Add(node);
            _blocks[bplClass.Namespace].Add(node);
         }

         // content frame
         if (ContentBounds != null) {
            ContentBounds.SizeChanged -= _onContentSizeChanged;
         }
         ContentBounds = new Rectangle();
         ContentBounds.SizeChanged += _onContentSizeChanged;
         Children.Add(ContentBounds);

         IsEmpty = (Blocks.Count == 0 || Nodes.Count == 0);
         _isFirstLayout = true;
      }
开发者ID:borkaborka,项目名称:gmit,代码行数:48,代码来源:DiagramCanvas.cs

示例8: TestTinyAccessors

        public void TestTinyAccessors()
        {
            using (var map = new MemoryMapStream())
            {
                using (var tempStream = new MemoryStream(new byte[1024]))
                {
                    var index = new Index<string>(map, 32);

                    var element = "Ben";
                    var id1 = index.Add(element);
                    Assert.AreEqual(0, id1);
                    var id2Ref = MemoryMapDelegates.WriteToString(tempStream, id1, ref element);

                    element = "Abelshausen";
                    var id2 = index.Add(element);
                    Assert.AreEqual(id2Ref, id2);
                    var id3Ref = MemoryMapDelegates.WriteToString(tempStream, id2, ref element) + id2;

                    element = "is";
                    var id3 = index.Add(element);
                    Assert.AreEqual(id3Ref, id3);
                    var id4Ref = MemoryMapDelegates.WriteToString(tempStream, id3, ref element) + id3;

                    element = "the";
                    var id4 = index.Add(element);
                    Assert.AreEqual(id4Ref, id4);
                    var id5Ref = MemoryMapDelegates.WriteToString(tempStream, id4, ref element) + id4;

                    element = "author";
                    var id5 = index.Add(element);
                    Assert.AreEqual(id5Ref, id5);
                    var id6Ref = MemoryMapDelegates.WriteToString(tempStream, id5, ref element) + id5;

                    element = "of";
                    var id6 = index.Add(element);
                    Assert.AreEqual(id6Ref, id6);
                    var id7Ref = MemoryMapDelegates.WriteToString(tempStream, id6, ref element) + id6;

                    element = "this";
                    var id7 = index.Add(element);
                    Assert.AreEqual(id7Ref, id7);
                    var id8Ref = MemoryMapDelegates.WriteToString(tempStream, id7, ref element) + id7;

                    element = "library";
                    var id8 = index.Add(element);
                    Assert.AreEqual(id8Ref, id8);
                    var id9Ref = MemoryMapDelegates.WriteToString(tempStream, id8, ref element) + id8;

                    element = "and";
                    var id9 = index.Add(element);
                    Assert.AreEqual(id9Ref, id9);
                    var id10Ref = MemoryMapDelegates.WriteToString(tempStream, id9, ref element) + id9;

                    element = "this";
                    var id10 = index.Add(element);
                    Assert.AreEqual(id10Ref, id10);
                    var id11Ref = MemoryMapDelegates.WriteToString(tempStream, id10, ref element) + id10;

                    element = "test!";
                    var id11 = index.Add("test!");
                    Assert.AreEqual(id11Ref, id11);
                    var id12Ref = MemoryMapDelegates.WriteToString(tempStream, id11, ref element) + id11;

                    Assert.AreEqual(id12Ref, index.SizeInBytes);

                    Assert.AreEqual("Ben", index.Get(id1));
                    Assert.AreEqual("Abelshausen", index.Get(id2));
                    Assert.AreEqual("is", index.Get(id3));
                    Assert.AreEqual("the", index.Get(id4));
                    Assert.AreEqual("author", index.Get(id5));
                    Assert.AreEqual("of", index.Get(id6));
                    Assert.AreEqual("this", index.Get(id7));
                    Assert.AreEqual("library", index.Get(id8));
                    Assert.AreEqual("and", index.Get(id9));
                    Assert.AreEqual("this", index.Get(id10));
                    Assert.AreEqual("test!", index.Get(id11));
                }
            }
        }
开发者ID:cmberryau,项目名称:reminiscence,代码行数:79,代码来源:IndexTests.cs

示例9: TestCreateFromAndCopyTo

        /// <summary>
        /// Tests create from and copy to in a row.
        /// </summary>
        public void TestCreateFromAndCopyTo()
        {
            byte[] data = null;
            var indexDictionary = new System.Collections.Generic.Dictionary<long, string>();

            using (var indexStream = new MemoryStream())
            {
                using (var map = new MemoryMapStream())
                {
                    // write to index and to a stream.
                    var index = new Index<string>(map, 32);

                    var element = "Ben";
                    var id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "Abelshausen";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "is";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "the";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "author";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "of";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "this";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "library";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "and";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "this";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "test!";
                    id = index.Add("test!");
                    indexDictionary[id] = element;

                    index.CopyToWithSize(indexStream);
                    data = indexStream.ToArray();
                }
            }

            using (var indexStream = new MemoryStream(data))
            {
                var index = Index<string>.CreateFromWithSize(indexStream);

                foreach (var refIndexElement in indexDictionary)
                {
                    var value = index.Get(refIndexElement.Key);
                    Assert.AreEqual(refIndexElement.Value, value);
                }

                using(var outputData = new MemoryStream())
                {
                    var size = index.CopyToWithSize(outputData);
                    Assert.AreEqual(data.Length, size);
                }
            }
        }
开发者ID:cmberryau,项目名称:reminiscence,代码行数:71,代码来源:IndexTests.cs

示例10: TestCopyTo

        /// <summary>
        /// Tests copying the data to a stream.
        /// </summary>
        public void TestCopyTo()
        {
            using (var map = new MemoryMapStream())
            {
                using (var refStream = new MemoryStream(new byte[1024]))
                {
                    // write to index and to a stream.
                    var index = new Index<string>(map, 32);

                    var element = "Ben";
                    var id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "Abelshausen";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "is";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "the";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "author";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "of";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "this";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "library";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "and";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "this";
                    id = index.Add(element);
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    element = "test!";
                    id = index.Add("test!");
                    MemoryMapDelegates.WriteToString(refStream, id, ref element);

                    refStream.SetLength(refStream.Position);

                    using(var indexStream = new MemoryStream((int)index.SizeInBytes))
                    {
                        var refBytes = refStream.ToArray();

                        Assert.AreEqual(refBytes.Length, index.CopyTo(indexStream));
                        var bytes = indexStream.ToArray();

                        Assert.AreEqual(index.SizeInBytes, bytes.Length);
                        Assert.AreEqual(index.SizeInBytes, refBytes.Length);

                        for(var i = 0; i < bytes.Length; i++)
                        {
                            Assert.AreEqual(refBytes[i], bytes[i]);
                        }
                    }

                    using (var indexStream = new MemoryStream((int)index.SizeInBytes + 8))
                    {
                        var refBytes = refStream.ToArray();

                        Assert.AreEqual(refBytes.Length + 8, index.CopyToWithSize(indexStream));
                        var bytes = indexStream.ToArray();

                        Assert.AreEqual(index.SizeInBytes, bytes.Length - 8);
                        Assert.AreEqual(index.SizeInBytes, refBytes.Length);

                        for (var i = 0; i < refBytes.Length; i++)
                        {
                            Assert.AreEqual(refBytes[i], bytes[i + 8]);
                        }
                    }
                }
            }
        }
开发者ID:cmberryau,项目名称:reminiscence,代码行数:92,代码来源:IndexTests.cs

示例11: 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

示例12: Execute

        public override void Execute()
        {
            foreach (string arg in Arguments)
            {
                //Todo: Add FileNameMatcher support. To be added when fnmatch is completed.
                //For now, pattern matching is not allowed. Please specify the files only.

                //Gain access to the Git index using the repository determined before command execution
                Index index = new Index(Repository);

                //Use full paths only to eliminate platform-based directory differences
                string path = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), arg));

                //Perform the validity tests outside of the index to handle the error messages
                if ((new FileInfo(path).Exists) || (new DirectoryInfo(path).Exists))
                    index.Add(path);
                else
                    OutputStream.WriteLine(path + " does not exist.");
            }
        }
开发者ID:spraints,项目名称:GitSharp,代码行数:20,代码来源:AddCommand.cs

示例13: ClassTree

         // Constructor
         public ClassTree(IEnumerable<BplClass> rootClasses, bool isHierarchical) {
            Index = new Index<BplClass, ClassNode>(node => node.Class);
            TopLevel = new List<ClassNode>();
            
            if (rootClasses == null) {
               rootClasses = new[] { BplClass.Get<BplObject>() };
            }

            IEnumerable<BplClass> topClasses = null;
            if (isHierarchical) {
               topClasses = rootClasses.SelectMany(r => r.DerivedClasses);
            } else {
               topClasses = rootClasses.SelectMany(r => r.SubClassesAndSelf);
            }

            foreach (var bplClass in topClasses.Where(InScope).OrderBy(c => c.Name)) {
               var classNode = new ClassNode(bplClass);
               TopLevel.Add(classNode);
               Index.Add(classNode);
               if (isHierarchical) {
                  AddNested(classNode);
               }
            }

            Disambiguate(TopLevel);
         }
开发者ID:borkaborka,项目名称:gmit,代码行数:27,代码来源:IndexSelector.xaml.cs


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