/// <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()); } }