SimulatorCaseManager.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.Util;
  10. namespace Aitex.Core.RT.Simulator
  11. {
  12. public class SimulatorCaseManager : Singleton<SimulatorCaseManager>
  13. {
  14. private const string FileName = "ExceptionCase.Obj";
  15. private PeriodicJob _thread;
  16. private Dictionary<string, bool> _dicValue = new Dictionary<string, bool>();
  17. public SimulatorCaseManager()
  18. {
  19. }
  20. public void Initialize()
  21. {
  22. if (File.Exists(FileName))
  23. {
  24. SerializeStatic.Load(typeof (ExceptionCase), FileName);
  25. }
  26. foreach (var propertyInfo in typeof(ExceptionCase).GetProperties())
  27. {
  28. _dicValue[propertyInfo.Name] = (bool)propertyInfo.GetValue(null, null);
  29. }
  30. _thread = new PeriodicJob(1000, OnMonitor, "simualtor case serializer", true);
  31. }
  32. bool OnMonitor()
  33. {
  34. try
  35. {
  36. foreach (var propertyInfo in typeof(ExceptionCase).GetProperties())
  37. {
  38. if (_dicValue[propertyInfo.Name] != (bool)propertyInfo.GetValue(null, null))
  39. {
  40. SerializeStatic.Save(typeof (ExceptionCase), FileName);
  41. break;
  42. }
  43. }
  44. }
  45. catch (Exception ex)
  46. {
  47. LOG.Write(ex);
  48. }
  49. return true;
  50. }
  51. }
  52. }