/// <summary> /// Initialize the Entity /// </summary> /// <param name="Context">The executable context of the entity</param> public virtual void Init(IExecutableContext Context) { mLogger.Info(string.Format("Initializing Entity '{0}'", mName)); mContext = Context; mContext.Entity = this; //Read in the entities components here string path = Context.ConfigManager.FindEntityType(mData.Type); EntityTypeData typeData = DataContractFactory.DeserializeObject <EntityTypeData>(path); foreach (string entry in typeData.Components) { try { mLogger.Info(string.Format("Creating component '{0}' for entity '{1}'", entry, mName)); Type componentType = Type.GetType(entry); Object[] objArray = {}; IComponent component = (IComponent)Activator.CreateInstance(componentType, objArray); component.Init(mContext, mData.DataSet); mComponents.Add(component); } catch (Exception e) { mLogger.Error(string.Format("Failed to create component '{0}' for entity '{1}", entry, mName), e); } } mContext.MessageRouter.RegisterTopic(mName, this); mLogger.Info(string.Format("Finished Initializing Entity '{0}'", mName)); }
/// <summary> /// Creates an instance of a World from a config file /// </summary> /// <param name="path">the path to the File defining the world to create</param> /// <returns>an IWorld object</returns> public static IWorld CreateWorld(string worldName, IExecutableContext context) { string path = context.ConfigManager.FindWorld(worldName); WorldData worldData = DataContractFactory.DeserializeObject <WorldData>(path); Type worldType = Type.GetType(worldData.Assembly); Object[] objArray = { worldData }; IWorld world = (IWorld)Activator.CreateInstance(worldType, objArray); world.Init(context); return(world); }
/// <summary> /// Initialize the Engine. Creates the World and all the Services /// </summary> /// <param name="PathToConfig">Path to the Config directory</param> /// <param name="world"></param> public void Init(string PathToConfig, string world) { mContext = new BaseExecutableContext(PathToConfig); string pathToEngineConfigFile = mContext.ConfigManager.FindEngineConfig(); EngineConfigDataContract engineConfig = DataContractFactory.DeserializeObject <EngineConfigDataContract>(pathToEngineConfigFile); //Initialize the Logger Type loggerType = Type.GetType(engineConfig.LoggerType); if (loggerType == null) { throw new NullReferenceException("loggerType"); } LoggerFactory.SetLoggerType(loggerType); LoggerFactory.SetLoggingLevel(engineConfig.LogLevel); mLogger = LoggerFactory.CreateLogger("ENGINE"); mLogger.Info(string.Format("Initializing engine with world: {0} and config path: {1}", world, PathToConfig)); foreach (string assembly in engineConfig.ServicesList) { try { mLogger.Debug(string.Format("Attempting to create service {0}", assembly)); Type assemblyType = Type.GetType(assembly); if (assembly == null) { throw new Exception(string.Format("Service assembly {0} not found!", assembly)); } IService service = (IService)Activator.CreateInstance(Type.GetType(assembly)); mServicesList.Add(service); mLogger.Debug(string.Format("Successfuly created service {0}", assembly)); } catch (Exception e) { mLogger.Warn("Error creating Service", e); } } foreach (IService service in mServicesList) { try { mLogger.Debug(string.Format("Initializing service {0}", service.ToString())); service.Init(mContext); mLogger.Debug(string.Format("Successfully initialized service {0}", service.ToString())); } catch (Exception e) { mLogger.Warn("Error initializing Service", e); } } try { mLogger.Debug(string.Format("Attempting to create world {0}", world)); mWorld = WorldFactory.CreateWorld(world, mContext); mLogger.Debug(string.Format("Successfully created world {0}", world)); } catch (Exception e) { mLogger.Warn("Error initializing world", e); } mLogger.Info("Done initializing Engine"); }