Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        /// <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());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Получить описание команды с указанием канала управления и пользователя
        /// </summary>
        public string GetCmdDescr(int ctrlCnlNum, int userID)
        {
            const int     VisCmdDataLen = 10; // длина отображаемой части данных команды
            StringBuilder sb            = new StringBuilder();

            if (Localization.UseRussian)
            {
                sb.Append("Команда ТУ: ");
                if (ctrlCnlNum > 0)
                {
                    sb.Append("канал упр. = ").Append(ctrlCnlNum).Append(", ");
                }
                if (userID > 0)
                {
                    sb.Append("ид. польз. = ").Append(userID).Append(", ");
                }
                sb.Append("тип = ").Append(BaseValues.CmdTypes.GetCmdTypeCode(CmdTypeID));
                if (KPNum > 0)
                {
                    sb.Append(", номер КП = ").Append(KPNum);
                }
                if (CmdTypeID == BaseValues.CmdTypes.Standard)
                {
                    sb.Append(", значение = ").AppendFormat(CmdVal.ToString("N3", Localization.Culture));
                }
                if (CmdTypeID == BaseValues.CmdTypes.Binary && CmdData != null)
                {
                    sb.Append(", данные = ").Append(ScadaUtils.BytesToHex(CmdData, 0,
                                                                          Math.Min(VisCmdDataLen, CmdData.Length)));
                }
            }
            else
            {
                sb.Append("Command: ");
                if (ctrlCnlNum > 0)
                {
                    sb.Append("out channel = ").Append(ctrlCnlNum).Append(", ");
                }
                if (userID > 0)
                {
                    sb.Append("user ID = ").Append(userID).Append(", ");
                }
                sb.Append("type = ").Append(BaseValues.CmdTypes.GetCmdTypeCode(CmdTypeID));
                if (KPNum > 0)
                {
                    sb.Append(", device num. = ").Append(KPNum);
                }
                if (CmdTypeID == BaseValues.CmdTypes.Standard)
                {
                    sb.Append(", value = ").AppendFormat(CmdVal.ToString("N3", Localization.Culture));
                }
                if (CmdTypeID == BaseValues.CmdTypes.Binary && CmdData != null)
                {
                    sb.Append(", data = ").Append(ScadaUtils.BytesToHex(CmdData, 0,
                                                                        Math.Min(VisCmdDataLen, CmdData.Length)));
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get command description with control channel and user
        /// </summary>
        public string GetCmdDescr(int ctrlCnlNum, int userID)
        {
            const int VisCmdDataLen = 10; // the length of the displayed data command
            var       sb            = new StringBuilder();

            sb.Append("Command: ");
            if (ctrlCnlNum > 0)
            {
                sb.Append("out ch.=").Append(ctrlCnlNum).Append(", ");
            }
            if (userID > 0)
            {
                sb.Append("user="******", ");
            }
            sb.Append("type=").Append(GetCmdTypeCode());
            if (KPNum > 0)
            {
                sb.Append(", device=").Append(KPNum);
            }
            if (CmdNum > 0)
            {
                sb.Append(", number=").Append(CmdNum);
            }
            if (CmdTypeID == BaseValues.CmdTypes.Standard)
            {
                sb.Append(", value=").AppendFormat(CmdVal.ToString("N3", Localization.Culture));
            }
            if (CmdTypeID == BaseValues.CmdTypes.Binary && CmdData != null)
            {
                sb.Append(", data=")
                .Append(ScadaUtils.BytesToHex(CmdData, 0, Math.Min(VisCmdDataLen, CmdData.Length)))
                .Append(VisCmdDataLen < CmdData.Length ? "..." : "");
            }

            return(sb.ToString());
        }