Example #1
0
        public void Compare_ScriptNames_AreComparedAlphaNumerically()
        {
            var x = "Z\\0001 Script 1.sql";
            var y = "A\\2 Script 2.sql";

            Assert.True(_comparer.Compare(x, y) < 0);
        }
        /// <summary>
        /// Get up to the specified number of child entries of the specified type that match the specified criteria.
        /// </summary>
        internal FileSystemEntry[] GetChildEntries(
            string name, FileSystemEntry parentEntry, EntryType entryType, int maxEntries)
        {
            if (parentEntry.FirstChild == null)
            {
                return(new FileSystemEntry[0]);
            }

            FilenameComparer comparer = new FilenameComparer(name);
            ArrayList        entries  = new ArrayList();

            FileSystemEntry currentEntry = parentEntry.FirstChild;

            if (currentEntry.EntryType == entryType)
            {
                if (comparer.Compare(currentEntry.Name))
                {
                    entries.Add(currentEntry);
                    if (entries.Count >= maxEntries)
                    {
                        return(entries.ToArray(typeof(FileSystemEntry)) as FileSystemEntry[]);
                    }
                }
            }

            int siblingCount = 0;

            while ((currentEntry.Sibling != null) && (siblingCount <= MaxSiblingCount))
            {
                currentEntry = currentEntry.Sibling;
                if (currentEntry.EntryType == entryType)
                {
                    if (currentEntry.Name == name)
                    {
                        entries.Add(currentEntry);
                        if (entries.Count >= maxEntries)
                        {
                            return(entries.ToArray(typeof(FileSystemEntry)) as FileSystemEntry[]);
                        }
                    }
                }

                siblingCount++;
            }
            if (siblingCount > MaxSiblingCount)
            {
                throw new MaxSiblingCountExceededException(MaxSiblingCount, BuildPath(parentEntry));
            }

            return(entries.ToArray(typeof(FileSystemEntry)) as FileSystemEntry[]);
        }