Beispiel #1
0
//        public static bool operator ==(DXC left, DXC right)
//        {
//            return left.Equals(right);
//        }
//
//        public static bool operator !=(DXC left, DXC right)
//        {
//
//            return !left.Equals(right);
//        }
      #endregion

      public void UpdateDb(string number)
      {
          string methodName = new StackTrace(false).GetFrame(0).GetMethod().Name;

          if (!IpPingOk(Ip))
          {
              DxcEvent(this.CustomName, this.Ip + " адрес не доступен. Не удалось сохранить Backup!");
              return;
          }
          TelnetConnection tc = new TelnetConnection(Ip, 23);

          try
          {
              //TelnetClient tc=new TelnetClient();
              //                tc.Connect(IPAddress.Parse(IP),23);
              //                tc.DataReceived += Tc_DataReceived;
              //                while (tc.IsConnected())
              //                {
              //                    var  buffer = tc.InputBuffer;
              //                    if(buffer.BaseStream.CanRead)
              //                     Program.MF.InvokeLog(methodName, tc.InputBuffer.ReadString());
              //                    tc.Disconnect();
              //                }

              string command = "upd db " + number;

              DxcEvent(this.Info.SysName, "Открытие telnet " + Ip);
              string ans = tc.Read();
              // DXCEvent(this.info.sys_name, "Успешно");
              Thread.Sleep(200);
              DxcEvent(this.Info.SysName, "Отправка команды " + command);
              tc.WriteLine(command);
              Thread.Sleep(2000);
              DxcEvent(this.Info.SysName, "Успешно.");
              tc.Close();
              DxcEvent(this.Info.SysName, "Соединение закрыто.");
          }
          catch (Exception exception)
          {
              if (tc.IsConnected)
              {
                  tc.Close();
                  DxcEvent(this.Info.SysName, "Произошла ошибка. Соединение закрыто");
              }
              Log.WriteLog(methodName, exception.Message);
          }
      }
Beispiel #2
0
//        void transfer_OnFinished(Tftp.Net.ITftpTransfer transfer)
//        {
//          //Log.WriteLog("","Файл скопирован");
//           TransferFinishedEvent.Set();
//          // SaveStreamToFile(, DestFile);
//
//        }

//        void transfer_OnProgress(Tftp.Net.ITftpTransfer transfer, Tftp.Net.TftpTransferProgress progress)
//        {
//          //Log.WriteLog("","Копируется "+progress);
//        }
//
//        void transfer_OnError(Tftp.Net.ITftpTransfer transfer, Tftp.Net.TftpTransferError error)
//        {
//          Log.WriteLog("",error.ToString());
//           TransferFinishedEvent.Set();
//        }
      public bool ReadInfoFromIp()
      {
          string methodName = new StackTrace(false).GetFrame(0).GetMethod().Name;

          try
          { DxcEvent("system", "tcp-opened");
            if (!IpPingOk(Ip))
            {
                // MessageBox.Show("Адрес "+ip+" не доступен.");
                DxcEvent(this.CustomName, this.Ip + " адрес не доступен");
                DxcEvent("system", "tcp-closed");
                return(false);
            }
            TelnetConnection tc  = new TelnetConnection(Ip, 23);
            string           ans = tc.Read();
            Buffer = ans;
            // Program.MF.InvokeLog(methodName, ans);
            Thread.Sleep(100);
            tc.WriteLine("dsp st sys");
            bool readed = false;
            while (!readed)        //ответ. первый блок аварий
            {
                Thread.Sleep(100); //пауза
                var b = tc.Read();
                Buffer += b;       //накапливаем ответ команды
                if (String.IsNullOrEmpty(b))
                {
                    readed = true;                       //ждём когда закончится чтение
                }
            }

            Info = ParseDxcInfo(Buffer);
            tc.Close();
            DxcEvent("system", "tcp-closed");
            return(true); }
          catch (Exception exception)
          {
              //Program.MF.InvokeLog(methodName, exception.Message);
              Log.WriteLog(methodName, exception.Message);
              DxcEvent("system", "tcp-closed");
              return(false);
          }
      }
