/JTacticalSim.DataContext/BaseDataContext.cs
C# | 447 lines | 347 code | 87 blank | 13 comment | 0 complexity | ff18d4ccded5f7d547e5c10506c8a9e4 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Dynamic;
- using System.Xml.Linq;
- using JTacticalSim.API.DTO;
- using JTacticalSim.API.Data;
- using JTacticalSim.Data.DTO;
- using JTacticalSim.API;
- using JTacticalSim.API.Game;
- using JTacticalSim.API.Component;
- using JTacticalSim.API.InfoObjects;
-
- namespace JTacticalSim.DataContext
- {
- public abstract class BaseDataContext : IDataContext
- {
- private readonly DataFileFactory _dataFileFactory = DataFileFactory.Instance;
-
- #region Objects/Accessors
-
- // Component Objects
-
- protected IBoardDTO _board;
- public IBoardDTO Board
- {
- get { return this._board; }
- protected set { this._board = value; }
- }
-
- protected IBasePointValues _basePointValues;
- public IBasePointValues BasePointValues
- {
- get { return this._basePointValues; }
- protected set { this._basePointValues = value; }
- }
-
- protected TableInfo<IDemographicDTO> _demographicsTable;
-
- [TableRecognizable(typeof(IDemographic))]
- public TableInfo<IDemographicDTO> DemographicsTable
- {
- get { return this._demographicsTable; }
- protected set { this._demographicsTable = value; }
- }
-
- protected TableInfo<INodeDTO> _nodesTable;
-
- [TableRecognizable(typeof(INode))]
- public TableInfo<INodeDTO> NodesTable
- {
- get { return this._nodesTable; }
- protected set { this._nodesTable = value; }
- }
-
- protected TableInfo<IUnitDTO> _unitsTable;
-
- [TableRecognizable(typeof(IUnit))]
- public TableInfo<IUnitDTO> UnitsTable
- {
- get { return this._unitsTable; }
- protected set { this._unitsTable = value; }
- }
-
- protected TableInfo<IFactionDTO> _factionsTable;
-
- [TableRecognizable(typeof(IFaction))]
- public TableInfo<IFactionDTO> FactionsTable
- {
- get { return this._factionsTable; }
- protected set { this._factionsTable = value; }
- }
-
- protected TableInfo<ICountryDTO> _countriesTable;
-
- [TableRecognizable(typeof(ICountry))]
- public TableInfo<ICountryDTO> CountriesTable
- {
- get { return this._countriesTable; }
- protected set { this._countriesTable = value; }
- }
-
- protected TableInfo<IPlayerDTO> _playersTable;
-
- [TableRecognizable(typeof(IPlayer))]
- public TableInfo<IPlayerDTO> PlayersTable
- {
- get { return this._playersTable; }
- protected set { this._playersTable = value; }
- }
-
- protected TableInfo<ITileDTO> _tilesTable;
-
- [TableRecognizable(typeof(ITile))]
- public TableInfo<ITileDTO> TilesTable
- {
- get { return this._tilesTable; }
- protected set { this._tilesTable = value; }
- }
-
- protected TableInfo<ISavedGameDTO> _savedGames;
-
- [TableRecognizable(typeof(ISavedGame))]
- public TableInfo<ISavedGameDTO> SavedGames
- {
- get { return this._savedGames; }
- protected set { this._savedGames = value; }
- }
-
- protected TableInfo<IScenarioDTO> _scenarios;
-
- [TableRecognizable(typeof(IScenario))]
- public TableInfo<IScenarioDTO> Scenarios
- {
- get { return this._scenarios; }
- protected set { this._scenarios = value; }
- }
-
-
- // Data Objects
-
- protected TableInfo<IUnitBaseTypeDTO> _unitBaseTypesTable;
-
- [TableRecognizable(typeof(IUnitBaseType))]
- public TableInfo<IUnitBaseTypeDTO> UnitBaseTypesTable
- {
- get { return this._unitBaseTypesTable; }
- protected set { this._unitBaseTypesTable = value; }
- }
-
- protected TableInfo<IUnitClassDTO> _unitClassesTable;
-
- [TableRecognizable(typeof(IUnitClass))]
- public TableInfo<IUnitClassDTO> UnitClassesTable
- {
- get { return this._unitClassesTable; }
- protected set { this._unitClassesTable = value; }
- }
-
- protected TableInfo<IUnitTypeDTO> _unitTypesTable;
-
- [TableRecognizable(typeof(IUnitType))]
- public TableInfo<IUnitTypeDTO> UnitTypesTable
- {
- get { return this._unitTypesTable; }
- protected set { this._unitTypesTable = value; }
- }
-
- protected TableInfo<IUnitTaskDTO> _unitTasksTable;
-
- [TableRecognizable(typeof(IUnitTask))]
- public TableInfo<IUnitTaskDTO> UnitTasksTable
- {
- get { return this._unitTasksTable; }
- protected set { this._unitTasksTable = value; }
- }
-
- protected TableInfo<IMissionObjectiveDTO> _missionObjectivesTable;
-
- [TableRecognizable(typeof(IMissionObjective))]
- public TableInfo<IMissionObjectiveDTO> MissionObjectivesTable
- {
- get { return this._missionObjectivesTable; }
- protected set { this._missionObjectivesTable = value; }
- }
-
- protected TableInfo<IUnitGroupTypeDTO> _unitGroupTypesTable;
-
- [TableRecognizable(typeof(IUnitGroupType))]
- public TableInfo<IUnitGroupTypeDTO> UnitGroupTypesTable
- {
- get { return this._unitGroupTypesTable; }
- protected set { this._unitGroupTypesTable = value; }
- }
-
- protected TableInfo<IUnitGeogTypeDTO> _unitGeogTypesTable;
-
- [TableRecognizable(typeof(IUnitGeogType))]
- public TableInfo<IUnitGeogTypeDTO> UnitGeogTypesTable
- {
- get { return this._unitGeogTypesTable; }
- protected set { this._unitGeogTypesTable = value; }
- }
-
- protected TableInfo<IDemographicClassDTO> _demographicClassesTable;
-
- [TableRecognizable(typeof(IDemographicClass))]
- public TableInfo<IDemographicClassDTO> DemographicClassesTable
- {
- get { return this._demographicClassesTable; }
- protected set { this._demographicClassesTable = value; }
- }
-
- protected TableInfo<IDemographicTypeDTO> _demographicTypesTable;
-
- [TableRecognizable(typeof(IDemographicType))]
- public TableInfo<IDemographicTypeDTO> DemographicTypesTable
- {
- get { return this._demographicTypesTable; }
- protected set { this._demographicTypesTable = value; }
- }
-
- protected TableInfo<IVictoryConditionDTO> _victoryConditionsTable;
-
- [TableRecognizable(typeof(IVictoryCondition))]
- public TableInfo<IVictoryConditionDTO> VictoryConditionsTable
- {
- get { return this._victoryConditionsTable; }
- protected set { this._victoryConditionsTable = value; }
- }
-
- // Lookups
-
- protected List<dynamic> _unitBaseTypeUnitClassesLookup;
- public List<dynamic> UnitBaseTypeUnitClassesLookup
- {
- get { return this._unitBaseTypeUnitClassesLookup; }
- protected set { this._unitBaseTypeUnitClassesLookup = value; }
- }
-
- protected List<dynamic> _unitBaseTypeUnitGeogTypesLookup;
- public List<dynamic> UnitBaseTypeUnitGeogTypesLookup
- {
- get { return this._unitBaseTypeUnitGeogTypesLookup; }
- protected set { this._unitBaseTypeUnitGeogTypesLookup = value; }
- }
-
- protected List<dynamic> _unitGeogTypeDemographicClassesLookup;
- public List<dynamic> UnitGeogTypeDemographicClassesLookup
- {
- get { return this._unitGeogTypeDemographicClassesLookup; }
- protected set { this._unitGeogTypeDemographicClassesLookup = value; }
- }
-
- // Missions
-
- protected List<dynamic> _unitGroupTypeUnitTaskLookup;
- public List<dynamic> UnitGroupTypeUnitTaskLookup
- {
- get { return this._unitGroupTypeUnitTaskLookup; }
- protected set { this._unitGroupTypeUnitTaskLookup = value; }
- }
-
- protected List<dynamic> _unitTaskUnitClassesLookup;
- public List<dynamic> UnitTaskUnitClassesLookup
- {
- get { return this._unitTaskUnitClassesLookup; }
- protected set { this._unitTaskUnitClassesLookup = value; }
- }
-
- protected List<dynamic> _missionObjectiveUnitTasks;
- public List<dynamic> MissionObjectiveUnitTasks
- {
- get { return this._missionObjectiveUnitTasks; }
- protected set { this._missionObjectiveUnitTasks = value; }
- }
-
- // ----------------------------------------------------
-
-
- protected List<dynamic> _unitAssignments;
- public List<dynamic> UnitAssignments
- {
- get { return this._unitAssignments; }
- protected set { this._unitAssignments = value; }
- }
-
- protected List<dynamic> _unitTransports;
- public List<dynamic> UnitTransports
- {
- get { return this._unitTransports; }
- protected set { this._unitTransports = value; }
- }
-
- protected List<dynamic> _unitBattleEffectiveLookup;
- public List<dynamic> UnitBattleEffectiveLookup
- {
- get { return this._unitBattleEffectiveLookup; }
- protected set { this._unitBattleEffectiveLookup = value; }
- }
-
- protected List<dynamic> _unitGeogTypeMovementOverrides;
- public List<dynamic> UnitGeogTypeMovementOverrides
- {
- get { return this._unitGeogTypeMovementOverrides; }
- protected set { this._unitGeogTypeMovementOverrides = value; }
- }
-
- protected List<dynamic> _unitTransportUnitTypeUnitClasses;
- public List<dynamic> UnitTransportUnitTypeUnitClasses
- {
- get { return this._unitTransportUnitTypeUnitClasses; }
- protected set { this._unitTransportUnitTypeUnitClasses = value; }
- }
-
- protected List<dynamic> _factionVictoryConditions;
- public List<dynamic> FactionVictoryConditions
- {
- get { return this._factionVictoryConditions; }
- protected set { this._factionVictoryConditions = value; }
- }
-
- protected List<int> _hybridDemographicClasses;
- public List<int> HybridDemographicClasses
- {
- get { return this._hybridDemographicClasses; }
- protected set { this._hybridDemographicClasses = value; }
- }
-
- protected List<dynamic> _movementHinderanceInDirection;
- public List<dynamic> MovementHinderanceInDirection
- {
- get { return this._movementHinderanceInDirection; }
- protected set { this._movementHinderanceInDirection = value; }
- }
-
- #endregion
-
- protected BaseDataContext()
- {
- // We don't want saved games refreshed when loading new games
- _savedGames = new TableInfo<ISavedGameDTO>();
- _scenarios = new TableInfo<IScenarioDTO>();
-
- Reset();
- }
-
- public virtual void Reset()
- {
- // Component Objects
-
- _nodesTable = new TableInfo<INodeDTO>();
- _unitsTable = new TableInfo<IUnitDTO>();
- _factionsTable = new TableInfo<IFactionDTO>();
- _countriesTable = new TableInfo<ICountryDTO>();
- _playersTable = new TableInfo<IPlayerDTO>();
- _demographicsTable = new TableInfo<IDemographicDTO>();
- _tilesTable = new TableInfo<ITileDTO>();
- _board = new BoardDTO();
- _basePointValues = new BasePointValuesDTO();
-
- // Data Objects
-
- _unitBaseTypesTable = new TableInfo<IUnitBaseTypeDTO>();
- _unitClassesTable = new TableInfo<IUnitClassDTO>();
- _unitTypesTable = new TableInfo<IUnitTypeDTO>();
- _unitGroupTypesTable = new TableInfo<IUnitGroupTypeDTO>();
- _unitGeogTypesTable = new TableInfo<IUnitGeogTypeDTO>();
- _unitTasksTable = new TableInfo<IUnitTaskDTO>();
- _missionObjectivesTable = new TableInfo<IMissionObjectiveDTO>();
- _demographicClassesTable = new TableInfo<IDemographicClassDTO>();
- _demographicTypesTable = new TableInfo<IDemographicTypeDTO>();
- _victoryConditionsTable = new TableInfo<IVictoryConditionDTO>();
-
-
- // Lookups
-
- _unitBaseTypeUnitClassesLookup = new List<dynamic>();
- _unitBaseTypeUnitGeogTypesLookup = new List<dynamic>();
- _unitGeogTypeDemographicClassesLookup = new List<dynamic>();
- _unitTaskUnitClassesLookup = new List<dynamic>();
- _missionObjectiveUnitTasks = new List<dynamic>();
- _unitGroupTypeUnitTaskLookup = new List<dynamic>();
- _unitAssignments = new List<dynamic>();
- _unitTransports = new List<dynamic>();
- _unitGeogTypeMovementOverrides = new List<dynamic>();
- _unitBattleEffectiveLookup = new List<dynamic>();
- _unitTransportUnitTypeUnitClasses = new List<dynamic>();
- _factionVictoryConditions = new List<dynamic>();
- _hybridDemographicClasses = new List<int>();
- _movementHinderanceInDirection = new List<dynamic>();
- }
-
- public virtual IResult<string> LoadSavedGameData(string gameDataDirectory, bool IsScenario)
- {
- var r = new DataResult<string>{Status = ResultStatus.SUCCESS, Result = gameDataDirectory};
-
- // We'll always store this in XML in the GameData root
- try
- {
- IDataFileInfo<XDocument> dataFiles = _dataFileFactory.GetDataFiles<XDocument>(gameDataDirectory, IsScenario);
-
- // Scenarios
-
- var scenarios = dataFiles.ScenarioDataFile.Descendants("Scenario")
- .Select(dto => new ScenarioDTO
- {
- ID = Convert.ToInt32(dto.Attribute("ID").Value),
- UID = Guid.NewGuid(),
- Name = dto.Attribute("Name").Value,
- GameFileDirectory = dto.Attribute("GameFileDirectory").Value,
- Author = dto.Attribute("GameFileDirectory").Value
- } as IScenarioDTO);
-
- // Games
-
- var savedGames = dataFiles.SavedGameDataFile.Descendants("SavedGame")
- .Select(dto => new SavedGameDTO
- {
- ID = Convert.ToInt32(dto.Attribute("ID").Value),
- UID = Guid.NewGuid(),
- Name = dto.Attribute("Name").Value,
- LastPlayed = Convert.ToBoolean(dto.Attribute("LastPlayed").Value),
- GameFileDirectory = dto.Attribute("GameFileDirectory").Value,
- Scenario = Convert.ToInt32(dto.Attribute("Scenario").Value)
- } as ISavedGameDTO);
-
- // Add to context
- this._scenarios.Records = scenarios.ToList();
- this._savedGames.Records = savedGames.ToList();
- }
- catch (Exception ex)
- {
- r.Status = ResultStatus.EXCEPTION;
- r.ex = ex;
- r.Messages.Add("Saved game data not loaded.");
- }
-
- r.Messages.Add("Saved game data loaded.");
- return r;
- }
-
- public virtual IResult<string> LoadData(string gameFileDirectory, bool IsScenario)
- {
- throw new NotImplementedException();
- }
-
- public virtual IResult<IGameFileCopyable> SaveData(IGameFileCopyable currentGame)
- {
- throw new NotImplementedException();
- }
-
- public virtual IResult<IGameFileCopyable> SaveDataAs(IGameFileCopyable current, IGameFileCopyable newGame)
- {
- throw new NotImplementedException();
- }
-
- public virtual IResult<IGameFileCopyable> RemoveSavedGameData(IGameFileCopyable delGame)
- {
- throw new NotImplementedException();
- }
-
-
- public void Dispose()
- {}
- }
- }