/// <summary> /// /// </summary> public void Load(BooleanSet boolSet) { _loadingSet = boolSet; _loaderSet = new BooleanSet("Loaders", OnLoadersLoadCompleted); _repository.Values.ToList().ForEach(loader => { _loaderSet.AddItem(loader.IdColumn); _log.DebugFormat("Loader {0} beginning loading: NameColumn={1}, IdColumn={2}.", loader.GetType(), loader.NameColumn, loader.IdColumn); loader.Load(_loaderSet); }); }
private void OnLoadChannelsComplete(RealmEventArgs args) { Validation.IsNotNull(args, "args"); Validation.IsNotNull(args.Data, "args.Data"); var data = args.Data.ToDictionaryAtom(); if (!data.GetBool("success")) { throw new ProcedureFailureException("Load Failure", GetType()); } var commandResults = data.GetAtom <ListAtom>("commandResult"); var results = commandResults.GetEnumerator().Current.CastAs <DictionaryAtom>().GetAtom <ListAtom>("Results"); using (var it = results.GetEnumerator()) { while (it.MoveNext()) { var result = it.Current.CastAs <DictionaryAtom>(); var channelDef = (ChannelDef)_staticDataManager.GetStaticData(Globals.SystemTypes.Channel, result.GetInt("ChannelPrimitiveID").ToString()); var obj = _entityManager.Create <Channel>(result.GetInt("ChannelID"), result.GetString("Name"), result, channelDef); if (obj == null) { throw new InstantiationException("Failed to instantiate Channel {0}", result.GetInt("ChannelID")); } obj.OnInit(_entityManager.InitializationAtom); _repository.Add(obj.ID, obj); } } _log.DebugFormat("Loaded {0} channels.", _repository.Count); _callback?.Invoke(new RealmEventArgs()); }
public void LoadGameState(EventCallback <RealmEventArgs> callback) { _callback = callback; _log.Debug("GameStateLoader initialized"); try { var gameState = _liveDbContext.GameStates.LastOrDefault(); if (gameState == null) { throw new ProcedureFailureException("Load Failure", GetType()); } var obj = new GameState(new MudTime { Year = gameState.Year, Month = gameState.MonthId, Day = gameState.Day, Hour = gameState.Hour, Minute = gameState.Minute }); _log.DebugFormat("GameStateLoader loaded the new game state: {0}", obj.ToString()); _callback?.Invoke(new RealmEventArgs(new EventTable { { "GameState", obj } })); } catch (Exception ex) { ex.Handle(ExceptionHandlingOptions.RecordAndThrow); } }
/// <summary> /// Do initialization that cannot be done at construction /// </summary> public void OnInit(DictionaryAtom args) { Validation.IsNotNull(args, "args"); _connectionString = args.GetString("ConnectionString"); Validation.IsNotNullOrEmpty(_connectionString, "_connectionString"); _numberServers = args.GetInt("NumberDBServers"); Validation.Validate <ArgumentOutOfRangeException>(_numberServers >= 1); _log.DebugFormat("{0} asked to spin up {1} database servers.", GetType(), _numberServers); InitDatabaseLoaders(args); _loaderArgs = args.GetAtom <ListAtom>("Loaders"); _eventManager.RegisterListener(this, typeof(OnGameInitialize), Instance_OnGameInitialize); }
public DatabaseServerContext(ILogWrapper log, string connectionString, int numberServers, IEnumerable <IProcedureLoader> procedureLoaders) : base(1, "DatabaseServerContext") { Validation.IsNotNull(log, "log"); Validation.IsNotNullOrEmpty(connectionString, "connectionString"); Validation.Validate <ArgumentOutOfRangeException>(numberServers > 0); Validation.IsNotNull(procedureLoaders, "procedureLoaders"); Validation.Validate(procedureLoaders.Any()); Enumerable.Range(0, numberServers) .ToList() .ForEach( i => _dbServers.Enqueue(new DatabaseServer(i + 1, connectionString, log, procedureLoaders))); log.DebugFormat("{0} database servers in the queue.", _dbServers.Count); }
/// <summary> /// /// </summary> /// <param name="args"></param> private void OnLoadComplete(RealmEventArgs args) { Validation.IsNotNull(args, "args"); Validation.IsNotNull(args.Data, "args.Data"); var data = args.Data.ToDictionaryAtom(); if (!data.GetBool("success")) { _log.ErrorFormat("Failure to load data in {0}", GetType()); return; } var commandResult = data.GetAtom <ListAtom>("commandResult").Get(0).CastAs <DictionaryAtom>(); PopulateHashRepository(commandResult.GetAtom <ListAtom>("Results")); _log.DebugFormat("{0} hashes loaded.", _repository.Count); _callback?.Invoke(new RealmEventArgs()); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="connectionString"></param> /// <param name="log"></param> /// <param name="procedureLoaders"></param> public DatabaseServer(long id, string connectionString, ILogWrapper log, IEnumerable <IProcedureLoader> procedureLoaders) : base(id, "DatabaseServer" + id) { Validation.Validate <ArgumentOutOfRangeException>(id >= 1); Validation.IsNotNullOrEmpty(connectionString, "connectionString"); Validation.IsNotNull(log, "log"); Validation.IsNotNull(procedureLoaders, "procedureLoaders"); Validation.Validate(procedureLoaders.Any()); _log = log; _connection = new SqlConnection(connectionString); _connection.Open(); _connection.Close(); _tasks = new Dictionary <Task, CancellationTokenSource>(); _procedureRepositories = new List <IProcedureRepository>(); procedureLoaders.ToList().ForEach(x => _procedureRepositories.Add(x.ProcedureRepository)); procedureLoaders.ToList().ForEach(x => _log.DebugFormat("ProcedureLoader {0} has {1} stored procedures.", x.GetType(), x.ProcedureRepository.Count)); }
/// <summary> /// Enqueues an event onto the event queue /// </summary> public void ThrowEvent(object sender, IEventBase thrownEvent) { _log.DebugFormat(Resources.MSG_DEBUG_THROW, sender.GetType(), thrownEvent.GetType()); _eventHandler.ThrowEvent(sender, thrownEvent); }