Esempio n. 1
0
        /// <summary> Check the Bibliographic package agaist the SobekCM METS standard</summary>
        /// <param name="bibPackagetoCheck">Package to validate</param>
        /// <param name="packageDir">Directory for the package</param>
        /// <returns>TRUE is succesful, otherwise FALSE</returns>
        public bool SobekCM_Standard_Check(SobekCM_Item bibPackagetoCheck, string packageDir)
        {
            bool returnVal = true;

            validationErrors = new StringBuilder();
            thisBibPackage   = bibPackagetoCheck;
            packageDirName   = packageDir;

            // check the BibID is in the right format
            if (SobekCM_Item.is_bibid_format(thisBibPackage.Bib_Info.BibID) == false)
            {
                validationErrors.Append("Invalid BibID" + "\n");
                returnVal = false;
            }
            // check the VID is in the right format
            if (SobekCM_Item.is_vids_format(thisBibPackage.Bib_Info.VID) == false)
            {
                validationErrors.Append("Invalid VID" + "\n");
                returnVal = false;
            }
            // check the title, it is a required field
            if (thisBibPackage.Bib_Info.Main_Title.Title.Length == 0)
            {
                validationErrors.Append("Item title is required but not supplied!" + "\n");
                returnVal = false;
            }

            // check if the objid is the combination of BibID_VID
            if (thisBibPackage.METS_Header.ObjectID != thisBibPackage.Bib_Info.BibID + "_" + thisBibPackage.Bib_Info.VID)
            {
                validationErrors.Append("The METS OBJID does not match its BibID and VID" + "\n");
                returnVal = false;
            }

            // Validate the folder matches the package object id
            DirectoryInfo dirInfo = new DirectoryInfo(packageDir);
            string        dirName = dirInfo.Name;

            if (dirName.Length < 16)
            {
                dirName = dirInfo.Parent.Name + "_" + dirName;
            }
            if (!String.Equals(dirName, thisBibPackage.METS_Header.ObjectID, StringComparison.InvariantCultureIgnoreCase))
            {
                validationErrors.Append("The folder name and the METS OBJID do not match" + "\n");
                returnVal = false;
            }

            // check if file sizes and MD5 checksums match with what indicate in the mets file
            return(returnVal);
        }
