Example #1
0
        /// <summary>
        /// Copies the base properties of this message instance to the given message.
        /// </summary>
        /// <param name="copyToMessage">The copy to message.</param>
        /// <returns>The copy message with the filled properties.</returns>
        protected virtual NetSimMessage CopyTo(NetSimMessage copyToMessage)
        {
            copyToMessage.Id       = this.Id;
            copyToMessage.Sender   = this.Sender;
            copyToMessage.Receiver = this.Receiver;

            return(copyToMessage);
        }
Example #2
0
        /// <summary>
        /// Wraps the message in the connection frame.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="senderEndPoint">The sender end point.</param>
        /// <param name="receiverEndPoint">The receiver end point.</param>
        /// <returns>The frame wrapped message.</returns>
        private ConnectionFrameMessage WrapMessage(
            NetSimMessage message,
            string senderEndPoint,
            string receiverEndPoint)
        {
            ConnectionFrameMessage frame = new ConnectionFrameMessage
            {
                InnerMessage     = message,
                Sender           = senderEndPoint,
                Receiver         = receiverEndPoint,
                TransmissionStep = NetSimMessageTransmissionStep.Sending
            };

            return(frame);
        }
Example #3
0
        /// <summary>
        /// Broadcasts the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="overrideSenderReceiver">if set to <c>true</c> [override sender receiver].</param>
        public void BroadcastMessage(NetSimMessage message, bool overrideSenderReceiver = true)
        {
            foreach (var connection in this.Connections)
            {
                // create copy of message
                NetSimMessage localCopy = (NetSimMessage)message.Clone();

                // insert receiver id
                if (overrideSenderReceiver)
                {
                    localCopy.Receiver = connection.Key;
                    localCopy.Sender   = this.Id;
                }

                // transport message
                connection.Value.StartTransportMessage(localCopy, this.Id, connection.Key);
            }
        }
Example #4
0
        /// <summary>
        /// Starts the transport message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="senderEndPoint">The sender end point.</param>
        /// <param name="receiverEndPoint">The receiver end point.</param>
        public void StartTransportMessage(NetSimMessage message, string senderEndPoint, string receiverEndPoint)
        {
            // compared with ethernet frame - mac address
            // only necessary for the connection class knows which end to transmit message
            var frameMessage = this.WrapMessage(message, senderEndPoint, receiverEndPoint);

            // start message transport
            if (this.EndPointA == null || this.EndPointB == null || this.IsOffline)
            {
                return;
            }

            if (this.EndPointA.Id.Equals(frameMessage.Receiver) || this.EndPointB.Id.Equals(frameMessage.Receiver))
            {
                this.PendingMessages.Enqueue(frameMessage);
                this.OnStateUpdated();
            }
        }
Example #5
0
 /// <summary>
 /// Sends the message.
 /// </summary>
 /// <param name="message">The message.</param>
 public abstract void SendMessage(NetSimMessage message);
Example #6
0
 /// <summary>
 /// Sends the message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void SendMessage(NetSimMessage message)
 {
     this.RoutingProtocol.SendMessage(message);
 }
Example #7
0
 /// <summary>
 /// Receives the message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void ReceiveMessage(NetSimMessage message)
 {
     this.InputQueue?.Enqueue(message);
 }
Example #8
0
 /// <summary>
 /// Receives a data message
 /// </summary>
 /// <param name="message">The message.</param>
 public void ReceiveData(NetSimMessage message)
 {
     this.clientData?.AppendLine(message.ToString());
 }