コード例 #1
0
        /// <summary>
        /// Used internally. Direct 1-1 Messages from the server are sent via a tempQueue.
        /// They are dispatched to their corresponding ComChannel, where they are handled just like 1-n messages.
        /// </summary>
        /// <param name="amqMessage">The received direct 1-1 message</param>
        private static void DispatchMessageToChannel(IMessage amqMessage)
        {
            string channelID = null;

            channelID = amqMessage.Properties.GetString(ComChannel.CHANNELID_PROPERTY);

            if (channelID == null)
            {
                Console.Error.WriteLine("[NetworkService] Received server message without channelID");
                return;
            }
            else if (channelID.Equals(string.Empty))
            {
                Console.Error.WriteLine("[NetworkService] Received server message without channelID");
                return;
            }

            if (!allComChannels.ContainsKey(channelID))
            {
                Console.Error.WriteLine("[NetworkService] Received server message for unknown channelID: " + channelID);
                return;
            }

            ComChannel channel = allComChannels[channelID];

            channel._OnMessage(amqMessage);
        }
コード例 #2
0
        /// <summary>
        /// Creates a ComChannel with the specified channel name/ID. Connect() has to be called first.
        /// </summary>
        /// <param name="channelID">The name/ID of the ComChannel</param>
        /// <returns></returns>
        public static ComChannel CreateComChannel(string channelID)
        {
            if (!IsConnected)
            {
                Console.Error.WriteLine("[NetworkService] not connected");
                return(null);
            }

            lock (allComChannels) {
                if (allComChannels.ContainsKey(channelID))
                {
                    Console.Error.WriteLine("[NetworkService] duplicate channelID: " + channelID);
                    return(null);
                }

                ComChannel comChannel = new ComChannel(connection, channelID);
                allComChannels.Add(channelID, comChannel);

                return(comChannel);
            }
        }