Exemple #1
0
        /// <summary>
        /// 打开连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                var tasks = new List <Task>();

                foreach (var iixServer in Global.ListIIXSerevr)
                {
                    if (iixServer.IsEnable == false)
                    {
                        continue;
                    }

                    tasks.Add(Task.Factory.StartNew(() =>
                    {
                        IIXExecute.ConnectToSlave(iixServer);
                    }));
                }

                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception ex)
            {
                Log.WriterExceptionLog(ex.ToString());
            }
        }
Exemple #2
0
        /// <summary>
        /// 初始化IIX服务端
        /// </summary>
        /// <returns></returns>
        private bool InitIIXServer()
        {
            bool f = false;

            try
            {
                IIXServer     iixServer = null;
                CmdResultCode cmdRes    = CmdResultCode.Other;

                #region Ted modified 20180522
                foreach (SlaveGroup slaveGroup in stationConfig.SlaveGroups)
                {
                    foreach (Slave slave in slaveGroup.Slaves)
                    {
                        int index = this.dgvServer.Rows.Add();
                        iixServer = new IIXServer();

                        iixServer.DmrSvrApi          = new IixDmrSvrApi();
                        iixServer.Ip                 = slave.ip;
                        iixServer.IsEnable           = slave.enable;
                        iixServer.AssociatedPanelPos = slave.description;
                        //iixServer.SvrType = SvrType.Left;

                        this.SetEventHandlers(iixServer);

                        DataGridViewRow row = this.dgvServer.Rows[index];
                        row.Cells["Enable"].Value       = slave.enable;
                        row.Cells["ServerIP"].Value     = slave.ip;
                        row.Cells["ServerPort"].Value   = iixServer.Port;
                        row.Cells["Open"].Value         = iixServer.ConnState.ToString();
                        row.Cells["PgPrimary"].Value    = iixServer.OutlineState[0].ToString();
                        row.Cells["PgSecondary"].Value  = iixServer.OutlineState[1].ToString();;
                        row.Cells["Status"].Value       = iixServer.ResultState.ToString();
                        row.Cells["LatestResult"].Value = iixServer.LatestResult;

                        Global.ListIIXSerevr.Add(iixServer);
                    }
                }

                //for (int i = 1; i <= 3; i++)
                //{
                //    int index = this.dgvServer.Rows.Add();

                //    iixServer = new IIXServer();

                //    string ip = IniFile.IniReadValue(string.Format("ServerLeft#" + i), "IP", Global.ConfigPath);
                //    bool isEnable = IniFile.IniReadValue(string.Format("ServerLeft#" + i), "IsEnable", Global.ConfigPath) == "1" ? true : false;

                //    iixServer.DmrSvrApi = new IixDmrSvrApi();
                //    iixServer.Ip = ip;
                //    iixServer.IsEnable = isEnable;
                //    iixServer.AssociatedPanelPos = "#" + i;
                //    iixServer.SvrType = SvrType.Left;

                //    this.SetEventHandlers(iixServer);

                //    this.dgvServer.Rows[index].Cells["Enable"].Value = isEnable;
                //    this.dgvServer.Rows[index].Cells["ServerIP"].Value = ip;
                //    this.dgvServer.Rows[index].Cells["ServerPort"].Value = iixServer.Port;
                //    this.dgvServer.Rows[index].Cells["Open"].Value = iixServer.ConnState.ToString();
                //    this.dgvServer.Rows[index].Cells["PgPrimary"].Value = iixServer.OutlineState[0].ToString();
                //    this.dgvServer.Rows[index].Cells["PgSecondary"].Value = iixServer.OutlineState[1].ToString(); ;
                //    this.dgvServer.Rows[index].Cells["Status"].Value = iixServer.ResultState.ToString();
                //    this.dgvServer.Rows[index].Cells["LatestResult"].Value = iixServer.LatestResult;

                //    Global.ListIIXSerevr.Add(iixServer);
                //}

                //for (int i = 1; i <= 3; i++)
                //{
                //    int index = this.dgvServer.Rows.Add();

                //    iixServer = new IIXServer();

                //    string ip = IniFile.IniReadValue(string.Format("ServerRight#" + i), "IP", Global.ConfigPath);
                //    bool isEnable = IniFile.IniReadValue(string.Format("ServerRight#" + i), "IsEnable", Global.ConfigPath) == "1" ? true : false;

                //    iixServer.DmrSvrApi = new IixDmrSvrApi();
                //    iixServer.Ip = ip;
                //    iixServer.IsEnable = isEnable;
                //    iixServer.AssociatedPanelPos = "#" + i;
                //    iixServer.SvrType = SvrType.Right;

                //    this.SetEventHandlers(iixServer);

                //    this.dgvServer.Rows[index].Cells["Enable"].Value = isEnable;
                //    this.dgvServer.Rows[index].Cells["ServerIP"].Value = ip;
                //    this.dgvServer.Rows[index].Cells["ServerPort"].Value = iixServer.Port;
                //    this.dgvServer.Rows[index].Cells["Open"].Value = iixServer.ConnState.ToString();
                //    this.dgvServer.Rows[index].Cells["PgPrimary"].Value = iixServer.OutlineState[0].ToString();
                //    this.dgvServer.Rows[index].Cells["PgSecondary"].Value = iixServer.OutlineState[1].ToString(); ;
                //    this.dgvServer.Rows[index].Cells["Status"].Value = iixServer.ResultState.ToString();
                //    this.dgvServer.Rows[index].Cells["LatestResult"].Value = iixServer.LatestResult;
                //    Global.ListIIXSerevr.Add(iixServer);
                //}

                #endregion

                var tasks = new List <Task>();

                foreach (var _iixServer in Global.ListIIXSerevr)
                {
                    tasks.Add(Task.Factory.StartNew(() =>
                    {
                        //连接
                        cmdRes = IIXExecute.ConnectToSlave(_iixServer);

                        //连接成功后就打开
                        if (cmdRes == CmdResultCode.Success)
                        {
                            Log.WriterActionLog(string.Format("Slave {0}:{1} connected SUCCESS!", _iixServer.Ip, _iixServer.Port));
                            cmdRes = IIXExecute.Open(_iixServer);
                            if (cmdRes == CmdResultCode.Success)
                            {
                                Log.WriterActionLog(string.Format("Slave {0}:{1} open SUCCESS!", _iixServer.Ip, _iixServer.Port));
                            }
                            else
                            {
                                Log.WriterExceptionLog(string.Format("Slave {0}:{1} open FAIL!", _iixServer.Ip, _iixServer.Port));
                            }
                        }
                        else
                        {
                            Log.WriterExceptionLog(string.Format("Slave {0}:{1} connected FAIL!", _iixServer.Ip, _iixServer.Port));
                        }
                    }));
                }

                Task.WaitAll(tasks.ToArray());

                f = true;
            }
            catch (Exception ex)
            {
                f = false;
                Log.WriterExceptionLog(ex.ToString());
            }

            return(f);
        }