123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading;
- using WCS.Data.Utils;
- namespace WCS.Workflow
- {
- public class SingLetonClass
- {
- private static readonly object obj = new object();
- public static bool GetLock(string method, string convNo)
- {
- bool result = false;
- lock (obj)
- {
- if (convNo == "1112" || convNo == "1518" || convNo=="1114")//7#
- {
- result = GetLock_Pvc_7(method, convNo);
- }
- else if (convNo == "1107" || convNo == "1504")//6#
- {
- result = GetLock_Pvc_6(method, convNo);
- }
- else if (convNo == "1099")//5#
- {
- result = GetLock_Pvc_5(method, convNo);
- }
- else if (convNo == "1092")//4#
- {
- result = GetLock_Pvc_4(method, convNo);
- }
- }
- return result;
- }
- public static bool ReleaseLock(string convNo)
- {
- if (convNo == "1112" || convNo == "1518")//7#
- {
- return Interlocked.CompareExchange(ref _processing_Pvc_7, 0, 1) == 0;
- }
- else if (convNo == "1107" || convNo == "1504")//6#
- {
- return Interlocked.CompareExchange(ref _processing_Pvc_6, 0, 1) == 0;
- }
- else if (convNo == "1099")//5#
- {
- return Interlocked.CompareExchange(ref _processing_Pvc_5, 0, 1) == 0;
- }
- else if (convNo == "1092")//4#
- {
- return Interlocked.CompareExchange(ref _processing_Pvc_4, 0, 1) == 0;
- }
- else
- {
- return false;
- }
- }
- private static int _processing_Pvc_4;//处理中
- private static bool GetLock_Pvc_4(string method,string convNo)
- {
- if (Interlocked.CompareExchange(ref _processing_Pvc_4, 1, 0) != 0)
- {
- LogMessageHelper.RecordLogMessage(string.Format("执行失败,方法[{0}]输送线[{1}]处理正在执行中", method, convNo));
- return false;
- }
- return true;
- }
- public static bool ReleaseLock_Pvc_4()
- {
- return Interlocked.CompareExchange(ref _processing_Pvc_4, 0, 1) == 0;
- }
- private static int _processing_Pvc_5;//处理中
- private static bool GetLock_Pvc_5(string method, string convNo)
- {
- if (Interlocked.CompareExchange(ref _processing_Pvc_5, 1, 0) != 0)
- {
- LogMessageHelper.RecordLogMessage(string.Format("执行失败,方法[{0}]输送线[{1}]处理正在执行中", method, convNo));
- return false;
- }
- return true;
- }
- public static bool ReleaseLock_Pvc_5()
- {
- return Interlocked.CompareExchange(ref _processing_Pvc_5, 0, 1) == 0;
- }
- private static int _processing_Pvc_6;//处理中
- private static bool GetLock_Pvc_6(string method, string convNo)
- {
- if (Interlocked.CompareExchange(ref _processing_Pvc_6, 1, 0) != 0)
- {
- LogMessageHelper.RecordLogMessage(string.Format("执行失败,方法[{0}]输送线[{1}]处理正在执行中", method, convNo));
- return false;
- }
- return true;
- }
- public static bool ReleaseLock_Pvc_6()
- {
- return Interlocked.CompareExchange(ref _processing_Pvc_6, 0, 1) == 0;
- }
- private static int _processing_Pvc_7;//处理中
- private static bool GetLock_Pvc_7(string method, string convNo)
- {
- if (Interlocked.CompareExchange(ref _processing_Pvc_7, 1, 0) != 0)
- {
- LogMessageHelper.RecordLogMessage(string.Format("执行失败,方法[{0}]输送线[{1}]处理正在执行中", method, convNo));
- return false;
- }
- return true;
- }
- public static bool ReleaseLock_Pvc_7()
- {
- return Interlocked.CompareExchange(ref _processing_Pvc_7, 0, 1) == 0;
- }
- }
- }
|