Esempio n. 1
0
 public void CanAddDuplicatesIfInitializedWithAllowDuplicateFlag()
 {
     SUT = new Index<string, double>(true);
     SUT.Add("hello", 40);
     SUT.Add("hello", 40);
     Assert.AreEqual(2, SUT["hello"].Count);
 }
Esempio n. 2
0
 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));
     }
 }
Esempio n. 3
0
 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));
 }
        private void OnAddToIndex()
        {
            var paths = SelectedPaths
                        .Select(pvm => Path.GetFullPath(pvm.Path))
                        .ToArray();
            IndexingOptions options = new IndexingOptions();

            options.IsAsync = true;
            index.Add(paths, options);
        }
        private void WriteAttachmentMetadata(Slice key, Etag etag, RavenJObject headers)
        {
            var memoryStream = CreateStream();

            memoryStream.Write(etag);
            headers.WriteTo(memoryStream);

            memoryStream.Position = 0;
            metadataIndex.Add(writeBatch.Value, key, memoryStream);
        }
Esempio n. 6
0
        public void Open(string filename = "list.txt")
        {
            this.filename = filename;
            Model         = MessagePackSerializer.Deserialize <DCInsideGalleryModel>(File.ReadAllBytes(filename));

            for (int i = 0; i < Model.articles.Count; i++)
            {
                Index.Add(Convert.ToInt32(Model.articles[i].no), i);
            }
        }
Esempio n. 7
0
    void CreateCheck()
    {
        //검사할 방향
        Index[] arrayDirection = new Index[4];
        arrayDirection[0] = Index.left;
        arrayDirection[1] = Index.right;
        arrayDirection[2] = Index.top;
        arrayDirection[3] = Index.bottom;

        for (int y = 0; y < mCellHeightCount; ++y)
        {
            for (int x = 0; x < mCellWidthCount; ++x)
            {
                Index tempIndex = new Index(x, y);

                //{{ 각 방향으로 매치 검사 ~
                for (int i = 0; i < arrayDirection.Length; ++i)
                {
                    List <Node> line = new List <Node>();
                    //가로 검사냐 세로 검사냐에 따라 최대 셀 수가 달라짐
                    int maxCellCount = arrayDirection[i].x != 0 ? mCellWidthCount : mCellHeightCount;

                    int matchCount = 0; //매치된 수
                                        //해당 방향으로 검사
                    for (int j = 1; j < maxCellCount; ++j)
                    {
                        Index nextIndex = Index.Add(tempIndex, Index.Mul(arrayDirection[i], j));
                        //같은 타입이라면
                        if (GetPieceType(nextIndex) == GetPieceType(tempIndex))
                        {
                            //추가
                            Node node = GetNode(nextIndex);
                            line.Add(node);
                            ++matchCount;
                        }
                        //아니라면 해당 방향으로 검사 그만
                        else
                        {
                            break;
                        }
                    }
                    //3매치가 되었다면 지워주고 다시 생성
                    if (matchCount >= 2)
                    {
                        mIsCreateCheck = false;
                        GetPiece(tempIndex).DestroyPiece();
                        //CreateBoard();
                    }
                }
            }
        }
        //안되었다면 게임 시작 가능.
        mIsCreateCheck = true;
    }
Esempio n. 8
0
        public void TryGetValue_KeyExists_ReturnsTrue()
        {
            var index = new Index <int, string>(i => i.ToString());

            index.Add(5);

            string value;
            var    ret = index.TryGetValue(5, out value);

            Assert.That(ret, Is.True);
        }
Esempio n. 9
0
        public void GetAllIndexedItems_ReturnsAddedItems()
        {
            // Arrange
            var item1 = GetItemMock("1");

            index.Add(item1);

            var item2 = GetItemMock("2");

            index.Add(item2);

            // Act
            var allItems = index.GetAllIndexedItems();

            // Assert
            Assert.That(allItems, Is.SupersetOf(new[] { item1, item2 }));
        }
Esempio n. 10
0
        public void Enqueue <T>(Serializer <T> serializer, T data)
        {
            StorageAllocation allocation = storage.Allocate();

            index.Add(allocation.Position);

            int size = serializer.Transfer(data, allocation);

            storage.Commit(size);

            flags.IsSorted = false;
        }
