public XmlNodeDiffInfo Compare(PolReaderXMLNode oldXMLNodeInfo) { XmlNodeDiffInfo returnValue = new XmlNodeDiffInfo(); if (PropertyExists("Name")) { returnValue.Name = Name + " : " + getPropertyValue("Name"); } else { returnValue.Name = Name; } foreach (PolReaderXMLProperty prop in Properties) { bool found = false; foreach (PolReaderXMLProperty oldProp in oldXMLNodeInfo.Properties) { if (prop.Name.Equals(oldProp.Name)) { if (!prop.Value.Equals(oldProp.Value)) { XmlPropertyDiffInfo DiffItem = new XmlPropertyDiffInfo(); DiffItem.Type = XmlPropertyDiffInfo.UPDATED_POLICY_ITEM; DiffItem.OldItem = oldProp; DiffItem.NewItem = prop; returnValue.propItems.Add(DiffItem); } found = true; break; } } if (!found) { XmlPropertyDiffInfo DiffItem = new XmlPropertyDiffInfo(); DiffItem.Type = XmlPropertyDiffInfo.NEW_POLICY_ITEM; DiffItem.NewItem = prop; returnValue.propItems.Add(DiffItem); } } foreach (PolReaderXMLProperty oldProp in oldXMLNodeInfo.Properties) { bool found = false; foreach (PolReaderXMLProperty prop in Properties) { if (prop.Name.Equals(oldProp.Name)) { found = true; } } if (!found) { XmlPropertyDiffInfo DiffItem = new XmlPropertyDiffInfo(); DiffItem.Type = XmlPropertyDiffInfo.DELETED_POLICY_ITEM; DiffItem.OldItem = oldProp; DiffItem.DBID = oldProp.DBID; returnValue.propItems.Add(DiffItem); } } foreach (PolReaderXMLNode node in Children) { bool found = false; foreach (PolReaderXMLNode oldNode in oldXMLNodeInfo.Children) { if (node.EqualsItem(oldNode)) { XmlNodeDiffInfo diffItem = node.Compare(oldNode); if (diffItem.propItems.Count > 0 || diffItem.nodeItems.Count > 0) { diffItem.Type = XmlNodeDiffInfo.UPDATED_POLICY; returnValue.nodeItems.Add(diffItem); } found = true; break; } } if (!found) { XmlNodeDiffInfo DiffItem = node.Compare(new PolReaderXMLNode()); DiffItem.Type = XmlNodeDiffInfo.NEW_POLICY; returnValue.nodeItems.Add(DiffItem); } } foreach (PolReaderXMLNode oldNode in oldXMLNodeInfo.Children) { bool found = false; foreach (PolReaderXMLNode node in Children) { if (node.EqualsItem(oldNode)) { found = true; break; } } if (!found) { XmlNodeDiffInfo DiffItem = new PolReaderXMLNode().Compare(oldNode); DiffItem.Name = oldNode.Name; DiffItem.Type = XmlNodeDiffInfo.DELETED_POLICY; DiffItem.DBID = oldNode.DBID; returnValue.nodeItems.Add(DiffItem); } } return(returnValue); }
public DiffPolicyInfo Compare(Policy OldPolicy) { DiffPolicyInfo returnValue = new DiffPolicyInfo(); returnValue.PolicyGuid = GUID; returnValue.Name = Name; if (MachinePreferencesFiles != null && OldPolicy.MachinePreferencesFiles != null) { if (OldPolicy.MachinePreferencesFiles.Count > 0) { returnValue.Name = Name; } foreach (PolReaderXMLNode PrefNode in MachinePreferencesFiles) { bool found = false; foreach (PolReaderXMLNode oldPrefNode in OldPolicy.MachinePreferencesFiles) { if (PrefNode.Name.Equals(oldPrefNode.Name)) { XmlNodeDiffInfo DiffItems = PrefNode.Compare(oldPrefNode); if (DiffItems.nodeItems.Count > 0 || DiffItems.propItems.Count > 0) { returnValue.MachinePreferenceDifferenceInfo.Name = "Machine Preferences"; returnValue.MachinePreferenceDifferenceInfo.Type = XmlNodeDiffInfo.UPDATED_POLICY; DiffItems.Type = XmlNodeDiffInfo.UPDATED_POLICY; returnValue.MachinePreferenceDifferenceInfo.nodeItems.Add(DiffItems); } found = true; break; } } if (!found) { returnValue.MachinePreferenceDifferenceInfo.Name = "Machine Preferences"; returnValue.MachinePreferenceDifferenceInfo.Type = XmlNodeDiffInfo.NEW_POLICY; XmlNodeDiffInfo DiffItem = PrefNode.Compare(new PolReaderXMLNode()); DiffItem.Type = XmlNodeDiffInfo.NEW_POLICY; returnValue.MachinePreferenceDifferenceInfo.nodeItems.Add(DiffItem); } } foreach (PolReaderXMLNode oldPrefNode in OldPolicy.MachinePreferencesFiles) { bool found = false; foreach (PolReaderXMLNode PrefNode in MachinePreferencesFiles) { if (PrefNode.Name.Equals(oldPrefNode.Name)) { found = true; break; } } if (!found) { returnValue.MachinePreferenceDifferenceInfo.Name = "Machine Preferences"; returnValue.MachinePreferenceDifferenceInfo.Type = XmlNodeDiffInfo.UPDATED_POLICY; XmlNodeDiffInfo DiffItem = new PolReaderXMLNode().Compare(oldPrefNode); DiffItem.DBID = oldPrefNode.DBID; DiffItem.Type = XmlNodeDiffInfo.DELETED_POLICY; DiffItem.Name = oldPrefNode.Name; returnValue.MachinePreferenceDifferenceInfo.nodeItems.Add(DiffItem); } } } if (PreferencesFiles != null && OldPolicy.PreferencesFiles != null) { if (OldPolicy.MachinePreferencesFiles.Count > 0) { returnValue.Name = Name; } foreach (PolReaderXMLNode PrefNode in PreferencesFiles) { bool found = false; foreach (PolReaderXMLNode oldPrefNode in OldPolicy.PreferencesFiles) { if (PrefNode.Name.Equals(oldPrefNode.Name)) { XmlNodeDiffInfo DiffItems = PrefNode.Compare(oldPrefNode); if (DiffItems.nodeItems.Count > 0 || DiffItems.propItems.Count > 0) { returnValue.PreferenceDifferenceInfo.Name = "User Preferences"; returnValue.PreferenceDifferenceInfo.Type = XmlNodeDiffInfo.UPDATED_POLICY; DiffItems.Type = XmlNodeDiffInfo.UPDATED_POLICY; returnValue.PreferenceDifferenceInfo.nodeItems.Add(DiffItems); } found = true; break; } } if (!found) { returnValue.PreferenceDifferenceInfo.Name = "User Preferences"; returnValue.PreferenceDifferenceInfo.Type = XmlNodeDiffInfo.NEW_POLICY; XmlNodeDiffInfo DiffItem = PrefNode.Compare(new PolReaderXMLNode()); DiffItem.Type = XmlNodeDiffInfo.NEW_POLICY; returnValue.PreferenceDifferenceInfo.nodeItems.Add(DiffItem); } } foreach (PolReaderXMLNode oldPrefNode in OldPolicy.PreferencesFiles) { bool found = false; foreach (PolReaderXMLNode PrefNode in PreferencesFiles) { if (PrefNode.Name.Equals(oldPrefNode.Name)) { found = true; break; } } if (!found) { returnValue.PreferenceDifferenceInfo.Name = "User Preferences"; returnValue.PreferenceDifferenceInfo.Type = XmlNodeDiffInfo.UPDATED_POLICY; XmlNodeDiffInfo DiffItem = new PolReaderXMLNode().Compare(oldPrefNode); DiffItem.Type = XmlNodeDiffInfo.DELETED_POLICY; DiffItem.DBID = oldPrefNode.DBID; DiffItem.Name = oldPrefNode.Name; returnValue.PreferenceDifferenceInfo.nodeItems.Add(DiffItem); } } } if (SecEditFileData != null && SecEditFileData.Sections != null && OldPolicy.SecEditFileData != null && OldPolicy.SecEditFileData.Sections != null) { foreach (SecEditSection Section in SecEditFileData.Sections) { bool found = false; foreach (SecEditSection oldSection in OldPolicy.SecEditFileData.Sections) { if (oldSection.Name.Equals(Section.Name)) { List <SecEditDiffValueInfo> Items = Section.Compare(oldSection); if (Items.Count > 0) { returnValue.SecEditDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = Section.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.UPDATED_POLICY_ITEM; secEditDiffInfo.Values = Items; returnValue.SecEditDifferenceInfo.Sections.Add(secEditDiffInfo); } found = true; break; } } if (!found && Section.Entries.Count > 0) { returnValue.SecEditDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = Section.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.NEW_POLICY_ITEM; secEditDiffInfo.Values = Section.Compare(new SecEditSection()); returnValue.SecEditDifferenceInfo.Sections.Add(secEditDiffInfo); } } foreach (SecEditSection oldSection in OldPolicy.SecEditFileData.Sections) { bool found = false; foreach (SecEditSection Section in SecEditFileData.Sections) { if (oldSection.Name.Equals(Section.Name)) { found = true; break; } } if (!found && oldSection.Entries.Count > 0) { returnValue.SecEditDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = oldSection.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.DELETED_POLICY_ITEM; secEditDiffInfo.Values = new SecEditSection().Compare(oldSection); returnValue.SecEditDifferenceInfo.Sections.Add(secEditDiffInfo); } } } if (IEAKFileData != null && IEAKFileData.Sections != null && OldPolicy.IEAKFileData != null && OldPolicy.IEAKFileData.Sections != null) { foreach (SecEditSection Section in IEAKFileData.Sections) { bool found = false; foreach (SecEditSection oldSection in OldPolicy.IEAKFileData.Sections) { if (oldSection.Name.Equals(Section.Name)) { List <SecEditDiffValueInfo> Items = Section.Compare(oldSection); if (Items.Count > 0) { returnValue.IEAKDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = Section.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.UPDATED_POLICY_ITEM; secEditDiffInfo.Values = Items; returnValue.IEAKDifferenceInfo.Sections.Add(secEditDiffInfo); } found = true; break; } } if (!found && Section.Entries.Count > 0) { returnValue.IEAKDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = Section.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.NEW_POLICY_ITEM; secEditDiffInfo.Values = Section.Compare(new SecEditSection()); returnValue.IEAKDifferenceInfo.Sections.Add(secEditDiffInfo); } } foreach (SecEditSection oldSection in OldPolicy.IEAKFileData.Sections) { bool found = false; foreach (SecEditSection Section in IEAKFileData.Sections) { if (oldSection.Name.Equals(Section.Name)) { found = true; break; } } if (!found && oldSection.Entries.Count > 0) { returnValue.IEAKDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = oldSection.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.DELETED_POLICY_ITEM; secEditDiffInfo.Values = new SecEditSection().Compare(oldSection); returnValue.IEAKDifferenceInfo.Sections.Add(secEditDiffInfo); } } } if (IEAKMachineFileData != null && IEAKMachineFileData.Sections != null && OldPolicy.IEAKMachineFileData != null && OldPolicy.IEAKMachineFileData.Sections != null) { foreach (SecEditSection Section in IEAKMachineFileData.Sections) { bool found = false; foreach (SecEditSection oldSection in OldPolicy.IEAKMachineFileData.Sections) { if (oldSection.Name.Equals(Section.Name)) { List <SecEditDiffValueInfo> Items = Section.Compare(oldSection); if (Items.Count > 0) { returnValue.IEAKDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = Section.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.UPDATED_POLICY_ITEM; secEditDiffInfo.Values = Items; returnValue.IEAKDifferenceInfo.Sections.Add(secEditDiffInfo); } found = true; break; } } if (!found && Section.Entries.Count > 0) { returnValue.IEAKDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = Section.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.NEW_POLICY_ITEM; secEditDiffInfo.Values = Section.Compare(new SecEditSection()); returnValue.IEAKDifferenceInfo.Sections.Add(secEditDiffInfo); } } foreach (SecEditSection oldSection in OldPolicy.IEAKMachineFileData.Sections) { bool found = false; foreach (SecEditSection Section in IEAKMachineFileData.Sections) { if (oldSection.Name.Equals(Section.Name)) { found = true; break; } } if (!found && oldSection.Entries.Count > 0) { returnValue.IEAKDifferenceInfo.Type = SecEditDiffInfo.UPDATED_POLICY_ITEM; SecEditDiffSectionInfo secEditDiffInfo = new SecEditDiffSectionInfo(); secEditDiffInfo.Name = oldSection.Name; secEditDiffInfo.Type = SecEditDiffSectionInfo.DELETED_POLICY_ITEM; secEditDiffInfo.Values = new SecEditSection().Compare(oldSection); returnValue.IEAKDifferenceInfo.Sections.Add(secEditDiffInfo); } } } foreach (WMIItem WmiFilter in WMIFilters) { bool found = false; foreach (WMIItem oldWmiFilter in OldPolicy.WMIFilters) { if (oldWmiFilter.WMIFilter.Equals(WmiFilter.WMIFilter)) { found = true; break; } } if (!found) { returnValue.WMIDifferenceInfo.Type = WMIDiffInfo.UPDATED_POLICY_ITEM; WMIDiffInfoItem wmiItem = new WMIDiffInfoItem(); wmiItem.WMIQuery = WmiFilter.WMIFilter; wmiItem.Type = SecEditDiffSectionInfo.NEW_POLICY_ITEM; returnValue.WMIDifferenceInfo.WMIItems.Add(wmiItem); } } foreach (WMIItem oldWmiFilter in OldPolicy.WMIFilters) { bool found = false; foreach (WMIItem WmiFilter in WMIFilters) { if (oldWmiFilter.WMIFilter.Equals(WmiFilter.WMIFilter)) { found = true; break; } } if (!found) { returnValue.WMIDifferenceInfo.Type = WMIDiffInfo.UPDATED_POLICY_ITEM; WMIDiffInfoItem wmiItem = new WMIDiffInfoItem(); wmiItem.WMIQuery = oldWmiFilter.WMIFilter; wmiItem.Type = SecEditDiffSectionInfo.DELETED_POLICY_ITEM; returnValue.WMIDifferenceInfo.WMIItems.Add(wmiItem); } } foreach (AssignmentItem Assignment in AppliedTo) { bool found = false; foreach (AssignmentItem oldAssignment in OldPolicy.AppliedTo) { if (oldAssignment.Assignment.Equals(Assignment.Assignment)) { found = true; break; } } if (!found) { returnValue.AssignmentsDifferenceInfo.Type = AssignmentsDiffInfo.UPDATED_POLICY_ITEM; AssignmentsDiffInfoItem assignItem = new AssignmentsDiffInfoItem(); assignItem.Name = Assignment.Assignment; assignItem.Type = AssignmentsDiffInfoItem.NEW_POLICY_ITEM; returnValue.AssignmentsDifferenceInfo.Assignmments.Add(assignItem); } } foreach (AssignmentItem oldAssignment in OldPolicy.AppliedTo) { bool found = false; foreach (AssignmentItem Assignment in AppliedTo) { if (oldAssignment.Assignment.Equals(Assignment.Assignment)) { found = true; break; } } if (!found) { returnValue.AssignmentsDifferenceInfo.Type = AssignmentsDiffInfo.UPDATED_POLICY_ITEM; AssignmentsDiffInfoItem assignItem = new AssignmentsDiffInfoItem(); assignItem.Name = oldAssignment.Assignment; assignItem.Type = AssignmentsDiffInfoItem.DELETED_POLICY_ITEM; returnValue.AssignmentsDifferenceInfo.Assignmments.Add(assignItem); } } foreach (LinkageItem Linkage in LinkedTo) { bool found = false; foreach (LinkageItem oldLinkage in OldPolicy.LinkedTo) { if (oldLinkage.Linkage.Equals(Linkage.Linkage)) { found = true; break; } } if (!found) { returnValue.LinkageDifferenceInfo.Type = LinkageDiffInfo.UPDATED_POLICY_ITEM; LinkageDiffInfoItem linkItem = new LinkageDiffInfoItem(); linkItem.Name = Linkage.Linkage; linkItem.Type = LinkageDiffInfoItem.NEW_POLICY_ITEM; returnValue.LinkageDifferenceInfo.Linkages.Add(linkItem); } } foreach (LinkageItem oldLinkage in OldPolicy.LinkedTo) { bool found = false; foreach (LinkageItem Linkage in LinkedTo) { if (oldLinkage.Linkage.Equals(Linkage.Linkage)) { found = true; break; } } if (!found) { returnValue.LinkageDifferenceInfo.Type = LinkageDiffInfo.UPDATED_POLICY_ITEM; LinkageDiffInfoItem linkItem = new LinkageDiffInfoItem(); linkItem.Name = oldLinkage.Linkage; linkItem.Type = LinkageDiffInfoItem.DELETED_POLICY_ITEM; returnValue.LinkageDifferenceInfo.Linkages.Add(linkItem); } } foreach (PolicyFile polFile in PolicyFiles) { bool found = false; foreach (PolicyFile oldPolFile in OldPolicy.PolicyFiles) { if (polFile.Type == oldPolFile.Type) { List <RegDiffItemInfo> DiffItems = polFile.Compare(oldPolFile); if (DiffItems.Count > 0) { if (polFile.Type == PolicyFile.POLICY_FILE_TYPE_MACHINE) { returnValue.MachineRegDifferenceInfo.Type = RegDiffInfo.UPDATED_POLICY_ITEM; returnValue.MachineRegDifferenceInfo.Items = polFile.Compare(oldPolFile); } else if (polFile.Type == PolicyFile.POLICY_FILE_TYPE_USER) { returnValue.UserRegDifferenceInfo.Type = RegDiffInfo.UPDATED_POLICY_ITEM; returnValue.UserRegDifferenceInfo.Items = polFile.Compare(oldPolFile); } } found = true; break; } } if (!found) { if (polFile.Type == PolicyFile.POLICY_FILE_TYPE_MACHINE && polFile.PolicyItems.Count > 0) { returnValue.MachineRegDifferenceInfo.Type = RegDiffInfo.NEW_POLICY_ITEM; returnValue.MachineRegDifferenceInfo.Items = polFile.Compare(new PolicyFile()); } else if (polFile.Type == PolicyFile.POLICY_FILE_TYPE_USER && polFile.PolicyItems.Count > 0) { returnValue.UserRegDifferenceInfo.Type = RegDiffInfo.NEW_POLICY_ITEM; returnValue.UserRegDifferenceInfo.Items = polFile.Compare(new PolicyFile()); } } } foreach (PolicyFile oldPolFile in OldPolicy.PolicyFiles) { bool found = false; foreach (PolicyFile polFile in PolicyFiles) { if (polFile.Type == oldPolFile.Type) { found = true; } } if (!found) { if (oldPolFile.Type == PolicyFile.POLICY_FILE_TYPE_MACHINE && oldPolFile.PolicyItems.Count > 0) { returnValue.MachineRegDifferenceInfo.Type = RegDiffInfo.DELETED_POLICY_ITEM; returnValue.MachineRegDifferenceInfo.Items = new PolicyFile().Compare(oldPolFile); } else if (oldPolFile.Type == PolicyFile.POLICY_FILE_TYPE_USER && oldPolFile.PolicyItems.Count > 0) { returnValue.UserRegDifferenceInfo.Type = RegDiffInfo.DELETED_POLICY_ITEM; returnValue.UserRegDifferenceInfo.Items = new PolicyFile().Compare(oldPolFile); } } } return(returnValue); }