internal int Recursive_Sort_Insert(Builder_Page_File newPage_File, int start, int end)
        {
            int startIndex = start;
            int endIndex   = end;
            int midIndex   = (int)Math.Ceiling((double)(endIndex - startIndex) / 2) + startIndex;

            if (endIndex - startIndex <= 1)
            {
                if (newPage_File.CompareTo(this[startIndex]) <= 0)
                {
                    List.Insert(startIndex, newPage_File);
                    return(startIndex);
                }
                else
                {
                    List.Insert(endIndex, newPage_File);
                    return(endIndex);
                }
            }
            else
            {
                if (newPage_File.CompareTo(this[midIndex]) < 0)
                {
                    endIndex = midIndex;
                }
                else
                {
                    startIndex = midIndex;
                }

                return(Recursive_Sort_Insert(newPage_File, startIndex, endIndex));
            }
        }
Beispiel #2
0
        /// <summary> Check to see if these two files are equivalent </summary>
        /// <param name="obj"> Object to compare to </param>
        /// <returns> Returns -1, 0, or 1, depending on how this object ranks in comparison to the testing object </returns>
        public int CompareTo(object obj)
        {
            // Check for null
            if (obj == null)
            {
                return(1);
            }

            // Perform comparison
            int result = 0;

            if (obj is Builder_Page_File)
            {
                // Same object types, so cast
                Builder_Page_File compareToObj = (Builder_Page_File)obj;

                // Check for comparison between all the parts
                int maximum_part_checks = Math.Min(Sorter.NameParts.Length, compareToObj.Sorter.NameParts.Length);
                int i = 0;
                while ((i < maximum_part_checks) && (result == 0))
                {
                    // Only check for roman numerals in the first section
                    if (i == 0)
                    {
                        result = CompareStrings(Sorter.NameParts[i], compareToObj.Sorter.NameParts[i], true);
                    }
                    else
                    {
                        result = CompareStrings(Sorter.NameParts[i], compareToObj.Sorter.NameParts[i], false);
                    }

                    // Increment the counter to look at the next one
                    i++;
                }

                // If there was no result, the file with more parts should follow the one with less
                if ((result == 0) && (Sorter.NameParts.Length != compareToObj.Sorter.NameParts.Length))
                {
                    if (Sorter.NameParts.Length > compareToObj.Sorter.NameParts.Length)
                    {
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                }

                return(result);
            }
            else
            {
                // comparing apples and oranges serves no one
                return(0);
            }
        }
Beispiel #3
0
        /// <summary> Check to see if these two files are equivalent </summary>
        /// <param name="compareTo"> Object to compare to </param>
        /// <returns> TRUE if equal, otherwise FALSE </returns>
        public bool Equals(Builder_Page_File compareTo)
        {
            // Must have same name, first of all
            if (!Same_Name(compareTo))
            {
                return(false);
            }

            // Made it past all these checks
            return(true);
        }
Beispiel #4
0
 /// <summary> Check to see if these two files have the same name </summary>
 /// <param name="compareTo"> Object to compare to </param>
 /// <returns>TRUE if they have the same name, otherwise FALSE </returns>
 public bool Same_Name(Builder_Page_File compareTo)
 {
     if (FullName.ToUpper() == compareTo.FullName.ToUpper())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        /// <summary> Insert a new page into this collection, based on the file name </summary>
        /// <param name="NewPageFile"></param>
        /// <returns></returns>
        internal int Insert(Builder_Page_File NewPageFile)
        {
            if (List.Count == 0)
            {
                return List.Add(NewPageFile);
            }

            if (NewPageFile.CompareTo(this[0]) <= 0)
            {
                List.Insert(0, NewPageFile);
                return 0;
            }

            if (NewPageFile.CompareTo(this[List.Count - 1]) >= 0)
            {
                return List.Add(NewPageFile);
            }

            return Recursive_Sort_Insert(NewPageFile, 0, List.Count - 1);
        }
        /// <summary> Insert a new page into this collection, based on the file name </summary>
        /// <param name="newPage_File"></param>
        /// <returns></returns>
        internal int Insert(Builder_Page_File newPage_File)
        {
            if (List.Count == 0)
            {
                return(List.Add(newPage_File));
            }

            if (newPage_File.CompareTo(this[0]) <= 0)
            {
                List.Insert(0, newPage_File);
                return(0);
            }

            if (newPage_File.CompareTo(this[List.Count - 1]) >= 0)
            {
                return(List.Add(newPage_File));
            }

            return(Recursive_Sort_Insert(newPage_File, 0, List.Count - 1));
        }
 /// <summary> Check to see if these two files have the same name </summary>
 /// <param name="compareTo"> Object to compare to </param>
 /// <returns>TRUE if they have the same name, otherwise FALSE </returns>
 public bool Same_Name(Builder_Page_File compareTo)
 {
     if (FullName.ToUpper() == compareTo.FullName.ToUpper())
         return true;
     else
         return false;
 }
        /// <summary> Check to see if these two files are equivalent </summary>
        /// <param name="compareTo"> Object to compare to </param>
        /// <returns> TRUE if equal, otherwise FALSE </returns>
        public bool Equals(Builder_Page_File compareTo)
        {
            // Must have same name, first of all
            if (!Same_Name(compareTo))
                return false;

            // Made it past all these checks
            return true;
        }
 /// <summary> Add a new Page_File to this collection. </summary>
 /// <param name="NewPageFile"> <see cref="Builder_Page_File"/> object for this new Page_File </param>
 internal void Add(Builder_Page_File NewPageFile)
 {
     // Add this constructed Page_File to the collection
     List.Add(NewPageFile);
 }
        internal int Recursive_Sort_Insert(Builder_Page_File NewPageFile, int Start, int End)
        {
            int startIndex = Start;
            int endIndex = End;
            int midIndex = (int) Math.Ceiling((double) (endIndex - startIndex)/2) + startIndex;
            if (endIndex - startIndex <= 1)
            {
                if (NewPageFile.CompareTo(this[startIndex]) <= 0)
                {
                    List.Insert(startIndex, NewPageFile);
                    return startIndex;
                }

                List.Insert(endIndex, NewPageFile);
                return endIndex;
            }

            if (NewPageFile.CompareTo(this[midIndex]) < 0)
                endIndex = midIndex;
            else
                startIndex = midIndex;

            return Recursive_Sort_Insert(NewPageFile, startIndex, endIndex);
        }
        private static void get_files_from_current_directory(Builder_Page_File_Collection FileList, List<string> FileFilters, string SourceDirectory, string RelativeDirectory, bool RecursivelyIncludeSubfolders)
        {
            // Get the files in this directory by using file filters ( a single filter may find the same
            // file in this directory twice, so special code is added for this case )
            List<string> files_in_this_dir = new List<string>();
            foreach (string thisFilter in FileFilters)
            {
                string[] thisFilterFiles = Directory.GetFiles(SourceDirectory, thisFilter);
                foreach (string thisFilterFile in thisFilterFiles)
                {
                    if (!files_in_this_dir.Contains(thisFilterFile))
                        files_in_this_dir.Add(thisFilterFile);
                }
            }

            // All found files should be added to the builder page file collection
            foreach (string thisFile in files_in_this_dir)
            {
                // Exclude the archival files
                if ((thisFile.ToUpper().IndexOf("_ARCHIVE.") < 0) && (thisFile.ToUpper().IndexOf(".QC.JPG") < 0))
                {
                    // Create the new page_file object
                    Builder_Page_File newFile = new Builder_Page_File(thisFile, RelativeDirectory, true);

                    // Add into the page file collection, sorting appropriately
                    FileList.Insert(newFile);
                }
            }

            // Check subdirectories
            if (RecursivelyIncludeSubfolders)
            {
                string[] subdirs = Directory.GetDirectories(SourceDirectory);
                foreach (string thisSubDir in subdirs)
                {
                    DirectoryInfo thisSubDirInfo = new DirectoryInfo(thisSubDir);
                    string dir_name = thisSubDirInfo.Name;
                    if (RelativeDirectory.Length == 0)
                        get_files_from_current_directory(FileList, FileFilters, thisSubDir, dir_name, true);
                    else
                        get_files_from_current_directory(FileList, FileFilters, thisSubDir, RelativeDirectory + "\\" + dir_name, true);
                }
            }
        }
        private static void recursively_add_all_METS_files(abstract_TreeNode RootNode,
                                                           List<SobekCM_File_Info> METSFiles, Builder_Page_File_Collection METSFileCollection,
                                                           Dictionary<SobekCM_File_Info, Page_TreeNode> FileToPage, Dictionary<Page_TreeNode, Division_TreeNode> PageToDiv,
                                                           List<string> FileFilters)
        {
            if (RootNode.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode) RootNode;
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    bool add_file = false;
                    if (FileFilters.Count == 0)
                    {
                        add_file = true;
                    }
                    else
                    {
                        foreach (string file_filter in FileFilters)
                        {
                            if (thisFile.System_Name.ToUpper().IndexOf(file_filter) > 0)
                            {
                                add_file = true;
                                break;
                            }
                        }
                    }

                    if (add_file)
                    {
                        METSFiles.Add(thisFile);
                        Builder_Page_File newPageFile = new Builder_Page_File(thisFile.System_Name, true);
                        newPageFile.METS_Page = pageNode;
                        newPageFile.METS_Division = PageToDiv[pageNode];
                        METSFileCollection.Insert(newPageFile);
                        FileToPage.Add(thisFile, pageNode);
                    }
                }
            }
            else
            {
                Division_TreeNode divNode = (Division_TreeNode) RootNode;
                foreach (abstract_TreeNode thisNode in divNode.Nodes)
                {
                    if (thisNode.Page)
                    {
                        try
                        {
                            if (!PageToDiv.ContainsKey((Page_TreeNode) thisNode))
                            {
                                PageToDiv.Add((Page_TreeNode) thisNode, divNode);
                            }
                        }
                        catch
                        {
                        }
                    }

                    recursively_add_all_METS_files(thisNode, METSFiles, METSFileCollection, FileToPage, PageToDiv, FileFilters);
                }
            }
        }
 /// <summary> Add a new Page_File to this collection. </summary>
 /// <param name="newPage_File"> <see cref="Builder_Page_File"/> object for this new Page_File </param>
 internal void Add(Builder_Page_File newPage_File)
 {
     // Add this constructed Page_File to the collection
     List.Add(newPage_File);
 }