Exemplo n.º 1
0
        protected override void SendCommand(DataRow dr)
        {
            SNMPDevice        _device;
            SNMPCommandSignal _command;

            // Komutun gideceği cihaz bulunur.
            _device = Devices.Where((d) => d.CommandSignals.Exists((c) => c.ID == dr.Field <uint>("command_signal_id"))).FirstOrDefault();

            if (_device != null)
            {
                // Komut sinyalinin bilgileri alınır.
                _command = _device.CommandSignals.Where((c) => c.ID == dr.Field <uint>("command_signal_id")).First();
                _command.CommandValue = dr.Field <float>("value");
                try
                {
                    if (_command != null)
                    {
                        // komut gönderilecek device'in hangi TCPClient üzerinden haberleştiği bulunur ve komut gönderilir.
                        AbstractTCPClient TCPClient = TCPClients.Where((m) => m.Devices.Exists((d) => d.ID == _device.ID)).First();

                        if (TCPClient.WriteValue(_device, _command))
                        {
                            DBHelper.DeleteActiveCommandFromDatabase(dr.Field <uint>("command_signal_id"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Instance.Error("{0} adlı cihaza {1} komutu gönderirirken hata => {2}", _device.Name, _command.Name, ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 通过监听客户端的连接请求,建立与客户端的TCP连接
        /// </summary>
        private void ListenToClientByTCP()
        {
            //TcpClient tc = new TcpClient();
            //tc.GetStream();
            IPAddress  localIP = IPAddress.Any;
            IPEndPoint iep     = new IPEndPoint(localIP, PublicParams.LocalPort);

            Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            server.Bind(iep);
            server.Listen(10);
            //PublicParams.pubSocketServer = server;
            while (true)
            {
                try
                {
                    Socket     client    = server.Accept();    //同步方式等待客户端接入
                    TCPClients newClient = new TCPClients(client);
                    PublicParams.pubSocketClients.Add(client); //记录连接的客户端的个数
                    Task newTask = new Task(newClient.ClientWork);
                    newTask.Start();
                }
                catch (Exception)
                {
                    LogHelper.WriteLog("客户端连接不成功");
                }
            }
        }
Exemplo n.º 3
0
        private void StartSendingPacketsToServer()
        {
            //Logger.Info("Enter");

            byte[] output = JSONCircularBuffer.ExportToHAR(CurrentBuffer);
            if (TestTCPClient.TestConfig.TestCheck)
            {
                if (TestTCPClient.SendLazyPacketsToServer("1", output))
                {
                    foreach (SessionHandler oSessionHandler in CurrentBuffer)
                    {
                        AnalyzerManager.ProxydbObj.UpdateDB("update response set lazy_status = 3 where request_id = '" + oSessionHandler.RequestID + "'");
                    }
                }
            }
            else
            {
                if (TCPClients.SendLazyPacketsToServer("1", output))
                {
                    foreach (SessionHandler oSessionHandler in CurrentBuffer)
                    {
                        AnalyzerManager.ProxydbObj.UpdateDB("update response set lazy_status = 3 where request_id = '" + oSessionHandler.RequestID + "'");
                    }
                }
            }

            //Logger.Info("Exit");
        }
Exemplo n.º 4
0
        private static void UpdateHostInfo()
        {
            //Logger.Info("Enter");

            byte[] bodyBytes = Registration.ConfigFinder.GetConfig(false);
            if (TestTCPClient.TestConfig.TestCheck)
            {
                TestTCPClient.UpdateClientInfo("01", bodyBytes);
            }
            else
            {
                TCPClients.UpdateClientInfo("01", bodyBytes);
            }

            //Logger.Info("Exit");
        }
Exemplo n.º 5
0
        private void ConnectToSNMPAgents(string _ipAddress, ParallelLoopState pls)
        {
            Log.Instance.Trace("{1}: {2} methodu {0} ip adresi için cagrıldı", _ipAddress, this.GetType().Name, MethodBase.GetCurrentMethod().Name);

            try
            {
                // Verilen IP adresi icin SNMPClient olusturuluyor
                SNMPClient _snmpClient = new SNMPClient(_ipAddress, ReadTimeOut, RetryNumber, PollingTime);

                // SNMPClient'ın haberleşeceği cihazlar SNMPClient instance'in Devices property'sine ekleniyor.
                _snmpClient.Devices = (from d in Devices where d.IpAddress == _ipAddress select d).ToList();

                // Sinyal okumayı hızlandırmak için tüm sinyaller liste SNMP adreslerine göre sıralanıyor.
                foreach (SNMPDevice d in _snmpClient.Devices)
                {
                    if (d.BinarySignals.Count > 0)
                    {
                        d.BinarySignals = d.BinarySignals.OrderBy(b => b.Address).ToList();
                    }
                    if (d.AnalogSignals.Count > 0)
                    {
                        d.AnalogSignals = d.AnalogSignals.OrderBy(a => a.Address).ToList();
                    }
                    if (d.CommandSignals.Count > 0)
                    {
                        d.CommandSignals = d.CommandSignals.OrderBy(c => c.Address).ToList();
                    }
                }

                // Eventler ayarlanıyor
                _snmpClient.ConnectedToServer            += ConnectedToServer;
                _snmpClient.DisconnectedFromServer       += DisconnectedFromServer;
                _snmpClient.AnyBinarySignalValueChanged  += AnyBinarySignalValueChanged;
                _snmpClient.AnyAnalogSignalValueChanged  += AnyAnalogSignalValueChanged;
                _snmpClient.DeviceConnectionStateChanged += DeviceConnectionStateChanged;
                TCPClients.Add(_snmpClient);

                _snmpClient.Connect();
            }
            catch (Exception e)
            {
                Log.Instance.Fatal("{0}: Driver baglantı hatası => {1}", this.GetType().Name, e.ToString());
            }
        }
Exemplo n.º 6
0
        private static void RegisterClient()
        {
            //Logger.Info("Enter");

            // CertHandler.RemoveConsoleServerCertificate();
            while (true)
            {
                if (TCPClients.GetCertificate("00"))
                {
                    break;
                }
                Thread.Sleep(TimeSpan.FromSeconds(30));
            }

            byte[] bodyBytes = Registration.ConfigFinder.GetConfig(true);
            while (true)
            {
                if (TestTCPClient.TestConfig.TestCheck)
                {
                    if (TestTCPClient.RegisterClientWithServer("0", bodyBytes))
                    {
                        TestTCPClient.GetGuids();
                        TestTCPClient.ReadHostIds();
                        break;
                    }
                }
                else
                {
                    if (TCPClients.RegisterClientWithServer("0", bodyBytes))
                    {
                        break;
                    }
                }

                Thread.Sleep(TimeSpan.FromSeconds(30));
            }

            //Logger.Info("Exit");
        }
Exemplo n.º 7
0
        public static void SearchConfigurationChange(object obj)
        {
            //Logger.Info("Enter");

            try
            {
                byte[] output = Encoding.ASCII.GetBytes("");
                if (TestTCPClient.TestConfig.TestCheck)
                {
                    TestTCPClient.SearchConfigChangeInServer("4", output);
                }
                else
                {
                    TCPClients.SearchConfigChangeInServer("4", output);
                }
            }
            catch (Exception ex)
            {
                //Logger.Error(ex);
            }

            //Logger.Info("Exit");
        }
Exemplo n.º 8
0
        private static void StartStoredAndForward(object obj)
        {
            //Logger.Info("Enter");
            try
            {
                string    tempQueryString = "select * from alert_failed";
                DataTable dt = AnalyzerManager.ProxydbObj.GetTableFromDB(tempQueryString, "AlertDetails");
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        if (TestTCPClient.TestConfig.TestCheck)
                        {
                            if (TestTCPClient.SendAlertMessageToServer("2", (byte[])row[1], false))
                            {
                                string command = "delete from  alert_failed where dbid = " + Convert.ToInt32(row[0]);
                                ProxyDbs.ProxyDb.DeleteRowFromTable(command);
                            }
                        }
                        else
                        {
                            if (TCPClients.SendAlertMessageToServer("2", (byte[])row[1], false))
                            {
                                string command = "delete from  alert_failed where dbid = " + Convert.ToInt32(row[0]);
                                ProxyDbs.ProxyDb.DeleteRowFromTable(command);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Logger.Error(ex);
            }

            try
            {
                string    tempQueryString = "select * from lazy_failed";
                DataTable dt = AnalyzerManager.ProxydbObj.GetTableFromDB(tempQueryString, "LazyDetails");
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        if (TestTCPClient.TestConfig.TestCheck)
                        {
                            if (TestTCPClient.SendLazyPacketsToServer("1", (byte[])row[1], false))
                            {
                                string command = "delete from  lazy_failed where dbid = " + Convert.ToInt32(row[0]);
                                ProxyDbs.ProxyDb.DeleteRowFromTable(command);
                            }
                        }
                        else
                        {
                            if (TCPClients.SendLazyPacketsToServer("1", (byte[])row[1], false))
                            {
                                string command = "delete from  lazy_failed where dbid = " + Convert.ToInt32(row[0]);
                                ProxyDbs.ProxyDb.DeleteRowFromTable(command);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Logger.Error(ex);
            }
            //Logger.Info("Exit");
        }