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);
            }
        }
Beispiel #2
0
        private void Complete_Item_Save()
        {
            if (isProject)
            {
                // Save the new project METS
                currentItem.Save_METS();

                // Clear the cache of this item
                CachedDataManager.Remove_Project(RequestSpecificValues.Current_User.UserID, currentItem.BibID, null);

                // Redirect
                RequestSpecificValues.Current_Mode.Mode             = Display_Mode_Enum.Administrative;
                RequestSpecificValues.Current_Mode.Admin_Type       = Admin_Type_Enum.Default_Metadata;
                RequestSpecificValues.Current_Mode.My_Sobek_SubMode = String.Empty;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
            else
            {
                string error_message;
                SobekCM_Item_Updater.Update_Item(currentItem, RequestSpecificValues.Current_User, out error_message);

                CachedDataManager.Items.Remove_Digital_Resource_Object(RequestSpecificValues.Current_User.UserID, currentItem.BibID, currentItem.VID, null);

                // Also clear the engine
                SobekEngineClient.Items.Clear_Item_Cache(currentItem.BibID, currentItem.VID, RequestSpecificValues.Tracer);

                // Forward to the display item again
                RequestSpecificValues.Current_Mode.Mode       = Display_Mode_Enum.Item_Display;
                RequestSpecificValues.Current_Mode.ViewerCode = "citation";
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
        }
Beispiel #3
0
        private void newProjectButton_Button_Pressed(object sender, EventArgs e)
        {
            New_Project_Form projForm = new New_Project_Form();

            this.Hide();
            projForm.ShowDialog();

            if (projForm.Valid_Project_Code.Length > 0)
            {
                try
                {
                    string       projCode = projForm.Valid_Project_Code;
                    SobekCM_Item newProj  = new SobekCM_Item();
                    newProj.BibID = projCode;
                    newProj.VID   = "00001";
                    newProj.Bib_Info.Main_Title.Title = "Project level metadata for '" + projCode + "'";
                    newProj.Bib_Info.SobekCM_Type     = TypeOfResource_SobekCM_Enum.Project;
                    newProj.Save_METS(Application.StartupPath + "\\Projects\\" + projCode + ".pmets");

                    MetaTemplate_UserSettings.Current_Project = projCode;
                    MetaTemplate_UserSettings.Save();

                    MessageBox.Show("New project '" + projCode + "' created and set to be your new default project.\n\nClick EDIT PROJECT to make any changes to the new project.", "New Project Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ee)
                {
                    MessageBox.Show("Unable to save new project file.\n\nEnsure you have access to write in the PROJECTS subfolder.\n\n" + Application.StartupPath + "\\Projects\n\n" + ee.Message);
                }
            }

            // Get the list of PROJECTS
            projectComboBox.Items.Clear();
            projectComboBox.Items.Add("(none)");
            string[] project_files = Directory.GetFiles(Application.StartupPath + "\\Projects\\", "*.pmets");
            foreach (string thisFile in project_files)
            {
                FileInfo thisFileInfo = new FileInfo(thisFile);
                string   name         = thisFileInfo.Name.Replace(thisFileInfo.Extension, "");
                projectComboBox.Items.Add(name);
            }
            if ((MetaTemplate_UserSettings.Current_Project.Length > 0) && (projectComboBox.Items.Contains(MetaTemplate_UserSettings.Current_Project)))
            {
                projectComboBox.Text = MetaTemplate_UserSettings.Current_Project;
            }
            else
            {
                projectComboBox.SelectedIndex = 0;
            }

            this.Show();
        }
Beispiel #4
0
        /// <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);
                }
            }
        }
        private void Complete_Item_Save()
        {
            if (isProject)
            {
                // Save the new project METS
                item.Save_METS();

                // Clear the cache of this item
                Cached_Data_Manager.Remove_Project(user.UserID, item.BibID, null);

                // Redirect
                currentMode.Mode             = Display_Mode_Enum.Administrative;
                currentMode.Admin_Type       = Admin_Type_Enum.Projects;
                currentMode.My_Sobek_SubMode = String.Empty;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }
            else
            {
                // Determine the in process directory for this
                string user_bib_vid_process_directory = SobekCM_Library_Settings.In_Process_Submission_Location + "\\" + user.UFID + "\\metadata_updates\\" + item.BibID + "_" + item.VID;
                if (user.UFID.Trim().Length == 0)
                {
                    user_bib_vid_process_directory = SobekCM_Library_Settings.In_Process_Submission_Location + "\\" + user.UserName.Replace(".", "").Replace("@", "") + "\\metadata_updates\\" + item.BibID + "_" + item.VID;
                }

                // Ensure the folder exists and is empty to start with
                if (!Directory.Exists(user_bib_vid_process_directory))
                {
                    Directory.CreateDirectory(user_bib_vid_process_directory);
                }
                else
                {
                    // Anything older than a day should be deleted
                    string[] files = Directory.GetFiles(user_bib_vid_process_directory);
                    foreach (string thisFile in files)
                    {
                        try
                        {
                            File.Delete(thisFile);
                        }
                        catch (Exception)
                        {
                            // Not much to do here
                        }
                    }
                }

                // Update the METS file with METS note and name
                item.METS_Header.Creator_Individual = user.UserName;
                item.METS_Header.Modify_Date        = DateTime.Now;
                item.METS_Header.RecordStatus_Enum  = METS_Record_Status.METADATA_UPDATE;

                // Save the METS file and related items
                bool successful_save = true;
                try
                {
                    SobekCM_Database.Save_Digital_Resource(item, DateTime.Now, true);
                }
                catch
                {
                    successful_save = false;
                }

                // Create the static html pages
                string base_url = currentMode.Base_URL;
                try
                {
                    Static_Pages_Builder staticBuilder = new Static_Pages_Builder(SobekCM_Library_Settings.System_Base_URL, SobekCM_Library_Settings.Base_Data_Directory, Translator, codeManager, itemList, iconList, webSkin);
                    string filename = user_bib_vid_process_directory + "\\" + item.BibID + "_" + item.VID + ".html";
                    staticBuilder.Create_Item_Citation_HTML(item, filename, SobekCM_Library_Settings.Image_Server_Network + item.Web.AssocFilePath);
                }
                catch (Exception)
                {
                    // Failing to make the static page is not the worst thing in the world...
                }

                currentMode.Base_URL = base_url;

                item.Source_Directory = user_bib_vid_process_directory;
                item.Save_SobekCM_METS();
                item.Save_Citation_Only_METS();


                // If this was not able to be saved in the UFDC database, try it again
                if (!successful_save)
                {
                    SobekCM_Database.Save_Digital_Resource(item, DateTime.Now, false);
                }

                // Make sure the progress has been added to this item's work log
                try
                {
                    Database.SobekCM_Database.Tracking_Online_Edit_Complete(item.Web.ItemID, user.Full_Name, String.Empty);
                }
                catch (Exception)
                {
                    // This is not critical
                }

                List <string>             collectionnames = new List <string>();
                MarcXML_File_ReaderWriter marcWriter      = new MarcXML_File_ReaderWriter();
                string Error_Message;
                Dictionary <string, object> options = new Dictionary <string, object>();
                options["MarcXML_File_ReaderWriter:Additional_Tags"] = item.MARC_Sobek_Standard_Tags(collectionnames, true, SobekCM_Library_Settings.System_Name, SobekCM_Library_Settings.System_Abbreviation);
                marcWriter.Write_Metadata(item.Source_Directory + "\\marc.xml", item, options, out Error_Message);

                // Copy this to all the image servers
                SobekCM_Library_Settings.Refresh(Database.SobekCM_Database.Get_Settings_Complete(null));
                string[] allFiles = Directory.GetFiles(user_bib_vid_process_directory);

                string serverNetworkFolder = SobekCM_Library_Settings.Image_Server_Network + item.Web.AssocFilePath;

                // Create the folder
                if (!Directory.Exists(serverNetworkFolder))
                {
                    Directory.CreateDirectory(serverNetworkFolder);
                }
                else
                {
                    // Rename any existing standard mets to keep a backup
                    if (File.Exists(serverNetworkFolder + "\\" + item.BibID + "_" + item.VID + ".mets.xml"))
                    {
                        FileInfo currentMetsFileInfo = new FileInfo(serverNetworkFolder + "\\" + item.BibID + "_" + item.VID + ".mets.xml");
                        DateTime lastModDate         = currentMetsFileInfo.LastWriteTime;
                        File.Copy(serverNetworkFolder + "\\" + item.BibID + "_" + item.VID + ".mets.xml", serverNetworkFolder + "\\" + item.BibID + "_" + item.VID + "_" + lastModDate.Year + "_" + lastModDate.Month + "_" + lastModDate.Day + ".mets.bak", true);
                    }
                }

                foreach (string thisFile in allFiles)
                {
                    string destination_file = serverNetworkFolder + "\\" + (new FileInfo(thisFile)).Name;
                    File.Copy(thisFile, destination_file, true);
                }

                // Copy the static HTML file as well
                try
                {
                    if (!Directory.Exists(SobekCM_Library_Settings.Static_Pages_Location + item.BibID.Substring(0, 2) + "\\" + item.BibID.Substring(2, 2) + "\\" + item.BibID.Substring(4, 2) + "\\" + item.BibID.Substring(6, 2) + "\\" + item.BibID.Substring(8)))
                    {
                        Directory.CreateDirectory(SobekCM_Library_Settings.Static_Pages_Location + item.BibID.Substring(0, 2) + "\\" + item.BibID.Substring(2, 2) + "\\" + item.BibID.Substring(4, 2) + "\\" + item.BibID.Substring(6, 2) + "\\" + item.BibID.Substring(8));
                    }
                    if (File.Exists(user_bib_vid_process_directory + "\\" + item.BibID + "_" + item.VID + ".html"))
                    {
                        File.Copy(user_bib_vid_process_directory + "\\" + item.BibID + "_" + item.VID + ".html", SobekCM_Library_Settings.Static_Pages_Location + item.BibID.Substring(0, 2) + "\\" + item.BibID.Substring(2, 2) + "\\" + item.BibID.Substring(4, 2) + "\\" + item.BibID.Substring(6, 2) + "\\" + item.BibID.Substring(8) + "\\" + item.BibID + "_" + item.VID + ".html", true);
                    }
                }
                catch (Exception)
                {
                    // This is not critical
                }

                // Add this to the cache
                itemList.Add_SobekCM_Item(item, false);

                // Now, delete all the files here
                string[] all_files = Directory.GetFiles(user_bib_vid_process_directory);
                foreach (string thisFile in all_files)
                {
                    File.Delete(thisFile);
                }

                // Clear the user-specific and global cache of this item
                Cached_Data_Manager.Remove_Digital_Resource_Object(user.UserID, item.BibID, item.VID, null);
                Cached_Data_Manager.Remove_Digital_Resource_Object(item.BibID, item.VID, null);
                Cached_Data_Manager.Remove_Items_In_Title(item.BibID, null);


                // Forward to the display item again
                currentMode.Mode       = Display_Mode_Enum.Item_Display;
                currentMode.ViewerCode = "citation";
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }
        }