Ejemplo n.º 1
0
 public XChannel(ChannelIdentification channelIdentification, object?targetId, bool exclusiveChannel, IWeakDelegate weakDelegate)
 {
     this.Identification   = channelIdentification;
     this.TargetId         = targetId;
     this.ExclusiveChannel = exclusiveChannel;
     this.WeakDelegate     = weakDelegate;
 }
Ejemplo n.º 2
0
        private static XChannel AddXChannel(LinkedList <XChannel> list, ChannelIdentification identification, object?targetId, bool exclusiveChannel, IWeakDelegate weakDelegate)
        { // lock (cs) required.
            if (exclusiveChannel)
            {
                if (list.Count > 0)
                { // other channel already exists.
                    throw new InvalidOperationException();
                }
            }
            else
            {
                if (list.First?.Value.ExclusiveChannel == true)
                { // Exclusive channel exists.
                    throw new InvalidOperationException();
                }
            }

            // New XChannel
            var channel = new XChannel(identification, targetId, exclusiveChannel, weakDelegate);

            // list: Identification to XChannels.
            channel.Node = list.AddLast(channel);

            return(channel);
        }
Ejemplo n.º 3
0
        public static XChannel Open <TMessage, TResult>(Func <TMessage, TResult> method, object?targetId = null, bool exclusiveChannel = false)
        {
            XChannel channel;
            var      identification = new ChannelIdentification(typeof(TMessage), typeof(TResult));

            lock (cs)
            {
                var list = Cache_WeakFunction <TMessage, TResult> .List;
                channel = AddXChannel(list, identification, targetId, exclusiveChannel, new WeakFunc <TMessage, TResult>(method));
                CleanupList(list);
            }

            return(channel);
        }