Exemplo n.º 1
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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateServiceFile()
        {
            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.ResetServName();
                            service.CopyDCSGatewayServiceFile();
                        }
                        else
                        {
                            XtraMessageBox.Show(
                                $"无法停止DCS网关服务[{service.ServName}]运行",
                                "提示",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                            trees.ResetMenuItemEnable();
                        }

                        ServiceHelper.Instance.StartService(service.ServName);

                        trees.RefreshTreeNodeStatue();
                    }
                    catch (Exception error)
                    {
                        XtraMessageBox.Show(
                            $"更新DCS网关服务程序文件的时候发生错误:{error.Message}",
                            "出错啦",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
            }
        }