예제 #1
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public FrmLineParams(Settings.CommLine commLine, CommEnvironment environment)
     : this()
 {
     this.commLine    = commLine ?? throw new ArgumentNullException("commLine");
     this.environment = environment ?? throw new ArgumentNullException("environment");
     customParams     = new SortedList <string, string>();
 }
예제 #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ValidateFields() && CheckFeasibility())
            {
                // create a new communication line
                CommLine commLineEntity = new CommLine
                {
                    CommLineNum = Convert.ToInt32(numCommLineNum.Value),
                    Name        = txtName.Text,
                    Descr       = txtDescr.Text
                };

                // insert the line in the configuration database
                project.ConfigBase.CommLineTable.AddItem(commLineEntity);
                project.ConfigBase.CommLineTable.Modified = true;

                // insert the line in the Communicator settings
                if (chkAddToComm.Checked && cbInstance.SelectedItem is Instance instance)
                {
                    if (instance.CommApp.Enabled)
                    {
                        CommLineSettings        = SettingsConverter.CreateCommLine(commLineEntity);
                        CommLineSettings.Parent = instance.CommApp.Settings;
                        instance.CommApp.Settings.CommLines.Add(CommLineSettings);
                    }

                    InstanceName = recentSelection.InstanceName = instance.Name;
                }

                recentSelection.CommLineNum = commLineEntity.CommLineNum;
                DialogResult = DialogResult.OK;
            }
        }