Esempio n. 11
0
        public static IIndex <TKey, TSource> UnequalIndexSpecificationToIndex <TSource, TKey>(
            this IEnumerable <TSource> source, Func <TSource, TKey> keySelector) where TKey : IComparable <TKey>
        {
            Index <TKey, TSource> index = new Index <TKey, TSource>();

            foreach (var item in source)
            {
                TKey key = keySelector(item);
                index.Add(key, item);
            }
            return(index);
        }
        private SortedDictionary <TKey, TEntity> GetOrAddEntities(int key)
        {
            if (!Index.TryGetValue(key, out var entities))
            {
                entities = _comparer == null
                    ? new SortedDictionary <TKey, TEntity>()
                    : new SortedDictionary <TKey, TEntity>(_comparer);
                Index.Add(key, entities);
            }

            return(entities);
        }
 private void OnEnable()
 {
     MaterialProperties.Clear();
     cache.Clear();
     foreach (Material mat in GetComponent <Renderer>().sharedMaterials)
     {
         if (!MaterialProperties.ContainsKey(mat.name))
         {
             MaterialProperties.Add(mat.name, GetShaderProperties(mat));
         }
     }
 }
Esempio n. 14
0
 private void AssertAddFailsWithIllegalArgument <ENTITY>(Index <ENTITY> index, ENTITY entity, string key, object value) where ENTITY : Org.Neo4j.Graphdb.PropertyContainer
 {
     try
     {
         index.Add(entity, key, value);
         fail("Should not accept value with null toString");
     }
     catch (System.ArgumentException)
     {
         // Good
     }
 }
        public override void Load()
        {
            var index = ModelService.GetIndex <T>();

            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                Index.Clear();
                foreach (var model in index)
                {
                    Index.Add(model);
                }
            });
        }
Esempio n. 16
0
        public void Drop(IDropInfo di)
        {
            var source = (Requirement)di.Data;

            if (source.Status != (int)_requirementStatus)
            {
                if (!Index.Contains(source))
                {
                    source.Status = (int)_requirementStatus;
                    Index.Add(source);
                }
            }
        }
Esempio n. 17
0
        public void TestEnumerationInt32Array()
        {
            var index = new Index <int[]>(new MemoryMapStream(), 32);
            var id    = index.Add(new int[] { 1, 2 });

            id = index.Add(new int[] { 3, 4 });
            id = index.Add(new int[] { 5, 6, 7 });
            id = index.Add(new int[] { 8, 9 });
            id = index.Add(new int[] { 10 });

            var list = new List <int>();

            foreach (var pair in index)
            {
                foreach (var item in pair.Value)
                {
                    list.Add(item);
                }
            }
            Assert.AreEqual(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                            list);
        }
Esempio n. 18
0
 private static void CreateInitialDataSet(GraphDatabaseService db)
 {
     // 4 transactions: THE transaction, "mykey" property key, "db-index" index, "KNOWS" rel type.
     using (Transaction tx = Db.beginTx())
     {
         Node node = Db.createNode(Label.label("Me"));
         node.SetProperty("myKey", "myValue");
         Index <Node> nodeIndex = Db.index().forNodes("db-index");
         nodeIndex.Add(node, "myKey", "myValue");
         Db.createNode().createRelationshipTo(node, RelationshipType.withName("KNOWS"));
         tx.Success();
     }
 }
Esempio n. 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void getSingleMustNotCloseStatementTwice()
        public virtual void getSingleMustNotCloseStatementTwice()
        {
            // given
            string indexName = "index";
            long   expected1;
            long   expected2;

            using (Transaction tx = Db.beginTx())
            {
                Node         node1     = Db.createNode();
                Node         node2     = Db.createNode();
                Index <Node> nodeIndex = Db.index().forNodes(indexName);
                nodeIndex.Add(node1, "key", "hej");
                nodeIndex.Add(node2, "key", "hejhej");

                expected1 = node1.Id;
                expected2 = node2.Id;
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Index <Node> nodeIndex = Db.index().forNodes(indexName);

                // when using getSingle this should not close statement for outer loop
                IndexHits <Node> hits = nodeIndex.query("key", "hej");
                while (hits.MoveNext())
                {
                    Node actual1 = hits.Current;
                    assertEquals(expected1, actual1.Id);

                    IndexHits <Node> hits2   = nodeIndex.query("key", "hejhej");
                    Node             actual2 = hits2.Single;
                    assertEquals(expected2, actual2.Id);
                }
                tx.Success();
            }
        }
Esempio n. 20
0
 public IndexedList(IEnumerable <string> values)
 {
     _index1 = new Index(1);
     _index2 = new Index(2);
     _index4 = new Index(4);
     _index8 = new Index(8);
     foreach (string value in values)
     {
         _index1.Add(value);
         _index2.Add(value);
         _index4.Add(value);
         _index8.Add(value);
     }
 }
        private void RegistIndex(object key, long startPosition, long endPosition)
        {
            IndexBlock block = Index.Find(it => it.Key == key);

            if (block == null)
            {
                block = new IndexBlock()
                {
                    Key = key, StartPos = startPosition, EndPos = endPosition
                };
                DoRegistIndex(block);
                Index.Add(block);
            }
        }
