/// <summary> Recalculates all the checksums for associated files </summary>
        /// <param name="Recalculate_All"> Flag indicates whether to recalculate all files, regardless of need </param>
        /// <param name="Progress_Delegate"> Progress delegate is called to update any progress displays </param>
        public void Calculate_Checksum(bool Recalculate_All, New_SobekCM_Bib_Package_Progress_Task_Group Progress_Delegate)
        {
            // Get the list of all pages from this division trees
            List<abstract_TreeNode> pageNodes = physicalDivisionTree.Pages_PreOrder;
            List<abstract_TreeNode> fileNodes = downloadDivisionTree.Pages_PreOrder;

            // Update progress
            if (Progress_Delegate != null)
            {
                Progress_Delegate("Calculating checksums", "Checking all files", 0, 2);
            }

            // Count how many pages to calculate for
            int total_files = 0;
            foreach (Page_TreeNode pageNode in pageNodes)
            {
                // Step through each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    // Recalculate this file info?
                    if ((Recalculate_All) || ((String.IsNullOrEmpty(thisFile.Checksum)) || (thisFile.Size <= 0)))
                    {
                        total_files++;
                    }
                }
            }
            foreach (Page_TreeNode pageNode in fileNodes)
            {
                // Step through each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    // Recalculate this file info?
                    if ((Recalculate_All) || ((String.IsNullOrEmpty(thisFile.Checksum)) || (thisFile.Size <= 0)))
                    {
                        total_files++;
                    }
                }
            }

            if (total_files == 0)
                return;

            // Now caulcate
            int file_count = 0;
            FileMD5 checksummer = new FileMD5();
            foreach (Page_TreeNode pageNode in pageNodes)
            {
                // Step through each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    // Recalculate this file info?
                    if ((thisFile.METS_LocType == SobekCM_File_Info_Type_Enum.SYSTEM) && ((Recalculate_All) || ((String.IsNullOrEmpty(thisFile.Checksum)) || (thisFile.Size <= 0))))
                    {
                        // Perform in a try catch
                        try
                        {
                            // Get the size first
                            FileInfo thisFileInfo = new FileInfo(source_directory + "/" + thisFile.System_Name);
                            thisFile.Size = thisFileInfo.Length;

                            // Get the checksum, if it doesn't exist
                            if ((String.IsNullOrEmpty(thisFile.Checksum)) || (Recalculate_All))
                            {
                                thisFile.Checksum = checksummer.Calculate_Checksum(source_directory + "/" + thisFile.System_Name);
                                thisFile.Checksum_Type = "MD5";
                            }
                        }
                        catch {}

                        file_count++;

                        // Update progress
                        if (Progress_Delegate != null)
                        {
                            Progress_Delegate("Calculating checksums", "Calculating '" + thisFile.System_Name + "'", file_count, total_files);
                        }
                    }
                }
            }
            foreach (Page_TreeNode pageNode in fileNodes)
            {
                // Step through each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    // Recalculate this file info?
                    if ((thisFile.METS_LocType == SobekCM_File_Info_Type_Enum.SYSTEM) && ((Recalculate_All) || ((String.IsNullOrEmpty(thisFile.Checksum)) || (thisFile.Size <= 0))))
                    {
                        // Perform in a try catch
                        try
                        {
                            // Get the size first
                            FileInfo thisFileInfo = new FileInfo(source_directory + "/" + thisFile.System_Name);
                            thisFile.Size = thisFileInfo.Length;

                            // Get the checksum, if it doesn't exist
                            if ((String.IsNullOrEmpty(thisFile.Checksum)) || (Recalculate_All))
                            {
                                thisFile.Checksum = checksummer.Calculate_Checksum(source_directory + "/" + thisFile.System_Name);
                                thisFile.Checksum_Type = "MD5";
                            }
                        }
                        catch{}

                        file_count++;

                        // Update progress
                        if (Progress_Delegate != null)
                        {
                            Progress_Delegate("Calculating checksums", "Calculating '" + thisFile.System_Name + "'", file_count, total_files);
                        }
                    }
                }
            }

            // Update progress
            if (Progress_Delegate != null)
            {
                Progress_Delegate("Checksum Complete", "Checksum Complete", file_count, total_files);
            }
        }