Esempio n. 2
0
        public Tiles_Home_AggregationViewer(RequestCache RequestSpecificValues, AggregationViewBag ViewBag) : base(RequestSpecificValues, ViewBag)
        {
            // Get the list of tiles
            string aggregation_tile_directory = Path.Combine(UI_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, ViewBag.Hierarchy_Object.ObjDirectory, "images", "tiles");

            string[] jpeg_tiles = Directory.GetFiles(aggregation_tile_directory, "*.jpg");

            // Compute the URL for these images
            string aggregation_tile_uri = RequestSpecificValues.Current_Mode.Base_URL + "design/aggregations/" + ViewBag.Hierarchy_Object.Code + "/images/tiles/";

            // Get the list of all potential tiles, by checking name
            List <Tiles_Home_Single_Tile> allTiles = new List <Tiles_Home_Single_Tile>();
            string bibid = null;
            string vid   = null;

            foreach (string thisJpegTile in jpeg_tiles)
            {
                // Get the filename
                string thisFileName = Path.GetFileName(thisJpegTile);
                string thisFileNameSansExtension = Path.GetFileNameWithoutExtension(thisJpegTile);


                // Check for a link to the bibid/vid
                string bib_vid_for_link = String.Empty;

                if ((thisFileNameSansExtension.Length == 10) && (SobekCM_Item.is_bibid_format(thisFileNameSansExtension)))
                {
                    bib_vid_for_link = thisFileNameSansExtension;
                    bibid            = bib_vid_for_link;
                    vid = "00001";
                }
                else if ((thisFileNameSansExtension.Length == 15) && (SobekCM_Item.is_bibid_format(thisFileNameSansExtension.Substring(0, 10))) && (SobekCM_Item.is_vids_format(thisFileNameSansExtension.Substring(10))))
                {
                    bib_vid_for_link = thisFileNameSansExtension.Substring(0, 10) + "/" + thisFileNameSansExtension.Substring(10);
                    bibid            = thisFileNameSansExtension.Substring(0, 10);
                    vid = thisFileNameSansExtension.Substring(10);
                }
                else if ((thisFileNameSansExtension.Length == 16) && (SobekCM_Item.is_bibid_format(thisFileNameSansExtension.Substring(0, 10))) && (SobekCM_Item.is_vids_format(thisFileNameSansExtension.Substring(11))))
                {
                    bib_vid_for_link = thisFileNameSansExtension.Substring(0, 10) + "/" + thisFileNameSansExtension.Substring(11);
                    bibid            = thisFileNameSansExtension.Substring(0, 10);
                    vid = thisFileNameSansExtension.Substring(11);
                }

                // If there was a link calculated, then use this jpeg
                if (!String.IsNullOrEmpty(bib_vid_for_link))
                {
                    allTiles.Add(new Tiles_Home_Single_Tile
                    {
                        JpegUri = aggregation_tile_uri + thisFileName,
                        LinkUri = RequestSpecificValues.Current_Mode.Base_URL + bib_vid_for_link,
                        BibID   = bibid ?? String.Empty,
                        VID     = vid ?? String.Empty
                    });
                }
            }

            // Is the metadata cached?
            string cache_key = ViewBag.Hierarchy_Object.Code + ":TILE METADATA";

            tileMetadata = HttpContext.Current.Cache.Get(cache_key) as Database_Results_Info;
            if (tileMetadata == null)
            {
                // Look for the metadat file
                string metadata_file = Path.Combine(aggregation_tile_directory, "tile_metadata.xml");

                // If no file, try to create it
                if (!File.Exists(metadata_file))
                {
                    // Step through each image, collecting the bibs and vids
                    List <string> bibs = new List <string>();
                    List <string> vids = new List <string>();
                    foreach (Tiles_Home_Single_Tile thisTile in allTiles)
                    {
                        bibs.Add(thisTile.BibID);
                        vids.Add(thisTile.VID);
                    }

                    // Now, look up each of these bib/vids

                    // First, pad the lists correctly
                    while (bibs.Count % 10 != 0)
                    {
                        bibs.Add(String.Empty);
                        vids.Add(String.Empty);
                    }

                    // Get the aggregation code
                    string aggrCode = ViewBag.Hierarchy_Object.Code;

                    // FOR TESTING DON'T USE COLLECTION CODE
                    aggrCode = "";

                    // Start the results object
                    Database_Results_Info allResults = new Database_Results_Info();

                    // Now, get the results
                    int offset = 0;
                    while (offset < bibs.Count)
                    {
                        //Get the results from the database
                        Database_Results_Info results = Engine_Library.Database.Engine_Database.Metadata_By_Bib_Vid(aggrCode, bibs[offset + 0], vids[offset + 0], bibs[offset + 1], vids[offset + 1],
                                                                                                                    bibs[offset + 2], vids[offset + 2], bibs[offset + 3], vids[offset + 3],
                                                                                                                    bibs[offset + 4], vids[offset + 4], bibs[offset + 5], vids[offset + 5],
                                                                                                                    bibs[offset + 6], vids[offset + 6], bibs[offset + 7], vids[offset + 7],
                                                                                                                    bibs[offset + 8], vids[offset + 8], bibs[offset + 9], vids[offset + 9], null);

                        // Combine into full results
                        if ((results != null) && (results.Metadata_Labels != null) && (results.Metadata_Labels.Count > 0))
                        {
                            allResults.Metadata_Labels = results.Metadata_Labels;
                        }

                        if ((results != null) && (results.Results != null) && (results.Results.Count > 0))
                        {
                            allResults.Results.AddRange(results.Results);
                        }

                        offset += 10;
                    }


                    // Save these results
                    StreamWriter writer = new StreamWriter(metadata_file, false);

                    XmlSerializer x = new XmlSerializer(allResults.GetType());
                    x.Serialize(writer, allResults);

                    writer.Close();
                }


                // Check again, and let's read the metadata
                if (File.Exists(metadata_file))
                {
                    try
                    {
                        FileStream fs     = new FileStream(metadata_file, FileMode.Open);
                        XmlReader  reader = XmlReader.Create(fs);

                        XmlSerializer x = new XmlSerializer(typeof(Database_Results_Info));

                        // Use the Deserialize method to restore the object's state.
                        tileMetadata = (Database_Results_Info)x.Deserialize(reader);
                        fs.Close();

                        // Also put this in the cache
                        HttpContext.Current.Cache.Insert(cache_key, tileMetadata, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5));
                    }
                    catch (Exception ee)
                    {
                        tileMetadata = null;
                    }
                }
            }

            // If less than or equal to fifteen, copy over as is.. otherwise, choose random ones
            if (allTiles.Count <= 15)
            {
                selectedTiles.AddRange(allTiles);
            }
            else
            {
                Random randomGen = new Random();
                while (selectedTiles.Count < 15)
                {
                    int random_index = randomGen.Next(0, allTiles.Count);
                    selectedTiles.Add(allTiles[random_index]);
                    allTiles.RemoveAt(random_index);
                }
            }
        }
