/// <summary> /// Adds a connection server after a new configuration has been added. /// </summary> /// <param name="configuration">The configuration.</param> public void ConnectionServerAdded(ConnectServerDefinition configuration) { var connectServer = this.connectServerFactory.CreateConnectServer(configuration, new ClientVersion(configuration.Client.Season, configuration.Client.Episode, configuration.Client.Language), configuration.GetId()); this.servers.Add(connectServer); }
/// <summary> /// Saves the specified configuration. /// </summary> /// <param name="configuration">The configuration.</param> public void Save(ConnectServerDefinition configuration) { try { Log.Info($"requested to save configuration of connect server {configuration.ServerId}"); DataModel.Configuration.ConnectServerDefinition currentConfiguration = null; if (this.servers.OfType <IConnectServer>().FirstOrDefault(s => s.Settings.GetId() == configuration.GetId()) is { } server) { currentConfiguration = server.Settings as DataModel.Configuration.ConnectServerDefinition; } bool isNew = false; using (var configContext = this.persistenceContextProvider.CreateNewContext()) { if (currentConfiguration != null) { configContext.Attach(currentConfiguration); } else { currentConfiguration = configContext.CreateNew <DataModel.Configuration.ConnectServerDefinition>(); currentConfiguration.ServerId = configuration.ServerId; var existingConfigs = configContext.Get <DataModel.Configuration.ConnectServerDefinition>().ToList(); if (existingConfigs.Count > 0) { var newId = existingConfigs.Max(c => c.ServerId) + 1; currentConfiguration.ServerId = (byte)newId; } isNew = true; } configuration.Adapt(currentConfiguration); if (!Equals(currentConfiguration.Client, configuration.Client)) { currentConfiguration.Client = configContext.GetById <DataModel.Configuration.GameClientDefinition>(configuration.Client.GetId()); } configContext.SaveChanges(); } if (isNew) { this.changeListener?.ConnectionServerAdded(currentConfiguration); } else { this.changeListener?.ConnectionServerChanged(currentConfiguration); } } catch (Exception ex) { Log.Error($"An unexpected exception occured during saving the connect server configuration for server id {configuration.ServerId}", ex); throw; } }