コード例 #1
0
ファイル: DXC.cs プロジェクト: YuraFilionchik/DXC
      public ClassDxc(string ip)
      {
          string methodName = new StackTrace(false).GetFrame(0).GetMethod().Name;

          Session = new TFTPSession();
          try
          {
              if (!MainForm.IsIPFormat(ip))
              {
                  MessageBox.Show("Неверный формат IP");
                  return;
              }
              dataStorage = new DataStorage(this);
              Buffer      = "";
              //Cfg=cfg;
              this.Ip         = ip;
              this.CustomName = "";
              this.BackupPath = "";
              this.Alarms     = new List <Alarm>();
              this.Info       = new Dxcinfo(false);
              this.Ports      = new List <Port>();

              Session.Connected        += new TFTPSession.ConnectedHandler(_session_Connected);
              Session.Transferring     += new TFTPSession.TransferringHandler(_session_Transferring);
              Session.TransferFailed   += new TFTPSession.TransferFailedHandler(_session_TransferFailed);
              Session.TransferFinished += new TFTPSession.TransferFinishedHandler(_session_TransferFinished);
              Session.Disconnected     += new TFTPSession.DisconnectedHandler(_session_Disconnected);
          }
          catch (Exception exception)
          {
              MessageBox.Show(exception.Message);
              Log.WriteLog(methodName, exception.Message);
          }
      }
コード例 #2
0
ファイル: MyStructures.cs プロジェクト: YuraFilionchik/DXC
 public bool Equals(Dxcinfo other)
 {
     // add comparisions for all members here
     return(this.SysName == other.SysName &&
            this.Nodalclock == other.Nodalclock &&
            this.ActiveDBnuber == other.ActiveDBnuber &&
            CompairModules(this.Modules, other.Modules)
            );
 }
コード例 #3
0
ファイル: DXC.cs プロジェクト: YuraFilionchik/DXC
//        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);
          }
      }
コード例 #4
0
ファイル: DXC.cs プロジェクト: YuraFilionchik/DXC
      private Dxcinfo ParseDxcInfo(string text)
      {
          string methodName = new StackTrace(false).GetFrame(0).GetMethod().Name;

          if (string.IsNullOrWhiteSpace(text))
          {
              return(new Dxcinfo());
          }
          Dxcinfo info = new Dxcinfo();

          try
          {
              info.Modules = new Dictionary <string, string>();
              text         = text.Replace('\r', ' ');
              var lines = text.Split('\n');

              for (int i = 0; i < lines.Length; i++)
              {
                  string line     = lines[i];
                  var    wordsAll = line.Split(' ');
                  var    words    = wordsAll.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

                  if (words.Length >= 6 && words[3].Contains("NAME"))
                  {
                      info.SysName = words[5]; //name
                      continue;
                  }
                  if (words.Length >= 4 && words[1].Contains("CLOCK"))
                  {
                      info.Nodalclock = words[3]; //nodal clock
                      continue;
                  }
                  if (words.Length >= 9 && words[5].Contains("DATABASE") && words[6].Contains("NUMBER")) //DB number
                  {
                      info.ActiveDBnuber = words[8];
                      continue;
                  }
                  if (words.Length >= 7 && words[0].Contains("I/O"))
                  {
                      var wordsNext = lines[i + 2].Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();;
                      info.Modules.Add(words[2], wordsNext[2]);
                      info.Modules.Add(words[3], wordsNext[3]);
                      info.Modules.Add(words[4], wordsNext[4]);
                      info.Modules.Add(words[5], wordsNext[5]);
                      info.Modules.Add(words[6], wordsNext[6]);
                      continue;
                  }
                  if (words.Length >= 4 && words[0].Contains("TIME"))
                  {
                      info.Time = DateTime.ParseExact(words[1], "HH:mm:ss", null);
                      info.Date = DateTime.Parse(words[3]);
                      DateTime fullDate = new DateTime(info.Date.Year, info.Date.Month, info.Date.Day,
                                                       info.Time.Hour, info.Time.Minute, info.Time.Second);
                      info.Dt = fullDate - DateTime.Now; //установка разницы во времени оборудования DXC и данного ПК
                  }
              }

              return(info);
          }
          catch (Exception exception)
          {
              Log.WriteLog(methodName, exception.Message);

              return(info);
          }
      }