Exemplo n.º 1
0
 public MulticastLogger(IList <ILogger> loggers)
 {
     _loggers = new SynchronizedList <ILogger>();
     _loggers.AddRange(loggers);
 }
Exemplo n.º 2
0
 public BaseKeyboardHook(IActiveApplicationMonitor activeApplicationMonitor)
 {
     ActiveApplicationMonitor = activeApplicationMonitor;
     InterceptKeys            = new SynchronizedList <Key>();
 }
Exemplo n.º 3
0
        public void Run(Stream input, Stream output)
        {
            if (_blockingStreams == null)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (!input.CanRead)
            {
                throw new ArgumentException("input");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (!output.CanWrite)
            {
                throw new ArgumentException("output");
            }

            var         errors    = new SynchronizedList <Exception>();
            ThreadStart lastStage = null;

            for (var i = 0; i < _filters.Length; i++)
            {
                var stageInput  = i == 0 ? input : _blockingStreams[i - 1];
                var stageOutput =
                    i == _filters.Length - 1 ? output : _blockingStreams[i];
                var         filter = _filters[i];
                ThreadStart stage  = delegate {
                    try {
                        filter(stageInput, stageOutput);
                        var blockingStream = stageOutput as BlockingStream;
                        if (blockingStream != null)
                        {
                            blockingStream.SetEndOfStream();
                        }
                    } catch (Exception error) {
                        errors.Add(error);
                        var blockingStream = stageOutput as BlockingStream;
                        if (blockingStream != null)
                        {
                            blockingStream.SetEndOfStreamDueToFailure();
                        }
                    }
                };
                if (i < _filters.Length - 1)
                {
                    var t = new Thread(stage)
                    {
                        IsBackground = true
                    };
                    t.Start();
                }
                else
                {
                    lastStage = stage;
                }
            }
            if (!errors.Any())
            {
                try {
                    lastStage();
                } catch (Exception error) {
                    errors.Add(error);
                }
            }
            if (errors.Any())
            {
                throw new AggregateException(errors);
            }
        }