Beispiel #1
0
        public IDisposable Create()
        {
            NamedPipeClientStream pipe;
            var observable = PipeStreamObservable.Create <T>(out pipe, _server, _name, (sender, args) => _auto.Set());

            Observer.PipeStream = pipe;
            observable.Subscribe(
                Observer.OnNext,
                ex =>
            {
                Observer.OnError(ex);
                pipe.Close();
                _auto.Set();
            },
                () =>
            {
                Observer.OnCompleted();
                pipe.Close();
            });
            _auto.WaitOne();
            if (pipe.IsConnected)
            {
                Observer.OnConnected();
            }
            return(pipe);
        }
Beispiel #2
0
        public void IpcServerPipeCreate <TPipeStreamObserver>(Task task)
            where TPipeStreamObserver : IPipeStreamObserver <T>, new()
        {
            NamedPipeServerStream pipe;
            var observable = PipeStreamObservable.Create <T>(out pipe, _name, (sender, args) => _auto.Set());

            var observer = new TPipeStreamObserver()
            {
                PipeStream = pipe
            };

            observable.Subscribe(
                observer.OnNext,
                ex =>
            {
                observer.OnError(ex);
                pipe.Close();
                lock (_pipes)
                {
                    _pipes.Remove(pipe);
                }
            },
                () =>
            {
                observer.OnCompleted();
                pipe.Close();
                lock (_pipes)
                {
                    _pipes.Remove(pipe);
                }
            });

            _auto.WaitOne();

            lock (_pipes)
            {
                if (_running)
                {
                    _pipes.Add(pipe);
                }
            }

            if (_running)
            {
                //error was here
                //task.ContinueWith(IpcServerPipeCreate<TPipeStreamObserver>);
                observer.OnConnected();
            }
            else
            {
                pipe.Close();
            }
        }