/// <summary> /// Saves the command to the specified file. /// </summary> public bool Save(string fileName, out string errMsg) { try { StringBuilder sb = new StringBuilder("[TeleCommand]") .Append("CommandID=").AppendLine(CommandID.ToString()) .Append("CreationTime=").AppendLine(CreationTime.ToString(DateTimeFormatInfo.InvariantInfo)) .Append("UserID=").AppendLine(UserID.ToString()) .Append("OutCnlNum=").AppendLine(OutCnlNum.ToString()) .Append("CmdTypeID=").AppendLine(CmdTypeID.ToString()) .Append("ObjNum=").AppendLine(ObjNum.ToString()) .Append("DeviceNum=").AppendLine(DeviceNum.ToString()) .Append("CmdNum=").AppendLine(CmdNum.ToString()) .Append("CmdCode=").AppendLine("CmdCode") .Append("CmdVal=").AppendLine(CmdVal.ToString(NumberFormatInfo.InvariantInfo)) .Append("CmdData=").AppendLine(ScadaUtils.BytesToHex(CmdData)) .Append("RecursionLevel=").AppendLine(RecursionLevel.ToString()) .AppendLine("End="); using (StreamWriter writer = new StreamWriter(fileName, false, Encoding.UTF8)) { writer.Write(sb.ToString()); } errMsg = ""; return(false); } catch (Exception ex) { errMsg = string.Format(Locale.IsRussian ? "Ошибка при сохранении команды ТУ: " : "Error saving telecontrol command: ") + ex.Message; return(false); } }
/// <summary> /// Saves the options to the specified writer. /// </summary> public void Save(Stream stream) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } StringBuilder sb = new StringBuilder() .AppendLine("[TeleCommand]") .Append("CommandID=").AppendLine(CommandID.ToString()) .Append("CreationTime=").AppendLine(CreationTime.ToString(DateTimeFormatInfo.InvariantInfo)) .Append("ClientName=").AppendLine(ClientName) .Append("UserID=").AppendLine(UserID.ToString()) .Append("CnlNum=").AppendLine(CnlNum.ToString()) .Append("ObjNum=").AppendLine(ObjNum.ToString()) .Append("DeviceNum=").AppendLine(DeviceNum.ToString()) .Append("CmdNum=").AppendLine(CmdNum.ToString()) .Append("CmdCode=").AppendLine(CmdCode) .Append("CmdVal=").AppendLine(CmdVal.ToString(NumberFormatInfo.InvariantInfo)) .Append("CmdData=").AppendLine(ScadaUtils.BytesToHex(CmdData)) .Append("RecursionLevel=").AppendLine(RecursionLevel.ToString()) .AppendLine("End="); using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8, 1024, true)) { writer.Write(sb.ToString()); } }
public void RemoveMsg(UInt64 msgNum, UInt64 userID, CmdNum msgID) { for (int i = msgList.Count - 1; i >= 0; i--) { if (msgList[i].userID == userID && msgList[i].msgID == msgID) { msgList.RemoveAt(i); return; } } }
public void AddMsg(UInt32 gameVer, UInt64 userID, CmdNum msgID, System.Object data, float interval, int count, EndPoint remote, bool addNum, UInt64 msgNum) { TimeControl tc = new TimeControl(); tc.gameVer = gameVer; tc.userID = userID; tc.msgID = msgID; tc.interval = interval; tc.count = count; tc.data = data; tc.remote = remote; tc.addNum = addNum; tc.msgNum = msgNum; tc.time = (float)((double)timeGetTime()/(double)1000); msgList.Add(tc); }
/// <summary> /// Compares the current instance with another object of the same type. /// </summary> public int CompareTo(ExportCmd other) { return(CmdNum.CompareTo(other.CmdNum)); }
public void SendMessage(UInt64 userID, CmdNum msgID, System.Object data, EndPoint remote, float interval = 0.0f, int count = 0, bool addNum = true, bool fistAddNum = true) { UInt64 msgNum = 0; if (fistAddNum && LoginServerManager.Instance.dicUserinfo.ContainsKey(userID)) { LoginServerManager.Instance.dicUserinfo[userID].msgSendNum++; msgNum = LoginServerManager.Instance.dicUserinfo[userID].msgSendNum; } //包头 MemoryStream mshead = new MemoryStream(); BinaryWriter writer = new BinaryWriter(mshead); writer.Write((UInt32)gameVersion); writer.Write((UInt64)userID); writer.Write((UInt64)msgNum); writer.Write((UInt32)msgID); ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(mshead, data); if (mshead.Length > 1024) { Console.WriteLine("Send Message Length > 1024"); return; } socket.SendTo(mshead.GetBuffer(), (int)mshead.Length, System.Net.Sockets.SocketFlags.None, remote); //放到缓冲队列重发 if (count > 0) msgResend.AddMsg(gameVersion, userID, msgID, data, interval, count, remote, addNum, msgNum); }