/// <summary>Reads the item aggregation browse or info file and returns a built <see cref="Item_Aggregation_Child_Page"/> object for /// inclusion in the item aggregation </summary> /// <param name="FileName"> Filename of the browse or info file</param> /// <param name="Browse_Type"> Flag indicates if this is a browse or info file</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param> /// <returns> Built object containing all of the pertinent details about this info or browse </returns> private static Complete_Item_Aggregation_Child_Page Get_Item_Aggregation_Browse_Info(string FileName, Item_Aggregation_Child_Visibility_Enum Browse_Type, Custom_Tracer Tracer) { HTML_Based_Content fileContent = HTML_Based_Content_Reader.Read_HTML_File(FileName, false, Tracer); Complete_Item_Aggregation_Child_Page returnObject = new Complete_Item_Aggregation_Child_Page(Browse_Type, Item_Aggregation_Child_Source_Data_Enum.Static_HTML, fileContent.Code, FileName, fileContent.Title ?? "Missing Title"); return returnObject; }
private static void read_browse(bool Browse, XmlNodeReader NodeReader, Complete_Item_Aggregation HierarchyObject) { // Create a new browse/info object Complete_Item_Aggregation_Child_Page newBrowse = new Complete_Item_Aggregation_Child_Page { Browse_Type = Item_Aggregation_Child_Visibility_Enum.Main_Menu, Source_Data_Type = Item_Aggregation_Child_Source_Data_Enum.Static_HTML }; bool isDefault = false; // Determine which XML node name to look for and set browse v. info string lastName = "HI:BROWSE"; if (!Browse) { lastName = "HI:INFO"; newBrowse.Browse_Type = Item_Aggregation_Child_Visibility_Enum.None; } // Check for the attributes if (NodeReader.HasAttributes) { if (NodeReader.MoveToAttribute("location")) { if (NodeReader.Value == "BROWSEBY") newBrowse.Browse_Type = Item_Aggregation_Child_Visibility_Enum.Metadata_Browse_By; } if (NodeReader.MoveToAttribute("default")) { if (NodeReader.Value == "DEFAULT") isDefault = true; } if (NodeReader.MoveToAttribute("visibility")) { switch (NodeReader.Value) { case "NONE": newBrowse.Browse_Type = Item_Aggregation_Child_Visibility_Enum.None; break; case "MAIN_MENU": newBrowse.Browse_Type = Item_Aggregation_Child_Visibility_Enum.Main_Menu; break; case "BROWSEBY": newBrowse.Browse_Type = Item_Aggregation_Child_Visibility_Enum.Metadata_Browse_By; break; } } if (NodeReader.MoveToAttribute("parent")) { newBrowse.Parent_Code = NodeReader.Value; } } // Step through the XML and build this browse/info object while (NodeReader.Read()) { // If this is the beginning tag for an element, assign the next values accordingly if (NodeReader.NodeType == XmlNodeType.Element) { // Get the node name, trimmed and to upper string nodeName = NodeReader.Name.Trim().ToUpper(); // switch the rest based on the tag name switch (nodeName) { case "HI:METADATA": NodeReader.Read(); newBrowse.Code = NodeReader.Value.ToLower(); newBrowse.Source_Data_Type = Item_Aggregation_Child_Source_Data_Enum.Database_Table; break; case "HI:CODE": NodeReader.Read(); newBrowse.Code = NodeReader.Value.ToLower(); break; case "HI:TITLE": // Look for a language attached to this title string titleLanguage = String.Empty; if ((NodeReader.HasAttributes) && ( NodeReader.MoveToAttribute("lang"))) { titleLanguage = NodeReader.GetAttribute("lang"); } // read and save the title NodeReader.Read(); newBrowse.Add_Label( NodeReader.Value, Web_Language_Enum_Converter.Code_To_Enum(titleLanguage)); break; case "HI:BODY": // Look for a language attached to this title string bodyLanguage = String.Empty; if ((NodeReader.HasAttributes) && (NodeReader.MoveToAttribute("lang"))) { bodyLanguage = NodeReader.GetAttribute("lang"); } // read and save the title NodeReader.Read(); string bodySource = NodeReader.Value; newBrowse.Add_Static_HTML_Source(bodySource, Web_Language_Enum_Converter.Code_To_Enum(bodyLanguage)); break; } } if (NodeReader.NodeType == XmlNodeType.EndElement) { if (NodeReader.Name.Trim().ToUpper() == lastName ) { // Don't add ALL or NEW here if ((String.Compare(newBrowse.Code, "all", StringComparison.InvariantCultureIgnoreCase) != 0) && (String.Compare(newBrowse.Code, "new", StringComparison.InvariantCultureIgnoreCase) != 0)) { HierarchyObject.Add_Child_Page(newBrowse); //HierarchyObject.Add // If this set the default browse by save that information if ((newBrowse.Browse_Type == Item_Aggregation_Child_Visibility_Enum.Metadata_Browse_By) && (isDefault)) { HierarchyObject.Default_BrowseBy = newBrowse.Code; } } return; } } } }
private void Save_Page_7_Postback(NameValueCollection Form) { string action = Form["admin_aggr_action"]; if (!String.IsNullOrEmpty(action)) { if ((action.IndexOf("delete_") == 0) && ( action.Length > 7 )) { string code_to_delete = action.Substring(7); itemAggregation.Remove_Child_Page(code_to_delete); // Save to the admins session HttpContext.Current.Session["Edit_Aggregation_" + itemAggregation.Code] = itemAggregation; } if (action == "save_childpage") { childPageCode = Form["admin_aggr_code"]; childPageLabel = Form["admin_aggr_label"]; childPageVisibility = Form["admin_aggr_visibility"]; childPageParent = Form["admin_aggr_parent"]; // Convert to the integer id for the parent and begin to do checking List<string> errors = new List<string>(); // Validate the code if (childPageCode.Length > 20) { errors.Add("New child page code must be twenty characters long or less"); } else if (childPageCode.Length == 0) { errors.Add("You must enter a CODE for this child page"); } else if (UI_ApplicationCache_Gateway.Settings.Static.Reserved_Keywords.Contains(childPageCode.ToLower())) { errors.Add("That code is a system-reserved keyword. Try a different code."); } else if (itemAggregation.Child_Page_By_Code(childPageCode.ToUpper()) != null) { errors.Add("New code must be unique... <i>" + childPageCode + "</i> already exists"); } if (childPageLabel.Trim().Length == 0) errors.Add("You must enter a LABEL for this child page"); if (childPageVisibility.Trim().Length == 0) errors.Add("You must select a VISIBILITY for this child page"); if (errors.Count > 0) { // Create the error message actionMessage = "ERROR: Invalid entry for new item child page<br />"; foreach (string error in errors) actionMessage = actionMessage + "<br />" + error; } else { Complete_Item_Aggregation_Child_Page newPage = new Complete_Item_Aggregation_Child_Page { Code = childPageCode, Parent_Code = childPageParent, Source_Data_Type = Item_Aggregation_Child_Source_Data_Enum.Static_HTML }; newPage.Add_Label(childPageLabel, UI_ApplicationCache_Gateway.Settings.System.Default_UI_Language); switch (childPageVisibility) { case "none": newPage.Browse_Type = Item_Aggregation_Child_Visibility_Enum.None; newPage.Parent_Code = String.Empty; break; case "browse": newPage.Browse_Type = Item_Aggregation_Child_Visibility_Enum.Main_Menu; break; case "browseby": newPage.Browse_Type = Item_Aggregation_Child_Visibility_Enum.Metadata_Browse_By; newPage.Parent_Code = String.Empty; break; } string html_source_dir = aggregationDirectory + "\\html\\browse"; if (!Directory.Exists(html_source_dir)) Directory.CreateDirectory(html_source_dir); string html_source_file = html_source_dir + "\\" + childPageCode + "_" + Web_Language_Enum_Converter.Enum_To_Code(UI_ApplicationCache_Gateway.Settings.System.Default_UI_Language) + ".html"; if (!File.Exists(html_source_file)) { HTML_Based_Content htmlContent = new HTML_Based_Content { Content = "<br /><br />This is a new browse page.<br /><br />" + childPageLabel + "<br /><br />The code for this browse is: " + childPageCode, Author = RequestSpecificValues.Current_User.Full_Name, Date = DateTime.Now.ToLongDateString(), Title = childPageLabel }; htmlContent.Save_To_File(html_source_file); } newPage.Add_Static_HTML_Source("html\\browse\\" + childPageCode + "_" + Web_Language_Enum_Converter.Enum_To_Code(UI_ApplicationCache_Gateway.Settings.System.Default_UI_Language) + ".html", UI_ApplicationCache_Gateway.Settings.System.Default_UI_Language); itemAggregation.Add_Child_Page(newPage); // Save to the admins session HttpContext.Current.Session["Edit_Aggregation_" + itemAggregation.Code] = itemAggregation; } } } }
private void Save_Page_4_Postback(NameValueCollection Form) { // Get the metadata browses List<Complete_Item_Aggregation_Child_Page> metadata_browse_bys = itemAggregation.Browse_By_Pages(UI_ApplicationCache_Gateway.Settings.System.Default_UI_Language).Where(ThisBrowse => ThisBrowse.Browse_Type == Item_Aggregation_Child_Visibility_Enum.Metadata_Browse_By).Where(ThisBrowse => ThisBrowse.Source_Data_Type == Item_Aggregation_Child_Source_Data_Enum.Database_Table).ToList(); // Remove all these browse by's foreach (Complete_Item_Aggregation_Child_Page browseBy in metadata_browse_bys) { itemAggregation.Remove_Child_Page(browseBy); } // Look for the default browse by short default_browseby_id = 0; itemAggregation.Default_BrowseBy = null; if (Form["admin_aggr_default_browseby"] != null) { string default_browseby = Form["admin_aggr_default_browseby"]; if (Int16.TryParse(default_browseby, out default_browseby_id)) { if (default_browseby_id > 0) { Metadata_Search_Field field = UI_ApplicationCache_Gateway.Settings.Metadata_Search_Field_By_ID(default_browseby_id); if (field != null) { Complete_Item_Aggregation_Child_Page newBrowse = new Complete_Item_Aggregation_Child_Page(Item_Aggregation_Child_Visibility_Enum.Metadata_Browse_By, Item_Aggregation_Child_Source_Data_Enum.Database_Table, field.Display_Term, String.Empty, field.Display_Term); itemAggregation.Add_Child_Page(newBrowse); itemAggregation.Default_BrowseBy = field.Display_Term; } } } else { itemAggregation.Default_BrowseBy = default_browseby; } } // Now, get all the new browse bys for (int i = 0; i < metadata_browse_bys.Count + 10; i++) { if (Form["admin_aggr_browseby_" + i] != null) { short browseby_id = Convert.ToInt16(Form["admin_aggr_browseby_" + i]); if ((browseby_id > 0) && (default_browseby_id != browseby_id)) { Metadata_Search_Field field = UI_ApplicationCache_Gateway.Settings.Metadata_Search_Field_By_ID(browseby_id); if (field != null) { Complete_Item_Aggregation_Child_Page newBrowse = new Complete_Item_Aggregation_Child_Page(Item_Aggregation_Child_Visibility_Enum.Metadata_Browse_By, Item_Aggregation_Child_Source_Data_Enum.Database_Table, field.Display_Term, String.Empty, field.Display_Term); itemAggregation.Add_Child_Page(newBrowse); } } } } itemAggregation.OAI_Enabled = Form["admin_aggr_oai_flag"] != null; if (Form["admin_aggr_oai_metadata"] != null) itemAggregation.OAI_Metadata = Form["admin_aggr_oai_metadata"]; }
/// <summary> Add a new browse or info object to this hierarchical object </summary> /// <param name = "Browse_Type">Flag indicates if this is a BROWSE or INFO object</param> /// <param name = "Browse_Code">SubMode indicator for this object</param> /// <param name = "StaticHtmlSource">Any static HTML source to be used for display</param> /// <param name = "Text">Text to display for this browse</param> /// <returns>The built data object</returns> public Complete_Item_Aggregation_Child_Page Add_Child_Page(Item_Aggregation_Child_Visibility_Enum Browse_Type, string Browse_Code, string StaticHtmlSource, string Text) { // Create the new Browse_Info object Complete_Item_Aggregation_Child_Page childPage = new Complete_Item_Aggregation_Child_Page(Browse_Type, Item_Aggregation_Child_Source_Data_Enum.Database_Table, Browse_Code, StaticHtmlSource, Text); if (Child_Pages == null) Child_Pages = new List<Complete_Item_Aggregation_Child_Page>(); // Add this to the Hash table Child_Pages.Add(childPage); childPagesHash[Browse_Code.ToUpper()] = childPage; return childPage; }
/// <summary> Add a child page to this item aggregatiion </summary> /// <param name="ChildPage"> New child page to add </param> public void Add_Child_Page(Complete_Item_Aggregation_Child_Page ChildPage) { if (Child_Pages == null) Child_Pages = new List<Complete_Item_Aggregation_Child_Page>(); string upper_code = ChildPage.Code.ToUpper(); if (childPagesHash.ContainsKey(upper_code)) { childPagesHash.Remove(upper_code); Child_Pages.RemoveAll(CurrentPage => CurrentPage.Code.ToUpper() == upper_code); } Child_Pages.Add(ChildPage); childPagesHash[upper_code] = ChildPage; }
/// <summary> Remove an existing browse or info object from this item aggregation </summary> /// <param name="Browse_Page"> Child page information to remove </param> public void Remove_Child_Page( Complete_Item_Aggregation_Child_Page Browse_Page ) { if (childPagesHash.ContainsKey(Browse_Page.Code.ToUpper())) { childPagesHash.Remove(Browse_Page.Code.ToUpper()); } Child_Pages.Remove(Browse_Page); }