private RegistryKeyViewModel SnapKey([NotNull] RegistryKey key) { var result = new RegistryKeyViewModel { Name = System.IO.Path.GetFileName(key.Name) }; foreach (var valueName in key.GetValueNames()) { result.Values.Add( new RegistryValueViewModel { Name = valueName, Kind = key.GetValueKind(valueName), Value = key.GetValue(valueName) }); } foreach (var subKeyName in key.GetSubKeyNames()) { var subKey = key.OpenSubKey(subKeyName); Debug.Assert(subKey != null, "subKey != null"); result.SubKeys.Add(this.SnapKey(subKey)); } return(result); }
private static bool Validate( [CanBeNull] RegistryKeyViewModel snapshot, [CanBeNull] RegistryKeyViewModel verifiedSnapshot) { if (snapshot == null) { if (verifiedSnapshot != null) { verifiedSnapshot.Diff = true; return(true); } throw new InvalidOperationException("Both parameters are null"); } if (verifiedSnapshot == null) { snapshot.Diff = true; return(true); } ValidateValues(snapshot, verifiedSnapshot); ValidateSubKeys(snapshot, verifiedSnapshot); return(snapshot.Diff || verifiedSnapshot.Diff); }
/// <summary> /// The validate sub keys. /// </summary> /// <param name="snapshot"> /// The snapshot. /// </param> /// <param name="verifiedSnapshot"> /// The verified snapshot. /// </param> private static void ValidateSubKeys( [NotNull] RegistryKeyViewModel snapshot, [NotNull] RegistryKeyViewModel verifiedSnapshot) { foreach (var verifiedSnapshotSubKey in verifiedSnapshot.SubKeys) { var snapshotSubKey = snapshot.SubKeys.SingleOrDefault(e => e.Name == verifiedSnapshotSubKey.Name); if (snapshotSubKey == null) { verifiedSnapshotSubKey.Diff = true; } else { snapshot.Diff = Validate(snapshotSubKey, verifiedSnapshotSubKey); } } }
/// <summary> /// The validate values. /// </summary> /// <param name="snapshot"> /// The snapshot. /// </param> /// <param name="verifiedSnapshot"> /// The verified snapshot. /// </param> private static void ValidateValues( [NotNull] RegistryKeyViewModel snapshot, [NotNull] RegistryKeyViewModel verifiedSnapshot) { foreach (var verifiedSnapshotValue in verifiedSnapshot.Values) { var snapshotValue = snapshot.Values.SingleOrDefault(e => e.Name == verifiedSnapshotValue.Name); // ReSharper disable once ComplexConditionExpression if (snapshotValue == null || snapshotValue.Kind != verifiedSnapshotValue.Kind || snapshotValue.Value == null || !snapshotValue.Value.Equals(verifiedSnapshotValue.Value)) { verifiedSnapshotValue.IsDiff = true; snapshot.Diff = true; verifiedSnapshot.Diff = true; } } }