SingLetonClass.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using WCS.Data.Utils;
  6. namespace WCS.Workflow
  7. {
  8. public class SingLetonClass
  9. {
  10. private static readonly object obj = new object();
  11. public static bool GetLock(string method, string convNo)
  12. {
  13. bool result = false;
  14. lock (obj)
  15. {
  16. if (convNo == "1112" || convNo == "1518" || convNo=="1114")//7#
  17. {
  18. result = GetLock_Pvc_7(method, convNo);
  19. }
  20. else if (convNo == "1107" || convNo == "1504")//6#
  21. {
  22. result = GetLock_Pvc_6(method, convNo);
  23. }
  24. else if (convNo == "1099")//5#
  25. {
  26. result = GetLock_Pvc_5(method, convNo);
  27. }
  28. else if (convNo == "1092")//4#
  29. {
  30. result = GetLock_Pvc_4(method, convNo);
  31. }
  32. }
  33. return result;
  34. }
  35. public static bool ReleaseLock(string convNo)
  36. {
  37. if (convNo == "1112" || convNo == "1518")//7#
  38. {
  39. return Interlocked.CompareExchange(ref _processing_Pvc_7, 0, 1) == 0;
  40. }
  41. else if (convNo == "1107" || convNo == "1504")//6#
  42. {
  43. return Interlocked.CompareExchange(ref _processing_Pvc_6, 0, 1) == 0;
  44. }
  45. else if (convNo == "1099")//5#
  46. {
  47. return Interlocked.CompareExchange(ref _processing_Pvc_5, 0, 1) == 0;
  48. }
  49. else if (convNo == "1092")//4#
  50. {
  51. return Interlocked.CompareExchange(ref _processing_Pvc_4, 0, 1) == 0;
  52. }
  53. else
  54. {
  55. return false;
  56. }
  57. }
  58. private static int _processing_Pvc_4;//处理中
  59. private static bool GetLock_Pvc_4(string method,string convNo)
  60. {
  61. if (Interlocked.CompareExchange(ref _processing_Pvc_4, 1, 0) != 0)
  62. {
  63. LogMessageHelper.RecordLogMessage(string.Format("执行失败,方法[{0}]输送线[{1}]处理正在执行中", method, convNo));
  64. return false;
  65. }
  66. return true;
  67. }
  68. public static bool ReleaseLock_Pvc_4()
  69. {
  70. return Interlocked.CompareExchange(ref _processing_Pvc_4, 0, 1) == 0;
  71. }
  72. private static int _processing_Pvc_5;//处理中
  73. private static bool GetLock_Pvc_5(string method, string convNo)
  74. {
  75. if (Interlocked.CompareExchange(ref _processing_Pvc_5, 1, 0) != 0)
  76. {
  77. LogMessageHelper.RecordLogMessage(string.Format("执行失败,方法[{0}]输送线[{1}]处理正在执行中", method, convNo));
  78. return false;
  79. }
  80. return true;
  81. }
  82. public static bool ReleaseLock_Pvc_5()
  83. {
  84. return Interlocked.CompareExchange(ref _processing_Pvc_5, 0, 1) == 0;
  85. }
  86. private static int _processing_Pvc_6;//处理中
  87. private static bool GetLock_Pvc_6(string method, string convNo)
  88. {
  89. if (Interlocked.CompareExchange(ref _processing_Pvc_6, 1, 0) != 0)
  90. {
  91. LogMessageHelper.RecordLogMessage(string.Format("执行失败,方法[{0}]输送线[{1}]处理正在执行中", method, convNo));
  92. return false;
  93. }
  94. return true;
  95. }
  96. public static bool ReleaseLock_Pvc_6()
  97. {
  98. return Interlocked.CompareExchange(ref _processing_Pvc_6, 0, 1) == 0;
  99. }
  100. private static int _processing_Pvc_7;//处理中
  101. private static bool GetLock_Pvc_7(string method, string convNo)
  102. {
  103. if (Interlocked.CompareExchange(ref _processing_Pvc_7, 1, 0) != 0)
  104. {
  105. LogMessageHelper.RecordLogMessage(string.Format("执行失败,方法[{0}]输送线[{1}]处理正在执行中", method, convNo));
  106. return false;
  107. }
  108. return true;
  109. }
  110. public static bool ReleaseLock_Pvc_7()
  111. {
  112. return Interlocked.CompareExchange(ref _processing_Pvc_7, 0, 1) == 0;
  113. }
  114. }
  115. }