コード例 #1
0
 private void btnClearMessages_Click(object sender, RoutedEventArgs e)
 {
     while (ReceivedMessages.Count > 0)
     {
         ReceivedMessages[0].DeleteTemporaryDocumentFiles();
         ReceivedMessages.RemoveAt(0);
     }
 }
コード例 #2
0
        private void client_OnMessageReceived(AbstractMessage message)
        {
            MessageInfo info = null;

            switch (message.MessageType)
            {
            case TemsInfoMessageType.Information:
                info = new MessageInfo(message as InformationMessage);
                break;

            case TemsInfoMessageType.Error:
                info = new MessageInfo(message as ErrorMessage);
                break;

            case TemsInfoMessageType.Heartbeat:
                HeartbeatMessage msgHeartbeat = message as HeartbeatMessage;
                if (lastHeartbeatSequenceNo.HasValue)
                {
                    uint expectedHeartbeatSequenceNo;
                    if (lastHeartbeatSequenceNo.HasValue && lastHeartbeatSequenceNo.Value < uint.MaxValue)
                    {
                        expectedHeartbeatSequenceNo = lastHeartbeatSequenceNo.Value + 1;
                    }
                    else
                    {
                        expectedHeartbeatSequenceNo = uint.MinValue;
                    }
                    if (expectedHeartbeatSequenceNo != msgHeartbeat.SequenceNo)
                    {
                        ctrlLog.AddLogMessage("Warning: Irregular heart beat sequence number (Last = {0:#,##0}, This = {1:#,##0})", lastHeartbeatSequenceNo, msgHeartbeat.SequenceNo);
                    }
                }
                lastHeartbeatSequenceNo = msgHeartbeat.SequenceNo;
                Dispatcher.BeginInvoke((Action)(() => {
                    txtHeartbeat.Text = string.Format("Heartbeat #: {0:#,##0}", msgHeartbeat.SequenceNo);
                }));
                break;

            case TemsInfoMessageType.Vehicle:
                info = new MessageInfo(message as VehicleMessage);
                break;

            case TemsInfoMessageType.ObjectStart:
                info = new MessageInfo(message as ObjectStartMessage);
                break;

            case TemsInfoMessageType.ObjectStop:
                info = new MessageInfo(message as ObjectStopMessage);
                break;

            case TemsInfoMessageType.ObjectLocation:
                info = new MessageInfo(message as ObjectLocationMessage);
                break;

            case TemsInfoMessageType.Status:
                info = new MessageInfo(message as StatusMessage);
                break;

            case TemsInfoMessageType.Value:
                info = new MessageInfo(message as ValueMessage);
                break;

            case TemsInfoMessageType.Data:
                info = new MessageInfo(message as DataMessage);
                break;

            case TemsInfoMessageType.Initialization:
            case TemsInfoMessageType.Configuration:
            case TemsInfoMessageType.SetSite:
            default:
                // Ignore because messages of this type
                // are never sent by the server
                break;
            }

            if (info != null)
            {
                Dispatcher.BeginInvoke((Action)(() => {
                    ReceivedMessages.Add(info);

                    while (ReceivedMessages.Count > MAX_DISPLAYED_MESSAGES)
                    {
                        ReceivedMessages[0].DeleteTemporaryDocumentFiles();
                        ReceivedMessages.RemoveAt(0);
                    }
                }));
            }
        }