Exemplo n.º 1
0
 public void LoadProject()
 {
     Task.Run(() =>
     {
         DataBaseFileName = Application.StartupPath + "\\IOProject\\IOCenterServer.station";
         //设置数据库数据源
         DbHelperSQLite.connectionString = "Data Source=" + DataBaseFileName;
         IO_SERVER serverBll             = new IO_SERVER();
         IO_COMMUNICATION commBll        = new IO_COMMUNICATION();
         IO_DEVICE deviceBll             = new IO_DEVICE();
         AddLog("初始化采集站数据......");
         Servers = serverBll.GetModelList("");
         AddLog("采集站数据已经完成!");
         AddLog("加载通道数据......");
         Communications = commBll.GetModelList("");
         AddLog("通道数据已经完成!");
         AddLog("加载设备及其IO点表......");
         Devices = deviceBll.GetModelList("");
         AddLog("加载设备及其IO点表已经完成");
         for (int i = 0; i < Communications.Count; i++)
         {
             Communications[i].Devices = Devices.FindAll(x => x.IO_COMM_ID == Communications[i].IO_COMM_ID && x.IO_SERVER_ID == Communications[i].IO_SERVER_ID);
         }
     });
 }
Exemplo n.º 2
0
        public void InitBaseModel()
        {
            Task.Run(() =>
            {
                try
                {
                    DbHelperSQLite.connectionString = "Data Source=" + Application.StartupPath + "\\IOProject\\Station.station";
                    IO_SERVER serverBll             = new IO_SERVER();
                    AddLogToMainLog("读取采集站信息......");
                    IOServer = serverBll.GetModel(ComputerInfo.GetInstall().ServerID);
                    if (IOServer == null)
                    {
                        return;
                    }
                    mServerID = IOServer.SERVER_ID;
                    //加载通道
                    AddLogToMainLog("读取采集站通道信息......");
                    IO_COMMUNICATION commBll = new IO_COMMUNICATION();
                    IOCommunications         = commBll.GetModelList(" IO_SERVER_ID='" + IOServer.SERVER_ID + "'");
                    AddLogToMainLog("读取采集站通道下的所有设备信息......");
                    IO_DEVICE deviceBll = new IO_DEVICE();
                    IODevices           = deviceBll.GetModelList(" IO_SERVER_ID='" + IOServer.SERVER_ID + "'");
                    AddLogToMainLog("数据处理中.....");

                    for (int i = 0; i < IOCommunications.Count; i++)
                    {
                        AddLogToMainLog("处理 " + IOCommunications[i].IO_COMM_NAME + "[" + IOCommunications[i].IO_COMM_LABEL + "]");
                        IOCommunications[i].Devices = IODevices.FindAll(x => x.IO_COMM_ID == IOCommunications[i].IO_COMM_ID && x.IO_SERVER_ID == IOCommunications[i].IO_SERVER_ID);
                    }
                    AddLogToMainLog("正在创建驱动.....");

                    AddLogToMainLog("读取工程完成!");
                    ProgressMaxNum = IOCommunications.Count + IODevices.Count;
                    FlowGraphEngineProject.IOServer         = IOServer;
                    FlowGraphEngineProject.IOCommunications = IOCommunications;
                }
                catch (Exception ex)
                {
                    ThrowExceptionToMain(ex);
                }
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// 卸载并重新加载资源
        /// </summary>
        /// <param name="IO_SERVER_ID"></param>
        /// <returns></returns>
        public void ReloadProject(string IO_SERVER_ID, EndPoint clientEndPoint)
        {
            Task.Run(() =>
            {
                if (IO_SERVER_ID == "")
                {
                    return;
                }
                IOCenterManager.TCPServer.TcpServerStatus = TcpServerStatus.暂停;//暂停TCP服务
                try
                {
                    IO_SERVER serverBll      = new IO_SERVER();
                    IO_COMMUNICATION commBll = new IO_COMMUNICATION();
                    IO_DEVICE deviceBll      = new IO_DEVICE();
                    AddLog("重新初始化采集站");
                    lock (Servers)
                    {
                        Scada.Model.IO_SERVER deleteServer = Servers.Find(x => x.SERVER_ID == IO_SERVER_ID);
                        if (deleteServer != null)
                        {
                            Servers.Remove(deleteServer);//删除这个采集站信息
                        }

                        Scada.Model.IO_SERVER newsServer = serverBll.GetModel(IO_SERVER_ID);
                        if (newsServer != null)
                        {
                            Servers.Add(newsServer);
                        }
                        else
                        {
                            return;
                        }
                    }

                    lock (Communications)
                    {
                        AddLog("重新初始化采集站通道.....");
                        for (int i = Communications.Count - 1; i >= 0; i--)
                        {
                            if (Communications[i].IO_SERVER_ID == IO_SERVER_ID)
                            {
                                //首先删除设备
                                for (int d = Communications[i].Devices.Count - 1; d >= 0; d--)
                                {
                                    Devices.Remove(Communications[i].Devices[d]);
                                }
                                Communications.RemoveAt(i);
                            }
                        }
                        AddLog("重新初始化采集站设备信息.....");
                        List <Scada.Model.IO_COMMUNICATION> newsCommunications = commBll.GetModelList(" IO_SERVER_ID='" + IO_SERVER_ID + "' ");
                        Communications.AddRange(newsCommunications);
                        List <Scada.Model.IO_DEVICE> newsDevices = deviceBll.GetModelList("  IO_SERVER_ID='" + IO_SERVER_ID + "'");
                        Devices.AddRange(newsDevices);
                        AddLog("处理通道与设备关系.....");
                        for (int i = 0; i < newsCommunications.Count; i++)
                        {
                            newsCommunications[i].Devices = newsDevices.FindAll(x => x.IO_COMM_ID == newsCommunications[i].IO_COMM_ID && x.IO_SERVER_ID == newsCommunications[i].IO_SERVER_ID);
                        }

                        AddLog("重新初始化功能树.......");
                        IOCenterManager.QueryFormManager.LoadIOProject();
                        AddLog("重新初始化模拟器.......");
                        IOCenterManager.SimulatorManager.ReloadSimulator(IO_SERVER_ID);
                        AddLog("重新初始化监视器.......");
                        IOCenterManager.TCPServer.InitTree();
                        AddLog("发布工程完成!");
                        TcpData sendData = new TcpData();
                        sendData.Items.Add(new TcpDataItem()
                        {
                            Key = "RELUST", Value = "true"
                        });
                        sendData.Items.Add(new TcpDataItem()
                        {
                            Key = "MSG", Value = "采集站工程发布成功,正在重新初始化数据中心服务器,请耐心等待......"
                        });
                        sendData.Items.Add(new TcpDataItem()
                        {
                            Key = "IO_SERVER_ID", Value = IO_SERVER_ID
                        });
                        IOCenterManager.TCPServer.SendData(clientEndPoint, sendData.TcpItemToString(), ScadaTcpOperator.发布工程成功);
                    }
                }
                catch (Exception ex)
                {
                    DisplyException(new Exception("更新服务器失败" + ex.Message));
                    TcpData sendData = new TcpData();
                    sendData.Items.Add(new TcpDataItem()
                    {
                        Key = "RELUST", Value = "true"
                    });
                    sendData.Items.Add(new TcpDataItem()
                    {
                        Key = "MSG", Value = "更新服务器失败"
                    });
                    sendData.Items.Add(new TcpDataItem()
                    {
                        Key = "IO_SERVER_ID", Value = IO_SERVER_ID
                    });
                    IOCenterManager.TCPServer.SendData(clientEndPoint, sendData.TcpItemToString(), ScadaTcpOperator.发布工程失败);
                }
                IOCenterManager.TCPServer.TcpServerStatus = TcpServerStatus.运行;//暂停TCP服务
            });
        }
Exemplo n.º 4
0
        public static void InitBaseModel()
        {
            if (ServerID == "")
            {
                return;
            }
            try
            {
                DbHelperSQLite.connectionString = "Data Source=" + Application.StartupPath + "\\IOProject\\Station.station";
                IO_SERVER serverBll = new IO_SERVER();
                AddLogToMainLog("读取采集站信息......");
                IOServer = serverBll.GetModel(mServerID);
                if (IOServer == null)
                {
                    return;
                }
                mServerID          = IOServer.SERVER_ID;
                IOServer.SERVER_IP = LocalIp.GetLocalIp();
                serverBll.Update(IOServer);
                //加载通道
                AddLogToMainLog("读取采集站通道信息......");
                IO_COMMUNICATION    commBll         = new IO_COMMUNICATION();
                SCADA_DRIVER        DriverBll       = new SCADA_DRIVER();
                SCADA_DEVICE_DRIVER DeviceDriverBll = new SCADA_DEVICE_DRIVER();
                CommDrivers      = DriverBll.GetModelList("");
                DeviceDrivers    = DeviceDriverBll.GetModelList("");
                IOCommunications = commBll.GetModelList(" IO_SERVER_ID='" + IOServer.SERVER_ID + "'");

                AddLogToMainLog("读取采集站通道下的所有设备信息......");
                IO_DEVICE deviceBll = new IO_DEVICE();
                IODevices = deviceBll.GetModelList(" IO_SERVER_ID='" + IOServer.SERVER_ID + "'");
                AddLogToMainLog("数据处理中.....");

                for (int i = 0; i < IOCommunications.Count; i++)
                {
                    IOCommunications[i].DriverInfo = CommDrivers.Find(x => x.Id == IOCommunications[i].IO_COMM_DRIVER_ID);
                    if (IOCommunications[i].DriverInfo != null)
                    {
                        IOCommunications[i].CommunicateDriver = DriverAssembly.CreateCommunicateDriver(IOCommunications[i].DriverInfo);
                    }
                    AddLogToMainLog("处理 " + IOCommunications[i].IO_COMM_NAME + "[" + IOCommunications[i].IO_COMM_LABEL + "]");
                    IOCommunications[i].Devices = IODevices.FindAll(x => x.IO_COMM_ID == IOCommunications[i].IO_COMM_ID && x.IO_SERVER_ID == IOCommunications[i].IO_SERVER_ID);
                    for (int j = 0; j < IOCommunications[i].Devices.Count; j++)
                    {
                        IOCommunications[i].Devices[j].DriverInfo = DeviceDrivers.Find(x => x.Id == IOCommunications[i].Devices[j].DEVICE_DRIVER_ID);

                        if (IOCommunications[i].Devices[j].DriverInfo != null)
                        {
                            IOCommunications[i].Devices[j].DeviceDrive = DriverAssembly.CreateDeviceDrive(IOCommunications[i].Devices[j].DriverInfo);
                        }
                    }
                }
                AddLogToMainLog("正在创建驱动.....");

                AddLogToMainLog("读取工程完成!");
                ProgressMaxNum = IOCommunications.Count + IODevices.Count;
            }
            catch (Exception ex)
            {
                ThrowExceptionToMain(ex);
            }
        }