/// <summary> /// 构造函数 /// </summary> /// <param name="name"></param> /// <param name="oType"></param> /// <param name="dType"></param> /// <param name="setting"></param> /// <param name="data"></param> /// <param name="time"></param> public UserOperation(string name, OprationType oType, DataType dType, object setting, string data, int time) { _name = name; _opreationType = oType; _dataType = dType; _setting = setting; _data = data; _time = time; }
private async Task SendParity(OprationType ThisType, OprationType ThatType) { await Socket.Send(ThisType); var Status = await Socket.Recive <OprationType>(); if (Status != ThatType) { var EX = "Wrong opration, This side is '" + ThisType.ToString() + "'" + " And other side must be '" + ThatType.ToString() + "'" + " But that is '" + Status.ToString() + "'"; throw new InvalidOperationException(EX); } }
public int UpdateCabinetStatus(Order2Cabinet obj, OprationType Opration, Sender sender) { try { using (ObjectProxy op = new ObjectProxy(true)) { int resurt = op.UpdateCabinetStatus(obj, Opration, sender); op.CommitTransaction();//加入事物处理,保证数据统一 return(resurt); } } catch (Exception ex) { PLogger.LogError(ex); throw ex; } }
private async Task ClientParity(OprationType ThisType, OprationType ThatType) { #if TRACE_NET Console.WriteLine($"Net:{Client.Address} {ThisType.ToString()} {ThatType.ToString()}"); Console.WriteLine($"Net:{Client.Address} Sequence:{Sequnce}"); #endif await Client.Send(new byte[] { (byte)ThisType }); await Client.Send(BitConverter.GetBytes(Sequnce)); OprationType Status = (OprationType)(await Client.Recive(1))[0]; int CurrentSequnce = BitConverter.ToInt32(await Client.Recive(4), 0); if (Status == OprationType.Exeption) { throw (await Client.RecivePacket()).Deserialize <Exception>(); } if (Sequnce != CurrentSequnce) { var Address = Client.Address.ToString(); var ex = $"Wrong Sequnce On {Address}, This side is {Sequnce}" + $" but other side is {CurrentSequnce}"; Client.AddDebugInfo(ex); await Client.Disconncet(); throw new InvalidOperationException(ex); } Sequnce++; if (Status != ThatType) { var Address = Client.Address.ToString(); var ex = "Wrong opration On " + Address + ", This side is '" + ThisType.ToString() + "'" + " And other side must be '" + ThatType.ToString() + "'" + " But that is '" + Status.ToString() + "'"; Client.AddDebugInfo(ex); await Client.Disconncet(); throw new InvalidOperationException(ex); } }
private async Task ServerParity( OprationType ThisType, OprationType ThatType) { #if TRACE_NET Console.WriteLine($"Net:{Client.Address} {ThisType.ToString()} {ThatType.ToString()}"); Console.WriteLine($"Net:{Client.Address} Sequence:{Sequnce}"); #endif OprationType Status = (OprationType)(await Client.Recive(1))[0]; int CurrentSequnce = BitConverter.ToInt32(await Client.Recive(4), 0); await Client.Send(new byte[] { (byte)ThisType }); await Client.Send(BitConverter.GetBytes(Sequnce)); if (Sequnce != CurrentSequnce) { var Address = Client.Address.ToString(); Client.WhyDisconnect = $"Wrong Sequnce On {Address}, This side is {Sequnce}" + $" but other side is {CurrentSequnce}"; await Client.Disconncet(); throw new InvalidOperationException(Client.WhyDisconnect); } Sequnce++; if (Status != ThatType) { var Address = Client.Address.ToString(); Misstake?.Invoke(Client.Address); Client.WhyDisconnect = "Wrong opration On " + Address + ", This side is '" + ThisType.ToString() + "'" + " And other side must be '" + ThatType.ToString() + "'" + " But that is '" + Status.ToString() + "'"; await Client.Disconncet(); throw new InvalidOperationException (Client.WhyDisconnect); } }
/// <summary> /// 加载配置文件 /// </summary> private void LoadConfig() { try { XmlDocument config = new XmlDocument(); config.Load(_configFile); XmlNode root = config.SelectSingleNode("Root"); #region LoadNormalCommand XmlNodeList areas = root.SelectNodes("Area"); _areas.Clear(); foreach (XmlNode area in areas) { string areaName = area.SelectSingleNode("AreaName").InnerText; Area tempArea = new Area(areaName); _areas.Add(tempArea); XmlNodeList actions = area.SelectNodes("Action"); foreach (XmlNode action in actions) { string actionName = action.SelectSingleNode("ActionName").InnerText; string actionReceiveData = action.SelectSingleNode("ActionReceiveData").InnerText; UserAction useraction = new UserAction(actionName, actionReceiveData); //tempArea.Actions.Add(useraction); _userAction.Add(useraction); XmlNodeList oprations = action.SelectNodes("Operation"); foreach (XmlNode operation in oprations) { string operationName = operation.SelectSingleNode("OperationName").InnerText; string operationTypeString = operation.SelectSingleNode("OperationType").InnerText; OprationType operationType = (OprationType)Enum.Parse(typeof(OprationType), operationTypeString, true); XmlNode operationSetting = operation.SelectSingleNode("OperationSetting"); object setting = null; if (operationType == OprationType.Com) { ComSetting cs = new ComSetting(); cs.ComNumber = operationSetting.SelectSingleNode("ComNumber").InnerText; cs.BaudRate = int.Parse(operationSetting.SelectSingleNode("BaudRate").InnerText); cs.DataBits = int.Parse(operationSetting.SelectSingleNode("DataBit").InnerText); cs.StopBits = int.Parse(operationSetting.SelectSingleNode("StopBit").InnerText); cs.Parity = (Parity)Enum.Parse(typeof(Parity), operationSetting.SelectSingleNode("Parity").InnerText); setting = cs; } else if (operationType == OprationType.TCP || operationType == OprationType.UDP) { NetworkSetting ns = new NetworkSetting(); ns.Ip = operationSetting.SelectSingleNode("IP").InnerText; ns.Port = int.Parse(operationSetting.SelectSingleNode("Port").InnerText); setting = ns; } string dataTypeString = operation.SelectSingleNode("OperationDataType").InnerText; DataType dataType = (DataType)Enum.Parse(typeof(DataType), dataTypeString, true); string data = operation.SelectSingleNode("OperationData").InnerText; int time = int.Parse(operation.SelectSingleNode("OperationTime").InnerText); UserOperation userOperation = new UserOperation(operationName, operationType, dataType, setting, data, time); _userOperation.Add(userOperation); } } } _arealist.Refresh(); #endregion } catch (Exception ex) { MessageBox.Show("未找到配置命令!"); } }
public Operation(OprationType type, params object[] args) { opType = type; opArgs = new object[args.Length]; Array.Copy(args, opArgs, args.Length); }