Exemplo n.º 1
0
        private void lockUpd_GetStringArgs(Udp sender, ReciveString reciveArgs)
        {
            string value = reciveArgs.Value;

            string[] buff  = value.Split(new string[] { "~~~" }, StringSplitOptions.None);
            T        index = (T)(Object)(buff[0]);

            LockClient <T> .SetStatueList statue = (LockClient <T> .SetStatueList)Num.ToInt(buff[1]);
            switch (statue)
            {
            case LockClient <T> .SetStatueList.连接测试:
                lockUdp.Write(string.Format("{0}", (int)GetStatueList.收到请求), reciveArgs.RemoteHost, reciveArgs.RemotePort);
                break;

            case LockClient <T> .SetStatueList.请求:
                if (!lockList.Contains(index))
                {
                    lockList.Add(index);
                }
                if (lockList.Count > 0)
                {
                    if ((string)(object)lockList[0] == (string)(object)index)
                    {
                        lockUdp.Write(string.Format("{0}", (int)GetStatueList.允许执行互锁要求), reciveArgs.RemoteHost, reciveArgs.RemotePort);
                    }
                    else
                    {
                        lockUdp.Write(string.Format("{0}", (int)GetStatueList.等待), reciveArgs.RemoteHost, reciveArgs.RemotePort);
                    }
                }
                else
                {
                    Error.Add("有添加的请求,但数组列为0", Environment.StackTrace);
                }
                break;

            case LockClient <T> .SetStatueList.执行要求完毕:
                if (lockList.Count > 0)
                {
                    if ((string)(object)lockList[0] != (string)(object)index)
                    {
                        Error.Add(string.Format("动作完成的工位和允许执行的工位不是同一个,大问题。允许工位为:{0},执行工位为:{1}", lockList[0], index), Environment.StackTrace);
                        return;
                    }
                    switch (nowStatueList)
                    {
                    case GetStatueList.收到请求:
                        if (AllTestNeedOk != null)
                        {
                            AllTestNeedOk();
                        }
                        nowStatueList = GetStatueList.正在执行互锁动作;
                        lockUdp.Write(string.Format("{0}", (int)GetStatueList.正在执行互锁动作), reciveArgs.RemoteHost, reciveArgs.RemotePort);
                        break;

                    case GetStatueList.正在执行互锁动作:
                        lockUdp.Write(string.Format("{0}~~~{1}", (int)GetStatueList.正在执行互锁动作, testingValue), reciveArgs.RemoteHost, reciveArgs.RemotePort);
                        break;

                    case GetStatueList.互锁动作执行完毕:
                        lockUdp.Write(string.Format("{0}~~~{1}", (int)GetStatueList.互锁动作执行完毕, testValue), reciveArgs.RemoteHost, reciveArgs.RemotePort);
                        break;
                    }
                }
                else
                {
                    Error.Add("有返回执行的工位请求,但数组列为0", Environment.StackTrace);
                }
                break;

            case LockClient <T> .SetStatueList.动作完毕取消请求:
                lockUdp.Write(string.Format("{0}", (int)GetStatueList.互锁请求正常结束), reciveArgs.RemoteHost, reciveArgs.RemotePort);
                if (lockList.Count > 0)
                {
                    if ((string)(object)lockList[0] == (string)(object)index)
                    {
                        nowStatueList = GetStatueList.收到请求;
                        testValue     = "";
                        testingValue  = "";
                        lockList.Remove(index);
                    }
                    else
                    {
                        Error.Add(string.Format("动作完成的工位和完成请求的工位不是同一个,大问题。允许工位为:{0},执行完成工位为:{1}", lockList[0], index), Environment.StackTrace);
                        return;
                    }
                }
                else
                {
                    Error.Add("有返回完毕的工位请求,但数组列为0", Environment.StackTrace);
                }
                break;

            case LockClient <T> .SetStatueList.除:

                if (lockList.Count > 0)
                {
                    if ((string)(object)lockList[0] == (string)(object)index)
                    {
                        nowStatueList = GetStatueList.收到请求;
                        testValue     = "";
                        testingValue  = "";
                        if (AllTestCancel != null)
                        {
                            AllTestCancel();
                        }
                    }
                }
                if (lockList.Contains(index))
                {
                    lockList.Remove(index);
                }
                lockUdp.Write(string.Format("{0}", (int)GetStatueList.除请求成功), reciveArgs.RemoteHost, reciveArgs.RemotePort);
                break;
            }
        }