/// <summary> Returns the directory list for this digital resource </summary>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <returns> HTML string with the directory list for this digital resource </returns>
        public string Directory_String(Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("Tracking_ItemViewer.Directory_String", "Pulling and displaying files in the image directory");
            }

            try
            {
                string directory = SobekCM_Library_Settings.Image_Server_Network + CurrentItem.Web.AssocFilePath;
                string url       = SobekCM_Library_Settings.Image_URL + CurrentItem.Web.AssocFilePath;

                FileInfo[] files = (new DirectoryInfo(directory)).GetFiles();

                StringBuilder builder = new StringBuilder(3000);

                // Get all the file info objects and order by name
                SortedList <string, FileInfo> sortedFiles = new SortedList <string, FileInfo>();
                foreach (FileInfo thisFile in files)
                {
                    sortedFiles.Add(thisFile.Name.ToUpper(), thisFile);
                }

                // Remove the THUMBS.DB file, if it exists
                if (sortedFiles.ContainsKey("THUMBS.DB"))
                {
                    sortedFiles.Remove("THUMBS.DB");
                }

                // Start the file table
                builder.AppendLine("<br />");
                builder.AppendLine("<br />");
                builder.AppendLine("<blockquote>");
                builder.AppendLine(" &nbsp; &nbsp; <a href=\"" + directory + "\">" + directory + "</a>");
                builder.AppendLine("</blockquote>");

                builder.AppendLine("<blockquote>");


                // Add all the page images first
                List <abstract_TreeNode> nodes = CurrentItem.Divisions.Physical_Tree.Pages_PreOrder;
                if ((nodes != null) && (nodes.Count > 0))
                {
                    builder.AppendLine("<span style=\"font-size:1.4em; color:#888888;\"><b>PAGE FILES</b></span><br />");
                    builder.AppendLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">");
                    builder.AppendLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >");
                    builder.AppendLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>");
                    builder.AppendLine("<th width=\"10px\">&nbsp;</th>");
                    builder.AppendLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>");
                    builder.AppendLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>");
                    builder.AppendLine("<th width=\"10px\">&nbsp;</th>");
                    builder.AppendLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>");
                    builder.AppendLine("</tr>");

                    List <string> file_names_added = new List <string>();
                    foreach (Page_TreeNode thisNode in nodes)
                    {
                        // Only show pages with files
                        if (thisNode.Files.Count > 0)
                        {
                            // Ensure that if a page is repeated, it only is written once
                            string[] filename_splitter = thisNode.Files[0].System_Name.Split(".".ToCharArray());

                            string fileName = filename_splitter[0].ToUpper();
                            if (filename_splitter.Length > 1)
                            {
                                fileName = filename_splitter[filename_splitter.Length - 2].ToUpper();
                            }
                            if (!file_names_added.Contains(fileName))
                            {
                                file_names_added.Add(fileName);

                                builder.AppendLine("<tr align=\"left\" bgcolor=\"#7d90d5\">");
                                string pageName = thisNode.Label;
                                if (pageName.Length == 0)
                                {
                                    pageName = "PAGE";
                                }

                                builder.AppendLine("<td colspan=\"6\" ><span style=\"color: White\"><b>" + pageName.ToUpper() + "</b></span></td>");
                                builder.AppendLine("</tr>");

                                // Now, check for each file
                                foreach (SobekCM_File_Info thisFile in thisNode.Files)
                                {
                                    string thisFileUpper = thisFile.System_Name.ToUpper();
                                    if (sortedFiles.ContainsKey(thisFileUpper))
                                    {
                                        // string file = SobekCM_Library_Settings.Image_Server_Network + CurrentItem.Web.AssocFilePath + thisFile.System_Name;
                                        Add_File_HTML(sortedFiles[thisFileUpper], builder, url, true);
                                        sortedFiles.Remove(thisFileUpper);
                                    }
                                }

                                // Ensure that there still aren't some page files that exist that were not linked
                                string[] other_page_file_endings = new[] { ".JPG", ".JP2", "THM.JPG", ".TXT", ".PRO", ".QC.JPG" };
                                foreach (string thisFileEnder in other_page_file_endings)
                                {
                                    if (sortedFiles.ContainsKey(fileName.ToUpper() + thisFileEnder))
                                    {
                                        //string file = SobekCM_Library_Settings.Image_Server_Network + CurrentItem.Web.AssocFilePath + fileName + thisFileEnder.ToLower();
                                        Add_File_HTML(sortedFiles[fileName.ToUpper() + thisFileEnder], builder, url, true);
                                        sortedFiles.Remove(fileName.ToUpper() + thisFileEnder);
                                    }
                                }
                            }
                        }
                    }

                    // FInish the table
                    builder.AppendLine("</table>");
                    builder.AppendLine("<br /><br />");
                }

                // Add all the metadata files
                builder.AppendLine("<span style=\"font-size:1.4em; color:#888888;\"><b>METADATA FILES</b></span><br />");
                builder.AppendLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">");
                builder.AppendLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >");
                builder.AppendLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>");
                builder.AppendLine("<th width=\"10px\">&nbsp;</th>");
                builder.AppendLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>");
                builder.AppendLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>");
                builder.AppendLine("<th width=\"10px\">&nbsp;</th>");
                builder.AppendLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>");
                builder.AppendLine("</tr>");

                // Add each metadata file
                List <string> files_handled = new List <string>();
                foreach (string thisFile in sortedFiles.Keys.Where(ThisFile => (ThisFile.IndexOf(".METS.BAK") > 0) || (ThisFile.IndexOf(".METS.XML") > 0) || (ThisFile == "DOC.XML") || (ThisFile == "MARC.XML") || (ThisFile == "CITATION_METS.XML") || (ThisFile == CurrentItem.BibID.ToUpper() + "_" + CurrentItem.VID + ".HTML")))
                {
                    files_handled.Add(thisFile);
                    Add_File_HTML(sortedFiles[thisFile], builder, url, true);
                }

                // REmove all handled files
                foreach (string thisKey in files_handled)
                {
                    sortedFiles.Remove(thisKey);
                }

                // FInish the table
                builder.AppendLine("</table>");
                builder.AppendLine("<br /><br />");

                // Finally, add all the remaining files
                if (sortedFiles.Count > 0)
                {
                    builder.AppendLine("<span style=\"font-size:1.4em; color:#888888;\"><b>OTHER FILES</b></span><br />");
                    builder.AppendLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">");
                    builder.AppendLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >");
                    builder.AppendLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>");
                    builder.AppendLine("<th width=\"10px\">&nbsp;</th>");
                    builder.AppendLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>");
                    builder.AppendLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>");
                    builder.AppendLine("<th width=\"10px\">&nbsp;</th>");
                    builder.AppendLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>");
                    builder.AppendLine("</tr>");

                    // Now add all the information
                    foreach (FileInfo thisFile in sortedFiles.Values)
                    {
                        Add_File_HTML(thisFile, builder, url, true);
                    }

                    // FInish the table
                    builder.AppendLine("</table>");
                }
                builder.AppendLine("</blockquote>");
                builder.AppendLine("<br />");

                return(builder.ToString());
            }
            catch
            {
                return("<br /><center><strong>UNABLE TO PULL DIRECTORY INFORMATION</strong></center><br />");
            }
        }
