예제 #1
0
        /// <summary>
        /// Конструктор
        /// </summary>
        public DataCache(ServerComm serverComm, Log log)
        {
            if (serverComm == null)
            {
                throw new ArgumentNullException("serverComm");
            }
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            this.serverComm = serverComm;
            this.log        = log;

            baseLock    = new object();
            curDataLock = new object();

            baseRefrDT    = DateTime.MinValue;
            tblCur        = new SrezTableLight();
            curDataRefrDT = DateTime.MinValue;

            BaseTables      = new BaseTables();
            CnlProps        = new InCnlProps[0];
            CtrlCnlProps    = new CtrlCnlProps[0];
            CnlStatProps    = new SortedList <int, CnlStatProps>();
            HourTableCache  = new Cache <DateTime, SrezTableLight>(HourCacheStorePeriod, HourCacheCapacity);
            EventTableCache = new Cache <DateTime, EventTableLight>(EventCacheStorePeriod, EventCacheCapacity);
        }
예제 #2
0
        /// <summary>
        /// Format command value
        /// </summary>
        public string FormatCmdVal(double cmdVal, CtrlCnlProps ctrlCnlProps)
        {
            if (ctrlCnlProps == null || ctrlCnlProps.CmdValID <= 0)
            {
                return(cmdVal.ToString("N", defNfi));
            }

            int cmdValArrLen = ctrlCnlProps.CmdValArr?.Length ?? 0;

            if (cmdValArrLen <= 0)
            {
                return(NoVal);
            }

            var cmdInd = (int)cmdVal;

            if (cmdInd < 0)
            {
                cmdInd = 0;
            }
            else if (cmdInd >= cmdValArrLen)
            {
                cmdInd = cmdValArrLen - 1;
            }
            return(ctrlCnlProps.CmdValArr[cmdInd]);
        }
예제 #3
0
        /// <summary>
        /// Форматировать значение команды
        /// </summary>
        public string FormatCmdVal(double cmdVal, CtrlCnlProps ctrlCnlProps)
        {
            if (ctrlCnlProps == null || ctrlCnlProps.CmdValID <= 0)
            {
                nfi.NumberDecimalDigits    = DefDecDig;
                nfi.NumberDecimalSeparator = defDecSep;
                nfi.NumberGroupSeparator   = defGrSep;
                return(cmdVal.ToString("N", nfi));
            }
            else
            {
                int cmdValArrLen = ctrlCnlProps.CmdValArr == null ? 0 : ctrlCnlProps.CmdValArr.Length;

                if (cmdValArrLen > 0)
                {
                    int cmdInd = (int)cmdVal;
                    if (cmdInd < 0)
                    {
                        cmdInd = 0;
                    }
                    else if (cmdInd >= cmdValArrLen)
                    {
                        cmdInd = cmdValArrLen - 1;
                    }
                    return(ctrlCnlProps.CmdValArr[cmdInd]);
                }
            }

            return(NoVal);
        }
예제 #4
0
        /// <summary>
        /// Конструктор
        /// </summary>
        public DataCache(ServerComm serverComm, Log log)
        {
            if (serverComm == null)
            {
                throw new ArgumentNullException("serverComm");
            }
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            this.serverComm = serverComm;
            this.log        = log;

            baseLock    = new object();
            curDataLock = new object();

            baseRefrDT = DateTime.MinValue;
            baseAge    = DateTime.MinValue;
            tblCur     = new SrezTableLight();
            curRefrDT  = DateTime.MinValue;

            BaseTables   = new BaseTables();
            CnlProps     = new InCnlProps[0];
            CtrlCnlProps = new CtrlCnlProps[0];
        }
