コード例 #1
0
ファイル: WccProject.cs プロジェクト: Unklenic/MultiConsole-W
        private void Worker()
        {
            Authorize();

            string host = "";

            if (this.MachineName == "localhost" ||
                this.MachineName == "127.0.0.1" ||
                this.MachineName == Dns.GetHostName())
            {
                tcpTimeOut = 250;
                host       = "127.0.0.1";
            }
            else
            {
                tcpTimeOut = 2000;
                host       = this.MachineName;
            }

            try
            {
                using (this.handler = WccTcp.tcpOpen(host, this.PmonPort))
                {
                    while (!this.shouldStop)
                    {
                        this.IsObserved = true;
                        RefreshInfo();
                        Thread.Sleep(this.TimeOut);
                    }
                    WccTcp.tcpClose(handler);
                }
            }
            catch (SocketException e)
            {
                Debugger.Write(ProjectAlias + ". " + e.Message);
                StopObserve();
            }

            this.shouldStop = false;
        }
コード例 #2
0
ファイル: WccProject.cs プロジェクト: Unklenic/MultiConsole-W
        /*
         * private string[] PmonQuery(string message)
         * {
         *  try
         *  {
         *      int iCount = 0;
         *      bool bAnswerFull = false;
         *      string result = "";
         *      string sTemp = "";
         *      List<string> ds1 = new List<string>();
         *      int tcpTimeOut;
         *      string host = "";
         *      if (this.MachineName == "localhost" ||
         *         this.MachineName == "127.0.0.1" ||
         *         this.MachineName == Dns.GetHostName())
         *      {
         *          tcpTimeOut = 250;
         *          host = "127.0.0.1";
         *      }
         *      else
         *      {
         *          tcpTimeOut = 2000;
         *          host = this.MachineName;
         *      }
         *      using (TcpHandler handler = ccTcp.tcpOpen(host, this.PmonPort))
         *      //using(TcpClient handler = new TcpClient())
         *      {
         *          ccTcp.tcpWrite(handler, message);
         *
         *          result = "-1";
         *
         *          while(result != "" && !bAnswerFull)
         *          {
         *              result = "";
         *              result = ccTcp.tcpRead(handler, tcpTimeOut);
         *
         *              if(message.Contains("#PROJECT"))
         *              {
         *                  ccTcp.tcpClose(handler);
         *                  return new string[] { result };
         *              }
         *
         *              sTemp += result;
         *              ds1.Clear();
         *              ds1.AddRange(sTemp.Split('\n'));
         *              if(ds1.Count > 1 && ds1[0].Contains("LIST") && iCount == 0)
         *              {
         *                  iCount = Convert.ToInt32(!string.IsNullOrEmpty(ds1[0]) ? ds1[0].Replace("LIST:", "") : "0");
         *                  if (message.Contains("#MGRLIST:STATI"))
         *                  {
         *                      iCount += 3;
         *                  }
         *                  else
         *                  {
         *                      iCount += 2;
         *                  }
         *              }
         *              else if (ds1.Count > 0 && iCount == 0)
         *              {
         *                  iCount = 1;
         *              }
         *
         *              while (ds1.Count > 0 && ds1[0].IndexOf("LIST:") == 0)
         *              {
         *                  ds1.RemoveAt(0);
         *              }
         *
         *              if (ds1.Count == iCount && iCount > 0)  //All pieces where get
         *              {
         *                  bAnswerFull = true;
         *                  break;
         *              }
         *              else
         *              {
         *                  Thread.Sleep(10);
         *              }
         *          }
         *          this.ConnectionState = WccConnectionState.Connected;
         *          ccTcp.tcpClose(handler);
         *      }
         *      return sTemp.Split('\n');
         *  }
         *  catch (ArgumentNullException e)
         *  {
         *      this.ConnectionState = WccConnectionState.Disconnected;
         *      Logger.Write(ProjectAlias + ". Ошибка при подключении к pmon: " + e.Message);
         *      // MessageBox.Show("ArgumentNullException: " + e); << В Лог
         *  }
         *  catch (SocketException e)
         *  {
         *      this.ConnectionState = WccConnectionState.Disconnected;
         *      Logger.Write(ProjectAlias + ". Ошибка при подключении к pmon: " + e.Message);
         *      // MessageBox.Show("SocketException: " + e); << В Лог
         *  }
         *  //this.ConnectionState = WccConnectionState.Warning;
         *  return null;//new string[] { string.Empty };
         * }
         */

        private string[] PmonQuery(string message)
        {
            try
            {
                int           iCount      = 0;
                bool          bAnswerFull = false;
                string        result      = "";
                string        sTemp       = "";
                List <string> ds1         = new List <string>();

                WccTcp.tcpWrite(handler, message);

                result = "-1";

                while (result != "" && !bAnswerFull)
                {
                    result = "";
                    result = WccTcp.tcpRead(handler, this.tcpTimeOut);

                    if (message.Contains("#PROJECT"))
                    {
                        //WccTcp.tcpClose(handler);
                        return(new string[] { result });
                    }

                    sTemp += result;
                    ds1.Clear();
                    ds1.AddRange(sTemp.Split('\n'));
                    if (ds1.Count > 1 && ds1[0].Contains("LIST") && iCount == 0)
                    {
                        iCount = Convert.ToInt32(!string.IsNullOrEmpty(ds1[0]) ? ds1[0].Replace("LIST:", "") : "0");
                        if (message.Contains("#MGRLIST:STATI"))
                        {
                            iCount += 3;
                        }
                        else
                        {
                            iCount += 2;
                        }
                    }
                    else if (ds1.Count > 0 && iCount == 0)
                    {
                        iCount = 1;
                    }

                    while (ds1.Count > 0 && ds1[0].IndexOf("LIST:") == 0)
                    {
                        ds1.RemoveAt(0);
                    }

                    if (ds1.Count == iCount && iCount > 0)  //All pieces where get
                    {
                        bAnswerFull = true;
                        break;
                    }
                    else
                    {
                        Thread.Sleep(10);
                    }

                    this.ConnectionState = WccConnectionState.Connected;
                }
                return(sTemp.Split('\n'));
            }
            catch (ArgumentNullException e)
            {
                this.ConnectionState = WccConnectionState.Disconnected;
                Debugger.Write(ProjectAlias + ". Ошибка при подключении к pmon: " + e.Message);
                // MessageBox.Show("ArgumentNullException: " + e); << В Лог
            }
            catch (SocketException e)
            {
                this.ConnectionState = WccConnectionState.Disconnected;
                if (!this.handler.Connected)
                {
                    StopObserve();
                }
                Debugger.Write(ProjectAlias + ". Ошибка при подключении к pmon: " + e.Message);
                // MessageBox.Show("SocketException: " + e); << В Лог
            }
            //this.ConnectionState = WccConnectionState.Warning;
            return(null);//new string[] { string.Empty };
        }