Exemplo n.º 1
0
        private void GetMsgCountInfo()
        {
            //_syncContext.Post(AppendTextToLogMsg, "GetMsgCountInfo开启了线程:" + Thread.CurrentThread.ManagedThreadId.ToString() + "\n");

            string msg = string.Empty;

            while (!isStopGetMsgThread)
            {
                msg = MessageQueueTool.MESSAGE_TOTAL_COUNT + "@" + MessageQueueTool.Count() + "@" + MessageQueueTool.MESSAGE_SEND_TIME;
                _syncContext.Post(SetMsgCountInfo, msg);
                Thread.Sleep(1000);
            }

            //_syncContext.Post(AppendTextToLogMsg, "GetMsgCountInfo退出了线程:" + Thread.CurrentThread.ManagedThreadId.ToString() + "\n");
        }
Exemplo n.º 2
0
        /// 发送消息
        private void SendMessage()
        {
            //_syncContext.Post(SetLabelText, "SendMessage开启了线程:" + Thread.CurrentThread.ManagedThreadId.ToString() + "\n");

            AEInfos tempInfo = null;
            string  jsonMsg  = string.Empty;

            while (!isStopSendThread)
            {
                if (userList.Count <= 0 || MessageQueueTool.Count() <= 0)
                {
                    Thread.Sleep(3000);
                    continue;
                }
                tempInfo = MessageQueueTool.DeMessage();
                jsonMsg  = JsonConvert.SerializeObject(tempInfo, Formatting.Indented) + "\n";

                for (int i = 0; i < userList.Count; i++)
                {
                    try
                    {
                        userList[i].Send(Encoding.UTF8.GetBytes(jsonMsg));
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            _syncContext.Post(SetLabelText, "客户端:" + userList[i].RemoteEndPoint.ToString() + "出现异常:" + ex.Message + "\n");//子线程中通过UI线程上下文更新UI
                            userList[i].Close();
                        }
                        catch { }
                        userList.RemoveAt(i);
                        i--;
                    }
                }
            }

            //_syncContext.Post(SetLabelText, "SendMessage关闭了线程:" + Thread.CurrentThread.ManagedThreadId.ToString() + "\n");
        }
Exemplo n.º 3
0
        // method that handles the AeSubscription.AeEventsReceived event; it displays on the console the received events
        public static void HandleEventsReceived(AeSubscription anAeSubscription, bool refresh, bool lastRefresh, AeEvent[] events)
        {
            for (int i = 0; i < events.Length; i++)
            {
                string time               = events[i].OccurenceTime.AddHours(8).ToString();
                string bitNumber          = events[i].SourcePath;
                string bitNumberDescribe  = string.Empty;
                string aeType             = string.Empty;
                string priority           = events[i].Severity.ToString();
                string realTimeValue      = string.Empty;
                string limitValue         = string.Empty;
                string engineeringUnit    = string.Empty;
                string aeDescribe         = events[i].Message;
                string device             = string.Empty;
                string area               = string.Empty;
                string operatingFloor     = string.Empty;
                string operatingPersonnel = string.Empty;
                string extension_1        = string.Empty;
                string extension_2        = string.Empty;
                string extension_3        = string.Empty;
                string extension_4        = string.Empty;
                string extension_5        = string.Empty;

                string messageType = events[i].Category.ToString();
                string isDCS       = string.Empty;

                string aeSubType     = string.Empty;
                string areaNumber    = string.Empty;
                string stationNumber = string.Empty;
                string alarmLevel    = string.Empty;
                string alarmOff      = string.Empty;
                string alarmBlink    = string.Empty;
                string alarmFilter   = string.Empty;
                string ackRequired   = string.Empty;
                string quality       = string.Empty;

                if (events[i].EventType == EnumEventType.CONDITION)
                {
                    aeType      = ((AeCondition)events[i]).ConditionName;
                    aeSubType   = ((AeCondition)events[i]).SubConditionName;
                    ackRequired = ((AeCondition)events[i]).AckRequired.ToString();
                    quality     = ((AeCondition)events[i]).Quality.ToString();
                }

                ArrayList     attributes = events[i].Attributes;
                List <string> temp       = CategoriesAndAttribute.getAttributeNamesFromCategoryID(events[i].Category);
                for (int j = 0; j < events[i].Attributes.Count; j++)
                {
                    if (temp[j].Equals("Data_value"))
                    {
                        realTimeValue = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Engineering_unit"))
                    {
                        engineeringUnit = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Area_number"))
                    {
                        areaNumber = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Station_number"))
                    {
                        stationNumber = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Alarm_level"))
                    {
                        alarmLevel = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Alarm_off"))
                    {
                        alarmOff = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Alarm_blink"))
                    {
                        alarmBlink = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Alarm_filter"))
                    {
                        alarmFilter = attributes[j].ToString();
                    }
                }

                AEInfos oneAEInfo = new AEInfos
                {
                    Time               = time,
                    BitNumber          = bitNumber,
                    BitNumberDescribe  = bitNumberDescribe,
                    AEType             = aeType,
                    Priority           = priority,
                    RealTimeValue      = realTimeValue,
                    LimitValue         = limitValue,
                    EngineeringUnit    = engineeringUnit,
                    AEDescribe         = aeDescribe,
                    Device             = device,
                    Area               = area,
                    OperatingFloor     = operatingFloor,
                    OperatingPersonnel = operatingPersonnel,
                    Extension_1        = extension_1,
                    Extension_2        = extension_2,
                    Extension_3        = extension_3,
                    Extension_4        = extension_4,
                    Extension_5        = extension_5,

                    MessageType = messageType,
                    IsDCS       = isDCS,

                    AESubType     = aeSubType,
                    AreaNumber    = areaNumber,
                    StationNumber = stationNumber,
                    AlarmLevel    = alarmLevel,
                    AlarmOff      = alarmOff,
                    AlarmBlink    = alarmBlink,
                    AlarmFilter   = alarmFilter,
                    AckRequired   = ackRequired,
                    Quality       = quality
                };

                MessageQueueTool.EnMessage(oneAEInfo);

                File.AppendAllText(@"./AEInfos.json", JsonConvert.SerializeObject(oneAEInfo, Formatting.Indented) + "\n");
                if (new FileInfo(@"./AEInfos.json").Length >= 50 * 1024 * 1024)
                {
                    File.Delete(@"./AEInfos_backup.json");
                    File.Move(@"./AEInfos.json", @"./AEInfos_backup.json");
                }
            }//end  for
        }