Пример #1
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public CnlDataFormatter(ConfigDataset configDataset, EnumDict enums, TimeZoneInfo timeZone)
 {
     culture            = Locale.Culture;
     this.configDataset = configDataset ?? throw new ArgumentNullException(nameof(configDataset));
     this.enums         = enums ?? throw new ArgumentNullException(nameof(enums));
     this.timeZone      = timeZone ?? throw new ArgumentNullException(nameof(timeZone));
 }
Пример #2
0
        /// <summary>
        /// Binds the device tags to the configuration database.
        /// </summary>
        public virtual void BindDeviceTags(ConfigDataset configDataset)
        {
            foreach (Cnl cnl in configDataset.CnlTable.SelectItems(new TableFilter("DeviceNum", DeviceNum), true))
            {
                if (cnl.Active && cnl.IsInput())
                {
                    DeviceTag deviceTag = null;

                    if (!string.IsNullOrEmpty(cnl.TagCode))
                    {
                        // find tag by code
                        DeviceTags.TryGetTag(cnl.TagCode, out deviceTag);
                    }
                    else if (cnl.TagNum > 0)
                    {
                        // find tag by index
                        DeviceTags.TryGetTag(cnl.TagNum.Value - 1, out deviceTag);
                    }

                    // check match and bind tag
                    if (deviceTag != null &&
                        (int)deviceTag.DataType == (cnl.DataTypeID ?? DataTypeID.Double) &&
                        deviceTag.DataLength == Math.Max(cnl.DataLen ?? 1, 1))
                    {
                        deviceTag.Cnl = cnl;
                    }
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public FrmMqttDSO(ConfigDataset configDataset, DataSourceConfig dataSourceConfig)
     : this()
 {
     this.configDataset    = configDataset ?? throw new ArgumentNullException(nameof(configDataset));
     this.dataSourceConfig = dataSourceConfig ?? throw new ArgumentNullException(nameof(dataSourceConfig));
     options = new MqttDSO(dataSourceConfig.CustomOptions);
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public FrmScadaServerDSO(ConfigDataset configDataset, AppDirs appDirs, DataSourceConfig dataSourceConfig)
     : this()
 {
     this.configDataset    = configDataset ?? throw new ArgumentNullException(nameof(configDataset));
     this.appDirs          = appDirs ?? throw new ArgumentNullException(nameof(appDirs));
     this.dataSourceConfig = dataSourceConfig ?? throw new ArgumentNullException(nameof(dataSourceConfig));
     options = new ScadaServerDSO(dataSourceConfig.CustomOptions);
 }
Пример #5
0
        public CnlProps(Cnl cnl, ConfigDataset configDataset)
        {
            ArgumentNullException.ThrowIfNull(cnl, nameof(cnl));
            ArgumentNullException.ThrowIfNull(configDataset, nameof(configDataset));

            CnlNum  = cnl.CnlNum;
            JoinLen = cnl.IsString() ? cnl.GetDataLength() : 1;
            Unit    = cnl.UnitID.HasValue ? configDataset.UnitTable.GetItem(cnl.UnitID.Value)?.Name : null;
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public FrmCnlSelect(ConfigDataset configDataset)
            : this()
        {
            this.configDataset = configDataset ?? throw new ArgumentNullException(nameof(configDataset));
            items         = null;
            selectedItems = null;

            MultiSelect     = true;
            SelectedCnlNums = null;
            SelectedCnlNum  = 0;
        }
Пример #7
0
        private TrendBundle trendBundle;                  // the chart data of many channels


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public ChartDataBuilder(ConfigDataset configDataset, ScadaClient scadaClient, ChartDataBuilderOptions options)
        {
            this.configDataset = configDataset ?? throw new ArgumentNullException(nameof(configDataset));
            this.scadaClient   = scadaClient ?? throw new ArgumentNullException(nameof(scadaClient));
            this.options       = options ?? throw new ArgumentNullException(nameof(options));
            options.Validate();
            formatter = new CnlDataFormatter(configDataset);

            cnls        = Array.Empty <Cnl>();
            singleTrend = null;
            trendBundle = null;
        }
Пример #8
0
 /// <summary>
 /// Calls the BindDeviceTags method of the device.
 /// </summary>
 public void BindDeviceTags(ConfigDataset configDataset)
 {
     try
     {
         if (DeviceLogic.IsBound && configDataset != null)
         {
             DeviceLogic.BindDeviceTags(configDataset);
         }
     }
     catch (Exception ex)
     {
         log.WriteError(ex, CommPhrases.ErrorInDevice, nameof(BindDeviceTags), DeviceLogic.Title);
     }
 }
Пример #9
0
        /// <summary>
        /// Fills the channel properties.
        /// </summary>
        public void FillCnlProps(ConfigDataset configDataset)
        {
            ArgumentNullException.ThrowIfNull(configDataset, nameof(configDataset));

            if (SchemeDoc?.SchemeView == null)
            {
                throw new InvalidOperationException("Scheme view must not be null.");
            }

            foreach (int cnlNum in SchemeDoc.SchemeView.CnlNumList)
            {
                if (configDataset.CnlTable.GetItem(cnlNum) is Cnl cnl)
                {
                    CnlProps.Add(new CnlProps(cnl, configDataset));
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Fills the tree view according to the configuration database.
        /// </summary>
        public void FillTreeView(ConfigDataset configDataset, int selectedLineNum)
        {
            ArgumentNullException.ThrowIfNull(configDataset, nameof(configDataset));

            try
            {
                treeView.BeginUpdate();
                treeView.Nodes.Clear();

                foreach (CommLine commLine in configDataset.CommLineTable.Enumerate())
                {
                    TreeNode lineNode = new(CommUtils.GetLineTitle(commLine))
                    {
                        Tag = new TreeNodeTag(commLine, CommNodeType.Line)
                    };

                    foreach (Device device in configDataset.DeviceTable.Select(
                                 new TableFilter("CommLineNum", commLine.CommLineNum), true))
                    {
                        lineNode.Nodes.Add(new TreeNode(CommUtils.GetDeviceTitle(device))
                        {
                            Tag = new TreeNodeTag(device, CommNodeType.Device)
                        });
                    }

                    treeView.Nodes.Add(lineNode);

                    if (commLine.CommLineNum == selectedLineNum)
                    {
                        lineNode.Checked = true;
                        lineNode.Expand();
                    }
                }
            }
            finally
            {
                treeView.EndUpdate();
            }
        }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public CnlDataFormatter(ConfigDataset configDataset, EnumDict enums)
     : this(configDataset, enums, TimeZoneInfo.Local)
 {
 }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public CnlDataFormatter(ConfigDataset configDataset)
     : this(configDataset, new EnumDict(configDataset), TimeZoneInfo.Local)
 {
 }
Пример #13
0
        /// <summary>
        /// Compiles the scripts and formulas.
        /// </summary>
        public bool CompileScripts(ConfigDataset configDataset, HashSet <int> enableFormulasObjNums,
                                   Dictionary <int, CnlTag> cnlTags, Dictionary <int, OutCnlTag> outCnlTags)
        {
            if (configDataset == null)
            {
                throw new ArgumentNullException(nameof(configDataset));
            }
            if (cnlTags == null)
            {
                throw new ArgumentNullException(nameof(cnlTags));
            }
            if (outCnlTags == null)
            {
                throw new ArgumentNullException(nameof(outCnlTags));
            }

            try
            {
                log.WriteAction(Locale.IsRussian ?
                                "Компиляция исходного кода скриптов и формул" :
                                "Compile the source code of scripts and formulas");

                string sourceCode = GenerateSourceCode(configDataset.CnlTable, configDataset.ScriptTable,
                                                       enableFormulasObjNums, out Dictionary <int, string> cnlClassNames);
                SaveSourceCode(sourceCode, out string sourceCodeFileName);
                Compilation compilation = PrepareCompilation(sourceCode);

                using (MemoryStream memoryStream = new MemoryStream())
                {
                    EmitResult result = compilation.Emit(memoryStream);

                    if (result.Success)
                    {
                        Assembly assembly = Assembly.Load(memoryStream.ToArray());
                        RetrieveMethods(assembly, cnlTags, outCnlTags, cnlClassNames);

                        log.WriteAction(Locale.IsRussian ?
                                        "Исходный код скриптов и формул скомпилирован успешно" :
                                        "The source code of scripts and formulas has been compiled successfully");
                        return(true);
                    }
                    else
                    {
                        // write errors to log
                        log.WriteError(Locale.IsRussian ?
                                       "Ошибка при компиляции исходного кода скриптов и формул:" :
                                       "Error compiling the source code of the scripts and formulas:");

                        foreach (Diagnostic diagnostic in result.Diagnostics)
                        {
                            if (diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error)
                            {
                                log.WriteLine(Indent + diagnostic);
                            }
                        }

                        log.WriteLine(Indent + string.Format(Locale.IsRussian ?
                                                             "Проверьте исходный код в файле {0}" :
                                                             "Check the source code in {0}", sourceCodeFileName));
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                log.WriteError(ex, Locale.IsRussian ?
                               "Ошибка при компиляции исходного кода скриптов и формул" :
                               "Error compiling the source code of the scripts and formulas");
                return(false);
            }
        }
Пример #14
0
 /// <summary>
 /// Binds the view to the configuration database.
 /// </summary>
 public override void Bind(ConfigDataset configDataset)
 {
     AddCnlNumsForArrays(configDataset.CnlTable);
 }