private bool ReplaceRule(GenericRule editedRule, GenericRule backupRule, RulesGroup groupToSearchInto) { Logger.EnteringMethod(); Logger.Write("Edited Rule : " + editedRule.GetXmlFormattedRule()); Logger.Write("Backup Rule : " + backupRule.GetXmlFormattedRule()); if (groupToSearchInto.InnerRules.ContainsKey(editedRule.Id)) { groupToSearchInto.InnerRules.Remove(editedRule.Id); groupToSearchInto.AddRule(backupRule); if (rdBtnUpdateLevel.Checked) { grpDspUpdateLevel.Initialize(_masterGroupUpdateLevel); } else { grpDspPackageLevel.Initialize(_masterGroupPackageLevel); } return(true); } else { foreach (RulesGroup group in groupToSearchInto.InnerGroups.Values) { if (ReplaceRule(editedRule, backupRule, group)) { break; } } } return(true); }
private void btnAddRule_Click(object sender, EventArgs e) { Logger.EnteringMethod(); GenericRule frmRule; frmRule = GetSelectedForm(cmbBxRules.SelectedItem); Form frm = new Form(); frm.KeyPreview = true; frm.KeyDown += new KeyEventHandler(frm_KeyDown); frm.StartPosition = FormStartPosition.CenterParent; frm.Controls.Add(frmRule); frm.Size = new Size(frmRule.Width + 20, frmRule.Height + 2 * SystemInformation.CaptionHeight); frmRule.Dock = DockStyle.Fill; if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Logger.Write("Adding Rule : " + frm.GetType().ToString()); if (rdBtnUpdateLevel.Checked) { _currentGroupUpdateLevel.AddRule(frmRule); } else { _currentGroupPackageLevel.AddRule(frmRule); } } frm.Hide(); frm.KeyDown -= new KeyEventHandler(frm_KeyDown); frm = null; if (rdBtnUpdateLevel.Checked) { grpDspUpdateLevel.Initialize(_masterGroupUpdateLevel); } else { grpDspPackageLevel.Initialize(_masterGroupPackageLevel); } }
private RulesGroup ParseXml(RulesGroup group, string xml, bool mergeGroup) { Logger.EnteringMethod(xml); bool reverseRule = false; bool thisGroup = true; XmlNamespaceManager namespaceMng = new XmlNamespaceManager(new System.Xml.NameTable()); namespaceMng.AddNamespace("lar", "http://schemas.microsoft.com/wsus/2005/04/CorporatePublishing/LogicalApplicabilityRules.xsd"); namespaceMng.AddNamespace("bar", "http://schemas.microsoft.com/wsus/2005/04/CorporatePublishing/BaseApplicabilityRules.xsd"); namespaceMng.AddNamespace("msiar", "http://schemas.microsoft.com/wsus/2005/04/CorporatePublishing/MsiApplicabilityRules.xsd"); XmlParserContext context = new XmlParserContext(null, namespaceMng, null, XmlSpace.Default); XmlTextReader xmlReader = new XmlTextReader(xml, XmlNodeType.Element, context); xmlReader.WhitespaceHandling = WhitespaceHandling.None; xmlReader.Read(); while (!xmlReader.EOF) { switch (xmlReader.Prefix) { case "lar": switch (xmlReader.LocalName) { case "Not": reverseRule = (xmlReader.NodeType != XmlNodeType.EndElement); xmlReader.Read(); break; case "And": if (xmlReader.NodeType == XmlNodeType.Element) { if (thisGroup && mergeGroup) { group.GroupType = RulesGroup.GroupLogicalOperator.And; thisGroup = false; xmlReader.Read(); } else { RulesGroup tempGroup = new RulesGroup(); group.AddGroup(ParseXml(tempGroup, xmlReader.ReadOuterXml(), true)); } } else if (xmlReader.NodeType == XmlNodeType.EndElement) { return(group); } break; case "Or": if (xmlReader.NodeType == XmlNodeType.Element) { if (thisGroup && mergeGroup) { group.GroupType = RulesGroup.GroupLogicalOperator.Or; thisGroup = false; xmlReader.Read(); } else { RulesGroup tempGroup = new RulesGroup(); group.AddGroup(ParseXml(tempGroup, xmlReader.ReadOuterXml(), true)); } } else if (xmlReader.NodeType == XmlNodeType.EndElement) { return(group); } break; default: xmlReader.Read(); break; } break; case "bar": case "msiar": foreach (GenericRule rule in _allSupportedRules) { if (xmlReader.LocalName == rule.XmlElementName) { GenericRule tempRule = GetSelectedForm(rule); tempRule.ReverseRule = reverseRule; tempRule.InitializeWithAttributes(GetAttributes(xmlReader)); group.AddRule(tempRule); break; } } xmlReader.Read(); break; default: xmlReader.Read(); break; } } return(group); }