private bool DeleteGroup(RulesGroup groupToDelete, RulesGroup groupToSearchInto)
        {
            Logger.EnteringMethod();
            if (groupToDelete.Id == _masterGroupUpdateLevel.Id || groupToDelete.Id == _masterGroupPackageLevel.Id)
            {
                return(false);
            }

            if (groupToSearchInto.InnerGroups.ContainsKey(groupToDelete.Id))
            {
                Logger.Write("Deleting Group : " + groupToDelete.Id.ToString());
                groupToSearchInto.InnerGroups.Remove(groupToDelete.Id);
                return(true);
            }
            else
            {
                foreach (RulesGroup group in groupToSearchInto.InnerGroups.Values)
                {
                    if (DeleteGroup(groupToDelete, group))
                    {
                        break;
                    }
                }
            }
            return(true);
        }
 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 grpDsp1_SelectionChange(GroupDisplayer sender)
        {
            Logger.EnteringMethod();
            int total = sender.SelectedRules.Count + sender.SelectedGroups.Count;

            btnEdit.Enabled      = (total == 1);
            btnDelete.Enabled    = (total > 0);
            btnSaveRules.Enabled = (total > 0);

            if (sender.SelectedGroups.Count == 1)
            {
                btnAddAndGroup.Enabled = true;
                btnAddOrGroup.Enabled  = true;
                btnAddRule.Enabled     = true;
                btnLoadRules.Enabled   = true;
                if (sender.Equals(grpDspPackageLevel))
                {
                    _currentGroupPackageLevel = sender.SelectedGroups[0];
                }
                else
                {
                    _currentGroupUpdateLevel = sender.SelectedGroups[0];
                }
            }
            else
            {
                btnAddAndGroup.Enabled = false;
                btnAddOrGroup.Enabled  = false;
                btnAddRule.Enabled     = false;
                btnLoadRules.Enabled   = false;
            }
        }
        internal void InitializePackageLevelwithXml(string xmlPackageLevel)
        {
            _masterGroupPackageLevel.Reset();
            if (!string.IsNullOrEmpty(xmlPackageLevel))
            {
                Logger.Write("XML at PackageLevel : " + xmlPackageLevel);
                _masterGroupPackageLevel = ParseXml(_masterGroupPackageLevel, xmlPackageLevel, true);
            }

            grpDspPackageLevel.Initialize(_masterGroupPackageLevel);
        }
 internal void Initialize(RulesGroup initialGroup)
 {
     InnerGroup = initialGroup;
     Display();
     AdjustBackColor();
     UpdateSelectedRulesAndGroupsList();
     if (SelectionChange != null)
     {
         SelectionChange(this);
     }
 }
        internal void InitializeUpdateLevelwithXml(string xmlUpdateLevel)
        {
            Logger.EnteringMethod();
            _masterGroupUpdateLevel.Reset();
            if (!string.IsNullOrEmpty(xmlUpdateLevel))
            {
                Logger.Write("XML at UpdateLevel : " + xmlUpdateLevel);
                _masterGroupUpdateLevel = ParseXml(_masterGroupUpdateLevel, xmlUpdateLevel, true);
            }

            grpDspUpdateLevel.Initialize(_masterGroupUpdateLevel);
        }
        internal FrmUpdateRulesWizard()
        {
            Logger.EnteringMethod("FrmUpdateRulesWizard");
            InitializeComponent();
            grpDspUpdateLevel.SelectionChange    += new GroupDisplayer.SelectionChangeEventHandler(grpDsp1_SelectionChange);
            grpDspUpdateLevel.EditionRequest     += new GroupDisplayer.EditionRequestEventHandler(grpDsp1_EditionRequest);
            grpDspUpdateLevel.RuleEditionRequest += new GroupDisplayer.RuleEditionRequestEventHandler(grpDsp1_RuleEditionRequest);

            grpDspPackageLevel.SelectionChange    += new GroupDisplayer.SelectionChangeEventHandler(grpDsp1_SelectionChange);
            grpDspPackageLevel.EditionRequest     += new GroupDisplayer.EditionRequestEventHandler(grpDsp1_EditionRequest);
            grpDspPackageLevel.RuleEditionRequest += new GroupDisplayer.RuleEditionRequestEventHandler(grpDsp1_RuleEditionRequest);
            _currentGroupUpdateLevel  = _masterGroupUpdateLevel;
            _currentGroupPackageLevel = _masterGroupPackageLevel;
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                _allSupportedRules.Add(new RuleMsiProductInstalled());
                _allSupportedRules.Add(new RuleProcessorArchitecture());
                _allSupportedRules.Add(new RuleWindowsVersion());
                _allSupportedRules.Add(new RuleWindowsLanguage());
                _allSupportedRules.Add(new RuleFileExists());
                _allSupportedRules.Add(new RuleFileExistsPrependRegSz());
                _allSupportedRules.Add(new RuleFileVersion());
                _allSupportedRules.Add(new RuleFileVersionPrependRegSZ());
                _allSupportedRules.Add(new RuleFileCreated());
                _allSupportedRules.Add(new RuleFileCreatedPrependRegSz());
                _allSupportedRules.Add(new RuleFileModified());
                _allSupportedRules.Add(new RuleFileSize());
                _allSupportedRules.Add(new RuleRegKeyExists());
                _allSupportedRules.Add(new RuleRegValueExists());
                _allSupportedRules.Add(new RuleRegDword());
                _allSupportedRules.Add(new RuleRegExpandSz());
                _allSupportedRules.Add(new RuleRegSz());
                _allSupportedRules.Add(new RuleRegSzToVersion());
                _allSupportedRules.Add(new RuleWmiQuery());
                _allSupportedRules.Add(new RuleMsiPatchInstalledForProduct());
                cmbBxRules.Items.AddRange(_allSupportedRules.ToArray());
                cmbBxRules.SelectedIndex = 0;
            }));
            thread.Start();

            cmbBxRules.Focus();

            _masterGroupUpdateLevel.IsSelected  = true;
            _masterGroupPackageLevel.IsSelected = true;
            grpDspUpdateLevel.Initialize(_masterGroupUpdateLevel);
            grpDspPackageLevel.Initialize(_masterGroupPackageLevel);
        }
 private bool DeleteRule(GenericRule ruleToDelete, RulesGroup groupToSearchInto)
 {
     Logger.EnteringMethod();
     if (groupToSearchInto.InnerRules.ContainsKey(ruleToDelete.Id))
     {
         Logger.Write("Deleting Rule : " + ruleToDelete.GetXmlFormattedRule());
         groupToSearchInto.InnerRules.Remove(ruleToDelete.Id);
         return(true);
     }
     else
     {
         foreach (RulesGroup group in groupToSearchInto.InnerGroups.Values)
         {
             if (DeleteRule(ruleToDelete, group))
             {
                 break;
             }
         }
     }
     return(true);
 }
        private void btnAddOrGroup_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();
            RulesGroup addedGroup = new RulesGroup();

            if (rdBtnUpdateLevel.Checked)
            {
                _currentGroupUpdateLevel.IsSelected = false;
                addedGroup.GroupType  = RulesGroup.GroupLogicalOperator.Or;
                addedGroup.IsSelected = true;
                _currentGroupUpdateLevel.AddGroup(addedGroup);
                grpDspUpdateLevel.Initialize(_masterGroupUpdateLevel);
            }
            else
            {
                _currentGroupPackageLevel.IsSelected = false;
                addedGroup.GroupType  = RulesGroup.GroupLogicalOperator.Or;
                addedGroup.IsSelected = true;
                _currentGroupPackageLevel.AddGroup(addedGroup);
                grpDspPackageLevel.Initialize(_masterGroupPackageLevel);
            }
        }
        private void btnLoadRules_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();
            string         xmlToLoad = string.Empty;
            OpenFileDialog openDlgBx = new OpenFileDialog();

            openDlgBx.AddExtension     = true;
            openDlgBx.CheckFileExists  = true;
            openDlgBx.CheckPathExists  = true;
            openDlgBx.DefaultExt       = ".Rules";
            openDlgBx.Filter           = "*.rules|*.rules";
            openDlgBx.InitialDirectory = Environment.CurrentDirectory + "\\Saved Rules";
            openDlgBx.Multiselect      = false;
            openDlgBx.Title            = resManager.GetString("OpenSavedRules");
            openDlgBx.ValidateNames    = true;

            try
            {
                if (openDlgBx.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    System.IO.StreamReader reader = new System.IO.StreamReader(openDlgBx.FileName);
                    xmlToLoad = reader.ReadToEnd();
                    Logger.Write("Loading rules from Xml : " + xmlToLoad);
                    reader.Close();
                    RulesGroup selectedGroup;
                    if (rdBtnUpdateLevel.Checked)
                    {
                        selectedGroup = grpDspUpdateLevel.SelectedGroups[0];
                    }
                    else
                    {
                        selectedGroup = grpDspPackageLevel.SelectedGroups[0];
                    }
                    RulesGroup tmpGroup      = new RulesGroup();
                    RulesGroup newRulesGroup = ParseXml(tmpGroup, xmlToLoad, false);

                    foreach (RulesGroup group in newRulesGroup.InnerGroups.Values)
                    {
                        selectedGroup.AddGroup(group);
                    }
                    foreach (GenericRule rule in newRulesGroup.InnerRules.Values)
                    {
                        selectedGroup.AddRule(rule);
                    }
#if DEBUG
                    MessageBox.Show(newRulesGroup.GetXmlFormattedRule());
#endif
                    if (rdBtnUpdateLevel.Checked)
                    {
                        grpDspUpdateLevel.Initialize(_masterGroupUpdateLevel);
                    }
                    else
                    {
                        grpDspPackageLevel.Initialize(_masterGroupPackageLevel);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write("**** " + ex.Message);
                MessageBox.Show(resManager.GetString("FailedToLoad" + "\r\n" + ex.Message));
            }
        }
        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);
        }
Example #12
0
 internal void AddGroup(RulesGroup groupToAdd)
 {
     _innerGroups.Add(groupToAdd.Id, groupToAdd);
 }