/// <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); }
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); } }
/// <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); }
/// <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 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 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); }
/// <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 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); }