예제 #5
0
파일: MainData.cs 프로젝트: iyus/scada
        /// <summary>
        /// �������� �������� ������ ���������� �� ��� ������
        /// </summary>
        public CtrlCnlProps GetCtrlCnlProps(int ctrlCnlNum)
        {
            Monitor.Enter(baseLock);
            CtrlCnlProps ctrlCnlProps = null;

            try
            {
                tblCtrlCnl.DefaultView.RowFilter = "CtrlCnlNum = " + ctrlCnlNum;
                if (tblCtrlCnl.DefaultView.Count > 0)
                {
                    DataRowView rowView = tblCtrlCnl.DefaultView[0];
                    ctrlCnlProps = new CtrlCnlProps(ctrlCnlNum);
                    ctrlCnlProps.CtrlCnlName = (string)rowView["Name"];
                    ctrlCnlProps.CmdTypeID = (int)rowView["CmdTypeID"];

                    // ����������� ������ � ������������ �������
                    ctrlCnlProps.ObjNum = (int)rowView["ObjNum"];
                    tblObj.DefaultView.RowFilter = "ObjNum = " + ctrlCnlProps.ObjNum;
                    ctrlCnlProps.ObjName = tblObj.DefaultView.Count > 0 ? (string)tblObj.DefaultView[0]["Name"] : "";

                    // ����������� ������ � ������������ ��
                    ctrlCnlProps.KPNum = (int)rowView["KPNum"];
                    tblKP.DefaultView.RowFilter = "KPNum = " + ctrlCnlProps.KPNum;
                    ctrlCnlProps.KPName = tblKP.DefaultView.Count > 0 ? (string)tblKP.DefaultView[0]["Name"] : "";

                    // ����������� �������� �������
                    tblCmdVal.DefaultView.RowFilter = "CmdValID = " + rowView["CmdValID"];
                    if (tblCmdVal.DefaultView.Count > 0)
                    {
                        string val = (string)tblCmdVal.DefaultView[0]["Val"];
                        ctrlCnlProps.CmdValArr = val.Split(';'); // ������� ������ ��������
                        for (int i = 0; i < ctrlCnlProps.CmdValArr.Length; i++)
                            ctrlCnlProps.CmdValArr[i] = ctrlCnlProps.CmdValArr[i].Trim();
                        if (ctrlCnlProps.CmdValArr.Length == 1 && ctrlCnlProps.CmdValArr[0] == "")
                            ctrlCnlProps.CmdValArr = null;
                    }
                    else
                    {
                        ctrlCnlProps.CmdValArr = null;
                    }
                }
            }
            catch (Exception ex)
            {
                AppData.Log.WriteAction(string.Format(Localization.UseRussian ?
                    "������ ��� ��������� ������� ������ ���������� {0}: {1}" :
                    "Error getting output channel {0} properties: {1}", ctrlCnlNum, ex.Message),
                    Log.ActTypes.Exception);
            }
            finally
            {
                Monitor.Exit(baseLock);
            }

            return ctrlCnlProps;
        }
예제 #6
0
        /// <summary>
        /// Заполнить свойства каналов управления
        /// </summary>
        protected void FillCtrlCnlProps()
        {
            try
            {
                log.WriteAction(Localization.UseRussian ?
                                "Заполнение свойств каналов управления" :
                                "Fill output channels properties");

                DataTable tblCtrlCnl = BaseTables.CtrlCnlTable;
                DataView  viewObj    = BaseTables.ObjTable.DefaultView;
                DataView  viewKP     = BaseTables.KPTable.DefaultView;
                DataView  viewCmdVal = BaseTables.CmdValTable.DefaultView;

                // установка сортировки для последующего поиска строк
                viewObj.Sort    = "ObjNum";
                viewKP.Sort     = "KPNum";
                viewCmdVal.Sort = "CmdValID";

                int            ctrlCnlCnt      = tblCtrlCnl.Rows.Count;
                CtrlCnlProps[] newCtrlCnlProps = new CtrlCnlProps[ctrlCnlCnt];

                for (int i = 0; i < ctrlCnlCnt; i++)
                {
                    DataRow      ctrlCnlRow   = tblCtrlCnl.Rows[i];
                    CtrlCnlProps ctrlCnlProps = new CtrlCnlProps();

                    // определение свойств, не использующих внешних ключей
                    ctrlCnlProps.CtrlCnlNum  = (int)ctrlCnlRow["CtrlCnlNum"];
                    ctrlCnlProps.CtrlCnlName = (string)ctrlCnlRow["Name"];
                    ctrlCnlProps.CmdTypeID   = (int)ctrlCnlRow["CmdTypeID"];
                    ctrlCnlProps.ObjNum      = (int)ctrlCnlRow["ObjNum"];
                    ctrlCnlProps.KPNum       = (int)ctrlCnlRow["KPNum"];
                    ctrlCnlProps.CmdNum      = (int)ctrlCnlRow["CmdNum"];
                    ctrlCnlProps.CmdValID    = (int)ctrlCnlRow["CmdValID"];
                    ctrlCnlProps.FormulaUsed = (bool)ctrlCnlRow["FormulaUsed"];
                    ctrlCnlProps.Formula     = (string)ctrlCnlRow["Formula"];
                    ctrlCnlProps.EvEnabled   = (bool)ctrlCnlRow["EvEnabled"];

                    // определение наименования объекта
                    int objRowInd = viewObj.Find(ctrlCnlProps.ObjNum);
                    if (objRowInd >= 0)
                    {
                        ctrlCnlProps.ObjName = (string)viewObj[objRowInd]["Name"];
                    }

                    // определение наименования КП
                    int kpRowInd = viewKP.Find(ctrlCnlProps.KPNum);
                    if (kpRowInd >= 0)
                    {
                        ctrlCnlProps.KPName = (string)viewKP[kpRowInd]["Name"];
                    }

                    // определение значений команды
                    int cmdValInd = viewCmdVal.Find(ctrlCnlProps.CmdValID);
                    if (cmdValInd >= 0)
                    {
                        DataRowView cmdValRowView = viewCmdVal[cmdValInd];
                        ctrlCnlProps.CmdValName = (string)cmdValRowView["Name"];
                        ctrlCnlProps.CmdVal     = (string)cmdValRowView["Val"];
                        string[] cmdValArr = ctrlCnlProps.CmdValArr =
                            ctrlCnlProps.CmdVal.Split(FieldSeparator, StringSplitOptions.RemoveEmptyEntries);
                        for (int j = 0; j < cmdValArr.Length; j++)
                        {
                            cmdValArr[j] = cmdValArr[j].Trim();
                        }
                        if (cmdValArr.Length == 1 && cmdValArr[0] == "")
                        {
                            ctrlCnlProps.CmdValArr = null;
                        }
                    }

                    newCtrlCnlProps[i] = ctrlCnlProps;
                }

                CtrlCnlProps = newCtrlCnlProps;
            }
            catch (Exception ex)
            {
                log.WriteException(ex, (Localization.UseRussian ?
                                        "Ошибка при заполнении свойств каналов управления: " :
                                        "Error filling output channels properties"));
            }
        }
