/// <summary> /// Deserialize a double index /// </summary> /// <typeparam name="TKey">The type of the key</typeparam> /// <typeparam name="TIndex1">The type of the first index</typeparam> /// <typeparam name="TIndex2">The type of the second index</typeparam> /// <param name="type">The type of the parent table</param> /// <param name="indexName">The name of the index</param> /// <returns>The index map</returns> public override async Task <Dictionary <TKey, Tuple <TIndex1, TIndex2> > > DeserializeIndexAsync <TKey, TIndex1, TIndex2>(Type type, string indexName) { var indexPath = _pathProvider.GetIndexPath(_basePath, DatabaseInstanceName, type, this, indexName); var dictionary = new Dictionary <TKey, Tuple <TIndex1, TIndex2> >(); if (_fileHelper.FileExists(indexPath)) { var pathLock = PathLock.GetLock(type.FullName); using (await pathLock.LockAsync().ConfigureAwait(false)) { using (var indexFile = _fileHelper.GetReader(indexPath)) { var count = indexFile.ReadInt32(); for (var x = 0; x < count; x++) { dictionary.Add((TKey)DatabaseSerializer.Deserialize(typeof(TKey), indexFile), Tuple.Create( (TIndex1)DatabaseSerializer.Deserialize(typeof(TIndex1), indexFile), (TIndex2)DatabaseSerializer.Deserialize(typeof(TIndex2), indexFile))); } } } } return(dictionary); }
public override async Task SerializeKeysAsync(Type type, Type keyType, IDictionary keyMap) { var pathLock = Lock.GetLock(type.FullName); using (await pathLock.LockAsync().ConfigureAwait(false)) { Action <BinaryWriter> action = writer => { writer.Write(keyMap.Count); foreach (var key in keyMap.Keys) { DatabaseSerializer.Serialize(key, writer); writer.Write((int)keyMap[key]); } }; await _keysTable.Value.CreateIfNotExistsAsync().ConfigureAwait(false); await Store(_keysTable.Value, action, type.FullName, keyType.FullName).ConfigureAwait(false); } await SerializeTypesAsync().ConfigureAwait(false); }
/// <summary> /// Deserialize a single index /// </summary> /// <typeparam name="TKey">The type of the key</typeparam> /// <typeparam name="TIndex">The type of the index</typeparam> /// <param name="type">The type of the parent table</param> /// <param name="indexName">The name of the index</param> /// <returns>The index map</returns> public override async Task <Dictionary <TKey, TIndex> > DeserializeIndexAsync <TKey, TIndex>(Type type, string indexName) { var indexPath = _pathProvider.GetIndexPath(_basePath, DatabaseInstanceName, type, this, indexName); var dictionary = new Dictionary <TKey, TIndex>(); if (_iso.FileExists(indexPath)) { using (await _lock.LockAsync().ConfigureAwait(false)) { using (var indexFile = _iso.GetReader(indexPath)) { var count = indexFile.ReadInt32(); for (var x = 0; x < count; x++) { var index = (TIndex)DatabaseSerializer.Deserialize(typeof(TIndex), indexFile); var key = (TKey)DatabaseSerializer.Deserialize(typeof(TKey), indexFile); dictionary.Add(key, index); } } } } return(dictionary); }
/// <summary> /// Serialize the keys /// </summary> /// <param name="type">Type of the parent table</param> /// <param name="keyType">Type of the key</param> /// <param name="keyMap">Key map</param> public override async Task SerializeKeysAsync(Type type, Type keyType, IDictionary keyMap) { _fileHelper.EnsureDirectory(_pathProvider.GetTablePath(_basePath, DatabaseInstanceName, type, this)); var pathLock = PathLock.GetLock(type.FullName); using (await pathLock.LockAsync().ConfigureAwait(false)) { var keyPath = _pathProvider.GetKeysPath(_basePath, DatabaseInstanceName, type, this); using (var keyFile = _fileHelper.GetWriter(keyPath)) { keyFile.Write(keyMap.Count); foreach (var key in keyMap.Keys) { DatabaseSerializer.Serialize(key, keyFile); keyFile.Write((int)keyMap[key]); } } } await SerializeTypesAsync().ConfigureAwait(false); }
public override async Task <Dictionary <TKey, Tuple <TIndex1, TIndex2> > > DeserializeIndexAsync <TKey, TIndex1, TIndex2>(Type type, string indexName) { var dictionary = new Dictionary <TKey, Tuple <TIndex1, TIndex2> >(); var pathLock = Lock.GetLock(type.FullName); using (await pathLock.LockAsync().ConfigureAwait(false)) { Action <BinaryReader> action = reader => { var count = reader.ReadInt32(); for (var x = 0; x < count; x++) { dictionary.Add((TKey)DatabaseSerializer.Deserialize(typeof(TKey), reader), Tuple.Create((TIndex1)DatabaseSerializer.Deserialize(typeof(TIndex1), reader), (TIndex2)DatabaseSerializer.Deserialize(typeof(TIndex2), reader))); } }; await _indexesTable.Value.CreateIfNotExistsAsync().ConfigureAwait(false); await Read(_indexesTable.Value, action, type.FullName, indexName).ConfigureAwait(false); return(dictionary); } }
public void CheckAmountOfNamespaces() { Reflector reflector = new Reflector(reflectorPath); DatabaseSerializer xmlSerialization = new DatabaseSerializer(); xmlSerialization.Save(AssemblyModelMapper.MapDown(reflector.AssemblyModel, assemblyModel.GetType()), null); AssemblyModel model = AssemblyModelMapper.MapUp(xmlSerialization.Read(null)); Assert.AreEqual(3, model.NamespaceModels.Count); }
/// <summary> /// Reads the specified XML stream for a Database schema. /// </summary> /// <param name="xmlStream">The XML stream.</param> /// <param name="validationErrors">The validation errors.</param> /// <returns></returns> public static Database Read(Stream xmlStream, IList <string> validationErrors) { using (Stream xsdStream = OpenXsd()) using (XmlReader xmlReader = OpenXml(xmlStream, xsdStream, validationErrors)) { var xmlSerializer = new DatabaseSerializer(); var dbml = (Database)xmlSerializer.Deserialize(xmlReader); return(dbml); } }
public void CheckAmountOfFieldsInClass() { Reflector reflector = new Reflector(reflectorPath); DatabaseSerializer xmlSerialization = new DatabaseSerializer(); xmlSerialization.Save(AssemblyModelMapper.MapDown(reflector.AssemblyModel, assemblyModel.GetType()), null); AssemblyModel model = AssemblyModelMapper.MapUp(xmlSerialization.Read(null)); List <TypeModel> classes = model.NamespaceModels .Find(t => t.Name == "TestLibrary").Types.Where(t => t.Name == "PublicClass").ToList(); Assert.AreEqual(2, classes.First().Fields.Count); }
public void CheckAmountOfInterfaces() { Reflector reflector = new Reflector(reflectorPath); DatabaseSerializer xmlSerialization = new DatabaseSerializer(); xmlSerialization.Save(AssemblyModelMapper.MapDown(reflector.AssemblyModel, assemblyModel.GetType()), null); AssemblyModel model = AssemblyModelMapper.MapUp(xmlSerialization.Read(null)); List <TypeModel> interfaces = model.NamespaceModels .Find(t => t.Name == "TestLibrary").Types.Where(t => t.Type == TypeEnum.Interface).ToList(); Assert.AreEqual(1, interfaces.Count); }
public void TestMethod1() { Reflector reflector = new Reflector(); reflector.Reflect(pathh); ISerializer ser = new DatabaseSerializer(); DBModelContext db = new DBModelContext(); ser.Serialize(reflector.AssemblyModel.MapUp(), null); AssemblyMetadata assemblyTest = new AssemblyMetadata(ser.Deserialize(null)); Assert.AreEqual(4, assemblyTest.m_Namespaces.ToList().Count()); }
public void CheckAmountOfClassesWithGenericArguments() { Reflector reflector = new Reflector(reflectorPath); DatabaseSerializer xmlSerialization = new DatabaseSerializer(); xmlSerialization.Save(AssemblyModelMapper.MapDown(reflector.AssemblyModel, assemblyModel.GetType()), null); AssemblyModel model = AssemblyModelMapper.MapUp(xmlSerialization.Read(null)); List <TypeModel> genericClasses = model.NamespaceModels .Find(t => t.Name == "TestLibrary.NamespaceTwo").Types.Where(t => t.GenericArguments?.Count > 0) .ToList(); Assert.AreEqual(1, genericClasses.Count); }
public void CheckAmountOfAbstractClasses() { Reflector reflector = new Reflector(reflectorPath); DatabaseSerializer xmlSerialization = new DatabaseSerializer(); xmlSerialization.Save(AssemblyModelMapper.MapDown(reflector.AssemblyModel, assemblyModel.GetType()), null); AssemblyModel model = AssemblyModelMapper.MapUp(xmlSerialization.Read(null)); List <TypeModel> abstractClasses = model.NamespaceModels .Find(t => t.Name == "TestLibrary").Types .Where(t => t.Modifiers.AbstractEnum == AbstractEnum.Abstract).ToList(); Assert.AreEqual(2, abstractClasses.Count); }
public void MethotsInClass() { Reflector reflector = new Reflector(); reflector.Reflect(pathh); ISerializer ser = new DatabaseSerializer(); DBModelContext db = new DBModelContext(); ser.Serialize(reflector.AssemblyModel.MapUp(), null); AssemblyMetadata assemblyTest = new AssemblyMetadata(ser.Deserialize(null)); List <TypeMetadata> test = assemblyTest.m_Namespaces.ToList().Find(t => t.m_NamespaceName == "TPA.ApplicationArchitecture.BusinessLogic").m_Types.ToList(); Assert.AreEqual(6, test.First().m_Methods.ToList().Count); }
public void CheckAmountOfClasses() { Reflector reflector = new Reflector(reflectorPath); DatabaseSerializer xmlSerialization = new DatabaseSerializer(); xmlSerialization.Save(AssemblyModelMapper.MapDown(reflector.AssemblyModel, assemblyModel.GetType()), null); AssemblyModel model = AssemblyModelMapper.MapUp(xmlSerialization.Read(null)); List <TypeModel> testLibraryTypes = model.NamespaceModels.Find(t => t.Name == "TestLibrary").Types; List <TypeModel> namespaceTwoTypes = model.NamespaceModels.Find(t => t.Name == "TestLibrary.NamespaceTwo").Types; List <TypeModel> namespaceWithRecursionTypes = model.NamespaceModels.Find(t => t.Name == "TestLibrary.NamespaceWithRecursion").Types; Assert.AreEqual(6, namespaceTwoTypes.Count); Assert.AreEqual(3, namespaceWithRecursionTypes.Count); Assert.AreEqual(4, testLibraryTypes.Count); }
/// <summary> /// Serialize a single index /// </summary> /// <typeparam name="TKey">The type of the key</typeparam> /// <typeparam name="TIndex">The type of the index</typeparam> /// <param name="type">The type of the parent table</param> /// <param name="indexName">The name of the index</param> /// <param name="indexMap">The index map</param> public override async Task SerializeIndexAsync <TKey, TIndex>(Type type, string indexName, Dictionary <TKey, TIndex> indexMap) { var indexPath = _pathProvider.GetIndexPath(_basePath, DatabaseInstanceName, type, this, indexName); using (await _lock.LockAsync().ConfigureAwait(false)) { using (var indexFile = _iso.GetWriter(indexPath)) { indexFile.Write(indexMap.Count); foreach (var index in indexMap) { DatabaseSerializer.Serialize(index.Value, indexFile); DatabaseSerializer.Serialize(index.Key, indexFile); } } } }
/// <summary> /// Serialize a double index /// </summary> /// <typeparam name="TKey">The type of the key</typeparam> /// <typeparam name="TIndex1">The type of the first index</typeparam> /// <typeparam name="TIndex2">The type of the second index</typeparam> /// <param name="type">The type of the parent table</param> /// <param name="indexName">The name of the index</param> /// <param name="indexMap">The index map</param> public override async Task SerializeIndexAsync <TKey, TIndex1, TIndex2>(Type type, string indexName, Dictionary <TKey, Tuple <TIndex1, TIndex2> > indexMap) { var indexPath = _pathProvider.GetIndexPath(_basePath, DatabaseInstanceName, type, this, indexName); var pathLock = PathLock.GetLock(type.FullName); using (await pathLock.LockAsync().ConfigureAwait(false)) { using (var indexFile = await StorageHelper.GetWriterForFileAsync(indexPath).ConfigureAwait(false)) { indexFile.Write(indexMap.Count); foreach (var index in indexMap) { DatabaseSerializer.Serialize(index.Value.Item1, indexFile); DatabaseSerializer.Serialize(index.Value.Item2, indexFile); DatabaseSerializer.Serialize(index.Key, indexFile); } } } }
/// <summary> /// Deserialize the keys /// </summary> /// <param name="type">Type of the parent table</param> /// <param name="keyType">Type of the key</param> /// <param name="dictionary">Empty dictionary</param> /// <returns>The key list</returns> public override async Task <IDictionary> DeserializeKeysAsync(Type type, Type keyType, IDictionary dictionary) { var keyPath = _pathProvider.GetKeysPath(_basePath, DatabaseInstanceName, type, this); if (_iso.FileExists(keyPath)) { using (await _lock.LockAsync().ConfigureAwait(false)) { using (var keyFile = _iso.GetReader(keyPath)) { var count = keyFile.ReadInt32(); for (var x = 0; x < count; x++) { dictionary.Add(DatabaseSerializer.Deserialize(keyType, keyFile), keyFile.ReadInt32()); } } } } return(dictionary); }
public void DBSerializationTest() { Compose(this); string path = "..\\..\\..\\MyLibrary\\TPA.ApplicationArchitecture.dll"; Mock <Reflector> reflector = new Mock <Reflector>(path); reflector.SetupAllProperties(); Reflector baseReflector = new Reflector(path); DatabaseSerializer db = new DatabaseSerializer(); reflector.Object.Serialization = db; reflector.Object.SerializeAssembly(path); reflector.Object.DeserializeAssembly(path); AssemblyMetadata test = new AssemblyMetadata(reflector.Object.M_AssemblyModel); Assert.AreEqual(test.Namespaces.ToList().Count(), baseReflector.M_AssemblyModel.Namespaces.Count()); }
public override async Task SerializeIndexAsync <TKey, TIndex>(Type type, string indexName, Dictionary <TKey, TIndex> indexMap) { var pathLock = Lock.GetLock(type.FullName); using (await pathLock.LockAsync().ConfigureAwait(false)) { Action <BinaryWriter> action = writer => { writer.Write(indexMap.Count); foreach (var index in indexMap) { DatabaseSerializer.Serialize(index.Key, writer); DatabaseSerializer.Serialize(index.Value, writer); } }; await _indexesTable.Value.CreateIfNotExistsAsync().ConfigureAwait(false); await Store(_indexesTable.Value, action, type.FullName, indexName).ConfigureAwait(false); } }
/// <summary> /// Gets the specified console using it's name as an identifier. /// </summary> /// <param name="name">The name of the console to get.</param> /// <param name="validate">if set to <c>true</c> [validate].</param> /// <returns></returns> /// <exception cref="Exception"></exception> public HyperValidator.Models.Console Get(String name, Boolean validate = false) { var console = new HyperValidator.Models.Console() { Name = name }; var databasePath = PathUtility.Combine(Settings.HyperSpinRootLocation, "databases", console.Name, $"{console.Name}.xml"); var database = DatabaseSerializer.DeserializeFromFile(databasePath); console.Database = database; var settingsPath = PathUtility.Combine(Settings.HyperSpinRootLocation, "settings", $"{console.Name}.ini"); if (!FileUtility.Exists(settingsPath)) { throw new Exception($"Failed to find settings file for {name}"); } var settings = ConsoleSerializer.DeserializeFromFile(settingsPath); console.Settings = settings; console.Status = ConsoleValidator.Validate(console); if (validate) { foreach (var game in console.Database.Games) { var status = GameValidator.Validate(console, game); OnGameValidated(status); game.Status = status; } OnValidationComplete(); } return(console); }
public override async Task <IDictionary> DeserializeKeysAsync(Type type, Type keyType, IDictionary dictionary) { var pathLock = Lock.GetLock(type.FullName); using (await pathLock.LockAsync().ConfigureAwait(false)) { Action <BinaryReader> action = reader => { var count = reader.ReadInt32(); for (var x = 0; x < count; x++) { dictionary.Add(DatabaseSerializer.Deserialize(keyType, reader), reader.ReadInt32()); } }; await _keysTable.Value.CreateIfNotExistsAsync().ConfigureAwait(false); await Read(_keysTable.Value, action, type.FullName, keyType.FullName).ConfigureAwait(false); return(dictionary); } }
/// <summary> /// Deserialize the keys /// </summary> /// <param name="type">Type of the parent table</param> /// <param name="keyType">Type of the key</param> /// <param name="dictionary">Empty dictionary</param> /// <returns>The key list</returns> public override async Task <IDictionary> DeserializeKeysAsync(Type type, Type keyType, IDictionary dictionary) { var keyPath = _pathProvider.GetKeysPath(_basePath, DatabaseInstanceName, type, this); if (await StorageHelper.FileExistsAsync(keyPath).ConfigureAwait(false)) { var pathLock = PathLock.GetLock(type.FullName); using (await pathLock.LockAsync().ConfigureAwait(false)) { using (var keyFile = await StorageHelper.GetReaderForFileAsync(keyPath).ConfigureAwait(false)) { var count = keyFile.ReadInt32(); for (var x = 0; x < count; x++) { dictionary.Add(DatabaseSerializer.Deserialize(keyType, keyFile), keyFile.ReadInt32()); } } } } return(dictionary); }
/// <summary> /// Writes the specified XML stream. /// </summary> /// <param name="xmlStream">The XML stream.</param> /// <param name="dbml">The DBML.</param> public static void Write(Stream xmlStream, Database dbml) { var xmlSerializer = new DatabaseSerializer(); xmlSerializer.Serialize(xmlStream, dbml); }