示例#1
0
        public void Stop()
        {
            lock (protocolOperationsLock) {
                if (this.exceptionsStream == null)
                {
                    return;
                }

                this.protocol?.Dispose();
                this.protocol = null;

                this.exceptionsStream.Close();
                this.exceptionsStream = null;
            }

            ProcessClosingMessage();

            this.OnDisposed?.Invoke(this);
            this.OnDisposed = null;
        }
示例#2
0
        public void SetupStream(Stream stream)
        {
            lock (protocolOperationsLock) {
                if (this.protocol == null)
                {
                    this.protocol = protocolFactory();
                    this.protocol.Initialize(this);

                    async void StartProtocolReading()
                    {
                        await HandleProtocolExceptionsAction(async delegate {
                            await protocol.StartReading();
                        });
                    }

                    StartProtocolReading();
                }

                var state = this.protocol.GetState();

                if (state == PXProtocolState.Working)
                {
                    this.exceptionsStream?.SwitchToErrorState();
                    this.exceptionsStream?.Close();
                }

                switch (state)
                {
                case PXProtocolState.None:
                case PXProtocolState.WaitingForConnection:
                case PXProtocolState.Working:
                    this.protocol.SetupStream(exceptionsStream = new PXExceptionsFilterStream(stream));
                    break;

                default:
                    throw new StreamSetupInWrongProtocolStateException(state);
                }
            }
        }