/// <summary> /// Add report menu items recursively, from the XML node. /// </summary> /// <param name="xmlNodeList">List of nodes that represent reports or submenu entries.</param> /// <param name="menuItem">ToolStripMenuItem object to be filled with nodes information.</param> private void AddReportMenuItems(XmlNodeList xmlNodeList, ToolStripMenuItem menuItem) { char[] lSeparators = new char[] { ',' }; // Process each node: Report or SubMenu. foreach (XmlNode node in xmlNodeList) { try { if (node.Name.Equals("Report", StringComparison.InvariantCultureIgnoreCase)) { #region Get Report information string lAgentsWithoutBlanks = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "agents"); lAgentsWithoutBlanks = lAgentsWithoutBlanks.Replace(" ", string.Empty); string[] lAgents = lAgentsWithoutBlanks.Split(lSeparators, StringSplitOptions.RemoveEmptyEntries); if (lAgents.Length > 0 && !Logics.Logic.Agent.IsActiveFacet(lAgents)) { continue; } // Connected agent can see this report. lAgents = Logics.Agents.All; string lClassName = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "class"); string lFilterName = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "filtername"); string lDataSetFileName = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "datasetfile"); if (File.Exists(lDataSetFileName)) { FileInfo lDataSetFileInfo = new FileInfo(lDataSetFileName); lDataSetFileName = lDataSetFileInfo.FullName; } #region Get report language information XmlNodeList lLanguageNodeList = node.SelectNodes("Language"); bool lExistLanguage = false; string lAlias = ""; string lTitle = ""; string lReportFileName = ""; foreach (XmlNode lNodeLanguage in lLanguageNodeList) { string lLanguageKey = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "key"); if (lLanguageKey.Length == 0 || lLanguageKey.Equals(CultureManager.Culture.Name, StringComparison.InvariantCultureIgnoreCase)) { lAlias = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "alias"); lTitle = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "title"); lReportFileName = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "reportfilepath"); lExistLanguage = true; break; } } #endregion Get report language information // If report is not for current language, skip it. if (!lExistLanguage) { continue; } if (File.Exists(lReportFileName)) { FileInfo lReportFileInfo = new FileInfo(lReportFileName); lReportFileName = lReportFileInfo.FullName; } // Create the Menu Report Controller. HatLeafReportController lController = new HatLeafReportController("Report_" + mController.HatElementNodes.Count.ToString(), lClassName, lFilterName, lAlias, lDataSetFileName, lReportFileName, lTitle, lAgents); // Add the option to the menu. ToolStripMenuItem lItem = new ToolStripMenuItem(lController.Alias); menuItem.DropDownItems.Add(lItem); // Assign the presentation to the controller. lController.Trigger = new ToolStripMenuItemPresentation(lItem, true); // Add the controller item to the Hat list. mController.HatElementNodes.Add(lController); #endregion Get Report information } if (node.Name.Equals("SubMenu", StringComparison.InvariantCultureIgnoreCase)) { #region Get SubMenu information string lAgentsWithoutBlanks = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "agents"); lAgentsWithoutBlanks = lAgentsWithoutBlanks.Replace(" ", string.Empty); string[] lAgents = lAgentsWithoutBlanks.Split(lSeparators, StringSplitOptions.RemoveEmptyEntries); if (lAgents.Length > 0 && !Logics.Logic.Agent.IsActiveFacet(lAgents)) { continue; } // Connected agent can see this report. lAgents = Logics.Agents.All; #region Get submenu language information XmlNodeList lLanguageNodeList = node.SelectNodes("Language"); bool lExistLanguage = false; string lAlias = ""; foreach (XmlNode lNodeLanguage in lLanguageNodeList) { string lLanguageKey = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "key"); if (lLanguageKey.Length == 0 || lLanguageKey.Equals(CultureManager.Culture.Name, StringComparison.InvariantCultureIgnoreCase)) { lAlias = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "alias"); lExistLanguage = true; break; } } #endregion Get submenu language information // If report is not for current language, skip it. if (!lExistLanguage) { continue; } // Create the Sub Menu Controller. HatNodeController lController = new HatNodeController("Report_" + mController.HatElementNodes.Count.ToString(), lAlias, "", lAgents); // Add the option to the menu. ToolStripMenuItem lItem = new ToolStripMenuItem(lController.Alias); menuItem.DropDownItems.Add(lItem); // Add the controller item to the Hat list. mController.HatElementNodes.Add(lController); // Add the sub elements of this sub menu. if (node.ChildNodes.Count > 0) { AddReportMenuItems(node.ChildNodes, lItem); } #endregion Get SubMenu information } } catch (Exception e) { Exception exc = new Exception(CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_LOADING_REPORTSCONFIG, LanguageConstantValues.L_ERROR_LOADING_REPORTSCONFIG), e); ScenarioManager.LaunchErrorScenario(exc); } } }
private void LoadConfigurationReportsFile() { // Remove Report item controller and the report menu entries. if (mController.HatElementNodes.Exist("Report_0")) { mController.HatElementNodes.Remove(mController.HatElementNodes["Report_0"]); mnuReports.DropDownItems.Clear(); } // Hide Reports menu option. mnuReports.Visible = false; HatNodeController lController = null; try { // Verify the path and file specified in MainMenuReports Settings. string lFilePath = Properties.Settings.Default.MainMenuReports; if (!System.IO.File.Exists(lFilePath)) { lFilePath = System.Windows.Forms.Application.StartupPath + "\\" + lFilePath; if (!System.IO.File.Exists(lFilePath)) { return; } } XmlDocument lXMLDoc = new XmlDocument(); lXMLDoc.Load(lFilePath); XmlNodeList lMainNodeList = lXMLDoc.GetElementsByTagName("Reports"); if (lMainNodeList.Count != 1) { return; } // Main Reports node. XmlNode lMainNode = lMainNodeList[0]; // Get the Reports Menu information. char[] lSeparators = new char[] { ',' }; string lAgentsWithoutBlanks = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lMainNode, "agents"); lAgentsWithoutBlanks = lAgentsWithoutBlanks.Replace(" ", string.Empty); string[] lAgents = lAgentsWithoutBlanks.Split(lSeparators, StringSplitOptions.RemoveEmptyEntries); if (lAgents.Length > 0 && !Logics.Logic.Agent.IsActiveFacet(lAgents)) { return; } // No agent specified means all the agents of the application. lAgents = Logics.Agents.All; XmlNodeList lLanguageNodeList = lMainNode.SelectNodes("Language"); bool lExistLanguage = false; string lAlias = ""; foreach (XmlNode lNodeLanguage in lLanguageNodeList) { string lLanguageKey = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "key"); if (lLanguageKey.Length == 0 || lLanguageKey.Equals(CultureManager.Culture.Name, StringComparison.InvariantCultureIgnoreCase)) { lAlias = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "alias"); lExistLanguage = true; break; } } // If report is not for current language, skip it. if (lExistLanguage) { lController = new HatNodeController("Report_0", lAlias, "", lAgents); // Assign the presentation to the controller. lController.Label = new ToolStripMenuItemPresentation(mnuReports, false); // Add the controller item to the Hat list. mController.HatElementNodes.Add(lController); // Get the sub menu items. AddReportMenuItems(lMainNode.ChildNodes, mnuReports); } } catch (Exception e) { Exception exc = new Exception(CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_LOADING_REPORTSCONFIG, LanguageConstantValues.L_ERROR_LOADING_REPORTSCONFIG), e); ScenarioManager.LaunchErrorScenario(exc); } if (mnuReports.DropDownItems.Count > 0) { mnuReports.Visible = true; } }