Пример #1
0
        private void UpdateDeviceTagsToService()
        {
            DeviceEntity device = null;
            DCSGatewayServiceController service = null;

            if (trees.CurrentNode().Tag is Guid id)
            {
                BaseEntity entity = DataHelper.Instance.AllEntities[id];
                if (entity is DeviceEntity deviceEntity)
                {
                    device  = deviceEntity;
                    service = deviceEntity.Service;
                }
                else if (entity is ProductionLineEntity line)
                {
                    if (lineProp == null)
                    {
                        return;
                    }

                    if (lineProp.FocusedDevice == null)
                    {
                        return;
                    }

                    device  = lineProp.FocusedDevice;
                    service = lineProp.FocusedDevice.Service;
                }

                if (service != null)
                {
                    try
                    {
                        if (ServiceHelper.Instance.StopService(service.ServName))
                        {
                            service.UpdateDeviceTagsParam();
                        }
                        else
                        {
                            XtraMessageBox.Show(
                                $"无法停止DCS网关服务[{service.ServName}]运行",
                                "提示",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                            trees.ResetMenuItemEnable();
                        }

                        ServiceHelper.Instance.StartService(service.ServName);
                    }
                    catch (Exception error)
                    {
                        XtraMessageBox.Show(
                            $"更新设备标签配置文件的时候发生错误:{error.Message}",
                            "出错啦",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
            }
        }
Пример #2
0
        private void RegisterService()
        {
            DeviceEntity device = null;
            DCSGatewayServiceController service = null;

            if (trees.CurrentNode().Tag is Guid id)
            {
                BaseEntity entity = DataHelper.Instance.AllEntities[id];
                if (entity is DeviceEntity deviceEntity)
                {
                    device  = deviceEntity;
                    service = deviceEntity.Service;
                }
                else if (entity is ProductionLineEntity line)
                {
                    if (lineProp == null)
                    {
                        return;
                    }

                    if (lineProp.FocusedDevice == null)
                    {
                        return;
                    }

                    device  = lineProp.FocusedDevice;
                    service = lineProp.FocusedDevice.Service;
                }

                if (service != null)
                {
                    try
                    {
                        service.ResetServName();
                        service.Deploy();

                        trees.RefreshTreeNodeStatue();

                        XtraMessageBox.Show(
                            $"设备[{device.Name}]的DCS网关部署成功",
                            "提示",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                        trees.ResetMenuItemEnable();
                    }
                    catch (Exception error)
                    {
                        XtraMessageBox.Show(
                            $"部署网关的时候发生错误:{error.Message}",
                            "出错啦",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
            }
        }
Пример #3
0
        public DeviceEntity(ProductionLineEntity parent)
        {
            Parent =
                parent ??
                throw new Exception(
                          "设备对象不能单独存在,必须要依赖于ProductLineEntity对象");

            name = $"KnownDevice[{Guid.NewGuid().ToString("N")}]";

            Service = new DCSGatewayServiceController(this);
        }