Esempio n. 22
0
        protected void ReadIndex(ITextualReader reader)
        {
            string line = NextLine(reader);

            while (!String.IsNullOrEmpty(line))
            {
                string field = ReadField(ref line);
                Names.Add(field);

                if (DateMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_DATE);
                }
                else if (DateAuxMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_DATE_AUX);
                }
                else if (CodeMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_CODE);
                }
                else if (PayeeMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_PAYEE);
                }
                else if (AmountMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_AMOUNT);
                }
                else if (CostMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_COST);
                }
                else if (TotalMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_TOTAL);
                }
                else if (NoteMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_NOTE);
                }
                else
                {
                    Index.Add(CsvHeadersEnum.FIELD_UNKNOWN);
                }

                Logger.Current.Debug("csv.parse", () => String.Format("Header field: {0}", field));
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Add a resource to the package
        /// </summary>
        /// <param name="rk">The resource key</param>
        /// <param name="stream">The stream that contains the resource data</param>
        /// <param name="rejectDups">If true, fail if the resource key already exists</param>
        /// <returns>Null if rejectDups and the resource key exists; else the new IResourceIndexEntry</returns>
        public override IResourceIndexEntry AddResource(IResourceKey rk, Stream stream, bool rejectDups)
        {
            if (rejectDups && Index[rk] != null && !Index[rk].IsDeleted)
            {
                return(null);
            }
            IResourceIndexEntry newrc = Index.Add(rk);

            if (stream != null)
            {
                (newrc as ResourceIndexEntry).ResourceStream = stream;
            }

            return(newrc);
        }
 private void FillData(List <string> data)
 {
     for (int i = 0; i < data.Count; i++)
     {
         var temp = data[i].Split(',');
         try
         {
             temp[1] = temp[1].Replace('.', ',');
             Value.Add(Convert.ToDouble(temp[1]));
             Index.Add(temp[0]);
         }
         catch
         { }
     }
 }
Esempio n. 25
0
 // setting a weakness from the player's perspective
 public void SetWeaknessPlayer(string image, int element)
 {
     if (Index.ContainsKey(image))
     {
         if (!Index[image].Contains(element))
         {
             Index[image].Add(element);
         }
     }
     else
     {
         Index.Add(image, new HashSet <int>());
         Index[image].Add(element);
     }
 }
Esempio n. 26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToDeleteAndRecreateIndex()
        public virtual void ShouldBeAbleToDeleteAndRecreateIndex()
        {
            RestartTx();
            assertContains(_index.query(_key, "own"));
            _index.delete();
            RestartTx();

            Index <Node> recreatedIndex = _graphDb.index().forNodes(INDEX_NAME, LuceneIndexImplementation.FulltextConfig);

            assertNull(recreatedIndex.get(_key, _value).Single);
            recreatedIndex.Add(_node, _key, _value);
            RestartTx();
            assertContains(recreatedIndex.query(_key, "own"), _node);
            recreatedIndex.Delete();
        }
Esempio n. 27
0
        //used by getDetailsModal

        public bool getDetails(int?id)
        {
            if (id == null)
            {
                return(false);
            }

            Item = _context.Items.FirstOrDefault(m => m.ItemId == id);

            if (Item == null)
            {
                return(false);
            }
            Index.Add(Item.ItemId);
            return(true);
        }
Esempio n. 28
0
        public void TestMakeWritableEmpty()
        {
            var index = new Index <int[]>(new MemoryMapStream(), 32);

            using (var stream = new MemoryStream())
            {
                index.CopyToWithSize(stream);
                stream.Seek(0, SeekOrigin.Begin);
                index = Index <int[]> .CreateFromWithSize(stream);
            }

            var id = index.Add(new int[] { 10, 100 });

            Assert.AreEqual(id, 0);
            Assert.AreEqual(new int[] { 10, 100 }, index.Get(id));
        }
Esempio n. 29
0
        public static bool TryAddNewReport(string ReportKey)
        {
            if (ContainsReport(ReportKey))
            {
                return(false);
            }

            Index.Add(ReportKey, DateTime.UtcNow);

            if (LastFlush.Date < DateTime.UtcNow.Date)
            {
                WriteToFile();
            }

            return(true);
        }
