IOSimulatorItemReader.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace MECF.Framework.Simulator.Core.Commons
  10. {
  11. public class IOSimulatorItemReader
  12. {
  13. private static Dictionary<string, IOSimulatorItemViewModelConfig> _commandModelConfigDict = new Dictionary<string, IOSimulatorItemViewModelConfig>();
  14. public static IOSimulatorItemViewModelConfig GetCommandModelConfig(string hardwarePath, string hardwareName)
  15. {
  16. IOSimulatorItemViewModelConfig commandModelConfig = null;
  17. if (_commandModelConfigDict.Keys.Contains(hardwareName))
  18. {
  19. commandModelConfig = _commandModelConfigDict[hardwareName];
  20. }
  21. else
  22. {
  23. commandModelConfig = JsonConvert.DeserializeObject<IOSimulatorItemViewModelConfig>(File.ReadAllText(ConfigPath.AssemblyPath + $"\\{hardwarePath}\\{hardwareName}\\IOSimulatorItems.json"));
  24. _commandModelConfigDict.Add(hardwareName, commandModelConfig);
  25. }
  26. return commandModelConfig;
  27. }
  28. public static IOSimulatorItemViewModelConfig GetCommandModelConfigV2(string hardwareName)
  29. {
  30. IOSimulatorItemViewModelConfig commandModelConfig = null;
  31. if (_commandModelConfigDict.Keys.Contains(hardwareName))
  32. {
  33. commandModelConfig = _commandModelConfigDict[hardwareName];
  34. }
  35. else
  36. {
  37. commandModelConfig = JsonConvert.DeserializeObject<IOSimulatorItemViewModelConfig>(File.ReadAllText(ConfigPath.AssemblyPath + $"\\SimulatorItems\\{hardwareName}_IOSimulatorItems.json"));
  38. _commandModelConfigDict.Add(hardwareName, commandModelConfig);
  39. }
  40. return commandModelConfig;
  41. }
  42. }
  43. public class ConfigPath
  44. {
  45. public static string AssemblyPath
  46. {
  47. get
  48. {
  49. string path = Assembly.GetExecutingAssembly().Location;
  50. FileInfo finfo = new FileInfo(path);
  51. return finfo.DirectoryName;
  52. }
  53. }
  54. }
  55. }