Save_METS() public method

Save this resource as a METS file
Will use either the default namespace, or the same namespace which was used in any previously read METS files.
public Save_METS ( ) : void
return void
        /// <summary> Check for folders that are not named in BibID or BibiD/VID format and do not have metadata.  For 
        /// these items, creates a BibID/VID folder with minimal metadata from the folder name.  </summary>
        /// <param name="BuilderFolder"> Builder folder upon which to perform all work </param>
        /// <param name="IncomingPackages"> List of valid incoming packages, which may be modified by this process </param>
        /// <param name="Deletes"> List of valid deletes, which may be modifyed by this process </param>
        public override void DoWork(Actionable_Builder_Source_Folder BuilderFolder, List<Incoming_Digital_Resource> IncomingPackages, List<Incoming_Digital_Resource> Deletes)
        {
            string[] subdirs = Directory.GetDirectories(BuilderFolder.Inbound_Folder);
            foreach ( string thisSubDir in subdirs)
            {
                try
                {
                    string thisSubDirName = (new DirectoryInfo(thisSubDir)).Name;

                    // Must have some files to continue
                    if (Directory.GetFiles(thisSubDir).Length == 0)
                        continue;

                    // Need to check if this MAY be a valid BibID.
                    // Need to make this a bit more specific in the future, as it will skip ANY folders
                    // that are ten digits long right now.
                    if ((thisSubDir.Length == 10) || ((thisSubDir.Length == 16) && (thisSubDirName[0] == '_')))
                        continue;

                    // Look for a METS file or any source of metadata in the folder
                    if ((Directory.GetFiles(thisSubDir, "*.mets").Length > 0) || (Directory.GetFiles(thisSubDir, "*.xml").Length > 0))
                        continue;

                    // Clean any additional periods in the filenames first
                    string[] allFiles = Directory.GetFiles(thisSubDir);
                    foreach (string thisFile in allFiles)
                    {
                        string fileName = Path.GetFileName(thisFile);
                        if (Regex.Matches(fileName, "\\.").Count > 1)
                        {
                            string newFileName = fileName;
                            while (Regex.Matches(newFileName, "\\.").Count > 1)
                            {
                                char[] charArr = newFileName.ToCharArray();
                                charArr[newFileName.IndexOf(".")] = '_'; // freely modify the array
                                newFileName = new string(charArr);
                            }

                            File.Move(thisFile, Path.Combine(thisSubDir, newFileName));
                        }
                    }

                    // Create the new object
                    SobekCM_Item newItem = new SobekCM_Item();
                    newItem.Bib_Info.SobekCM_Type = TypeOfResource_SobekCM_Enum.Archival;
                    newItem.Bib_Info.Main_Title.Title = thisSubDirName;
                    newItem.Bib_Info.Add_Identifier(thisSubDirName);
                    newItem.Bib_Info.Source.Code = Arguments[1];
                    newItem.Bib_Info.Source.Statement = Arguments[2];
                    newItem.BibID = Arguments[0];
                    newItem.VID = "00001";

                    // Save this item, for the necessary bibid
                    SobekCM_Item_Database.Save_New_Digital_Resource(newItem, false, false, "Builder", "Created BibID folder from '" + thisSubDirName + "'", -1);

                    string newFolderName = newItem.BibID + "_" + newItem.VID;
                    string newFolder = Path.Combine(BuilderFolder.Inbound_Folder, newFolderName);
                    Directory.Move(thisSubDir, newFolder);

                    newItem.Source_Directory = newFolder;
                    newItem.Save_METS();
                }
                catch (Exception ee)
                {
                    Console.WriteLine("Error moving directory " + ee.Message);
                }
            }
        }
        protected bool save_to_mets(SobekCM_Item bibPackage, bool preview_mode)
        {
            bibPackage.METS_Header.RecordStatus_Enum = METS_Record_Status.METADATA_UPDATE;

            // Saves the data members in the SobekCM.Bib_Package to a METS file
            try
            {
                // check if the mets file is needed
                if (bibPackage.VID.Length > 0)
                {
                    // Set the directory where the METS file will be saved
                    if (!preview_mode)
                    {
                        string inbound_folder = Library.SobekCM_Library_Settings.Main_Builder_Input_Folder + "\\" + bibPackage.BibID + "_" + bibPackage.VID;
                        bibPackage.Source_Directory = inbound_folder;
                        if (!Directory.Exists(inbound_folder))
                        {
                            Directory.CreateDirectory(inbound_folder);
                        }

                        // create the METS file
                        bibPackage.Save_METS();
                    }
                    else
                    {
                        bibPackage.Source_Directory = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\SMaRT\\Temporary";

                        // create the METS file
                        bibPackage.Save_METS();

                        if (File.Exists(bibPackage.Source_Directory + "\\" + bibPackage.BibID + "_" + bibPackage.VID + ".mets"))
                        {
                            if (File.Exists(bibPackage.Source_Directory + "\\" + bibPackage.BibID + "_" + bibPackage.VID + "_PREVIEW.mets"))
                                File.Delete(bibPackage.Source_Directory + "\\" + bibPackage.BibID + "_" + bibPackage.VID + "_PREVIEW.mets");
                            File.Move(bibPackage.Source_Directory + "\\" + bibPackage.BibID + "_" + bibPackage.VID + ".mets", bibPackage.Source_Directory + "\\" + bibPackage.BibID + "_" + bibPackage.VID + "_PREVIEW.mets");
                        }
                    }

                }

                return true;
            }
            catch (Exception e)
            {
                DLC.Tools.Forms.ErrorMessageBox.Show("Error encountered while creating METS file!\n\n" + e.Message, "DLC Importer Error", e);
                return false;
            }
        }