RecipeLockManager.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.OperationCenter;
  3. using Aitex.Core.Util;
  4. using DocumentFormat.OpenXml.Vml.Office;
  5. using MECF.Framework.Common.OperationCenter;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. public class RecipeLockManager : Singleton<RecipeLockManager>
  13. {
  14. private bool _isLocked;
  15. private bool IsLocked
  16. {
  17. get { return _isLocked; }
  18. set
  19. {
  20. locktimer?.Dispose();
  21. _isLocked = value;
  22. if (!value)
  23. return;
  24. locktimer = new Timer(LockCallBack, null, 12000, 10000);
  25. }
  26. }
  27. private Timer locktimer;
  28. private bool _isInit = false;
  29. void LockCallBack(object state)
  30. {
  31. this.IsLocked = false;
  32. }
  33. public void Initialize()
  34. {
  35. if (this._isInit)
  36. return;
  37. try
  38. {
  39. DATA.Subscribe("RecipeEditLock", () => this.IsLocked, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  40. OP.Subscribe($"RecipeEditLock", LockCallBack);
  41. this._isInit = true;
  42. }
  43. catch
  44. {
  45. }
  46. }
  47. private bool LockCallBack(out string reason, int time, object[] param)
  48. {
  49. reason = string.Empty;
  50. if (param.Length >= 1 && param[0] is bool isLocked)
  51. this.IsLocked = isLocked;
  52. return true;
  53. }
  54. }