예제 #3
0
파일: CommShell.cs 프로젝트: ytchhh/scada
        /// <summary>
        /// Updates labels of the nodes that represent a communication line.
        /// </summary>
        public void UpdateCommLineNode(TreeNode commLineNode, CommEnvironment environment)
        {
            if (commLineNode == null)
            {
                throw new ArgumentNullException("commLineNode");
            }

            // update text of the line node
            Settings.CommLine commLine = (Settings.CommLine)((TreeNodeTag)commLineNode.Tag).RelatedObject;
            commLineNode.Text = string.Format(CommShellPhrases.CommLineNode, commLine.Number, commLine.Name);

            // remove the existing device nodes
            foreach (TreeNode lineSubNode in new ArrayList(commLineNode.Nodes))
            {
                if (lineSubNode.TagIs(CommNodeType.Device))
                {
                    lineSubNode.Remove();
                }
            }

            // add new device nodes
            foreach (Settings.KP kp in commLine.ReqSequence)
            {
                commLineNode.Nodes.Add(CreateDeviceNode(kp, environment));
            }
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public FrmDeviceData(Settings.KP kp, Settings.CommLine commLine, CommEnvironment environment)
     : this()
 {
     this.kp          = kp ?? throw new ArgumentNullException("kp");
     this.commLine    = commLine ?? throw new ArgumentNullException("commLine");
     this.environment = environment ?? throw new ArgumentNullException("environment");
     dataBox          = new RemoteLogBox(lbDeviceData)
     {
         FullLogView = true
     };
     frmDeviceCommand = null;
 }
예제 #5
0
 /// <summary>
 /// Создать линию связи и КП на основе настроек
 /// </summary>
 private CommLine CreateCommLine(Settings.CommLine commLineSett)
 {
     try
     {
         return(CommLine.Create(commLineSett, Settings.Params, AppDirs, PassCmd, kpTypes, AppLog));
     }
     catch (Exception ex)
     {
         AppLog.WriteException(ex, string.Format(Localization.UseRussian ?
                                                 "Ошибка при создании линии связи {0}" :
                                                 "Error creating communication line {0}", commLineSett.Number));
         return(null);
     }
 }
예제 #6
0
        /// <summary>
        /// Creates a node that represents the communication line.
        /// </summary>
        public TreeNode CreateCommLineNode(Settings.CommLine commLine, CommEnvironment environment)
        {
            string   commLineImageKey = commLine.Active ? "comm_line.png" : "comm_line_inactive.png";
            TreeNode commLineNode     = new TreeNode(string.Format(CommShellPhrases.CommLineNode,
                                                                   commLine.Number, commLine.Name))
            {
                ImageKey         = commLineImageKey,
                SelectedImageKey = commLineImageKey,
                Tag = new TreeNodeTag()
                {
                    RelatedObject = commLine,
                    NodeType      = CommNodeType.CommLine
                }
            };

            TreeNodeCollection lineSubNodes = commLineNode.Nodes;

            lineSubNodes.Add(new TreeNode(CommShellPhrases.LineParamsNode)
            {
                ImageKey         = "comm_params.png",
                SelectedImageKey = "comm_params.png",
                Tag = new TreeNodeTag()
                {
                    FormType      = typeof(FrmLineParams),
                    FormArgs      = new object[] { commLine, environment },
                    RelatedObject = commLine,
                    NodeType      = CommNodeType.LineParams
                }
            });

            lineSubNodes.Add(new TreeNode(CommShellPhrases.LineStatsNode)
            {
                ImageKey         = "comm_stats.png",
                SelectedImageKey = "comm_stats.png",
                Tag = new TreeNodeTag()
                {
                    FormType      = typeof(FrmLineStats),
                    FormArgs      = new object[] { commLine, environment },
                    RelatedObject = commLine,
                    NodeType      = CommNodeType.LineStats
                }
            });

            foreach (Settings.KP kp in commLine.ReqSequence)
            {
                lineSubNodes.Add(CreateDeviceNode(kp, commLine, environment));
            }

            return(commLineNode);
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public FrmLineStats(Settings.CommLine commLine, CommEnvironment environment)
     : this()
 {
     this.commLine    = commLine ?? throw new ArgumentNullException("commLine");
     this.environment = environment ?? throw new ArgumentNullException("environment");
     stateBox         = new RemoteLogBox(lbState)
     {
         FullLogView = true
     };
     logBox = new RemoteLogBox(lbLog, true)
     {
         AutoScroll = true
     };
     stateTabActive = true;
 }
예제 #8
0
 /// <summary>
 /// Creates a node that represents the device.
 /// </summary>
 public TreeNode CreateDeviceNode(Settings.KP kp, Settings.CommLine commLine, CommEnvironment environment)
 {
     return(new TreeNode(string.Format(CommShellPhrases.DeviceNode, kp.Number, kp.Name))
     {
         ImageKey = "comm_device.png",
         SelectedImageKey = "comm_device.png",
         Tag = new TreeNodeTag()
         {
             FormType = typeof(FrmDeviceData),
             FormArgs = new object[] { kp, commLine, environment },
             RelatedObject = kp,
             NodeType = CommNodeType.Device
         }
     });
 }
예제 #9
0
        /// <summary>
        /// Imports communication lines and devices.
        /// </summary>
        private void Import(out bool noData)
        {
            noData            = true;
            ImportedCommLines = new List <Settings.CommLine>();
            ImportedDevices   = new List <Settings.KP>();
            Settings settings = instance.CommApp.Settings;

            foreach (TreeNode commLineNode in treeView.Nodes)
            {
                if (commLineNode.Checked)
                {
                    CommLine          commLineEntity   = (CommLine)commLineNode.Tag;
                    Settings.CommLine commLineSettings = CommLineSettings;

                    if (commLineSettings == null)
                    {
                        // import communication line
                        noData                  = false;
                        commLineSettings        = SettingsConverter.CreateCommLine(commLineEntity);
                        commLineSettings.Parent = settings;
                        settings.CommLines.Add(commLineSettings);
                        ImportedCommLines.Add(commLineSettings);
                    }

                    foreach (TreeNode kpNode in commLineNode.Nodes)
                    {
                        if (kpNode.Checked)
                        {
                            // import device
                            noData = false;
                            KP          kpEntity   = (KP)kpNode.Tag;
                            Settings.KP kpSettings = SettingsConverter.CreateKP(kpEntity,
                                                                                project.ConfigBase.KPTypeTable);
                            kpSettings.Parent = commLineSettings;

                            if (commEnvironment.TryGetKPView(kpSettings, true, null, out KPView kpView, out string errMsg))
                            {
                                kpSettings.SetReqParams(kpView.DefaultReqParams);
                            }

                            commLineSettings.ReqSequence.Add(kpSettings);
                            ImportedDevices.Add(kpSettings);
                        }
                    }
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Synchronizes the communication line.
        /// </summary>
        private void SyncCommLine(Settings.CommLine commLineSettings)
        {
            if (project.ConfigBase.CommLineTable.Items.TryGetValue(commLineSettings.Number,
                                                                   out CommLine commLineEntity))
            {
                commLineSettings.Name = commLineEntity.Name;
            }

            BaseTable <KP>     kpTable     = project.ConfigBase.KPTable;
            BaseTable <KPType> kpTypeTable = project.ConfigBase.KPTypeTable;

            foreach (Settings.KP kpSettings in commLineSettings.ReqSequence)
            {
                if (kpTable.Items.TryGetValue(kpSettings.Number, out KP kpEntity))
                {
                    SettingsConverter.Copy(kpEntity, kpSettings, kpTypeTable);
                }
            }
        }
예제 #11
0
        private void btnSync_Click(object sender, EventArgs e)
        {
            CommLineSettings = cbCommLine.SelectedValue as Settings.CommLine;

            if (CommLineSettings == null)
            {
                // synchronize all lines
                foreach (Settings.CommLine commLineSettings in instance.CommApp.Settings.CommLines)
                {
                    SyncCommLine(commLineSettings);
                }
            }
            else
            {
                // synchronize selected line
                SyncCommLine(CommLineSettings);
            }

            DialogResult = DialogResult.OK;
        }
예제 #12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ValidateFields() && CheckFeasibility(out Comm.Settings.CommLine commLineSettings))
            {
                // create a new device
                int commLineNum = (int)cbCommLine.SelectedValue;
                KP  kpEntity    = new KP
                {
                    KPNum       = Convert.ToInt32(numKPNum.Value),
                    Name        = txtName.Text,
                    KPTypeID    = (int)cbKPType.SelectedValue,
                    Address     = txtAddress.Text == "" ? null : (int?)int.Parse(txtAddress.Text),
                    CallNum     = txtCallNum.Text,
                    CommLineNum = commLineNum > 0 ? (int?)commLineNum : null,
                    Descr       = txtDescr.Text
                };

                // insert the device in the configuration database
                project.ConfigBase.KPTable.AddItem(kpEntity);
                project.ConfigBase.KPTable.Modified = true;

                // insert the line in the Communicator settings
                if (chkAddToComm.Checked && cbInstance.SelectedItem is Instance instance)
                {
                    if (instance.CommApp.Enabled)
                    {
                        KPSettings        = SettingsConverter.CreateKP(kpEntity, project.ConfigBase.KPTypeTable);
                        KPSettings.Parent = commLineSettings;
                        commLineSettings.ReqSequence.Add(KPSettings);
                        CommLineSettings = commLineSettings;
                    }

                    InstanceName = recentSelection.InstanceName = instance.Name;
                }

                recentSelection.CommLineNum = commLineNum;
                recentSelection.KPNum       = kpEntity.KPNum;
                recentSelection.KPTypeID    = kpEntity.KPTypeID;
                DialogResult = DialogResult.OK;
            }
        }
예제 #13
0
        /// <summary>
        /// Checks feasibility of adding a device.
        /// </summary>
        private bool CheckFeasibility(out Settings.CommLine commLineSettings)
        {
            commLineSettings = null;
            int kpNum       = Convert.ToInt32(numKPNum.Value);
            int commLineNum = (int)cbCommLine.SelectedValue;

            if (project.ConfigBase.KPTable.PkExists(kpNum))
            {
                ScadaUiUtils.ShowError(AppPhrases.DeviceAlreadyExists);
                return(false);
            }

            if (chkAddToComm.Checked && cbInstance.SelectedItem is Instance instance && instance.CommApp.Enabled)
            {
                // load instance settings
                if (!instance.LoadAppSettings(out string errMsg))
                {
                    ScadaUiUtils.ShowError(errMsg);
                    return(false);
                }

                // reverse search communication line
                for (int i = instance.CommApp.Settings.CommLines.Count - 1; i >= 0; i--)
                {
                    Settings.CommLine commLine = instance.CommApp.Settings.CommLines[i];
                    if (commLine.Number == commLineNum)
                    {
                        commLineSettings = commLine;
                        break;
                    }
                }

                if (commLineSettings == null)
                {
                    ScadaUiUtils.ShowError(AppPhrases.CommLineNotFound);
                    return(false);
                }
            }

            return(true);
        }
예제 #14
0
 public bool Match(Settings.CommLine commLine)
 {
     return(CommChannelView.TypeName == commLine.CommCnlType);
 }
예제 #15
0
        private readonly CommEnvironment environment; // the application environment

        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public CommLineCommand(Settings.CommLine commLine, CommEnvironment environment)
        {
            this.commLine    = commLine ?? throw new ArgumentNullException("commLine");
            this.environment = environment ?? throw new ArgumentNullException("environment");
        }
예제 #16
0
파일: CommShell.cs 프로젝트: ytchhh/scada
 /// <summary>
 /// Creates a node and a corresponding object that represents the communication line.
 /// </summary>
 public TreeNode CreateCommLineNode(CommEnvironment environment)
 {
     Settings.CommLine commLine = new Settings.CommLine();
     return(CreateCommLineNode(commLine, environment));
 }