Esempio n. 3
0
        /// <summary> Moves the incoming digital resource folder, along with all files and subdirectories, to a new location </summary>
        /// <param name="DestinationDirectory"> New location for this incoming digital resource </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public bool Move(string DestinationDirectory)
        {
            try
            {
                // Make sure the destination directory exists
                if (!Directory.Exists(DestinationDirectory))
                {
                    Directory.CreateDirectory(DestinationDirectory);
                }

                // Determine the new folder for this
                DirectoryInfo dirInfo    = new DirectoryInfo(resourceFolder);
                string        destFolder = DestinationDirectory + dirInfo.Name;

                // Does this directory appear to be a VID folder, with a BibID folder above it?
                // If so, we will flatten this folder structure
                string thisDirName = dirInfo.Name.ToUpper().Replace("VID", "");
                if ((thisDirName.Length == 5) && (SobekCM_Item.is_vids_format(thisDirName)))
                {
                    // Is the parent directory is a bibid format, we will flatten this a Bib ID?
                    string bibidCheck = Directory.GetParent(resourceFolder).Name;
                    if (SobekCM_Item.is_bibid_format(bibidCheck))
                    {
                        // Flatten this bibi/vid structure then and make the new destination folder bibid_vid
                        destFolder = DestinationDirectory + bibidCheck + "_" + dirInfo.Name.ToUpper().Replace("VID", "");
                    }
                    else if (bibidCheck.Length == 2)
                    {
                        // Put in special code for directories dropped in builder from resource folder
                        // That is, look for the pair-tree format
                        string check = bibidCheck;
                        int    count = 0;
                        while ((Directory.GetParent(bibidCheck) != null) && (count < 4))
                        {
                            string parent = Directory.GetParent(bibidCheck).Name;
                            if (parent.Length != 2)
                            {
                                check = String.Empty;
                                break;
                            }

                            check = check + parent;
                            count++;
                        }

                        if (check.Length == 10)
                        {
                            destFolder = DestinationDirectory + check + "_" + dirInfo.Name.ToUpper().Replace("VID", "");
                        }
                    }
                }

                // If the destination directory exists, delete it
                if (Directory.Exists(destFolder))
                {
                    Directory.Delete(destFolder, true);
                }

                // Move this directory
                Directory.Move(resourceFolder, destFolder);
                resourceFolder = destFolder;

                // If the parent directory is empty, try to delete it
                string parentDir = resourceFolder;
                while ((Directory.GetParent(parentDir) != null) && (Directory.GetParent(parentDir).GetFiles().Length == 0))
                {
                    parentDir = Directory.GetParent(parentDir).FullName;
                    try
                    {
                        Directory.Delete(parentDir);
                    }
                    catch (Exception)
                    {
                        // If unable to delete the directory, not the worst thing
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 4
0
        /// <summary> Looks in the aggregation design folders for tiles and pulls the metadata for each
        /// tile to enable the hover-over in the aggregation tile display </summary>
        /// <param name="Settings"> Instance-wide settings which may be required for this process </param>
        public override void DoWork(InstanceWide_Settings Settings)
        {
            // Get the spot where the aggregations sit
            string aggregation_base = Path.Combine(Settings.Servers.Base_Design_Location, "aggregations");

            // Ensure it exists before continuing
            if (!Directory.Exists(aggregation_base))
            {
                return;
            }

            // Step through each aggregation folder
            string[] aggregation_folders = Directory.GetDirectories(aggregation_base);
            foreach (string thisAggrFolder in aggregation_folders)
            {
                // Find the associated aggregation tiles folder
                string tile_folder = Path.Combine(thisAggrFolder, "images", "tiles");

                // Skip this aggregation if it doesn't exist
                if (!Directory.Exists(tile_folder))
                {
                    continue;
                }

                // Get JPEG images
                string[] tile_images = Directory.GetFiles(tile_folder, "*.jpg");

                // Skip this aggregation if no images exist
                if (tile_images.Length == 0)
                {
                    continue;
                }

                // Step through each image, collecting the bibs and vids
                List <string> bibs = new List <string>();
                List <string> vids = new List <string>();
                foreach (string thisTile in tile_images)
                {
                    string thisFileNameSansExtension = Path.GetFileNameWithoutExtension(thisTile);
                    if ((thisFileNameSansExtension.Length == 10) && (SobekCM_Item.is_bibid_format(thisFileNameSansExtension)))
                    {
                        bibs.Add(thisFileNameSansExtension);
                        vids.Add("00001");
                    }
                    else if ((thisFileNameSansExtension.Length == 15) && (SobekCM_Item.is_bibid_format(thisFileNameSansExtension.Substring(0, 10))) && (SobekCM_Item.is_vids_format(thisFileNameSansExtension.Substring(10))))
                    {
                        bibs.Add(thisFileNameSansExtension.Substring(0, 10));
                        vids.Add(thisFileNameSansExtension.Substring(10));
                    }
                    else if ((thisFileNameSansExtension.Length == 16) && (SobekCM_Item.is_bibid_format(thisFileNameSansExtension.Substring(0, 10))) && (SobekCM_Item.is_vids_format(thisFileNameSansExtension.Substring(11))))
                    {
                        bibs.Add(thisFileNameSansExtension.Substring(0, 10));
                        vids.Add(thisFileNameSansExtension.Substring(11));
                    }
                }

                // Skip if no valid bib/vid names were found
                if (bibs.Count == 0)
                {
                    continue;
                }

                // Now, look up each of these bib/vids

                // First, pad the lists correctly
                while (bibs.Count % 10 != 0)
                {
                    bibs.Add(String.Empty);
                    vids.Add(String.Empty);
                }

                // Get the aggregation code
                string aggrCode = Path.GetFileName(thisAggrFolder);

                // FOR TESTING DON'T USE COLLECTION CODE
                aggrCode = "";

                // Start the results object
                Database_Results_Info allResults = new Database_Results_Info();

                // Now, get the results
                int offset = 0;
                while (offset < bibs.Count)
                {
                    //Get the results from the database
                    Database_Results_Info results = Engine_Library.Database.Engine_Database.Metadata_By_Bib_Vid(aggrCode, bibs[offset + 0], vids[offset + 0], bibs[offset + 1], vids[offset + 1],
                                                                                                                bibs[offset + 2], vids[offset + 2], bibs[offset + 3], vids[offset + 3],
                                                                                                                bibs[offset + 4], vids[offset + 4], bibs[offset + 5], vids[offset + 5],
                                                                                                                bibs[offset + 6], vids[offset + 6], bibs[offset + 7], vids[offset + 7],
                                                                                                                bibs[offset + 8], vids[offset + 8], bibs[offset + 9], vids[offset + 9], null);

                    // Combine into full results
                    if ((results != null) && (results.Metadata_Labels != null) && (results.Metadata_Labels.Count > 0))
                    {
                        allResults.Metadata_Labels = results.Metadata_Labels;
                    }

                    if ((results != null) && (results.Results != null) && (results.Results.Count > 0))
                    {
                        allResults.Results.AddRange(results.Results);
                    }

                    offset += 10;
                }


                // Save these results
                string       cached_results_file = Path.Combine(tile_folder, "tile_metadata.xml");
                StreamWriter writer = new StreamWriter(cached_results_file, false);

                XmlSerializer x = new XmlSerializer(allResults.GetType());
                x.Serialize(writer, allResults);
            }
        }