コード例 #1
0
        public static CommDatagram ParseDatagram(DataGram datagram)
        {
            CommDatagram result = new CommDatagram();
            int          idx    = -1;

            //Sender ID
            string msgPart = GetMessagePart(datagram.Message, ref idx);

            if (msgPart == null)
            {
                return(null);
            }
            result.SenderId = new Guid(msgPart);

            //Message type
            msgPart = GetMessagePart(datagram.Message, ref idx);
            if (msgPart == null)
            {
                return(null);
            }
            result.MessageType = (MessageType)Convert.ToInt32(msgPart);

            //Data
            msgPart     = datagram.Message.Substring(idx + 1, datagram.Message.Length - idx - 1);
            result.Data = msgPart;

            return(result);
        }
コード例 #2
0
        private void SendMessage(Guid?toID, MessageType messageType, string data)
        {
            string message = CommDatagram.GetMessage(myID, messageType, data);

            if (toID == null)
            {
                broadcast.SendToChannel(ChannelBroadcast, message);
            }
            else
            {
                broadcast.SendToChannel(toID.ToString(), message);
            }
        }
コード例 #3
0
        private void listener_MessageReceived(object sender, XDMessageEventArgs e)
        {
            CommDatagram dtg = CommDatagram.ParseDatagram(e.DataGram);

            if (dtg.SenderId == myID)
            {
                return;
            }

            switch (dtg.MessageType)
            {
            case MessageType.GetInstance:
                //if (!String.IsNullOrEmpty(this.CurrentLogFileName))
                SendMessage(dtg.SenderId, MessageType.ReturnInstance, new LogViewerInstance(myID, this.CurrentLogFileName, this.AppLastActivation, this.MainWindowHandle).GetTextMessage());
                break;

            case MessageType.ReturnInstance:
                this.otherInstances.Add(new LogViewerInstance(dtg.Data));
                break;

            case MessageType.GoToDateTime:
                OnGoToItemRequest(DateTime.ParseExact(dtg.Data, CommDateFormat, CultureInfo.InvariantCulture));
                break;

            case MessageType.ReturnCurrentLogFileName:
                OnAnotherInstanceOpenedLogFile(dtg.Data);
                break;

            case MessageType.ProcessAppArgs:
                OnProcessAppArgs(dtg.Data.Split('|'));
                break;

            default:
                throw new NotImplementedException(String.Format("Message type: '{0}' is not supported.", dtg.MessageType));
            }
        }