예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <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());
            }
        }
예제 #3
0
        /// <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);
            }
        }
예제 #4
0
        /// <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();
            }
            //}
        }
예제 #5
0
        /// <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();
        }
예제 #6
0
 /// <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);
 }
예제 #7
0
 /// <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));
 }
예제 #8
0
        /// <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));
        }