Example #1
0
        internal bool SendPacket(DataPacket p, DateTime time)
        {
            string s = p.ToString();

            this.DoLog(Agent.ScadaDataClient, string.Format("[{0}]-->: {1}", DateTime.Now, s));
            return(this.Send(Encoding.ASCII.GetBytes(s)));
        }
Example #2
0
        internal bool SendDataPacket(DataPacket p)
        {
            if (p == null)
            {
                return(false);
            }

            if (this.SendDataStarted || this.Type == Type.Country)
            {
                string s = p.ToString();
                return(this.Send(Encoding.ASCII.GetBytes(s)));
            }
            return(false);
        }
Example #3
0
        // '大流量' 数据
        private void SendFlowDataPackets(string deviceKey, Dictionary <string, object> data)
        {
            DataPacket p = builder.GetFlowDataPacket(deviceKey, data, true);

            if (this.agent != null)
            {
                if (this.agent.SendDataPacket(p))
                {
                    string msg = string.Format("RD: {0}", p.ToString());
                    Log.GetLogFile(deviceKey).Log(msg);
                    this.UpdateSendDataRecord(deviceKey, false);
                }
            }

            if (this.countryCenterAgent != null && this.countryCenterAgent.Stream != null)
            {
                if (this.countryCenterAgent.SendDataPacket(p))
                {
                    string msg = string.Format("RD: {0}", p.ToString());
                    Log.GetLogFile(deviceKey).Log(msg);
                    this.UpdateSendDataRecord(deviceKey, false);
                }
            }
        }
Example #4
0
        internal bool SendHistoryDataPacket(DataPacket p)
        {
            if (p == null)
            {
                return(false);
            }
            bool result = false;

            string s = p.ToString();

            result = this.Send(Encoding.ASCII.GetBytes(s));
            if (result)
            {
                if (this.NotifyEvent != null && !string.IsNullOrEmpty(p.DeviceKey))
                {
                    this.NotifyEvent(this, NotifyEvents.HistoryDataSent, p.DeviceKey, s);
                }
            }
            return(result);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="time"></param>
        /// <param name="deviceKey"></param>
        private void SendNonFileDataPackets(DateTime time, string deviceKey)
        {
            this.data.Clear();
            string errorMessage = string.Empty;
            var    r            = DBDataSource.GetData(this.MySqlCommand, deviceKey, time, default(DateTime), null, null, this.data, out errorMessage);

            if (r == ReadResult.ReadOK)
            {
                if (this.data.Count > 0)
                {
                    DataPacket p = null;

                    if (Case(deviceKey, "Scada.MDS") || Case(deviceKey, "Scada.AIS"))
                    {
                        this.SendFlowDataPackets(deviceKey, this.data[0]);
                    }
                    else if (Case(deviceKey, "scada.shelter"))
                    {
                        this.SendShelterDataPackets(deviceKey, this.data[0]);
                    }
                    else
                    {
                        // 其他数据
                        if (deviceKey == "scada.hpic" && this.InHpicException)
                        {
                            this.InHpicException = false;
                            DataPacket packet = this.builder.GetExceptionNotifyPacket(deviceKey, false);
                            this.agent.SendExceptionNotify(packet);
                        }

                        p = builder.GetDataPacket(deviceKey, this.data[0], true);
                        if (this.agent.SendDataPacket(p))
                        {
                            string msg = string.Format("RD: {0}", p.ToString());
                            Log.GetLogFile(deviceKey).Log(msg);
                            this.UpdateSendDataRecord(deviceKey, false);
                        }

                        if (this.countryCenterAgent != null && this.agent.SendDataDirectlyStarted)
                        {
                            this.countryCenterAgent.SendDataPacket(p);
                        }
                    }
                }
                else
                {
                    string line = string.Format("RD Error: count={0} [{1}: {2}]", this.data.Count, deviceKey, time);
                    Log.GetLogFile(deviceKey).Log(line);
                }
            }
            else
            {
                // 发送异常通知
                if (r == ReadResult.NoDataFound && deviceKey == "scada.hpic")
                {
                    if (!this.InHpicException)
                    {
                        this.InHpicException = true;
                        DataPacket packet = this.builder.GetExceptionNotifyPacket(deviceKey, true);
                        this.agent.SendExceptionNotify(packet);
                    }
                }

                string line = string.Format("RD Error: {0} - {1} [{2}: {3}]", r.ToString(), errorMessage, deviceKey, time);
                Log.GetLogFile(deviceKey).Log(line);
            }
        }
Example #6
0
 internal void SendReplyPacket(DataPacket p, DateTime time)
 {
     string s = p.ToString();
     this.Send(Encoding.ASCII.GetBytes(s));
 }
Example #7
0
 internal void SendDataPacket(DataPacket p, DateTime time)
 {
     if (p == null)
         return;
     // Only start or history.
     if (this.SendDataStarted || this.OnHistoryData)
     {
         string s = p.ToString();
         this.Send(Encoding.ASCII.GetBytes(s));
     }
 }
Example #8
0
        internal bool SendReplyPacket(DataPacket p, DateTime time)
        {
            string s = p.ToString();

            return(this.Send(Encoding.ASCII.GetBytes(s)));
        }
Example #9
0
File: Agent.cs Project: oisy/scada
        internal bool SendHistoryDataPacket(DataPacket p)
        {
            if (p == null)
                return false;
            bool result = false;

            string s = p.ToString();
            result = this.Send(Encoding.ASCII.GetBytes(s));
            if (result)
            {
                if (this.NotifyEvent != null && !string.IsNullOrEmpty(p.DeviceKey))
                {
                    this.NotifyEvent(this, NotifyEvents.HistoryDataSent, p.DeviceKey, s);
                }
            }
            return result;
        }
Example #10
0
File: Agent.cs Project: oisy/scada
        internal bool SendDataPacket(DataPacket p)
        {
            if (p == null)
                return false;

            if (this.SendDataStarted)
            {
                string s = p.ToString();
                return this.Send(Encoding.ASCII.GetBytes(s));
            }
            return false;
        }
Example #11
0
File: Agent.cs Project: oisy/scada
 internal bool SendPacket(DataPacket p, DateTime time)
 {
     string s = p.ToString();
     // TODO:!
     this.DoLog(Agent.ScadaDataClient, string.Format("-->: {0}", s));
     return this.Send(Encoding.ASCII.GetBytes(s));
 }