Esempio n. 30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testGettingAutoIndexByNameReturnsSomethingReadOnly()
        public virtual void TestGettingAutoIndexByNameReturnsSomethingReadOnly()
        {
            // Create the node and relationship auto-indexes
            NewTransaction();
            _graphDb.index().NodeAutoIndexer.Enabled = true;
            _graphDb.index().NodeAutoIndexer.startAutoIndexingProperty("nodeProp");
            _graphDb.index().RelationshipAutoIndexer.Enabled = true;
            _graphDb.index().RelationshipAutoIndexer.startAutoIndexingProperty("relProp");

            Node         node1 = _graphDb.createNode();
            Node         node2 = _graphDb.createNode();
            Relationship rel   = node1.CreateRelationshipTo(node2, RelationshipType.withName("FOO"));

            node1.SetProperty("nodeProp", "nodePropValue");
            rel.SetProperty("relProp", "relPropValue");

            NewTransaction();

            assertEquals(1, _graphDb.index().nodeIndexNames().length);
            assertEquals(1, _graphDb.index().relationshipIndexNames().length);

            assertEquals("node_auto_index", _graphDb.index().nodeIndexNames()[0]);
            assertEquals("relationship_auto_index", _graphDb.index().relationshipIndexNames()[0]);

            Index <Node>      nodeIndex = _graphDb.index().forNodes("node_auto_index");
            RelationshipIndex relIndex  = _graphDb.index().forRelationships("relationship_auto_index");

            assertEquals(node1, nodeIndex.get("nodeProp", "nodePropValue").Single);
            assertEquals(rel, relIndex.get("relProp", "relPropValue").Single);
            try
            {
                nodeIndex.Add(null, null, null);
                fail("Auto indexes should not allow external manipulation");
            }
            catch (System.NotSupportedException)
            {               // good
            }

            try
            {
                relIndex.add(null, null, null);
                fail("Auto indexes should not allow external manipulation");
            }
            catch (System.NotSupportedException)
            {               // good
            }
        }
Esempio n. 31
0
 /// <summary>
 /// Loads the given file into the local collection, in order to compare it when Compare() is called.
 /// </summary>
 /// <param name="folder">Path where the files will be looked for.</param>
 /// /// <param name="file">File that will be loaded into the copy detector.</param>
 public override void Load(string folder, string file)
 {
     if (string.IsNullOrEmpty(folder))
     {
         throw new ArgumentNullException("path");
     }
     if (string.IsNullOrEmpty(file))
     {
         throw new ArgumentNullException("file");
     }
     if (Index.ContainsKey(folder))
     {
         throw new ArgumentInvalidException("Only one file per folder is allowed.");                             //Because files from different folders (students) are compared, and the folder will be de unique key to distinguish between sources.
     }
     Index.Add(folder, Files.Count);
     Files.Add(new File(folder, file));
 }
Esempio n. 32
0
 /// <summary>
 /// Gets or sets the element at the given index.
 /// </summary>
 public sealed override T this[long idx]
 {
     get
     {
         var id = _index[idx];
         if (id == 0)
         {
             return(default(T));
         }
         return(_data.Get(id - 1));
     }
     set
     {
         var id = _data.Add(value);
         _index[idx] = id + 1;
     }
 }
Esempio n. 33
0
        public SpriteSheet GenerateIndexes(int width, int height, int xCount, int yCount)
        {
            SpriteWidth  = width;
            SpriteHeight = height;
            Radius       = width / 2.0f;
            int i = 0;

            for (int y = 0; y < yCount; y++)
            {
                for (int x = 0; x < xCount; x++)
                {
                    Index.Add($"Sprite{i:000}", new Rectangle(x * width, y * height, width, height));
                    i++;
                }
            }
            return(this);
        }
Esempio n. 34
0
 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;
 }
Esempio n. 35
0
		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);
			}
		}
Esempio n. 36
0
         // 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);
         }
Esempio n. 37
0
        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));

            }
        }
Esempio n. 38
0
        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.");
            }
        }
Esempio n. 39
0
        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);

                // Stage the file removal
                index.Remove (filenameSubdir1);

                filesToCheck.Clear ();
                results = oper (repo, filesToCheck);
                AssertStatus (results, filesToCheck, filename, results.Untracked);
                AssertStatus (results, filesToCheck, filenameSubdir1, results.Removed);
                AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);

                // Commit changes
                repo.Commit ("test 3");
                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, stage it and delete it
                File.WriteAllText(repo.FromGitPath (filenameSubdir1), "Modified before delete.");
                index.Add (filenameSubdir1);
                File.Delete (repo.FromGitPath (filenameSubdir1));
                filesToCheck.Clear ();
                results = oper (repo, filesToCheck);
                AssertStatus (results, filesToCheck, filename, results.Untracked);
                AssertStatus (results, filesToCheck, filenameSubdir1, results.Added, results.Missing);  // FIXME: should be Removed??
                AssertStatus (results, filesToCheck, filenameSubdir2, results.Untracked);
            }
        }
Esempio n. 40
0
        /// <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]);
                        }
                    }
                }
            }
        }
Esempio n. 41
0
        /// <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);
                }
            }
        }
Esempio n. 42
0
      /// <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;
      }
Esempio n. 43
0
        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));
                }
            }
        }