PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/JTacticalSim.DataContext/DataFileFactory.cs

https://github.com/Queztionmark/JTacticalSim
C# | 49 lines | 43 code | 6 blank | 0 comment | 5 complexity | 403ae34310b7e40b911a2d50f5af2c5a MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Linq;
  6. using System.Configuration;
  7. using JTacticalSim.API.InfoObjects;
  8. using JTacticalSim.Data;
  9. using JTacticalSim.API;
  10. using JTacticalSim.API.Data;
  11. namespace JTacticalSim.DataContext
  12. {
  13. public class DataFileFactory
  14. {
  15. private static volatile DataFileFactory _instance = null;
  16. static readonly object padlock = new object();
  17. public static DataFileFactory Instance
  18. {
  19. get
  20. {
  21. if (_instance == null)
  22. {
  23. lock (padlock)
  24. if (_instance == null) _instance = new DataFileFactory();
  25. }
  26. return _instance;
  27. }
  28. }
  29. private Type _fileType = Utility.GetDataFileType().GetType();
  30. public IDataFileInfo<fileType> GetDataFiles<fileType>(string gameFileDirectory, bool IsScenario)
  31. {
  32. switch (Utility.GetDataSourceType())
  33. {
  34. case DataSourceType.XML:
  35. return new XMLDataFileInfo(gameFileDirectory, IsScenario) as IDataFileInfo<fileType>;
  36. default:
  37. {
  38. throw new Exception("No data source type found for current configuration or current data source configuration is not a file type");
  39. }
  40. }
  41. }
  42. }
  43. }