Exemple #1
0
        private void check_for_bib()
        {
            DataSet bibInfo = SobekCM_Database.Get_Item_Details(bibIdTextBox.Text.Trim(), String.Empty, null);

            if ((bibInfo != null) && (bibInfo.Tables[0].Rows.Count > 0))
            {
                titleLabel.Text = bibInfo.Tables[0].Rows[0]["GroupTitle"].ToString();
                vidComboBox.Items.Clear();
                DataColumn vidColumn = bibInfo.Tables[1].Columns["VID"];
                foreach (DataRow vidRow in bibInfo.Tables[1].Rows)
                {
                    vidComboBox.Items.Add(vidRow[vidColumn].ToString());
                }
                vidComboBox.SelectedIndex    = vidComboBox.Items.Count - 1;
                bibidLabel.Text              = bibIdTextBox.Text.Trim();
                executeButton.Button_Enabled = true;
            }
            else
            {
                vidComboBox.Items.Clear();
                titleLabel.Text = String.Empty;
                executeButton.Button_Enabled = false;
            }
        }
Exemple #2
0
        /// <summary> Constructor for a new instance of the Delete_Item_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="All_Items_Lookup"> Allows individual items to be retrieved by various methods as <see cref="SobekCM.Library.Application_State.Single_Item"/> objects.</param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Delete_Item_MySobekViewer(User_Object User,
                                         SobekCM_Navigation_Object Current_Mode,
                                         Item_Lookup_Object All_Items_Lookup,

                                         Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Delete this item");

            // Save mode and set defaults
            currentMode = Current_Mode;
            errorCode   = -1;

            // First, ensure this is a logged on user and system administrator before continuing
            Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Validate user permissions");
            if ((User == null) || ((!User.Is_System_Admin) && (User.UserName.ToLower() != "neldamaxs")))
            {
                Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "User does not have delete permissions", Custom_Trace_Type_Enum.Error);
                errorCode = 1;
            }

            // Second, ensure the item is valid
            if (errorCode == -1)
            {
                Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Validate item exists");
                if (!All_Items_Lookup.Contains_BibID_VID(Current_Mode.BibID, Current_Mode.VID))
                {
                    Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Item indicated is not valid", Custom_Trace_Type_Enum.Error);
                    errorCode = 2;
                }
            }

            // Get the current item details
            string bib_location = String.Empty;
            string vid_location = String.Empty;

            if (errorCode == -1)
            {
                // Get item details
                DataSet itemDetails = SobekCM_Database.Get_Item_Details(currentMode.BibID, currentMode.VID, Tracer);

                // If the itemdetails was null, this item is somehow invalid item then
                if (itemDetails == null)
                {
                    Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Item indicated is not valid", Custom_Trace_Type_Enum.Error);
                    errorCode = 2;
                }
                else
                {
                    // Get the location for this METS file from the returned value
                    DataRow mainItemRow = itemDetails.Tables[2].Rows[0];
                    bib_location = SobekCM_Library_Settings.Image_Server_Network + mainItemRow["File_Location"].ToString().Replace("/", "\\");
                    vid_location = bib_location + "\\" + currentMode.VID;
                }
            }

            // If this is a postback, handle any events first
            if ((currentMode.isPostBack) && (errorCode < 0))
            {
                Debug.Assert(User != null, "User != null");

                // Pull the standard values
                string save_value = HttpContext.Current.Request.Form["admin_delete_item"];
                string text_value = HttpContext.Current.Request.Form["admin_delete_confirm"];

                // Better say "DELETE", or just send back to the item
                if ((save_value == null) || (save_value.ToUpper() != "DELETE") || (text_value.ToUpper() != "DELETE"))
                {
                    HttpContext.Current.Response.Redirect(Current_Mode.Base_URL + currentMode.BibID + "/" + currentMode.VID);
                }
                else
                {
                    errorCode = 0;

                    // Perform the database delete
                    Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Perform database update");
                    bool database_result = SobekCM_Database.Delete_SobekCM_Item(currentMode.BibID, currentMode.VID, User.Is_System_Admin, String.Empty);

                    if (!database_result)
                    {
                        Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Error performing delete in the database", Custom_Trace_Type_Enum.Error);
                        errorCode = 3;
                    }
                    else
                    {
                        // Move the folder to deletes
                        try
                        {
                            Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Move resource files to DELETED folder");

                            // Make sure upper deleted folder exists, or create it
                            string delete_folder = SobekCM_Library_Settings.Image_Server_Network + "DELETED";
                            if (!Directory.Exists(delete_folder))
                            {
                                Directory.CreateDirectory(delete_folder);
                            }

                            // Create the bib level folder next
                            string bib_folder = SobekCM_Library_Settings.Image_Server_Network + "DELETED\\" + currentMode.BibID;
                            if (!Directory.Exists(bib_folder))
                            {
                                Directory.CreateDirectory(bib_folder);
                            }

                            // Ensure the VID folder does not exist
                            string vid_folder = SobekCM_Library_Settings.Image_Server_Network + "DELETED\\" + currentMode.BibID + "\\" + currentMode.VID;
                            if (Directory.Exists(vid_folder))
                            {
                                Directory.Move(vid_folder, vid_folder + "_OLD");
                            }

                            // Move the VID folder over now
                            Directory.Move(vid_location, vid_folder);

                            // Check if this was the last VID under this BIB
                            if (Directory.GetDirectories(bib_location).Length == 0)
                            {
                                // Move all files over to the bib folder then
                                string[] bib_files = Directory.GetFiles(bib_location);
                                foreach (string thisFile in bib_files)
                                {
                                    string fileName = (new FileInfo(thisFile)).Name;
                                    string new_file = bib_folder + "\\" + fileName;
                                    File.Move(thisFile, new_file);
                                }
                            }
                        }
                        catch (Exception ee)
                        {
                            Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", "Error moving the folder and files to the DELETED folder", Custom_Trace_Type_Enum.Error);
                            Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", ee.Message, Custom_Trace_Type_Enum.Error);
                            Tracer.Add_Trace("Delete_Item_MySobekViewer.Constructor", ee.StackTrace, Custom_Trace_Type_Enum.Error);
                            errorCode = 4;
                        }

                        // Remove from the item list
                        All_Items_Lookup.Remove_Item(currentMode.BibID, currentMode.VID);

                        // Also remove from the cache
                        Cached_Data_Manager.Remove_Digital_Resource_Object(currentMode.BibID, currentMode.VID, Tracer);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary> Builds a digital resource for a single volume within a title </summary>
        /// <param name="BibID"> Bibliographic identifier for the title </param>
        /// <param name="VID"> Volume identifier for the title </param>
        /// <param name="Icon_Dictionary"> Dictionary of information about every wordmark/icon in this digital library, used to build the HTML for the icons linked to this digital resource</param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <returns> Fully built version of a digital resource </returns>
        public SobekCM_Item Build_Item(string BibID, string VID, Dictionary <string, Wordmark_Icon> Icon_Dictionary, Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Build_Item", "Create the requested item");
            }

            try
            {
                // Get the basic information about this item
                DataSet itemDetails = SobekCM_Database.Get_Item_Details(BibID, VID, Tracer);

                // If the itemdetails was null, this item is somehow invalid item then
                if (itemDetails == null)
                {
                    return(null);
                }

                // Get the location for this METS file from the returned value
                DataRow mainItemRow   = itemDetails.Tables[2].Rows[0];
                string  mets_location = mainItemRow["File_Location"] + "/" + VID;
                if (mets_location.Length < 10)
                {
                    mets_location = BibID.Substring(0, 2) + "/" + BibID.Substring(2, 2) + "/" + BibID.Substring(4, 2) + "/" + BibID.Substring(6, 2) + "/" + BibID.Substring(8) + "/" + VID;
                }



                // Get the response object for this METS file
                string mets_file = mets_location.Replace("\\", "/") + "/" + BibID + "_" + VID + ".mets.xml";
                if (mets_file.IndexOf("http:") < 0)
                {
                    mets_file = SobekCM_Library_Settings.Image_Server_Network + mets_file;
                }

                // Could point directly to a METS file in some off-site location, in which case, use it
                if (mets_location.IndexOf(".mets") > 0)
                {
                    mets_file = mets_location;
                }

                // Try to read the UFDC service METS
                SobekCM_Item thisPackage = Build_Item_From_METS(mets_file, BibID + "_" + VID + ".mets.xml", Tracer);

                if (thisPackage == null)
                {
                    if (Tracer != null)
                    {
                        Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Build_Item", "Unable to read the UFDC service METS file", Custom_Trace_Type_Enum.Error);
                    }

                    return(null);
                }

                if (Tracer != null)
                {
                    Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Build_Item", "Finish building this item");
                }

                // Check to see if multiple sibling volumes exist
                bool multiple_volumes_exist = false;
                if (Convert.ToInt32(mainItemRow["Total_Volumes"]) > 1)
                {
                    multiple_volumes_exist = true;
                }

                // Now finish building the object from the application state values
                Finish_Building_Item(thisPackage, itemDetails, multiple_volumes_exist);

                return(thisPackage);
            }
            catch (Exception ee)
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Build_Item", ee.ToString().Replace("\n", "<br />"), Custom_Trace_Type_Enum.Error);
                }
                return(null);
            }
        }