private void SerializeDeserialize(ISpecificationCache cache, string file) { var stopwatch = new Stopwatch(); IUnityContainer container = GetContainer(); stopwatch.Start(); cache.Serialize(file); stopwatch.Stop(); TimeSpan serializeInterval = stopwatch.Elapsed; stopwatch.Reset(); // and roundtrip container.RegisterType <ISpecificationCache, ImmutableInMemorySpecCache>( new PerResolveLifetimeManager(), new InjectionConstructor(file)); stopwatch.Start(); var newCache = container.Resolve <ISpecificationCache>(); stopwatch.Stop(); TimeSpan deserializeInterval = stopwatch.Elapsed; stopwatch.Reset(); CompareCaches(cache, newCache); Console.WriteLine("serialize {0} deserialize {1} ", serializeInterval, deserializeInterval); }
private static void CompareCaches(ISpecificationCache cache, ISpecificationCache newCache) { Assert.AreEqual(cache.AllSpecifications().Count(), newCache.AllSpecifications().Count()); // checks for fields and Objects actions string error = newCache.AllSpecifications().Where(s => s.Fields.Any() && s.Fields.Any(f => f == null)).Select(s => s.FullName).Aggregate("", (s, t) => s + " " + t); Assert.IsTrue(newCache.AllSpecifications().Select(s => s.Fields).All(fs => !fs.Any() || fs.All(f => f != null)), error); error = newCache.AllSpecifications().Where(s => s.ObjectActions.Any() && s.ObjectActions.Any(f => f == null)).Select(s => s.FullName).Aggregate("", (s, t) => s + " " + t); Assert.IsTrue(newCache.AllSpecifications().Select(s => s.ObjectActions).All(fs => !fs.Any() || fs.All(f => f != null)), error); var zipped = cache.AllSpecifications().Zip(newCache.AllSpecifications(), (a, b) => new { a, b }); foreach (var item in zipped) { Assert.AreEqual(item.a.FullName, item.b.FullName); Assert.AreEqual(item.a.GetFacets().Count(), item.b.GetFacets().Count()); var zipfacets = item.a.GetFacets().Zip(item.b.GetFacets(), (x, y) => new { x, y }); foreach (var zipfacet in zipfacets) { Assert.AreEqual(zipfacet.x.FacetType, zipfacet.y.FacetType); } } }
private void SerializeDeserializeLocalEach(ISpecificationCache cache, string file) { var stopwatch = new Stopwatch(); //IUnityContainer container = GetContainer(); //stopwatch.Start(); IFormatter formatter = new NetDataContractSerializer(); //IFormatter formatter = new BinaryFormatter(); //IFormatter formatter = new SoapFormatter(); var specs = cache.AllSpecifications(); var index = 0; foreach (var spec in specs) { try { ITypeSpecImmutable[] singleSpec = { spec }; stopwatch.Start(); string fileName = file + index++; Serialize(fileName, formatter, singleSpec); stopwatch.Stop(); TimeSpan serializeInterval = stopwatch.Elapsed; stopwatch.Reset(); // and roundtrip stopwatch.Start(); var newSpecs = DeSerialize(fileName, formatter); stopwatch.Stop(); TimeSpan deserializeInterval = stopwatch.Elapsed; stopwatch.Reset(); Assert.AreEqual(1, newSpecs.Length); //CompareCaches(cache, newCache); Console.WriteLine("serialize {0} deserialize {1} ", serializeInterval.TotalMilliseconds, deserializeInterval.TotalMilliseconds); } catch (Exception e) { Console.WriteLine("failed " + index + " " + spec.FullName + " " + e.Message); } } }
private static void CompareCaches(ISpecificationCache cache, ISpecificationCache newCache) { Assert.AreEqual(cache.AllSpecifications().Count(), newCache.AllSpecifications().Count()); var zipped = cache.AllSpecifications().Zip(newCache.AllSpecifications(), (a, b) => new { a, b }); foreach (var item in zipped) { Assert.AreEqual(item.a.FullName, item.b.FullName); Assert.AreEqual(item.a.GetFacets().Count(), item.b.GetFacets().Count()); var zipfacets = item.a.GetFacets().Zip(item.b.GetFacets(), (x, y) => new { x, y }); foreach (var zipfacet in zipfacets) { Assert.AreEqual(zipfacet.x.FacetType, zipfacet.y.FacetType); } } }
private void SerializeDeserializeLocal(ISpecificationCache cache, string file) { var stopwatch = new Stopwatch(); IUnityContainer container = GetContainer(); stopwatch.Start(); IFormatter formatter = new NetDataContractSerializer(); //IFormatter formatter = new BinaryFormatter(); //IFormatter formatter = new SoapFormatter(); var specs = cache.AllSpecifications(); Serialize(file, formatter, specs); stopwatch.Stop(); TimeSpan serializeInterval = stopwatch.Elapsed; stopwatch.Reset(); // and roundtrip stopwatch.Start(); var newSpecs = DeSerialize(file, formatter); stopwatch.Stop(); TimeSpan deserializeInterval = stopwatch.Elapsed; stopwatch.Reset(); Assert.AreEqual(specs.Length, newSpecs.Length); //CompareCaches(cache, newCache); Console.WriteLine("serialize {0} deserialize {1} ", serializeInterval.TotalMilliseconds, deserializeInterval.TotalMilliseconds); }
private void SerializeDeserialize(ISpecificationCache cache, string file) { var stopwatch = new Stopwatch(); IUnityContainer container = GetContainer(); stopwatch.Start(); IFormatter formatter = new NetDataContractSerializer(); //IFormatter formatter = new BinaryFormatter(); //IFormatter formatter = new SoapFormatter(); //cache.Serialize(file, formatter); stopwatch.Stop(); TimeSpan serializeInterval = stopwatch.Elapsed; stopwatch.Reset(); // and roundtrip container.RegisterType <ISpecificationCache, ImmutableInMemorySpecCache>( new PerResolveLifetimeManager(), new InjectionConstructor(file, formatter)); stopwatch.Start(); var newCache = container.Resolve <ISpecificationCache>(); stopwatch.Stop(); TimeSpan deserializeInterval = stopwatch.Elapsed; stopwatch.Reset(); CompareCaches(cache, newCache); Console.WriteLine("serialize {0} deserialize {1} ", serializeInterval.TotalMilliseconds, deserializeInterval.TotalMilliseconds); }
public Metamodel(IClassStrategy classStrategy, ISpecificationCache cache, ILogger <Metamodel> logger) { this.classStrategy = classStrategy; this.cache = cache; this.logger = logger; }
public Metamodel(IClassStrategy classStrategy, ISpecificationCache cache) { this.classStrategy = classStrategy; this.cache = cache; }
public Metamodel(ISpecificationCache cache, ILogger <Metamodel> logger) { this.cache = cache; this.logger = logger; }