예제 #7
0
파일: MainData.cs 프로젝트: raydtang/scada
        /// <summary>
        /// Получить свойства канала управления по его номеру
        /// </summary>
        public CtrlCnlProps GetCtrlCnlProps(int ctrlCnlNum)
        {
            Monitor.Enter(baseLock);
            CtrlCnlProps ctrlCnlProps = null;

            try
            {
                tblCtrlCnl.DefaultView.RowFilter = "CtrlCnlNum = " + ctrlCnlNum;
                if (tblCtrlCnl.DefaultView.Count > 0)
                {
                    DataRowView rowView = tblCtrlCnl.DefaultView[0];
                    ctrlCnlProps = new CtrlCnlProps(ctrlCnlNum, (string)rowView["Name"], (int)rowView["CmdTypeID"]);

                    // определение номера и наименования объекта
                    ctrlCnlProps.ObjNum = (int)rowView["ObjNum"];
                    tblObj.DefaultView.RowFilter = "ObjNum = " + ctrlCnlProps.ObjNum;
                    ctrlCnlProps.ObjName = tblObj.DefaultView.Count > 0 ? (string)tblObj.DefaultView[0]["Name"] : "";

                    // определение номера и наименования КП
                    ctrlCnlProps.KPNum = (int)rowView["KPNum"];
                    tblKP.DefaultView.RowFilter = "KPNum = " + ctrlCnlProps.KPNum;
                    ctrlCnlProps.KPName = tblKP.DefaultView.Count > 0 ? (string)tblKP.DefaultView[0]["Name"] : "";

                    // определение значений команды
                    tblCmdVal.DefaultView.RowFilter = "CmdValID = " + rowView["CmdValID"];
                    if (tblCmdVal.DefaultView.Count > 0)
                    {
                        string val = (string)tblCmdVal.DefaultView[0]["Val"];
                        ctrlCnlProps.CmdValArr = val.Split(';'); // включая пустые элементы
                        for (int i = 0; i < ctrlCnlProps.CmdValArr.Length; i++)
                            ctrlCnlProps.CmdValArr[i] = ctrlCnlProps.CmdValArr[i].Trim();
                        if (ctrlCnlProps.CmdValArr.Length == 1 && ctrlCnlProps.CmdValArr[0] == "")
                            ctrlCnlProps.CmdValArr = null;
                    }
                    else
                    {
                        ctrlCnlProps.CmdValArr = null;
                    }
                }
            }
            catch (Exception ex)
            {
                AppData.Log.WriteAction(string.Format(Localization.UseRussian ?
                    "Ошибка при получении свойств канала управления {0}: {1}" :
                    "Error getting output channel {0} properties: {1}", ctrlCnlNum, ex.Message), 
                    Log.ActTypes.Exception);
            }
            finally
            {
                Monitor.Exit(baseLock);
            }

            return ctrlCnlProps;
        }