/// <summary> Map one or more data elements from the original METS-based object to the /// BriefItem object </summary> /// <param name="Original"> Original METS-based object </param> /// <param name="New"> New object to populate some data from the original </param> /// <returns> TRUE if successful, FALSE if an exception is encountered </returns> public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New) { // Add the aggregations if ((Original.Behaviors.Aggregation_Count > 0) && (Engine_ApplicationCache_Gateway.Codes != null)) { foreach (Aggregation_Info thisAggr in Original.Behaviors.Aggregations) { // Look for the aggregation in the current aggregation codes Item_Aggregation_Related_Aggregations aggrObj = Engine_ApplicationCache_Gateway.Codes[thisAggr.Code]; // If the aggregation is NULL, as it may have been deleted, skip it if (aggrObj == null) { continue; } // If active, add with the URL, otherwise just add the short name if (aggrObj.Active) { New.Add_Description("Aggregations", aggrObj.ShortName).Add_URI("[%BASEURL%]" + aggrObj.Code + "[%URLOPTS%]"); } else { New.Add_Description("Aggregations", aggrObj.ShortName); } } } return(true); }
/// <summary> Map one or more data elements from the original METS-based object to the /// BriefItem object </summary> /// <param name="Original"> Original METS-based object </param> /// <param name="New"> New object to populate some data from the original </param> /// <returns> TRUE if successful, FALSE if an exception is encountered </returns> public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New) { // Add the HOLDING LOCATION information if ((Original.Bib_Info.hasLocationInformation) && (!String.IsNullOrWhiteSpace(Original.Bib_Info.Location.Holding_Name))) { // Add the source institution BriefItem_DescTermValue sourceValue = New.Add_Description("Holding Location", Original.Bib_Info.Location.Holding_Name); // Was the code present, and active? if (!String.IsNullOrWhiteSpace(Original.Bib_Info.Location.Holding_Code)) { if ((Engine_ApplicationCache_Gateway.Codes != null) && (Engine_ApplicationCache_Gateway.Codes.isValidCode("i" + Original.Bib_Info.Location.Holding_Code))) { Item_Aggregation_Related_Aggregations sourceAggr = Engine_ApplicationCache_Gateway.Codes["i" + Original.Bib_Info.Location.Holding_Code]; if (sourceAggr.Active) { sourceValue.Add_URI("[%BASEURL%]" + "i" + Original.Bib_Info.Location.Holding_Code + "[%URLOPTS%]"); } // Was there an external link on this agggreation? if (!String.IsNullOrWhiteSpace(sourceAggr.External_Link)) { sourceValue.Add_URI(sourceAggr.External_Link); } } } } return(true); }
internal void Add_Collection(Item_Aggregation_Related_Aggregations New_Aggregation, int Theme) { // Add this to the various collections aggregationsByCode[New_Aggregation.Code] = New_Aggregation; allAggregations.Add(New_Aggregation); if (!allTypes.Contains(New_Aggregation.Type)) { allTypes.Add(New_Aggregation.Type); } if (aggregationsByType.ContainsKey(New_Aggregation.Type)) { aggregationsByType[New_Aggregation.Type].Add(New_Aggregation); } else { aggregationsByType[New_Aggregation.Type] = new List <Item_Aggregation_Related_Aggregations> { New_Aggregation }; } if (Theme > 0) { if (aggregationsByThematicheading.ContainsKey(Theme)) { aggregationsByThematicheading[Theme].Add(New_Aggregation); } else { aggregationsByThematicheading[Theme] = new List <Item_Aggregation_Related_Aggregations> { New_Aggregation }; } } }
/// <summary> Wites a section of citation from a provided digital resource </summary> /// <param name="ElementInfo"> Additional possible data about this citation element </param> /// <param name="Output"> Response stream for the item viewer to write directly to </param> /// <param name="Item"> Digital resource with all the data to write </param> /// <param name="LeftColumnWidth"> Number of pixels of the left column, or the definition terms </param> /// <param name="SearchLink"> Beginning of the search link that can be used to allow the web patron to select a term and run a search against this instance </param> /// <param name="SearchLinkEnd"> End of the search link that can be used to allow the web patron to select a term and run a search against this instance </param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> public void Write_Citation_Section(CitationElement ElementInfo, StringBuilder Output, BriefItemInfo Item, int LeftColumnWidth, string SearchLink, string SearchLinkEnd, Custom_Tracer Tracer, Navigation_Object CurrentRequest) { string displayLabel = "Aggregations"; Output.AppendLine(" <dt class=\"sbk_CivAGGGR_Element\" style=\"width:" + LeftColumnWidth + "px;\" >" + displayLabel + ": </dt>"); Output.Append(" <dd class=\"sbk_CivAGGR_Element\" style=\"margin-left:" + LeftColumnWidth + "px;\" >"); bool first = true; foreach (string code in Item.Behaviors.Aggregation_Code_List) { // Get the aggregation by code Item_Aggregation_Related_Aggregations aggr = UI_ApplicationCache_Gateway.Aggregations[code]; // If it found the aggr stuff if (aggr != null) { // Go to a new line if not the first if (first) { first = false; } else { Output.AppendLine("<br />"); } // Write this Output.AppendLine("<a href=\"" + CurrentRequest.Base_URL + code + "\">" + HttpUtility.HtmlEncode(aggr.Name) + "</a>"); } } Output.AppendLine("</dd>"); Output.AppendLine(); }
/// <summary> Set an aggregation to be a part of an existing thematic heading id </summary> /// <param name="Code"></param> /// <param name="ThematicHeadingID"></param> public void Set_Aggregation_Thematic_Heading(string Code, int?ThematicHeadingID) { Item_Aggregation_Related_Aggregations thisAggr = aggregationsByCode[Code.ToUpper()]; // If this is NULL, just return if ((!ThematicHeadingID.HasValue) || (ThematicHeadingID.Value < 0)) { foreach (KeyValuePair <int, List <Item_Aggregation_Related_Aggregations> > theme in Aggregations_By_Thematic_Heading) { if (theme.Value.Contains(thisAggr)) { theme.Value.Remove(thisAggr); } } return; } // If the thematic heading ID does not exit, just return if (!Aggregations_By_Thematic_Heading.ContainsKey(ThematicHeadingID.Value)) { return; } // If this aggregation does not exist, just return if (!aggregationsByCode.ContainsKey(Code.ToUpper())) { return; } // Get this aggregation and list for this thematic heading List <Item_Aggregation_Related_Aggregations> thematicHeadingList = Aggregations_By_Thematic_Heading[ThematicHeadingID.Value]; // If this is already a part of the thematic heading, just return if (thematicHeadingList.Contains(thisAggr)) { return; } // Ensure this aggregation is not a part of any other thematic headings foreach (KeyValuePair <int, List <Item_Aggregation_Related_Aggregations> > theme in Aggregations_By_Thematic_Heading) { if (theme.Value.Contains(thisAggr)) { theme.Value.Remove(thisAggr); } } // Now, add this to the list for this thematic heading int index = 0; while ((index < thematicHeadingList.Count) && (string.CompareOrdinal(thisAggr.Code, thematicHeadingList[index].Code) > 0)) { index++; } thematicHeadingList.Insert(index, thisAggr); }
/// <summary> Add the basic information about an aggregation to this aggreation manager </summary> /// <param name="New_Aggregation"> New aggregation to add information about </param> public void Add_Collection(Item_Aggregation_Related_Aggregations New_Aggregation) { // Insert this into the proper spot in the item aggregation list int index = 0; while ((index < All_Aggregations.Count) && (string.CompareOrdinal(New_Aggregation.Code, All_Aggregations[index].Code) > 0)) { index++; } All_Aggregations.Insert(index, New_Aggregation); // Add this to the various dictionaries aggregationsByCode[New_Aggregation.Code] = New_Aggregation; if (!allTypes.Contains(New_Aggregation.Type)) { allTypes.Add(New_Aggregation.Type); } if (aggregationsByType.ContainsKey(New_Aggregation.Type)) { aggregationsByType[New_Aggregation.Type].Add(New_Aggregation); } else { aggregationsByType[New_Aggregation.Type] = new List <Item_Aggregation_Related_Aggregations> { New_Aggregation }; } if ((New_Aggregation.Thematic_Heading != null) && (New_Aggregation.Thematic_Heading.ID > 0)) { if (Aggregations_By_Thematic_Heading.ContainsKey(New_Aggregation.Thematic_Heading.ID)) { Aggregations_By_Thematic_Heading[New_Aggregation.Thematic_Heading.ID].Add(New_Aggregation); } else { Aggregations_By_Thematic_Heading[New_Aggregation.Thematic_Heading.ID] = new List <Item_Aggregation_Related_Aggregations> { New_Aggregation }; } } }
internal void Add_Collection(Item_Aggregation_Related_Aggregations New_Aggregation, int Theme) { // Insert this into the proper spot in the item aggregation list int index = 0; while ((index < allAggregations.Count) && (string.CompareOrdinal(New_Aggregation.Code, All_Aggregations[index].Code) > 0)) { index++; } allAggregations.Insert(index, New_Aggregation); // Add this to the various dictionaries aggregationsByCode[New_Aggregation.Code] = New_Aggregation; if (!allTypes.Contains(New_Aggregation.Type)) { allTypes.Add(New_Aggregation.Type); } if (aggregationsByType.ContainsKey(New_Aggregation.Type)) { aggregationsByType[New_Aggregation.Type].Add(New_Aggregation); } else { aggregationsByType[New_Aggregation.Type] = new List <Item_Aggregation_Related_Aggregations> { New_Aggregation }; } if (Theme > 0) { if (aggregationsByThematicheading.ContainsKey(Theme)) { aggregationsByThematicheading[Theme].Add(New_Aggregation); } else { aggregationsByThematicheading[Theme] = new List <Item_Aggregation_Related_Aggregations> { New_Aggregation }; } } }
/// <summary> Adds the child information to the item aggregation object from the datatable extracted from the database </summary> /// <param name="AggrList"> List into which to populate the hierarchy </param> /// <param name="ChildInfo"> Datatable from database calls with child item aggregation information </param> private static void add_hierarchy_children(List <Item_Aggregation_Related_Aggregations> AggrList, DataTable ChildInfo) { if (ChildInfo.Rows.Count == 0) { return; } // Build a dictionary of nodes while building this tree Dictionary <string, Item_Aggregation_Related_Aggregations> nodes = new Dictionary <string, Item_Aggregation_Related_Aggregations>(ChildInfo.Rows.Count); // Step through each row of children foreach (DataRow thisRow in ChildInfo.Rows) { // pull some of the basic data out int hierarchyLevel = Convert.ToInt16(thisRow[5]); string code = thisRow[0].ToString().ToLower(); string parentCode = thisRow[1].ToString().ToLower(); // If this does not already exist, create it if (!nodes.ContainsKey(code)) { // Create the object Item_Aggregation_Related_Aggregations childObject = new Item_Aggregation_Related_Aggregations(code, thisRow[2].ToString(), thisRow[4].ToString(), Convert.ToBoolean(thisRow[6]), Convert.ToBoolean(thisRow[7])); // Add this object to the node dictionary nodes.Add(code, childObject); // Check for parent in the node list if ((parentCode.Length > 0) && (nodes.ContainsKey(parentCode))) { nodes[parentCode].Add_Child_Aggregation(childObject); } // If this is the first hierarchy, add to the main item aggregation object if (hierarchyLevel == -1) { AggrList.Add(childObject); } } } }
/// <summary> [PUBLIC] Get the list of uploaded images for a particular aggregation </summary> /// <param name="Response"></param> /// <param name="UrlSegments"></param> /// <param name="QueryString"></param> /// <param name="Protocol"></param> /// <param name="IsDebug"></param> /// <remarks> This REST API should be publicly available for users that are performing administrative work </remarks> public void GetAggregationUploadedImages(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { if (UrlSegments.Count > 0) { string aggregation = UrlSegments[0]; // Ensure a valid aggregation Item_Aggregation_Related_Aggregations aggrInfo = Engine_ApplicationCache_Gateway.Codes[aggregation]; if (aggrInfo != null) { List <UploadedFileFolderInfo> serverFiles = new List <UploadedFileFolderInfo>(); string design_folder = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + "aggregations\\" + aggregation + "\\uploads"; if (Directory.Exists(design_folder)) { string foldername = aggrInfo.ShortName; if (String.IsNullOrEmpty(foldername)) { foldername = aggregation; } string[] files = SobekCM_File_Utilities.GetFiles(design_folder, "*.jpg|*.bmp|*.gif|*.png"); foreach (string thisFile in files) { string filename = Path.GetFileName(thisFile); string extension = Path.GetExtension(thisFile); // Exclude some files if ((!String.IsNullOrEmpty(extension)) && (extension.ToLower().IndexOf(".db") < 0) && (extension.ToLower().IndexOf("bridge") < 0) && (extension.ToLower().IndexOf("cache") < 0)) { string url = Engine_ApplicationCache_Gateway.Settings.Servers.System_Base_URL + "design/aggregations/" + aggregation + "/uploads/" + filename; serverFiles.Add(new UploadedFileFolderInfo(url, foldername)); } } } JSON.Serialize(serverFiles, Response.Output, Options.ISO8601ExcludeNulls); } } }
internal void Add_Collection(Item_Aggregation_Related_Aggregations New_Aggregation, int Theme) { // Add this to the various collections aggregationsByCode[New_Aggregation.Code] = New_Aggregation; allAggregations.Add(New_Aggregation); if (!allTypes.Contains(New_Aggregation.Type)) { allTypes.Add(New_Aggregation.Type); } if (aggregationsByType.ContainsKey(New_Aggregation.Type)) { aggregationsByType[New_Aggregation.Type].Add(New_Aggregation); } else { aggregationsByType[New_Aggregation.Type] = new List<Item_Aggregation_Related_Aggregations> {New_Aggregation}; } if (Theme > 0) { if (aggregationsByThematicheading.ContainsKey(Theme)) { aggregationsByThematicheading[Theme].Add(New_Aggregation); } else { aggregationsByThematicheading[Theme] = new List<Item_Aggregation_Related_Aggregations> {New_Aggregation}; } } }
private void add_children_to_tree(Item_Aggregation_Related_Aggregations Aggr, TreeNode Node) { // Step through each node under this SortedList<string, TreeNode> sorted_node_list = new SortedList<string, TreeNode>(); foreach (Item_Aggregation_Related_Aggregations childAggr in Aggr.Children) { if ((!childAggr.Hidden) && ( childAggr.Active )) { // Set the aggregation value, for the redirect URL currentMode.Aggregation = childAggr.Code.ToLower(); // Create this tree node TreeNode childNode = new TreeNode("<a href=\"" + currentMode.Redirect_URL() + "\"><abbr title=\"" + childAggr.Description + "\">" + childAggr.Name + "</abbr></a>"); if (currentMode.Internal_User) { childNode.Text = string.Format("<a href=\"{0}\"><abbr title=\"{1}\">{2} ( {3} )</abbr></a>", currentMode.Redirect_URL(), childAggr.Description, childAggr.Name, childAggr.Code); } childNode.SelectAction = TreeNodeSelectAction.None; childNode.NavigateUrl = currentMode.Redirect_URL(); // Add to the sorted list if ((childAggr.Name.Length > 4) && (childAggr.Name.IndexOf("The ") == 0)) sorted_node_list.Add(childAggr.Name.Substring(4).ToUpper(), childNode); else sorted_node_list.Add(childAggr.Name.ToUpper(), childNode); // Check the children nodes recursively add_children_to_tree(childAggr, childNode); } } // Now add the sorted nodes to the tree foreach (TreeNode childNode in sorted_node_list.Values) { Node.ChildNodes.Add(childNode); } }
/// <summary> Adds the child information to the item aggregation object from the datatable extracted from the database </summary> /// <param name="AggrList"> List into which to populate the hierarchy </param> /// <param name="ChildInfo"> Datatable from database calls with child item aggregation information </param> private static void add_hierarchy_children(List<Item_Aggregation_Related_Aggregations> AggrList, DataTable ChildInfo) { if (ChildInfo.Rows.Count == 0) return; // Build a dictionary of nodes while building this tree Dictionary<string, Item_Aggregation_Related_Aggregations> nodes = new Dictionary<string, Item_Aggregation_Related_Aggregations>(ChildInfo.Rows.Count); // Step through each row of children foreach (DataRow thisRow in ChildInfo.Rows) { // pull some of the basic data out int hierarchyLevel = Convert.ToInt16(thisRow[5]); string code = thisRow[0].ToString().ToLower(); string parentCode = thisRow[1].ToString().ToLower(); // If this does not already exist, create it if (!nodes.ContainsKey(code)) { // Create the object Item_Aggregation_Related_Aggregations childObject = new Item_Aggregation_Related_Aggregations(code, thisRow[2].ToString(), thisRow[4].ToString(), Convert.ToBoolean(thisRow[6]), Convert.ToBoolean(thisRow[7])); // Add this object to the node dictionary nodes.Add(code, childObject); // Check for parent in the node list if ((parentCode.Length > 0) && (nodes.ContainsKey(parentCode))) { nodes[parentCode].Add_Child_Aggregation(childObject); } // If this is the first hierarchy, add to the main item aggregation object if (hierarchyLevel == -1) { AggrList.Add(childObject); } } } }
private void add_children_to_tree(string LeadingSpaces, TextWriter Output, Item_Aggregation_Related_Aggregations Aggr ) { // Step through each node under this if (Aggr.Children_Count > 0) { Output.WriteLine(LeadingSpaces + "<ul>"); foreach (Item_Aggregation_Related_Aggregations childAggr in Aggr.Children) { if ((!childAggr.Hidden) && (childAggr.Active)) { // Set the aggregation value, for the redirect URL RequestSpecificValues.Current_Mode.Aggregation = childAggr.Code.ToLower(); if (childAggr.Children_Count > 0) { Output.WriteLine(LeadingSpaces + " <li><a href=\"" + UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode) + "\"><abbr title=\"" + childAggr.Description + "\">" + childAggr.Name + "</abbr></a>"); // Check the children nodes recursively add_children_to_tree(LeadingSpaces + " ", Output, childAggr); Output.WriteLine(LeadingSpaces + " </li>"); } else { Output.WriteLine(LeadingSpaces + " <li><a href=\"" + UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode) + "\"><abbr title=\"" + childAggr.Description + "\">" + childAggr.Name + "</abbr></a></li>"); } } } Output.WriteLine(LeadingSpaces + "</ul>"); } }
internal void Add_Collection(Item_Aggregation_Related_Aggregations New_Aggregation, int Theme) { // Insert this into the proper spot in the item aggregation list int index = 0; while ((index < allAggregations.Count) && ( string.CompareOrdinal(New_Aggregation.Code, All_Aggregations[index].Code) > 0 )) { index++; } allAggregations.Insert(index, New_Aggregation); // Add this to the various dictionaries aggregationsByCode[New_Aggregation.Code] = New_Aggregation; if (!allTypes.Contains(New_Aggregation.Type)) { allTypes.Add(New_Aggregation.Type); } if (aggregationsByType.ContainsKey(New_Aggregation.Type)) { aggregationsByType[New_Aggregation.Type].Add(New_Aggregation); } else { aggregationsByType[New_Aggregation.Type] = new List<Item_Aggregation_Related_Aggregations> {New_Aggregation}; } if (Theme > 0) { if (aggregationsByThematicheading.ContainsKey(Theme)) { aggregationsByThematicheading[Theme].Add(New_Aggregation); } else { aggregationsByThematicheading[Theme] = new List<Item_Aggregation_Related_Aggregations> {New_Aggregation}; } } }
/// <summary> Map one or more data elements from the original METS-based object to the /// BriefItem object </summary> /// <param name="Original"> Original METS-based object </param> /// <param name="New"> New object to populate some data from the original </param> /// <returns> TRUE if successful, FALSE if an exception is encountered </returns> public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New) { // Ensure the behaviors object exists if (New.Behaviors == null) { New.Behaviors = new BriefItem_Behaviors(); } // Copy aggregation codes over if (Original.Behaviors.Aggregation_Code_List != null) { New.Behaviors.Aggregation_Code_List = Original.Behaviors.Aggregation_Code_List.ToList(); // Add the collections as well foreach (string aggrCode in Original.Behaviors.Aggregation_Code_List) { Item_Aggregation_Related_Aggregations thisAggr = Engine_ApplicationCache_Gateway.Codes[aggrCode]; if ((thisAggr != null) && (thisAggr.Active)) { New.Add_Description("Aggregation", thisAggr.Name).Add_URI(Engine_ApplicationCache_Gateway.Settings.Servers.Base_URL + thisAggr.Code); } } } // Copy over the source and holing New.Behaviors.Holding_Location_Aggregation = Original.Bib_Info.HoldingCode; if (Original.Bib_Info.Source != null) { New.Behaviors.Source_Institution_Aggregation = Original.Bib_Info.Source.Code; } // Copy the behavior information New.Behaviors.Dark_Flag = Original.Behaviors.Dark_Flag; New.Behaviors.Embedded_Video = Original.Behaviors.Embedded_Video; New.Behaviors.GroupTitle = Original.Behaviors.GroupTitle; New.Behaviors.GroupType = Original.Behaviors.GroupType; New.Behaviors.IP_Restriction_Membership = Original.Behaviors.IP_Restriction_Membership; New.Behaviors.Single_Use = Original.Behaviors.CheckOut_Required; New.Behaviors.Main_Thumbnail = Original.Behaviors.Main_Thumbnail; New.Behaviors.Full_Text_Searchable = Original.Behaviors.Text_Searchable; // Copy over the viewers foreach (View_Object origView in Original.Behaviors.Views) { New.Behaviors.Viewers.Add(new BriefItem_BehaviorViewer(origView.View_Type, origView.MenuOrder, origView.Exclude, origView.Label)); } // Copy over the wordmarks if (Original.Behaviors.Wordmark_Count > 0) { New.Behaviors.Wordmarks = new List <string>(); foreach (Wordmark_Info origWordmark in Original.Behaviors.Wordmarks) { New.Behaviors.Wordmarks.Add(origWordmark.Code); } } // Copy over the citation set, if it exists if (!String.IsNullOrEmpty(Original.Behaviors.CitationSet)) { New.Behaviors.CitationSet = Original.Behaviors.CitationSet; } // Copy over all the loose settings, if they exist if ((Original.Behaviors.Settings != null) && (Original.Behaviors.Settings.Count > 0)) { foreach (Tuple <string, string> setting in Original.Behaviors.Settings) { New.Behaviors.Add_Setting(setting.Item1, setting.Item2); } } return(true); }
/// <summary> Add the basic information about an aggregation to this aggreation manager </summary> /// <param name="New_Aggregation"> New aggregation to add information about </param> public void Add_Collection(Item_Aggregation_Related_Aggregations New_Aggregation) { // Insert this into the proper spot in the item aggregation list int index = 0; while ((index < All_Aggregations.Count) && ( string.CompareOrdinal(New_Aggregation.Code, All_Aggregations[index].Code) > 0 )) { index++; } All_Aggregations.Insert(index, New_Aggregation); // Add this to the various dictionaries aggregationsByCode[New_Aggregation.Code] = New_Aggregation; if (!allTypes.Contains(New_Aggregation.Type)) { allTypes.Add(New_Aggregation.Type); } if (aggregationsByType.ContainsKey(New_Aggregation.Type)) { aggregationsByType[New_Aggregation.Type].Add(New_Aggregation); } else { aggregationsByType[New_Aggregation.Type] = new List<Item_Aggregation_Related_Aggregations> {New_Aggregation}; } if (( New_Aggregation.Thematic_Heading != null ) && ( New_Aggregation.Thematic_Heading.ID > 0 )) { if (Aggregations_By_Thematic_Heading.ContainsKey(New_Aggregation.Thematic_Heading.ID)) { Aggregations_By_Thematic_Heading[New_Aggregation.Thematic_Heading.ID].Add(New_Aggregation); } else { Aggregations_By_Thematic_Heading[New_Aggregation.Thematic_Heading.ID] = new List<Item_Aggregation_Related_Aggregations> { New_Aggregation }; } } }
/// <summary> Add the header to the output </summary> /// <param name="Output"> Stream to which to write the HTML for this header </param> /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param> /// <param name="Container_CssClass"> Class name for the container around the page </param> /// <param name="Web_Page_Title"> Title for this web page, to include behind the banner possibly </param> /// <param name="Behaviors"> List of behaviors from the html subwriters </param> /// <param name="Current_Aggregation"> Current aggregation object, if there is one </param> /// <param name="Current_Item"> Current item object, if there is one </param> public static void Add_Header(TextWriter Output, RequestCache RequestSpecificValues, string Container_CssClass, string Web_Page_Title, List <HtmlSubwriter_Behaviors_Enum> Behaviors, Item_Aggregation Current_Aggregation, BriefItemInfo Current_Item) { // Get the url options string url_options = UrlWriterHelper.URL_Options(RequestSpecificValues.Current_Mode); string modified_url_options = String.Empty; if (url_options.Length > 0) { modified_url_options = "?" + url_options; } // Get the current contact URL Display_Mode_Enum thisMode = RequestSpecificValues.Current_Mode.Mode; RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Contact; string contact = UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode); // Restore the old mode RequestSpecificValues.Current_Mode.Mode = thisMode; // Determine which header and footer to display bool useItemHeader = (RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Item_Display) || (RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Item_Print) || ((Behaviors != null) && (Behaviors.Contains(HtmlSubwriter_Behaviors_Enum.MySobek_Subwriter_Mimic_Item_Subwriter))); // Create the breadcrumbs text string breadcrumbs = " "; if (useItemHeader) { StringBuilder breadcrumb_builder = new StringBuilder("<a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + modified_url_options + "\">" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Home</a>"); int codes_added = 0; if ((RequestSpecificValues.Current_Mode.Aggregation.Length > 0) && (RequestSpecificValues.Current_Mode.Aggregation != "all")) { breadcrumb_builder.Append(" | <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + RequestSpecificValues.Current_Mode.Aggregation + modified_url_options + "\">" + UI_ApplicationCache_Gateway.Aggregations.Get_Collection_Short_Name(RequestSpecificValues.Current_Mode.Aggregation) + "</a>"); codes_added++; } if (Current_Item != null) { if ((Current_Item.Behaviors.Aggregation_Code_List != null) && (Current_Item.Behaviors.Aggregation_Code_List.Count > 0)) { foreach (string aggrCode in Current_Item.Behaviors.Aggregation_Code_List) { if (aggrCode.ToLower() != RequestSpecificValues.Current_Mode.Aggregation) { if ((String.Compare(aggrCode, Current_Item.Behaviors.Source_Institution_Aggregation, StringComparison.OrdinalIgnoreCase) != 0) && (String.Compare(aggrCode, "i" + Current_Item.Behaviors.Source_Institution_Aggregation, StringComparison.OrdinalIgnoreCase) != 0) && (String.Compare(aggrCode, Current_Item.Behaviors.Holding_Location_Aggregation, StringComparison.OrdinalIgnoreCase) != 0) && (String.Compare(aggrCode, "i" + Current_Item.Behaviors.Holding_Location_Aggregation, StringComparison.OrdinalIgnoreCase) != 0)) { Item_Aggregation_Related_Aggregations thisAggr = UI_ApplicationCache_Gateway.Aggregations[aggrCode]; if ((thisAggr != null) && (thisAggr.Active)) { breadcrumb_builder.Append(" | <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + aggrCode.ToLower() + modified_url_options + "\">" + thisAggr.ShortName + "</a>"); codes_added++; } } } if (codes_added == 5) { break; } } } if (codes_added < 5) { if (!String.IsNullOrEmpty(Current_Item.Behaviors.Source_Institution_Aggregation)) { // Add source code string source_code = Current_Item.Behaviors.Source_Institution_Aggregation; if ((source_code[0] != 'i') && (source_code[0] != 'I')) { source_code = "I" + source_code; } Item_Aggregation_Related_Aggregations thisSourceAggr = UI_ApplicationCache_Gateway.Aggregations[source_code]; if ((thisSourceAggr != null) && (!thisSourceAggr.Hidden) && (thisSourceAggr.Active)) { string source_name = thisSourceAggr.ShortName; if (source_name.ToUpper() != "ADDED AUTOMATICALLY") { breadcrumb_builder.Append(" | <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + source_code.ToLower() + modified_url_options + "\">" + source_name + "</a>"); } } // Add the holding code if ((!String.IsNullOrEmpty(Current_Item.Behaviors.Holding_Location_Aggregation)) && (String.Compare(Current_Item.Behaviors.Source_Institution_Aggregation, Current_Item.Behaviors.Source_Institution_Aggregation, StringComparison.OrdinalIgnoreCase) != 0)) { // Add holding code string holding_code = Current_Item.Behaviors.Holding_Location_Aggregation; if ((holding_code[0] != 'i') && (holding_code[0] != 'I')) { holding_code = "I" + holding_code; } Item_Aggregation_Related_Aggregations thisAggr = UI_ApplicationCache_Gateway.Aggregations[holding_code]; if ((thisAggr != null) && (!thisAggr.Hidden) && (thisAggr.Active)) { string holding_name = thisAggr.ShortName; if (holding_name.ToUpper() != "ADDED AUTOMATICALLY") { breadcrumb_builder.Append(" | <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + holding_code.ToLower() + modified_url_options + "\">" + holding_name + "</a>"); } } } } else { if (!String.IsNullOrEmpty(Current_Item.Behaviors.Holding_Location_Aggregation)) { // Add holding code string holding_code = Current_Item.Behaviors.Holding_Location_Aggregation; if ((holding_code[0] != 'i') && (holding_code[0] != 'I')) { holding_code = "I" + holding_code; } string holding_name = UI_ApplicationCache_Gateway.Aggregations.Get_Collection_Short_Name(holding_code); if (holding_name.ToUpper() != "ADDED AUTOMATICALLY") { breadcrumb_builder.Append(" | <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + holding_code.ToLower() + modified_url_options + "\">" + holding_name + "</a>"); } } } } } breadcrumbs = breadcrumb_builder.ToString(); } else { switch (RequestSpecificValues.Current_Mode.Mode) { case Display_Mode_Enum.Error: breadcrumbs = "<a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + modified_url_options + "\">" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Home</a>"; break; case Display_Mode_Enum.Aggregation: if ((RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Home) || (RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Home_Edit)) { if ((RequestSpecificValues.Current_Mode.Aggregation.Length > 0) && (RequestSpecificValues.Current_Mode.Aggregation != "all")) { breadcrumbs = "<a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + modified_url_options + "\">" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Home</a>"; } } else { breadcrumbs = "<a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + modified_url_options + "\">" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Home</a>"; if ((RequestSpecificValues.Current_Mode.Aggregation.Length > 0) && (RequestSpecificValues.Current_Mode.Aggregation != "all")) { breadcrumbs = breadcrumbs + " | <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + RequestSpecificValues.Current_Mode.Aggregation + modified_url_options + "\">" + UI_ApplicationCache_Gateway.Aggregations.Get_Collection_Short_Name(RequestSpecificValues.Current_Mode.Aggregation) + "</a>"; } } break; default: breadcrumbs = "<a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + modified_url_options + "\">" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Home</a>"; if ((RequestSpecificValues.Current_Mode.Aggregation.Length > 0) && (RequestSpecificValues.Current_Mode.Aggregation != "all")) { breadcrumbs = breadcrumbs + " | <a href=\"" + RequestSpecificValues.Current_Mode.Base_URL + RequestSpecificValues.Current_Mode.Aggregation + modified_url_options + "\">" + UI_ApplicationCache_Gateway.Aggregations.Get_Collection_Short_Name(RequestSpecificValues.Current_Mode.Aggregation) + "</a>"; } break; } } // Create the mySobek text string mySobekLinks = create_mysobek_link(RequestSpecificValues, url_options, null); // Look for some basic mode data string collection_code = String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.Aggregation) ? String.Empty : RequestSpecificValues.Current_Mode.Aggregation; if (String.Compare(collection_code, "ALL", StringComparison.OrdinalIgnoreCase) == 0) { collection_code = String.Empty; } string bibid = String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID) ? String.Empty : RequestSpecificValues.Current_Mode.BibID; string vid = String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID) ? String.Empty : RequestSpecificValues.Current_Mode.BibID; string mode = String.Empty; switch (RequestSpecificValues.Current_Mode.Mode) { case Display_Mode_Enum.Item_Display: mode = "item"; break; case Display_Mode_Enum.Aggregation: case Display_Mode_Enum.Search: mode = "aggregation"; break; case Display_Mode_Enum.Results: mode = "results"; break; } // Get the language selections Web_Language_Enum language = RequestSpecificValues.Current_Mode.Language; RequestSpecificValues.Current_Mode.Language = Web_Language_Enum.TEMPLATE; string template_language = UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode); string english = template_language.Replace("l=XXXXX", "l=en"); string french = template_language.Replace("l=XXXXX", "l=fr"); string spanish = template_language.Replace("l=XXXXX", "l=es"); RequestSpecificValues.Current_Mode.Language = language; if (RequestSpecificValues.Current_Mode.Is_Robot) { english = String.Empty; french = String.Empty; spanish = String.Empty; } // Determine which container to use, depending on the current mode string container_inner = Container_CssClass; // Get the skin url string skin_url = RequestSpecificValues.Current_Mode.Base_Design_URL + "skins/" + RequestSpecificValues.Current_Mode.Skin + "/"; // Determine the URL options for replacement string urlOptions1 = String.Empty; string urlOptions2 = String.Empty; if (url_options.Length > 0) { urlOptions1 = "?" + url_options; urlOptions2 = "&" + url_options; } // Determine the possible banner to display string banner = String.Empty; if ((Behaviors != null) && (!Behaviors.Contains(HtmlSubwriter_Behaviors_Enum.Suppress_Banner))) { if ((RequestSpecificValues.HTML_Skin != null) && (RequestSpecificValues.HTML_Skin.Override_Banner.HasValue) && (RequestSpecificValues.HTML_Skin.Override_Banner.Value)) { banner = !String.IsNullOrEmpty(RequestSpecificValues.HTML_Skin.Banner_HTML) ? RequestSpecificValues.HTML_Skin.Banner_HTML : String.Empty; } else { if (Current_Aggregation != null) { string banner_image = Current_Aggregation.Get_Banner_Image(RequestSpecificValues.HTML_Skin); if (Current_Aggregation.Code != "all") { if (banner_image.Length > 0) { banner = "<section id=\"sbkHmw_BannerDiv\" role=\"banner\" title=\"" + Current_Aggregation.ShortName + "\"><h1 class=\"hidden-element\">" + Web_Page_Title + "</h1><a alt=\"" + Current_Aggregation.ShortName + "\" href=\"" + RequestSpecificValues.Current_Mode.Base_URL + Current_Aggregation.Code + urlOptions1 + "\"><img id=\"mainBanner\" src=\"" + RequestSpecificValues.Current_Mode.Base_URL + banner_image + "\" alt=\"" + Current_Aggregation.ShortName + "\" /></a></section>"; } } else { if (banner_image.Length > 0) { banner = "<section id=\"sbkHmw_BannerDiv\" role=\"banner\" title=\"" + Current_Aggregation.ShortName + "\"><h1 class=\"hidden-element\">" + Web_Page_Title + "</h1><a alt=\"" + Current_Aggregation.ShortName + "\" href=\"" + RequestSpecificValues.Current_Mode.Base_URL + urlOptions1 + "\"><img id=\"mainBanner\" src=\"" + RequestSpecificValues.Current_Mode.Base_URL + banner_image + "\" alt=\"" + Current_Aggregation.ShortName + "\" /></a></section>"; } else { banner = "<section id=\"sbkHmw_BannerDiv\" role=\"banner\" title=\"" + Current_Aggregation.ShortName + "\"><h1 class=\"hidden-element\">" + Web_Page_Title + "</h1><a alt=\"" + Current_Aggregation.ShortName + "\" href=\"" + RequestSpecificValues.Current_Mode.Base_URL + urlOptions1 + "\"><img id=\"mainBanner\" src=\"" + skin_url + "default.jpg\" alt=\"" + Current_Aggregation.ShortName + "\" /></a></section>"; } } } } } // Get the session id and user id string sessionId = HttpContext.Current.Session.SessionID ?? String.Empty; string userid = ((RequestSpecificValues.Current_User != null) && (RequestSpecificValues.Current_User.UserID > 0)) ? RequestSpecificValues.Current_User.UserID.ToString() : String.Empty; // Add the appropriate header StringBuilder headerBuilder = new StringBuilder(); try { if (useItemHeader) { headerBuilder.Append(RequestSpecificValues.HTML_Skin.Header_Item_HTML); } else { headerBuilder.Append(RequestSpecificValues.HTML_Skin.Header_HTML); if ((!String.IsNullOrEmpty(container_inner)) && ((!RequestSpecificValues.HTML_Skin.Header_Has_Container_Directive.HasValue) || (!RequestSpecificValues.HTML_Skin.Header_Has_Container_Directive.Value))) { headerBuilder.Insert(0, "<div id=\"" + container_inner + "\">" + Environment.NewLine); } } // Do all the replacements headerBuilder.Replace("<%COLLCODE%>", collection_code); headerBuilder.Replace("<%BIBID%>", bibid); headerBuilder.Replace("<%VID%>", vid); headerBuilder.Replace("<%MODE%>", mode); // headerBuilder.Replace("<%COLLNAME%>", collection_name); headerBuilder.Replace("<%CONTACT%>", contact); headerBuilder.Replace("<%URLOPTS%>", url_options); headerBuilder.Replace("<%?URLOPTS%>", urlOptions1); headerBuilder.Replace("<%&URLOPTS%>", urlOptions2); headerBuilder.Replace("<%BREADCRUMBS%>", breadcrumbs); headerBuilder.Replace("<%MYSOBEK%>", mySobekLinks); headerBuilder.Replace("<%ENGLISH%>", english); headerBuilder.Replace("<%FRENCH%>", french); headerBuilder.Replace("<%SPANISH%>", spanish); headerBuilder.Replace("<%BASEURL%>", RequestSpecificValues.Current_Mode.Base_URL); headerBuilder.Replace("\"container-inner\"", "\"" + container_inner + "\""); headerBuilder.Replace("<%BANNER%>", banner); headerBuilder.Replace("<%SKINURL%>", skin_url); if ((!useItemHeader) && (!String.IsNullOrEmpty(container_inner)) && (RequestSpecificValues.HTML_Skin.Header_Has_Container_Directive.HasValue) && (RequestSpecificValues.HTML_Skin.Header_Has_Container_Directive.Value)) { headerBuilder.Replace("<%CONTAINER%>", "<div id=\"" + container_inner + "\">"); } else { headerBuilder.Replace("<%CONTAINER%>", String.Empty); } headerBuilder.Replace("<%INSTANCENAME%>", RequestSpecificValues.Current_Mode.Instance_Name); headerBuilder.Replace("<%SESSIONID%>", sessionId); headerBuilder.Replace("<%USERID%>", userid); } catch (Exception ee) { RequestSpecificValues.Tracer.Add_Trace("HeaderFooter_Helper_HtmlSubWriter.Add_Header", "EXCEPTION CAUGHT while trying to write the header."); if (RequestSpecificValues.HTML_Skin == null) { RequestSpecificValues.Tracer.Add_Trace("HeaderFooter_Helper_HtmlSubWriter.Add_Header", "HTML Skin was NULL"); } else if (RequestSpecificValues.HTML_Skin.Header_Item_HTML == null) { RequestSpecificValues.Tracer.Add_Trace("HeaderFooter_Helper_HtmlSubWriter.Add_Header", "HTML Skin was not NULL, but Header_Item_HTML property was NULL"); } } // Write the header Output.WriteLine(headerBuilder.ToString()); }
/// <summary> Adds the child information to the item aggregation object from the datatable extracted from the database </summary> /// <param name="AggrInfo">Partially built item aggregation object</param> /// <param name="ParentInfo">Datatable from database calls with parent item aggregation information ( from SobekCM_Get_Item_Aggregation only )</param> private static void add_parents(Item_Aggregation AggrInfo, DataTable ParentInfo) { foreach (DataRow parentRow in ParentInfo.Rows) { Item_Aggregation_Related_Aggregations parentObject = new Item_Aggregation_Related_Aggregations(parentRow[0].ToString(), parentRow[1].ToString(), parentRow[3].ToString(), Convert.ToBoolean(parentRow[4]), false); AggrInfo.Add_Parent_Aggregation(parentObject); } }
/// <summary> Adds the child information to the item aggregation object from the datatable extracted from the database </summary> /// <param name="AggrInfo">Partially built item aggregation object</param> /// <param name="ChildInfo">Datatable from database calls with child item aggregation information ( either SobekCM_Get_Item_Aggregation or SobekCM_Get_All_Groups )</param> private static void add_children(Item_Aggregation AggrInfo, DataTable ChildInfo) { string childTypes = String.Empty; // Build a dictionary of nodes while building this tree Dictionary<string, Item_Aggregation_Related_Aggregations> nodes = new Dictionary<string, Item_Aggregation_Related_Aggregations>(ChildInfo.Rows.Count); // Step through each row of children foreach (DataRow thisRow in ChildInfo.Rows) { // pull some of the basic data out int hierarchyLevel = Convert.ToInt16(thisRow[5]); string code = thisRow[0].ToString().ToLower(); string parentCode = thisRow[1].ToString().ToLower(); // If this does not already exist, create it if (!nodes.ContainsKey(code)) { // Create the object Item_Aggregation_Related_Aggregations childObject = new Item_Aggregation_Related_Aggregations(code, thisRow[2].ToString(), thisRow[4].ToString(), Convert.ToBoolean(thisRow[6]), Convert.ToBoolean(thisRow[7])); // Add this object to the node dictionary nodes.Add(code, childObject); // If this is not ALL, no need to add the full hierarchy if ((AggrInfo.Code == "all") || (hierarchyLevel == -1)) { // Check for parent in the node list if ((parentCode.Length > 0) && (AggrInfo.Code != parentCode) && (nodes.ContainsKey(parentCode))) { nodes[parentCode].Add_Child_Aggregation(childObject); } } // If this is the first hierarchy, add to the main item aggregation object if (hierarchyLevel == -1) { AggrInfo.Add_Child_Aggregation(childObject); // If this is active and not hidden, check the type and save to list if ((!childObject.Hidden) && (childObject.Active)) { if (childTypes.Length == 0) childTypes = childObject.Type + "s"; else if (childTypes != childObject.Type ) childTypes = "SubCollections"; } } } } // Save the type for the child collections AggrInfo.Child_Types = childTypes; }
/// <summary> Populates the code manager object for translating SobekCM codes to greenstone collection codes </summary> /// <param name="tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param> /// <param name="Codes"> Code object to populate with the all the code and aggregation information</param> /// <returns> TRUE if successful, otherwise FALSE </returns> /// <remarks> This calls the 'SobekCM_Get_Codes' stored procedure </remarks> public static bool Populate_Code_Manager(Aggregation_Code_Manager Codes, Custom_Tracer tracer) { if (tracer != null) { tracer.Add_Trace("SobekCM_Database.Populate_Code_Manager", String.Empty); } // Create the connection using (SqlConnection connect = new SqlConnection(connectionString)) { SqlCommand executeCommand = new SqlCommand("SobekCM_Get_Codes", connect); // Create the data reader connect.Open(); using (SqlDataReader reader = executeCommand.ExecuteReader()) { // Clear the codes list and then move in the new data Codes.Clear(); // get the column indexes out const int codeCol = 0; const int typeCol = 1; const int nameCol = 2; const int shortNameCol = 3; const int isActiveCol = 4; const int hiddenCol = 5; const int idCol = 6; const int descCol = 7; const int themeCol = 8; const int linkCol = 9; while (reader.Read()) { // Get the list key values out string code = reader.GetString(codeCol).ToUpper(); string type = reader.GetString( typeCol); int theme = reader.GetInt32(themeCol); // Only do anything else if this is not somehow a repeat if ( !Codes.isValidCode(code)) { // Create the object Item_Aggregation_Related_Aggregations thisAggr = new Item_Aggregation_Related_Aggregations(code, reader.GetString(nameCol), reader.GetString(shortNameCol), type, reader.GetBoolean(isActiveCol), reader.GetBoolean(hiddenCol), reader.GetString(descCol), (ushort) reader.GetInt32(idCol)) {External_Link = reader.GetString(linkCol)}; // Add this to the codes manager Codes.Add_Collection(thisAggr, theme ); } } reader.Close(); } connect.Close(); } // Succesful return true; }
/// <summary> /// Method adds another aggregation as a child of this /// </summary> /// <param name = "Child_Aggregation">New child aggregation</param> internal void Add_Child_Aggregation(Item_Aggregation_Related_Aggregations Child_Aggregation) { // If the list is currently null, create it if (children == null) { children = new List<Item_Aggregation_Related_Aggregations> {Child_Aggregation}; } else { // If this does not exist, add it if (!children.Contains(Child_Aggregation)) { children.Add(Child_Aggregation); } } }
/// <summary> Populates the code manager object for translating SobekCM codes to greenstone collection codes </summary> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param> /// <param name="Codes"> Code object to populate with the all the code and aggregation information</param> /// <returns> TRUE if successful, otherwise FALSE </returns> /// <remarks> This calls the 'SobekCM_Get_Item_Aggregation_AllCodes' stored procedure </remarks> public static bool Populate_Code_Manager(Aggregation_Code_Manager Codes, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Engine_Database.Populate_Code_Manager", String.Empty); } // Create the database agnostic reader EalDbReaderWrapper readerWrapper = EalDbAccess.ExecuteDataReader(DatabaseType, Connection_String, CommandType.StoredProcedure, "SobekCM_Get_Item_Aggregation_AllCodes"); // Pull out the database reader DbDataReader reader = readerWrapper.Reader; // Clear the codes list and then move in the new data Codes.Clear(); // get the column indexes out const int CODE_COL = 0; const int TYPE_COL = 1; const int NAME_COL = 2; const int SHORT_NAME_COL = 3; const int IS_ACTIVE_COL = 4; const int HIDDEN_COL = 5; const int ID_COL = 6; const int DESC_COL = 7; const int THEME_COL = 8; const int LINK_COL = 9; const int THEME_NAME_COL = 12; const int PARENT_SHORT_NAME = 13; const int PARENT_NAME = 14; const int PARENT_CODE = 15; Item_Aggregation_Related_Aggregations lastAggr = null; while (reader.Read()) { // Get the list key values out string code = reader.GetString(CODE_COL).ToUpper(); string type = reader.GetString(TYPE_COL); if ((lastAggr != null) && (lastAggr.Code == code)) { if (!reader.IsDBNull(PARENT_CODE)) { string second_parent_code = reader.GetString(PARENT_CODE).ToUpper(); string second_parent_name = reader.GetString(PARENT_NAME).ToUpper(); string second_parent_short = reader.GetString(PARENT_SHORT_NAME); lastAggr.Add_Parent_Aggregation(second_parent_code, second_parent_name, second_parent_short); } } else { // Only do anything else if this is not somehow a repeat if (!Codes.isValidCode(code)) { // Create the object lastAggr = new Item_Aggregation_Related_Aggregations(code, reader.GetString(NAME_COL), reader.GetString(SHORT_NAME_COL), type, reader.GetBoolean(IS_ACTIVE_COL), reader.GetBoolean(HIDDEN_COL), reader.GetString(DESC_COL), (ushort) reader.GetInt32(ID_COL)); if (!reader.IsDBNull(LINK_COL)) lastAggr.External_Link = reader.GetString(LINK_COL); if (!reader.IsDBNull(THEME_NAME_COL)) { string theme_name = reader.GetString(THEME_NAME_COL); int theme = reader.GetInt32(THEME_COL); if (theme > 0) { lastAggr.Thematic_Heading = new Thematic_Heading(theme, theme_name); } } if (!reader.IsDBNull(PARENT_CODE)) { string parent_code = reader.GetString(PARENT_CODE).ToUpper(); string parent_name = reader.GetString(PARENT_NAME).ToUpper(); string parent_short = reader.GetString(PARENT_SHORT_NAME); lastAggr.Add_Parent_Aggregation(parent_code, parent_name, parent_short); } // Add this to the codes manager Codes.Add_Collection(lastAggr); } } } // Close the reader (which also closes the connection) readerWrapper.Close(); // Succesful return true; }
/// <summary> Add a new aggregation to the system </summary> /// <param name="NewAggregation"> Information for the new aggregation </param> /// <returns> Message indicating success or any errors encountered </returns> public static RestResponseMessage add_new_aggregation(New_Aggregation_Arguments NewAggregation) { // Convert to the integer id for the parent and begin to do checking List <string> errors = new List <string>(); int parentid = -1; if (NewAggregation.ParentCode.Length > 0) { Item_Aggregation_Related_Aggregations parentAggr = Engine_ApplicationCache_Gateway.Codes[NewAggregation.ParentCode]; if (parentAggr != null) { parentid = parentAggr.ID; } else { errors.Add("Parent code is not valid"); } } else { errors.Add("You must select a PARENT for this new aggregation"); } // Validate the code if (NewAggregation.Code.Length > 20) { errors.Add("New aggregation code must be twenty characters long or less"); } else if (NewAggregation.Code.Length == 0) { errors.Add("You must enter a CODE for this item aggregation"); } else if (Engine_ApplicationCache_Gateway.Codes[NewAggregation.Code.ToUpper()] != null) { errors.Add("New code must be unique... <i>" + NewAggregation.Code + "</i> already exists"); } else if (Engine_ApplicationCache_Gateway.Settings.Static.Reserved_Keywords.Contains(NewAggregation.Code.ToLower())) { errors.Add("That code is a system-reserved keyword. Try a different code."); } else { bool alphaNumericTest = NewAggregation.Code.All(C => Char.IsLetterOrDigit(C) || C == '_' || C == '-'); if (!alphaNumericTest) { errors.Add("New aggregation code must be only letters and numbers"); NewAggregation.Code = NewAggregation.Code.Replace("\"", ""); } } // Was there a type and name if (NewAggregation.Type.Length == 0) { errors.Add("You must select a TYPE for this new aggregation"); } if (NewAggregation.Description.Length == 0) { errors.Add("You must enter a DESCRIPTION for this new aggregation"); } if (NewAggregation.Name.Length == 0) { errors.Add("You must enter a NAME for this new aggregation"); } else { if (NewAggregation.ShortName.Length == 0) { NewAggregation.ShortName = NewAggregation.Name; } } // Check for the thematic heading int thematicHeadingId = -1; if (!String.IsNullOrEmpty(NewAggregation.Thematic_Heading)) { // Look for the matching thematic heading foreach (Thematic_Heading thisHeading in Engine_ApplicationCache_Gateway.Thematic_Headings) { if (String.Compare(thisHeading.Text, NewAggregation.Thematic_Heading, StringComparison.InvariantCultureIgnoreCase) == 0) { thematicHeadingId = thisHeading.ID; break; } } // If there was no match, the thematic heading was invalid, unless it was new if (thematicHeadingId < 0) { if ((!NewAggregation.NewThematicHeading.HasValue) || (!NewAggregation.NewThematicHeading.Value)) { errors.Add("Invalid thematic heading indicated"); } else if (errors.Count == 0) { // Add the thematic heading first if ((thematicHeadingId < 0) && (NewAggregation.NewThematicHeading.HasValue) && (NewAggregation.NewThematicHeading.Value)) { thematicHeadingId = Engine_Database.Edit_Thematic_Heading(-1, 10, NewAggregation.Thematic_Heading, null); } } } } if (errors.Count > 0) { // Create the error message StringBuilder actionMessage = new StringBuilder("ERROR: Invalid entry for new item aggregation.<br />"); foreach (string error in errors) { actionMessage.Append("<br />" + error); } return(new RestResponseMessage(ErrorRestTypeEnum.InputError, actionMessage.ToString())); } string language = Web_Language_Enum_Converter.Enum_To_Code(Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language); // Try to save the new item aggregation if (!Engine_Database.Save_Item_Aggregation(NewAggregation.Code, NewAggregation.Name, NewAggregation.ShortName, NewAggregation.Description, thematicHeadingId, NewAggregation.Type, NewAggregation.Active, NewAggregation.Hidden, NewAggregation.External_Link, parentid, NewAggregation.User, language, null)) { return(new RestResponseMessage(ErrorRestTypeEnum.Exception, "ERROR saving the new item aggregation to the database")); } // Ensure a folder exists for this, otherwise create one try { string folder = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + "aggregations\\" + NewAggregation.Code.ToLower(); if (!Directory.Exists(folder)) { // Create this directory and all the subdirectories Directory.CreateDirectory(folder); Directory.CreateDirectory(folder + "/html"); Directory.CreateDirectory(folder + "/images"); Directory.CreateDirectory(folder + "/html/home"); Directory.CreateDirectory(folder + "/html/custom/home"); Directory.CreateDirectory(folder + "/images/buttons"); Directory.CreateDirectory(folder + "/images/banners"); Directory.CreateDirectory(folder + "/uploads"); // Get the parent name string link_to_parent = String.Empty; Item_Aggregation_Related_Aggregations parentAggr = Engine_ApplicationCache_Gateway.Codes.Aggregation_By_ID(parentid); if (parentAggr != null) { if (String.Compare(parentAggr.Code, "all", StringComparison.InvariantCultureIgnoreCase) == 0) { link_to_parent = "<p>← Back to <a href=\"<%BASEURL%>\" alt=\"Return to parent collection\">" + parentAggr.Name + "</a></p>" + Environment.NewLine; } else { link_to_parent = "<p>← Back to <a href=\"<%BASEURL%>" + parentAggr.Code + "\" alt=\"Return to parent collection\">" + parentAggr.Name + "</a></p>" + Environment.NewLine; } } // Create a default home text file StreamWriter writer = new StreamWriter(folder + "/html/home/text.html"); writer.WriteLine(link_to_parent + "<h3>About " + NewAggregation.Name + "</h3>" + Environment.NewLine + "<p>" + NewAggregation.Description + "</p>" + Environment.NewLine + "<p>To edit this, log on as the aggregation admin and hover over this text to edit it.</p>" + Environment.NewLine); writer.Flush(); writer.Close(); // Was a button indicated, and does it exist? if ((!String.IsNullOrEmpty(NewAggregation.ButtonFile)) && (File.Exists(NewAggregation.ButtonFile))) { File.Copy(NewAggregation.ButtonFile, folder + "/images/buttons/coll.gif"); } else { // Copy the default banner and buttons from images if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.png")) { File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.png", folder + "/images/buttons/coll.png"); } if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.gif")) { File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.gif", folder + "/images/buttons/coll.gif"); } } // Was a banner indicated, and does it exist? string banner_file = String.Empty; if ((!String.IsNullOrEmpty(NewAggregation.BannerFile)) && (File.Exists(NewAggregation.BannerFile))) { banner_file = "images/banners/" + Path.GetFileName(NewAggregation.BannerFile); File.Copy(NewAggregation.BannerFile, folder + "//" + banner_file, true); } else { // Try to create a new custom banner bool custom_banner_created = false; // Create the banner with the name of the collection if (Directory.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network + "\\default\\banner_images")) { try { string[] banners = Directory.GetFiles(Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network + "\\default\\banner_images", "*.jpg"); if (banners.Length > 0) { Random randomizer = new Random(); string banner_to_use = banners[randomizer.Next(0, banners.Length - 1)]; Bitmap bitmap = (Bitmap)(Image.FromFile(banner_to_use)); RectangleF rectf = new RectangleF(30, bitmap.Height - 55, bitmap.Width - 40, 40); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawString(NewAggregation.Name, new Font("Tahoma", 25, FontStyle.Bold), Brushes.Black, rectf); g.Flush(); string new_file = folder + "/images/banners/coll.jpg"; if (!File.Exists(new_file)) { bitmap.Save(new_file, ImageFormat.Jpeg); custom_banner_created = true; banner_file = "images/banners/coll.jpg"; } } } catch (Exception) { // Suppress this Error... } } if ((!custom_banner_created) && (!File.Exists(folder + "/images/banners/coll.jpg"))) { if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_banner.jpg")) { banner_file = "images/banners/coll.jpg"; File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_banner.jpg", folder + "/images/banners/coll.jpg", true); } } } // Now, try to create the item aggregation and write the configuration file Custom_Tracer tracer = new Custom_Tracer(); Complete_Item_Aggregation itemAggregation = SobekEngineClient.Aggregations.Get_Complete_Aggregation(NewAggregation.Code, true, tracer); if (banner_file.Length > 0) { itemAggregation.Banner_Dictionary.Clear(); itemAggregation.Add_Banner_Image(banner_file, Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language); } itemAggregation.Write_Configuration_File(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + itemAggregation.ObjDirectory); // If an email shoudl be sent, do that now if (String.Compare(Engine_ApplicationCache_Gateway.Settings.Email.Send_On_Added_Aggregation, "always", StringComparison.OrdinalIgnoreCase) == 0) { string user = String.Empty; if (!String.IsNullOrEmpty(NewAggregation.User)) { user = NewAggregation.User; } string body = "New aggregation added to this system:\n\n\tCode:\t" + itemAggregation.Code + "\n\tType:\t" + itemAggregation.Type + "\n\tName:\t" + itemAggregation.Name + "\n\tShort:\t" + itemAggregation.ShortName + "\n\tUser:\t" + user + "\n\n" + Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_URL + "/" + itemAggregation.Code; Email_Helper.SendEmail(Engine_ApplicationCache_Gateway.Settings.Email.System_Email, "New " + itemAggregation.Type + " - " + itemAggregation.ShortName, body, false, Engine_ApplicationCache_Gateway.Settings.System.System_Name); } } } catch { // Reload the list of all codes, to include this new one and the new hierarchy lock (Engine_ApplicationCache_Gateway.Codes) { Engine_Database.Populate_Code_Manager(Engine_ApplicationCache_Gateway.Codes, null); } return(new RestResponseMessage(ErrorRestTypeEnum.Exception, "ERROR completing the new aggregation add")); } // Reload the list of all codes, to include this new one and the new hierarchy lock (Engine_ApplicationCache_Gateway.Codes) { Engine_Database.Populate_Code_Manager(Engine_ApplicationCache_Gateway.Codes, null); } // Clear all aggregation information (and thematic heading info) from the cache as well CachedDataManager.Aggregations.Clear(); return(new RestResponseMessage(ErrorRestTypeEnum.Successful, null)); }
/// <summary> /// Method adds another aggregation as a parent to this /// </summary> /// <param name = "Parent_Aggregation">New parent aggregation</param> internal void Add_Parent_Aggregation(Item_Aggregation_Related_Aggregations Parent_Aggregation) { // If the list is currently null, create it if (parents == null) { parents = new List<Item_Aggregation_Related_Aggregations> {Parent_Aggregation}; } else { // If this does not exist, add it if (!parents.Contains(Parent_Aggregation)) { parents.Add(Parent_Aggregation); } } }
/// <summary> Populates the code manager object for translating SobekCM codes to greenstone collection codes </summary> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param> /// <param name="Codes"> Code object to populate with the all the code and aggregation information</param> /// <returns> TRUE if successful, otherwise FALSE </returns> /// <remarks> This calls the 'SobekCM_Get_Codes' stored procedure </remarks> public static bool Populate_Code_Manager(Aggregation_Code_Manager Codes, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("SobekCM_Database.Populate_Code_Manager", String.Empty); } // Create the connection using (SqlConnection connect = new SqlConnection(connectionString)) { SqlCommand executeCommand = new SqlCommand("SobekCM_Get_Codes", connect); // Create the data reader connect.Open(); using (SqlDataReader reader = executeCommand.ExecuteReader()) { // Clear the codes list and then move in the new data Codes.Clear(); // get the column indexes out const int CODE_COL = 0; const int TYPE_COL = 1; const int NAME_COL = 2; const int SHORT_NAME_COL = 3; const int IS_ACTIVE_COL = 4; const int HIDDEN_COL = 5; const int ID_COL = 6; const int DESC_COL = 7; const int THEME_COL = 8; const int LINK_COL = 9; while (reader.Read()) { // Get the list key values out string code = reader.GetString(CODE_COL).ToUpper(); string type = reader.GetString( TYPE_COL); int theme = reader.GetInt32(THEME_COL); // Only do anything else if this is not somehow a repeat if ( !Codes.isValidCode(code)) { // Create the object Item_Aggregation_Related_Aggregations thisAggr = new Item_Aggregation_Related_Aggregations(code, reader.GetString(NAME_COL), reader.GetString(SHORT_NAME_COL), type, reader.GetBoolean(IS_ACTIVE_COL), reader.GetBoolean(HIDDEN_COL), reader.GetString(DESC_COL), (ushort) reader.GetInt32(ID_COL)) {External_Link = reader.GetString(LINK_COL)}; // Add this to the codes manager Codes.Add_Collection(thisAggr, theme ); } } reader.Close(); } connect.Close(); } // Succesful return true; }