Beispiel #3
0
      public Port DSP_CON(int bord, int port)
      {
          string methodName = new StackTrace(false).GetFrame(0).GetMethod().Name;
          var    PORT       = this.Ports.FirstOrDefault(x => x.BordNumber == bord && x.PortNumber == port);

          try
          {
              if (!IpPingOk(Ip))
              {
                  // MessageBox.Show("Адрес "+ip+" не доступен.");
                  DxcEvent(this.CustomName, this.Ip + " адрес не доступен");
                  return(PORT);
              }


              TelnetConnection tc  = new TelnetConnection(Ip, 23);
              string           ans = tc.Read();
              Buffer = ans;
              Thread.Sleep(100);
              tc.WriteLine(String.Format("dsp con {0} {1}", bord, port));

              Thread.Sleep(1500);
              Buffer = tc.Read();
              //Thread.Sleep(500);
              if (!String.IsNullOrWhiteSpace(Buffer))
              {
                  PORT.Connections.ParseTextDSP_CON(Buffer);
              }
              tc.Close();
              return(PORT);
          }
          catch (Exception exception)
          {
              //Program.MF.InvokeLog(methodName, exception.Message);
              Log.WriteLog(methodName, exception.Message + "buffer: " + Buffer);
              return(PORT);
          }
      }
Beispiel #4
0
      /// <summary>
      /// Чтение аварий через telnet и заполнение списка аварий
      /// </summary>
      /// <param name="repeats">Количество повторов dsp alm</param>
      public void ReadAlarms(int repeats)
      {
          string methodName = new StackTrace(false).GetFrame(0).GetMethod().Name;

          try
          {
              DxcEvent("system", "tcp-opened");
              if (!IpPingOk(Ip))
              {
                  //MessageBox.Show(ip+" адрес не доступен");
                  DxcEvent(this.CustomName, this.Ip + " адрес не доступен");
                  DxcEvent("system", "tcp-closed");
                  return;
              }
              List <Alarm>     buffAlarms = new List <Alarm>();
              TelnetConnection tc         = new TelnetConnection(Ip, 23);
              string           ans        = tc.Read();
              Buffer = "";
              Thread.Sleep(100);
              tc.WriteLine("dsp alm"); //запрос
              Thread.Sleep(200);       //пауза
              bool readed = false;
              while (!readed)
              {
                  var b0 = tc.Read();
                  Thread.Sleep(200); //пауза
                  Buffer += b0;      //ответ. первый блок аварий
                  if (String.IsNullOrEmpty(b0))
                  {
                      readed = true;
                  }
              }

              buffAlarms = ParseAlarms(Buffer); //аварии первого запроса

              if (Alarms.Any(x => buffAlarms.Any(b => b == x && b.Active == x.Active)))
              { //в буфере уже есть хотябы одна авария из ранее считанных
                  Alarms = Program.Helper.MergeAlarms(Alarms, buffAlarms);
                  tc.Close();
                  DxcEvent("system", "tcp-closed");
                  return;
              } //повторяем пока не дойдем до существующей аварии или не достигнем счетчика
              while (repeats > 1 && !Alarms.Any(x => buffAlarms.Any(b => b == x && b.Active == x.Active)))
              {
                  tc.Write(" ");
                  Thread.Sleep(100);
                  bool endread = false;
                  Buffer = "";
                  while (!endread)
                  {
                      var b0 = tc.Read();
                      Thread.Sleep(100); //пауза
                      Buffer += b0;      //ответ. первый блок аварий
                      if (String.IsNullOrEmpty(b0))
                      {
                          endread = true;
                      }
                  }
                  buffAlarms = Program.Helper.MergeAlarms(buffAlarms, ParseAlarms(Buffer));           //объединяем считанные аварии с прошлыми
                  repeats--;
              }
              //вышли из цикла

              #region analyze new alarms and generate event for Beep

              var diffAlarms = buffAlarms.Where(x => !Alarms.Any(c => c == x));  //only new alarms
              if (diffAlarms.Any(x => this.Ports.Any(p => p.Monitored &&
                                                     p.BordNumber == x.BordNumber &&
                                                     p.PortNumber == x.PortNumber)))
              {  //среди новых аварий есть аварии, принадлежащие порту с включенным мониторингом
                  DxcEvent(this.CustomName, "new alarms: " + diffAlarms.Count());
              }

              #endregion
              Alarms = Program.Helper.MergeAlarms(Alarms, buffAlarms);
              tc.Close();
              DxcEvent("system", "tcp-closed");
          }
          catch (Exception exception)
          {
              Log.WriteLog(methodName, exception.Message);
              DxcEvent("system", "tcp-closed");
          }
      }