/// <summary> Constructor for a new instance of the <see cref="ItemWriterConfig"/> class </summary> public ItemWriterConfig() { Class = "SobekCM.Library.HTML.Item_HtmlSubwriter"; Viewers = new List <ItemSubViewerConfig>(); Layout = new ItemWriterLayoutConfig(); set_default(); }
/// <summary> Add a new item layout configuration </summary> /// <param name="Layout"> Object with all the layout details </param> public void Add_Layout(ItemWriterLayoutConfig Layout) { // Ensure the dictionary is built if (layoutsLookup == null) { layoutsLookup = new Dictionary <string, ItemWriterLayoutConfig>(StringComparer.OrdinalIgnoreCase); } // Ensure all items in the list are in the dictionary if (layoutsLookup.Count != Layouts.Count) { layoutsLookup.Clear(); foreach (ItemWriterLayoutConfig exstingConfig in Layouts) { layoutsLookup[exstingConfig.ID] = exstingConfig; if (exstingConfig.Default) { defaultLayout = exstingConfig; } } } // Did this already exist? if (layoutsLookup.ContainsKey(Layout.ID)) { ItemWriterLayoutConfig existing = null; foreach (ItemWriterLayoutConfig thisOne in Layouts) { if (String.Compare(thisOne.ID, Layout.ID, StringComparison.OrdinalIgnoreCase) == 0) { existing = thisOne; break; } } if (existing != null) { Layouts.Remove(existing); } layoutsLookup.Remove(Layout.ID); } // Add this layoutsLookup[Layout.ID] = Layout; Layouts.Add(Layout); // Was this the new default? if (Layout.Default) { defaultLayout = Layout; } }
/// <summary> Get a specific item layout configuration, by code </summary> /// <param name="Code"> Code from the configuration for this layout </param> /// <returns> The requested layout, or the default layout </returns> public ItemWriterLayoutConfig Get_Layout(string Code) { // Ensure the dictionary is built if (layoutsLookup == null) { layoutsLookup = new Dictionary <string, ItemWriterLayoutConfig>(StringComparer.OrdinalIgnoreCase); } // Ensure all items in the list are in the dictionary if (layoutsLookup.Count != Layouts.Count) { layoutsLookup.Clear(); foreach (ItemWriterLayoutConfig exstingConfig in Layouts) { layoutsLookup[exstingConfig.ID] = exstingConfig; if (exstingConfig.Default) { defaultLayout = exstingConfig; } } } // Try to find this, by code if (layoutsLookup.ContainsKey(Code)) { return(layoutsLookup[Code]); } // If there is a default, return that if (defaultLayout != null) { return(defaultLayout); } // Return the first, if no default if (layoutsLookup.Count > 0) { return(layoutsLookup[layoutsLookup.Keys.First()]); } // Finally, return NULL return(null); }
/// <summary> Clears all the previously loaded information, such as the default values </summary> /// <remarks> This clears all the item viewer information, clears the assembly, and sets the class to the /// default item html subwriter class. </remarks> public void ClearAll() { Viewers.Clear(); if (viewersByCode != null) { viewersByCode.Clear(); } if (viewersByType != null) { viewersByType.Clear(); } if (layoutsLookup != null) { layoutsLookup.Clear(); } Assembly = String.Empty; Class = "SobekCM.Library.HTML.Item_HtmlSubwriter"; defaultLayout = null; }