Beispiel #1
0
        internal void Send(ProtocolChannel <TSender> protocolChannel, byte[] bytes)
        {
            if (!protocolChannel.Announced)
            {
                lock (this._protocols)
                    if (!protocolChannel.Announced)
                    {
                        this.Reset(protocolChannel);
                    }
            }

            this._channel.Send(ByteHelper.InsertByte(protocolChannel.Id, bytes));
        }
Beispiel #2
0
        private void RegisterProtocolInternal(string protocolName, Action <IMessageChannel <TSender> > callback)
        {
            if (string.IsNullOrEmpty(protocolName))
            {
                throw new ArgumentNullException(nameof(protocolName));
            }

            ProtocolChannel <TSender> proto;

            lock (this._protocols)
            {
                if (this._protocols.ContainsKey(protocolName))
                {
                    throw new InvalidOperationException("The given protocol is already registered!");
                }

                var protocolId = this.GetFreeId();
                proto = new ProtocolChannel <TSender>(this, protocolName, protocolId);
                this._protocols.Add(protocolName, proto);
            }

            callback(proto);
            this.Reset(proto);
        }
Beispiel #3
0
 internal void RemoveSender(ProtocolChannel <TSender> protocolChannel, TSender sender)
 {
     this._byteProtocol.RemoveSender(sender, protocolChannel.Id);
     protocolChannel.OnRemovedSender(sender);
 }
Beispiel #4
0
 internal void Reset(ProtocolChannel <TSender> protocolChannel)
 {
     protocolChannel.Announced = true;
     this._byteProtocol.SetProtocol(protocolChannel.Id, protocolChannel.Name);
 }