Esempio n. 2
0
        public static List <string> FindTempStorageManifests(CommandEnvironment Env, string StorageBlockName, bool LocalOnly = false, bool SharedOnly = false, string GameFolder = "")
        {
            var Files = new List <string>();

            var LocalFiles  = LocalTempStorageManifestFilename(Env, StorageBlockName);
            var LocalParent = Path.GetDirectoryName(LocalFiles);
            var WildCard    = Path.GetFileName(LocalFiles);

            int IndexOfStar = WildCard.IndexOf("*");

            if (IndexOfStar < 0 || WildCard.LastIndexOf("*") != IndexOfStar)
            {
                throw new AutomationException("Wildcard {0} either has no star or it has more than one.", WildCard);
            }

            string PreStarWildcard  = WildCard.Substring(0, IndexOfStar);
            string PostStarWildcard = Path.GetFileNameWithoutExtension(WildCard.Substring(IndexOfStar + 1));

            if (!SharedOnly && DirectoryExists_NoExceptions(LocalParent))
            {
                foreach (var ThisFile in CommandUtils.FindFiles_NoExceptions(WildCard, true, LocalParent))
                {
                    Log("  Found local file {0}", ThisFile);
                    int IndexOfWildcard = ThisFile.IndexOf(PreStarWildcard);
                    if (IndexOfWildcard < 0)
                    {
                        throw new AutomationException("File {0} didn't contain {1}.", ThisFile, PreStarWildcard);
                    }
                    int LastIndexOfWildcardTail = ThisFile.LastIndexOf(PostStarWildcard);
                    if (LastIndexOfWildcardTail < 0 || LastIndexOfWildcardTail < IndexOfWildcard + PreStarWildcard.Length)
                    {
                        throw new AutomationException("File {0} didn't contain {1} or it was before the prefix", ThisFile, PostStarWildcard);
                    }
                    string StarReplacement = ThisFile.Substring(IndexOfWildcard + PreStarWildcard.Length, LastIndexOfWildcardTail - IndexOfWildcard - PreStarWildcard.Length);
                    if (StarReplacement.Length < 1)
                    {
                        throw new AutomationException("Dir {0} didn't have any string to fit the star in the wildcard {1}", ThisFile, WildCard);
                    }
                    if (!Files.Contains(StarReplacement))
                    {
                        Files.Add(StarReplacement);
                    }
                }
            }

            if (!LocalOnly)
            {
                var SharedFiles  = SharedTempStorageManifestFilename(Env, StorageBlockName, GameFolder);
                var SharedParent = Path.GetDirectoryName(Path.GetDirectoryName(SharedFiles));

                if (DirectoryExists_NoExceptions(SharedParent))
                {
                    string[] Dirs = null;

                    try
                    {
                        Dirs = Directory.GetDirectories(SharedParent, Path.GetFileNameWithoutExtension(SharedFiles), SearchOption.TopDirectoryOnly);
                    }
                    catch (Exception Ex)
                    {
                        Log("Unable to Find Directories in {0} with wildcard {1}", SharedParent, Path.GetFileNameWithoutExtension(SharedFiles));
                        Log(" Exception was {0}", LogUtils.FormatException(Ex));
                    }
                    if (Dirs != null)
                    {
                        foreach (var ThisSubDir in Dirs)
                        {
                            int IndexOfWildcard = ThisSubDir.IndexOf(PreStarWildcard);
                            if (IndexOfWildcard < 0)
                            {
                                throw new AutomationException("Dir {0} didn't contain {1}.", ThisSubDir, PreStarWildcard);
                            }
                            int LastIndexOfWildcardTail = ThisSubDir.LastIndexOf(PostStarWildcard);
                            if (LastIndexOfWildcardTail < 0 || LastIndexOfWildcardTail < IndexOfWildcard + PreStarWildcard.Length)
                            {
                                throw new AutomationException("Dir {0} didn't contain {1} or it was before the prefix", ThisSubDir, PostStarWildcard);
                            }
                            string StarReplacement = ThisSubDir.Substring(IndexOfWildcard + PreStarWildcard.Length, LastIndexOfWildcardTail - IndexOfWildcard - PreStarWildcard.Length);
                            if (StarReplacement.Length < 1)
                            {
                                throw new AutomationException("Dir {0} didn't have any string to fit the star in the wildcard {1}", ThisSubDir, WildCard);
                            }
                            // these are a bunch of false positives
                            if (StarReplacement.Contains("-"))
                            {
                                continue;
                            }
                            if (!Files.Contains(StarReplacement))
                            {
                                Files.Add(StarReplacement);
                            }
                        }
                    }
                }
            }

            var OutFiles = new List <string>();

            foreach (var StarReplacement in Files)
            {
                var NewBlock = StorageBlockName.Replace("*", StarReplacement);

                if (TempStorageExists(Env, NewBlock, GameFolder, LocalOnly, true))
                {
                    OutFiles.Add(StarReplacement);
                }
            }
            return(OutFiles);
        }
        /// <summary> Write the item viewer main section as HTML directly to the HTTP output stream </summary>
        /// <param name="Output"> Response stream for the item viewer to write directly to </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public override void Write_Main_Viewer_Section(TextWriter Output, Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("Directory_ItemViewer.Write_Main_Viewer_Section", "");

            // Add the HTML for the image
            Output.WriteLine("<!-- DIRECTORY ITEM VIEWER OUTPUT -->");

            // Start the citation table
            Output.WriteLine("  <td align=\"left\"><span class=\"sbkTrk_ViewerTitle\">Tracking Information</span></td>");
            Output.WriteLine("</tr>");
            Output.WriteLine("<tr>");
            Output.WriteLine("  <td class=\"sbkTrk_MainArea\">");

            // Add the tabs for related admin viewers (if they exist)
            Tracking_ItemViewer.Write_Tracking_Tabs(Output, CurrentRequest, BriefItem);

            Tracer.Add_Trace("Directory_ItemViewer.Directory_String", "Pulling and displaying files in the image directory");

            try
            {
                string directory = SobekFileSystem.Resource_Network_Uri(BriefItem);
                string url       = SobekFileSystem.Resource_Web_Uri(BriefItem);
                List <SobekFileSystem_FileInfo> files = SobekFileSystem.GetFiles(BriefItem);

                // Get all the file info objects and order by name
                SortedList <string, SobekFileSystem_FileInfo> sortedFiles = new SortedList <string, SobekFileSystem_FileInfo>();
                foreach (SobekFileSystem_FileInfo thisFile in files)
                {
                    sortedFiles.Add(thisFile.Name.ToUpper(), thisFile);
                }

                // Remove the THUMBS.DB file, if it exists
                if (sortedFiles.ContainsKey("THUMBS.DB"))
                {
                    sortedFiles.Remove("THUMBS.DB");
                }

                // Start the file table
                Output.WriteLine("<br />");
                Output.WriteLine("<br />");
                Output.WriteLine("<blockquote>");
                Output.WriteLine(" &nbsp; &nbsp; <a href=\"" + directory + "\">" + directory + "</a>");
                Output.WriteLine("</blockquote>");

                Output.WriteLine("<blockquote>");

                // Add all the page images first
                List <BriefItem_FileGrouping> nodes = BriefItem.Images;
                if ((nodes != null) && (nodes.Count > 0))
                {
                    Output.WriteLine("<span style=\"font-size:1.4em; color:#888888;\"><b>PAGE FILES</b></span><br />");
                    Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">");
                    Output.WriteLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >");
                    Output.WriteLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>");
                    Output.WriteLine("<th width=\"10px\">&nbsp;</th>");
                    Output.WriteLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>");
                    Output.WriteLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>");
                    Output.WriteLine("<th width=\"10px\">&nbsp;</th>");
                    Output.WriteLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>");
                    Output.WriteLine("</tr>");

                    List <string> file_names_added = new List <string>();
                    foreach (BriefItem_FileGrouping thisNode in nodes)
                    {
                        // Only show pages with files
                        if (thisNode.Files.Count > 0)
                        {
                            // Ensure that if a page is repeated, it only is written once
                            string[] filename_splitter = thisNode.Files[0].Name.Split(".".ToCharArray());

                            string fileName = filename_splitter[0].ToUpper();
                            if (filename_splitter.Length > 1)
                            {
                                fileName = filename_splitter[filename_splitter.Length - 2].ToUpper();
                            }
                            if (!file_names_added.Contains(fileName))
                            {
                                file_names_added.Add(fileName);

                                Output.WriteLine("<tr align=\"left\" bgcolor=\"#7d90d5\">");
                                string pageName = thisNode.Label;
                                if (pageName.Length == 0)
                                {
                                    pageName = "PAGE";
                                }

                                Output.WriteLine("<td colspan=\"6\" ><span style=\"color: White\"><b>" + pageName.ToUpper() + "</b></span></td>");
                                Output.WriteLine("</tr>");

                                // Now, check for each file
                                foreach (BriefItem_File thisFile in thisNode.Files)
                                {
                                    string thisFileUpper = thisFile.Name.ToUpper();
                                    if (sortedFiles.ContainsKey(thisFileUpper))
                                    {
                                        // string file = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + currentItem.Web.AssocFilePath + thisFile.System_Name;
                                        Add_File_HTML(sortedFiles[thisFileUpper], Output, url, true);
                                        sortedFiles.Remove(thisFileUpper);
                                    }
                                }

                                // Ensure that there still aren't some page files that exist that were not linked
                                string[] other_page_file_endings = { ".JPG", ".JP2", "THM.JPG", ".TXT", ".PRO", ".QC.JPG" };
                                foreach (string thisFileEnder in other_page_file_endings)
                                {
                                    if (sortedFiles.ContainsKey(fileName.ToUpper() + thisFileEnder))
                                    {
                                        //string file = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + currentItem.Web.AssocFilePath + fileName + thisFileEnder.ToLower();
                                        Add_File_HTML(sortedFiles[fileName.ToUpper() + thisFileEnder], Output, url, true);
                                        sortedFiles.Remove(fileName.ToUpper() + thisFileEnder);
                                    }
                                }
                            }
                        }
                    }

                    // FInish the table
                    Output.WriteLine("</table>");
                    Output.WriteLine("<br /><br />");
                }

                // Add all the metadata files
                Output.WriteLine("<span style=\"font-size:1.4em; color:#888888;\"><b>METADATA FILES</b></span><br />");
                Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">");
                Output.WriteLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >");
                Output.WriteLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>");
                Output.WriteLine("<th width=\"10px\">&nbsp;</th>");
                Output.WriteLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>");
                Output.WriteLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>");
                Output.WriteLine("<th width=\"10px\">&nbsp;</th>");
                Output.WriteLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>");
                Output.WriteLine("</tr>");

                // Add each metadata file
                List <string> files_handled = new List <string>();
                foreach (string thisFile in sortedFiles.Keys.Where(ThisFile => (ThisFile.IndexOf(".METS.BAK") > 0) || (ThisFile.IndexOf(".METS.XML") > 0) || (ThisFile == "DOC.XML") || (ThisFile == "MARC.XML") || (ThisFile == "CITATION_METS.XML") || (ThisFile == BriefItem.BibID.ToUpper() + "_" + BriefItem.VID + ".HTML")))
                {
                    files_handled.Add(thisFile);
                    Add_File_HTML(sortedFiles[thisFile], Output, url, true);
                }

                // REmove all handled files
                foreach (string thisKey in files_handled)
                {
                    sortedFiles.Remove(thisKey);
                }

                // FInish the table
                Output.WriteLine("</table>");
                Output.WriteLine("<br /><br />");

                // Finally, add all the remaining files
                if (sortedFiles.Count > 0)
                {
                    Output.WriteLine("<span style=\"font-size:1.4em; color:#888888;\"><b>OTHER FILES</b></span><br />");
                    Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">");
                    Output.WriteLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >");
                    Output.WriteLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>");
                    Output.WriteLine("<th width=\"10px\">&nbsp;</th>");
                    Output.WriteLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>");
                    Output.WriteLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>");
                    Output.WriteLine("<th width=\"10px\">&nbsp;</th>");
                    Output.WriteLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>");
                    Output.WriteLine("</tr>");

                    // Now add all the information
                    foreach (SobekFileSystem_FileInfo thisFile in sortedFiles.Values)
                    {
                        Add_File_HTML(thisFile, Output, url, true);
                    }

                    // FInish the table
                    Output.WriteLine("</table>");
                }
                Output.WriteLine("</blockquote>");
                Output.WriteLine("<br />");
            }
            catch
            {
                Output.WriteLine("<br /><center><strong>UNABLE TO PULL DIRECTORY INFORMATION</strong></center><br />");
            }

            Output.WriteLine("  </td>");
            Output.WriteLine("  <!-- END DIRECTORY VIEWER OUTPUT -->");
        }