Exemple #1
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="METS_Location"> Location of the METS file to read </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 Tuple <SobekCM_Item, SobekCM_Item_Error> Build_Item(string METS_Location, 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 = Engine_Database.Get_Item_Details(BibID, VID, Tracer);

                // If the itemdetails was null, this item is somehow invalid item then
                // If the item details was null, this item is somehow invalid item then
                // and we did not get a valid error message either
                if (itemDetails == null)
                {
                    SobekCM_Item_Error itemError = new SobekCM_Item_Error(SobekCM_Item_Error_Type_Enum.System_Error);
                    if (Engine_Database.Last_Exception != null)
                    {
                        itemError.Message = Engine_Database.Last_Exception.Message;
                    }

                    return(new Tuple <SobekCM_Item, SobekCM_Item_Error>(null, itemError));
                }

                // Was this an error returned though?
                if ((itemDetails.Tables.Count == 1) && (itemDetails.Tables[0].Rows.Count > 0) && (itemDetails.Tables[0].Columns[0].ColumnName == "ErrorMsg"))
                {
                    // Was a VID provided?
                    if ((itemDetails.Tables[0].Rows[0]["VID"] != DBNull.Value) && (itemDetails.Tables[0].Rows[0]["VID"].ToString().Length > 0))
                    {
                        SobekCM_Item_Error itemError = new SobekCM_Item_Error(SobekCM_Item_Error_Type_Enum.Invalid_VID)
                        {
                            Message       = itemDetails.Tables[0].Rows[0]["ErrorMsg"].ToString(),
                            FirstValidVid = itemDetails.Tables[0].Rows[0]["VID"].ToString()
                        };

                        return(new Tuple <SobekCM_Item, SobekCM_Item_Error>(null, itemError));
                    }
                    else
                    {
                        SobekCM_Item_Error itemError = new SobekCM_Item_Error(SobekCM_Item_Error_Type_Enum.Invalid_BibID)
                        {
                            Message = itemDetails.Tables[0].Rows[0]["ErrorMsg"].ToString()
                        };

                        return(new Tuple <SobekCM_Item, SobekCM_Item_Error>(null, itemError));
                    }
                }

                // Try to read the service METS
                SobekCM_Item thisPackage = Build_Item_From_METS(METS_Location, String.Empty, Tracer);

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

                    return(null);
                }

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

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

                return(new Tuple <SobekCM_Item, SobekCM_Item_Error>(thisPackage, null));
            }
            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);
            }
        }
Exemple #2
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 Tuple <SobekCM_Item, SobekCM_Item_Error> 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 = Engine_Database.Get_Item_Details(BibID, VID, Tracer);

                // If the item details was null, this item is somehow invalid item then
                // and we did not get a valid error message either
                if (itemDetails == null)
                {
                    SobekCM_Item_Error itemError = new SobekCM_Item_Error(SobekCM_Item_Error_Type_Enum.System_Error);
                    if (Engine_Database.Last_Exception != null)
                    {
                        itemError.Message = Engine_Database.Last_Exception.Message;
                    }

                    return(new Tuple <SobekCM_Item, SobekCM_Item_Error>(null, itemError));
                }

                // Was this an error returned though?
                if ((itemDetails.Tables.Count == 1) && (itemDetails.Tables[0].Rows.Count > 0) && (itemDetails.Tables[0].Columns[0].ColumnName == "ErrorMsg"))
                {
                    // Was a VID provided?
                    if ((itemDetails.Tables[0].Rows[0]["VID"] != DBNull.Value) && (itemDetails.Tables[0].Rows[0]["VID"].ToString().Length > 0))
                    {
                        SobekCM_Item_Error itemError = new SobekCM_Item_Error(SobekCM_Item_Error_Type_Enum.Invalid_VID)
                        {
                            Message       = itemDetails.Tables[0].Rows[0]["ErrorMsg"].ToString(),
                            FirstValidVid = itemDetails.Tables[0].Rows[0]["VID"].ToString()
                        };

                        return(new Tuple <SobekCM_Item, SobekCM_Item_Error>(null, itemError));
                    }
                    else
                    {
                        SobekCM_Item_Error itemError = new SobekCM_Item_Error(SobekCM_Item_Error_Type_Enum.Invalid_BibID)
                        {
                            Message = itemDetails.Tables[0].Rows[0]["ErrorMsg"].ToString()
                        };

                        return(new Tuple <SobekCM_Item, SobekCM_Item_Error>(null, itemError));
                    }
                }

                // 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 = Engine_ApplicationCache_Gateway.Settings.Servers.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 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 SobekCM 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 = Convert.ToInt32(mainItemRow["Total_Volumes"]) > 1;

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

                return(new Tuple <SobekCM_Item, SobekCM_Item_Error>(thisPackage, null));
            }
            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);
            }
        }