Ejemplo n.º 2
0
        /// <summary> Recalculates all the checksums for associated files </summary>
        /// <param name="Recalculate_All"> Flag indicates whether to recalculate all files, regardless of need </param>
        /// <param name="Progress_Delegate"> Progress delegate is called to update any progress displays </param>
        public void Calculate_Checksum(bool Recalculate_All, New_SobekCM_Bib_Package_Progress_Task_Group Progress_Delegate)
        {
            // Get the list of all pages from this division trees
            List <abstract_TreeNode> pageNodes = physicalDivisionTree.Pages_PreOrder;
            List <abstract_TreeNode> fileNodes = downloadDivisionTree.Pages_PreOrder;

            // Update progress
            if (Progress_Delegate != null)
            {
                Progress_Delegate("Calculating checksums", "Checking all files", 0, 2);
            }

            // Count how many pages to calculate for
            int total_files = 0;

            foreach (Page_TreeNode pageNode in pageNodes)
            {
                // Step through each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    // Recalculate this file info?
                    if ((Recalculate_All) || ((String.IsNullOrEmpty(thisFile.Checksum)) || (thisFile.Size <= 0)))
                    {
                        total_files++;
                    }
                }
            }
            foreach (Page_TreeNode pageNode in fileNodes)
            {
                // Step through each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    // Recalculate this file info?
                    if ((Recalculate_All) || ((String.IsNullOrEmpty(thisFile.Checksum)) || (thisFile.Size <= 0)))
                    {
                        total_files++;
                    }
                }
            }

            if (total_files == 0)
            {
                return;
            }

            // Now caulcate
            int     file_count  = 0;
            FileMD5 checksummer = new FileMD5();

            foreach (Page_TreeNode pageNode in pageNodes)
            {
                // Step through each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    // Recalculate this file info?
                    if ((thisFile.METS_LocType == SobekCM_File_Info_Type_Enum.SYSTEM) && ((Recalculate_All) || ((String.IsNullOrEmpty(thisFile.Checksum)) || (thisFile.Size <= 0))))
                    {
                        // Perform in a try catch
                        try
                        {
                            // Get the size first
                            FileInfo thisFileInfo = new FileInfo(source_directory + "/" + thisFile.System_Name);
                            thisFile.Size = thisFileInfo.Length;

                            // Get the checksum, if it doesn't exist
                            if ((String.IsNullOrEmpty(thisFile.Checksum)) || (Recalculate_All))
                            {
                                thisFile.Checksum      = checksummer.Calculate_Checksum(source_directory + "/" + thisFile.System_Name);
                                thisFile.Checksum_Type = "MD5";
                            }
                        }
                        catch {}

                        file_count++;

                        // Update progress
                        if (Progress_Delegate != null)
                        {
                            Progress_Delegate("Calculating checksums", "Calculating '" + thisFile.System_Name + "'", file_count, total_files);
                        }
                    }
                }
            }
            foreach (Page_TreeNode pageNode in fileNodes)
            {
                // Step through each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    // Recalculate this file info?
                    if ((thisFile.METS_LocType == SobekCM_File_Info_Type_Enum.SYSTEM) && ((Recalculate_All) || ((String.IsNullOrEmpty(thisFile.Checksum)) || (thisFile.Size <= 0))))
                    {
                        // Perform in a try catch
                        try
                        {
                            // Get the size first
                            FileInfo thisFileInfo = new FileInfo(source_directory + "/" + thisFile.System_Name);
                            thisFile.Size = thisFileInfo.Length;

                            // Get the checksum, if it doesn't exist
                            if ((String.IsNullOrEmpty(thisFile.Checksum)) || (Recalculate_All))
                            {
                                thisFile.Checksum      = checksummer.Calculate_Checksum(source_directory + "/" + thisFile.System_Name);
                                thisFile.Checksum_Type = "MD5";
                            }
                        }
                        catch {}

                        file_count++;

                        // Update progress
                        if (Progress_Delegate != null)
                        {
                            Progress_Delegate("Calculating checksums", "Calculating '" + thisFile.System_Name + "'", file_count, total_files);
                        }
                    }
                }
            }

            // Update progress
            if (Progress_Delegate != null)
            {
                Progress_Delegate("Checksum Complete", "Checksum Complete", file_count, total_files);
            }
        }