private void RefreshProjectState()
        {
            int result = GetProjectInfo();

            switch (result)
            {
            case -1:
                this.ConnectionState = WccConnectionState.Disconnected;
                break;

            case 0:
                this.ConnectionState = WccConnectionState.Warning;
                break;
            }

            if (ProjectStateChanged != null && this.IsObserved && !this.shouldStop)
            {
                RefreshManagersState();
                if (this.ConnectionState == WccConnectionState.Disconnected)
                {
                    this.Managers.Clear();
                }
                ProjectStateChanged(this);
            }
        }
 private void Initialize()
 {
     this.Managers        = new WccManagerCollection();
     this.shouldStop      = false;
     this.IsObserved      = false;
     this.IsReady         = false;
     this.TimeOut         = 5000;
     this.pmonPort        = 0;
     this.machineName     = "";
     this.autoconnect     = false;
     this.ConnectionState = WccConnectionState.Non;
     //this.managerCounter = -1;
     this.Credential = new EncryptContainer();
     this.Credential.DefaultAutorization = true;
     this.Credential.Login    = "";
     this.Credential.Password = "";
     this.authorized          = false;
     this.IsStarted           = false;
     //this.needReloadManagerList = false;
     this.ProjectName = "";
     this.tcpTimeOut  = 250;
     this.Path        = "";
     //this.receiveDone = new ManualResetEvent(false);
     //thread = new Thread(this.Worker);
 }
 public void Observe()
 {
     this.ConnectionState = WccConnectionState.Processing;
     if (this.IsReady && !this.IsObserved)
     {
         thread = new Thread(Worker);
         thread.Start();
     }
 }
 public void StopObserve()
 {
     this.ConnectionState = WccConnectionState.Processing;
     this.shouldStop      = true;
     this.Managers.Clear();
     //this.managerCounter = -1;
     if (this.thread != null && this.IsObserved)
     {
         //this.thread.Abort();
         DeleteAutorize();
     }
     this.ConnectionState = WccConnectionState.Disconnected;
     this.IsObserved      = false;
     //this.Managers.Clear();
     if (ProjectStateChanged != null)
     {
         ProjectStateChanged(this);
     }
 }
        /*
         * 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 };
        }