/// <summary> /// Loads all the entities found in the entities cache file. /// </summary> /// <param name="includeDisabled"></param> /// <returns>An array of the the entities found in the cache file.</returns> public EntityInfo[] LoadInfoFromFile(bool includeDisabled) { // Logging disabled to boost performance //using (LogGroup logGroup = LogGroup.StartDebug("Loading the entities from the XML file.")) //{ if (Entities == null) { List<EntityInfo> validEntities = new List<EntityInfo>(); EntityInfo[] entities = new EntityInfo[]{}; using (StreamReader reader = new StreamReader(File.OpenRead(FileNamer.EntitiesInfoFilePath))) { XmlSerializer serializer = new XmlSerializer(typeof(EntityInfo[])); entities = (EntityInfo[])serializer.Deserialize(reader); } foreach (EntityInfo entity in entities) if (entity.Enabled || includeDisabled) validEntities.Add(entity); Entities = validEntities.ToArray(); } //} return Entities; }
/// <summary> /// Disposes the entities found by the scanner. /// </summary> public void Dispose() { using (LogGroup logGroup = LogGroup.StartDebug("Disposing the entities.")) { EntityInfo[] entities = new EntityInfo[]{}; Dispose(EntityState.Entities.ToArray()); } }
/// <summary> /// Disposes the provided entities. /// </summary> public void Dispose(EntityInfo[] entities) { using (LogGroup logGroup = LogGroup.StartDebug("Disposing the entities.")) { foreach (EntityInfo entity in entities) { EntityState.Entities.Remove( EntityState.Entities[entity.TypeName] ); } File.Delete(FileNamer.EntitiesInfoFilePath); } }
/// <summary> /// Saves the provided entities to file. /// </summary> /// <param name="entities">An array of the entities to save to file.</param> public void SaveToFile(EntityInfo[] entities) { // Logging disabled to boost performance //using (LogGroup logGroup = LogGroup.StartDebug("Saving the provided entities to XML file.")) //{ string path = FileNamer.EntitiesInfoFilePath; //LogWriter.Debug("Path : " + path); if (!Directory.Exists(Path.GetDirectoryName(path))) Directory.CreateDirectory(Path.GetDirectoryName(path)); using (StreamWriter writer = File.CreateText(path)) { XmlSerializer serializer = new XmlSerializer(entities.GetType()); serializer.Serialize(writer, entities); writer.Close(); } //} }
/// <summary> /// Finds all the entities in the available assemblies. /// </summary> /// <param name="includeTestEntities">A flag indicating whether to find test/mock entities as well.</param> /// <returns>An array of info about the entities found.</returns> public EntityInfo[] FindEntities(bool includeTestEntities) { List<EntityInfo> entities = new List<EntityInfo>(); //using (LogGroup logGroup = LogGroup.StartDebug("Finding entities by scanning the attributes of the available type.")) //{ foreach (string assemblyPath in AssemblyPaths) { try { Assembly assembly = Assembly.LoadFrom(assemblyPath); if (ContainsEntities(assembly, includeTestEntities)) { foreach (Type type in assembly.GetTypes()) { if (IsEntity(type)) { //LogWriter.Debug("Found entity type: " + type.ToString()); EntityInfo entityInfo = new EntityInfo(type); if (entityInfo.TypeName != null && entityInfo.TypeName != String.Empty) { //LogWriter.Debug("Found match."); entities.Add(entityInfo); } } } } } catch(ReflectionTypeLoadException ex) { LogWriter.Error("An error occurred when scanning for entities..."); LogWriter.Error(ex.ToString()); } } //} return entities.ToArray(); }
/// <summary> /// Loads the entity type matching the provided info. /// </summary> /// <param name="info">The info to load the type for.</param> /// <returns>The type matching the provided info.</returns> public Type Load(EntityInfo info) { return Type.GetType(info.FullType); }
/// <summary> /// Loads the entity type matching the provided info. /// </summary> /// <param name="info">The info to load the type for.</param> /// <returns>The type matching the provided info.</returns> public Type Load(EntityInfo info) { return(Type.GetType(info.FullType)); }
/// <summary> /// Loads the specified entity type. /// </summary> /// <param name="typeName">The name of the type involved in the action.</param> /// <returns>The type with the specified name.</returns> public Type Load(string typeName) { EntityInfo info = EntityState.Entities[typeName]; return(Load(info)); }