/// <summary> Add a new item viewer for the writer to use </summary>
        /// <param name="NewViewer"> New viewer to add </param>
        /// <remarks> If a viewer config already exists for the viewer type or viewer code, this
        /// will replace the existing one </remarks>
        public void Add_Viewer(ItemSubViewerConfig NewViewer)
        {
            // Ensure the dictionaries are built
            if (viewersByCode == null)
            {
                viewersByCode = new Dictionary <string, ItemSubViewerConfig>(StringComparer.InvariantCultureIgnoreCase);
            }
            if (viewersByType == null)
            {
                viewersByType = new Dictionary <string, ItemSubViewerConfig>(StringComparer.InvariantCultureIgnoreCase);
            }

            // Check for the count of items in the dictionaries
            if (viewersByCode.Count != Viewers.Count)
            {
                viewersByCode.Clear();
                foreach (ItemSubViewerConfig existingConfig in Viewers)
                {
                    viewersByCode[existingConfig.ViewerCode] = existingConfig;
                }
            }
            if (viewersByType.Count != Viewers.Count)
            {
                viewersByType.Clear();
                foreach (ItemSubViewerConfig existingConfig in Viewers)
                {
                    viewersByType[existingConfig.ViewerType] = existingConfig;
                }
            }

            // Look for a match by code - remove any existing matches
            if (viewersByCode.ContainsKey(NewViewer.ViewerCode))
            {
                if (Viewers.Contains(viewersByCode[NewViewer.ViewerCode]))
                {
                    Viewers.Remove(viewersByCode[NewViewer.ViewerCode]);
                }
            }

            // Look for a match by type - remove any existing matches
            if (viewersByType.ContainsKey(NewViewer.ViewerType))
            {
                if (Viewers.Contains(viewersByType[NewViewer.ViewerType]))
                {
                    Viewers.Remove(viewersByType[NewViewer.ViewerType]);
                }
            }

            // Now, add the new viewer
            viewersByCode[NewViewer.ViewerCode] = NewViewer;
            viewersByType[NewViewer.ViewerType] = NewViewer;
            Viewers.Add(NewViewer);
        }
        /// <summary> Add a new item viewer for the writer to use </summary>
        /// <param name="NewViewer"> New viewer to add </param>
        /// <remarks> If a viewer config already exists for the viewer type or viewer code, this 
        /// will replace the existing one </remarks>
        public void Add_Viewer(ItemSubViewerConfig NewViewer)
        {
            // Ensure the dictionaries are built
            if (viewersByCode == null) viewersByCode = new Dictionary<string, ItemSubViewerConfig>(StringComparer.InvariantCultureIgnoreCase);
            if (viewersByType == null) viewersByType = new Dictionary<string, ItemSubViewerConfig>(StringComparer.InvariantCultureIgnoreCase);

            // Check for the count of items in the dictionaries
            if (viewersByCode.Count != Viewers.Count)
            {
                viewersByCode.Clear();
                foreach (ItemSubViewerConfig existingConfig in Viewers)
                    viewersByCode[existingConfig.ViewerCode] = existingConfig;
            }
            if (viewersByType.Count != Viewers.Count)
            {
                viewersByType.Clear();
                foreach (ItemSubViewerConfig existingConfig in Viewers)
                    viewersByType[existingConfig.ViewerType] = existingConfig;
            }

            // Look for a match by code - remove any existing matches
            if (viewersByCode.ContainsKey(NewViewer.ViewerCode))
            {
                if (Viewers.Contains(viewersByCode[NewViewer.ViewerCode]))
                    Viewers.Remove(viewersByCode[NewViewer.ViewerCode]);
            }

            // Look for a match by type - remove any existing matches
            if (viewersByType.ContainsKey(NewViewer.ViewerType))
            {
                if (Viewers.Contains(viewersByType[NewViewer.ViewerType]))
                    Viewers.Remove(viewersByType[NewViewer.ViewerType]);
            }

            // Now, add the new viewer
            viewersByCode[NewViewer.ViewerCode] = NewViewer;
            viewersByType[NewViewer.ViewerType] = NewViewer;
            Viewers.Add(NewViewer);
        }
        private static void read_item_writer_viewer_configs(XmlReader ReaderXml, WriterViewerConfig Config)
        {
            while (ReaderXml.Read())
            {
                if (ReaderXml.NodeType == XmlNodeType.Element)
                {
                    switch (ReaderXml.Name.ToLower())
                    {
                        case "menuprovider":
                            string menuassembly = null;
                            if (ReaderXml.MoveToAttribute("assembly"))
                                menuassembly = ReaderXml.Value.Trim();
                            if (ReaderXml.MoveToAttribute("class"))
                            {
                                string menuclass = ReaderXml.Value.Trim();
                                if ( !String.IsNullOrEmpty(menuclass))
                                    Config.Items.SetMainMenu(menuclass, menuassembly);
                            }
                            break;

                        case "itemviewer":
                            ItemSubViewerConfig newConfig = new ItemSubViewerConfig();
                            if (ReaderXml.MoveToAttribute("type"))
                                newConfig.ViewerType = ReaderXml.Value.Trim();
                            if (ReaderXml.MoveToAttribute("viewerCode"))
                                newConfig.ViewerCode = ReaderXml.Value.Trim();
                            if (ReaderXml.MoveToAttribute("assembly"))
                                newConfig.Assembly = ReaderXml.Value.Trim();
                            if (ReaderXml.MoveToAttribute("class"))
                                newConfig.Class = ReaderXml.Value.Trim();
                            if (ReaderXml.MoveToAttribute("enabled"))
                            {
                                bool tempValue;
                                if (bool.TryParse(ReaderXml.Value, out tempValue))
                                {
                                    newConfig.Enabled = tempValue;
                                }
                            }
                            if (ReaderXml.MoveToAttribute("mgmtViewer"))
                            {
                                bool tempValue;
                                if (bool.TryParse(ReaderXml.Value, out tempValue))
                                {
                                    newConfig.ManagementViewer = tempValue;
                                    if (ReaderXml.MoveToAttribute("mgmtOrder"))
                                    {
                                        float tempFloatValue;
                                        if (float.TryParse(ReaderXml.Value, out tempFloatValue))
                                            newConfig.ManagementOrder = tempFloatValue;
                                        else
                                            newConfig.ManagementOrder = 1000;
                                    }
                                    else
                                    {
                                        newConfig.ManagementOrder = 1000;
                                    }
                                }
                            }
                            if (ReaderXml.MoveToAttribute("pageFileExtensions"))
                            {
                                newConfig.PageExtensions = ReaderXml.Value.Trim().Split(new char[] { '|', ',' });
                            }
                            if (ReaderXml.MoveToAttribute("fileExtensions"))
                            {
                                newConfig.FileExtensions = ReaderXml.Value.Trim().Split(new char[] { '|', ',' });
                            }

                            // Check for minimum requirements
                            if ((!String.IsNullOrEmpty(newConfig.ViewerType)) && (!String.IsNullOrEmpty(newConfig.ViewerCode)))
                                Config.Items.Add_Viewer(newConfig);
                            break;
                    }
                }
            }
        }