Esempio n. 1
0
        public bool Send(IClientMessageExecutor executor, bool register = true)
        {
            if (executor == null)
            {
                return(false);
            }

            if (!this.IsConnected)
            {
                throw new Exception("The status of im client is disconnect.");
            }

            if (register)
            {
                this.Register(executor);
            }

            ImMessageContext context = executor.BuildContext();

            if (context == null)
            {
                throw new Exception("The content sent through the im client cannot be empty.");
            }

            if (context.Head == null)
            {
                context.Head = this.GlobalMessageHead;
            }

            this.CurrentChannel.WriteAndFlushAsync(context).Wait();
            return(true);
        }
Esempio n. 2
0
        public void Register(IClientMessageExecutor executor)
        {
            if (executor == null)
            {
                return;
            }

            ImMessageType type = executor.BuildContext().Type;

            if (this.messageExecutors.ContainsKey(type))
            {
                this.messageExecutors.Remove(type);
            }
            this.messageExecutors.Add(type, executor);
        }