public static void LoadFromXmlFile(this Dictionary <int, SharedList <ParameterRewriteAction> > actions, string fileName, int portalId, bool portalSpecific, ref List <string> messages) { if (messages == null) { messages = new List <string>(); } if (File.Exists(fileName)) { var rdr = new XmlTextReader(fileName) { XmlResolver = null, DtdProcessing = DtdProcessing.Prohibit, }; while (rdr.Read()) { switch (rdr.NodeType) { case XmlNodeType.Element: if (rdr.Name == "parameterRewrite") { string portalIdRaw = rdr.GetAttribute("portalId"); int rulePortalId = -1; int actionCount = 0; if (portalIdRaw != null) { int.TryParse(portalIdRaw, out rulePortalId); } if (rulePortalId == portalId || rulePortalId == -1 || portalId == -1 || portalSpecific) { // now set up the action string tabIdRaw = rdr.GetAttribute("tabIds"); string tabNames = rdr.GetAttribute("tabNames"); string name = rdr.GetAttribute("name"); string fromSiteRootRaw = rdr.GetAttribute("fromSiteRoot"); bool fromSiteRoot; bool.TryParse(fromSiteRootRaw, out fromSiteRoot); List <int> tabIds = XmlHelpers.TabIdsFromAttributes(tabIdRaw, tabNames, portalId, ref messages); foreach (int tabId in tabIds) { var action = new ParameterRewriteAction { LookFor = rdr.GetAttribute("lookFor"), RewriteTo = rdr.GetAttribute("rewriteTo"), Name = name, TabId = tabId, }; if (fromSiteRoot) { action.ForSiteRoot = true; action.TabId = -3; } else { // older rule specified tabid -3 meant site root action.ForSiteRoot = tabId == -3; } action.PortalId = portalId; SharedList <ParameterRewriteAction> tabActionCol; if (actions.ContainsKey(action.TabId)) { tabActionCol = actions[action.TabId]; } else { tabActionCol = new SharedList <ParameterRewriteAction>(); actions.Add(action.TabId, tabActionCol); } tabActionCol.Add(action); actionCount++; } messages.Add(name + " rewrite actions added:" + actionCount.ToString()); } } break; case XmlNodeType.EndElement: break; } } rdr.Close(); } else { messages.Add("Filename does not exist:" + fileName); } }
public static void LoadFromXmlFile(this Dictionary<int, SharedList<ParameterRewriteAction>> actions, string fileName, int portalId, bool portalSpecific, ref List<string> messages) { if (messages == null) { messages = new List<string>(); } if (File.Exists(fileName)) { var rdr = new XmlTextReader(fileName); while (rdr.Read()) { switch (rdr.NodeType) { case XmlNodeType.Element: if (rdr.Name == "parameterRewrite") { string portalIdRaw = rdr.GetAttribute("portalId"); int rulePortalId = -1; int actionCount = 0; if (portalIdRaw != null) { Int32.TryParse(portalIdRaw, out rulePortalId); } if (rulePortalId == portalId || rulePortalId == -1 || portalId == -1 || portalSpecific) { //now set up the action string tabIdRaw = rdr.GetAttribute("tabIds"); string tabNames = rdr.GetAttribute("tabNames"); string name = rdr.GetAttribute("name"); string fromSiteRootRaw = rdr.GetAttribute("fromSiteRoot"); bool fromSiteRoot; bool.TryParse(fromSiteRootRaw, out fromSiteRoot); List<int> tabIds = XmlHelpers.TabIdsFromAttributes(tabIdRaw, tabNames, portalId, ref messages); foreach (int tabId in tabIds) { var action = new ParameterRewriteAction { LookFor = rdr.GetAttribute("lookFor"), RewriteTo = rdr.GetAttribute("rewriteTo"), Name = name, TabId = tabId }; if (fromSiteRoot) { action.ForSiteRoot = true; action.TabId = -3; } else { //older rule specified tabid -3 meant site root action.ForSiteRoot = tabId == -3; } action.PortalId = portalId; SharedList<ParameterRewriteAction> tabActionCol; if (actions.ContainsKey(action.TabId)) { tabActionCol = actions[action.TabId]; } else { tabActionCol = new SharedList<ParameterRewriteAction>(); actions.Add(action.TabId, tabActionCol); } tabActionCol.Add(action); actionCount++; } messages.Add(name + " rewrite actions added:" + actionCount.ToString()); } } break; case XmlNodeType.EndElement: break; } } rdr.Close(); } else { messages.Add("Filename does not exist:" + fileName); } }