コード例 #1
0
        public void AddTranslator <TIn, TOut>(IPipe <TIn, TOut> pipe) where TIn : IMessage where TOut : IMessage
        {
            pipe.AttachConsumer(new ActionConsumer <TOut>(m => this.Handle(m)));

            Action <IMessage> handler = o => pipe.Handle((TIn)o);

            _consumerInvokers.Add(typeof(TIn).GUID, handler);
        }
コード例 #2
0
        public void AddTranslator <TIn, TOut>(IPipe <TIn, TOut> pipe) where TIn : IMessage where TOut : IMessage
        {
            pipe.AttachConsumer(new ActionConsumer <TOut>(m => this.Handle(m)));

            Action <IMessage> handler = o => pipe.Handle((TIn)o);

            _readerWriterConsumersLock.EnterWriteLock();
            try
            {
                _consumerInvokers.Add(typeof(TIn).GUID, handler);
            }
            finally
            {
                _readerWriterConsumersLock.ExitWriteLock();
            }
        }
コード例 #3
0
        public void AddTranslator <TIn, TOut>(IPipe <TIn, TOut> pipe) where TIn : IMessage where TOut : IMessage
        {
            pipe.AttachConsumer(new ActionConsumer <TOut>(m => this.Handle(m)));

            Action <IMessage> handler = o => pipe.Handle((TIn)o);
            var typeGuid = typeof(TIn).AssemblyQualifiedName ??
#if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4
                           typeof(TIn).GetTypeInfo().GUID.ToString();
#else
                           typeof(TIn).GUID.ToString();
#endif
            // never gets removed, inline guid
            var delegateGuid = Guid.NewGuid();
            _readerWriterConsumersLock.EnterWriteLock();
            try
            {
                if (_consumerInvokers.ContainsKey(typeGuid))
                {
                    _consumerInvokersDictionaries[typeGuid][delegateGuid] = handler;
#if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4
                    Action <IMessage> actions = _consumerInvokersDictionaries[typeGuid].Values.First();
                    foreach (var action in _consumerInvokersDictionaries[typeGuid].Values.Skip(1))
                    {
                        actions = actions + action;
                    }
                    _consumerInvokers[typeGuid] = actions;
#else
                    _consumerInvokers[typeGuid] =
                        _consumerInvokersDictionaries[typeGuid].Values.Sum();
#endif
                }
                else
                {
                    _consumerInvokersDictionaries.Add(typeGuid,
                                                      new Dictionary <Guid, Action <IMessage> > {
                        { delegateGuid, handler }
                    });
                    _consumerInvokers.Add(typeGuid, handler);
                }
            }
            finally
            {
                _readerWriterConsumersLock.ExitWriteLock();
            }
        }