public ICompareFluentInterface ToMemento(out EngineMemento memento) { memento = new EngineMemento(); foreach (var comparer in this.comparerList) { memento.Entities.Add(comparer.ToEntityMemento()); } return(this); }
public static ICompareFluentInterface FromMemento(EngineMemento memento) { if (memento == null) { throw new ArgumentNullException(nameof(memento)); } var validationResults = new List <ValidationResult>(); if (!Validator.TryValidateObject(memento, new ValidationContext(memento), validationResults)) { throw new ExtendedValidationException("memento", memento, validationResults); } var f = new FluentInterface(); if (memento.Entities == null) { return(f); } if (memento.Entities.Count == 0) { return(f); } foreach (var entityMemento in memento.Entities) { IKeyProvider <Entity> keyProvider; if (entityMemento.KeyUseGuid) { keyProvider = AsKey.UseGuid; } else { keyProvider = AsKey.UseAttributes(entityMemento.KeyAttributeNames.ToArray()); } if (entityMemento.AttributesToSkip?.Count > 0) { var skipAttributeCriteria = Skip.Attributes(entityMemento.AttributesToSkip.ToArray()); f.Entity(entityMemento.EntityName, keyProvider, skipAttributeCriteria, entityMemento.OnlyActive); } else { f.Entity(entityMemento.EntityName, keyProvider, entityMemento.OnlyActive); } } return(f); }
public static ICompareFluentInterface FromMemento(string mementoFileName, out EngineMemento memento) { if (string.IsNullOrWhiteSpace(mementoFileName)) { throw new ArgumentNullException(nameof(mementoFileName)); } var jsonData = File.ReadAllText(mementoFileName); memento = JsonConvert.DeserializeObject <EngineMemento>(jsonData); if (memento == null) { throw new ArgumentException("Cannot deserialize memento from file " + mementoFileName); } memento.FileName = mementoFileName; return(FromMemento(memento)); }