Beispiel #1
0
        async Task WritingProcessorAsync()
        {
            try
            {
                //Start
                lastStreamWorkingTime = DateTime.Now;
                await outputStream.WriteAsync(new byte[] { 128 }, 0, 1, shuttingdownToken); //Hello

                startingLock.Set();

                //Looping
                while (!shuttingdownToken.IsCancellationRequested)
                {
                    var buffer = sendingBuffers.Take(shuttingdownToken);
                    lastStreamWorkingTime = DateTime.Now;
                    await outputStream.WriteAsync(buffer, 0, buffer.Length, shuttingdownToken);
                }
            }
            catch (InvalidOperationException) { } //Finish adding, called only from StopProcessing
            catch (OperationCanceledException) { }
            catch (Exception ex)
            {
                sendingNormal = false;
                if (ConnectionErrorOccurred != null)
                {
                    ConnectionExceptionEventArgs e = new ConnectionExceptionEventArgs(ex, true, false);
                    ConnectionErrorOccurred(this, e);
                }
                StopProcessing(false);
            }
        }
Beispiel #2
0
        void ReadingProcessor()
        {
            using (BinaryReader binaryReader = new BinaryReader(inputStream))
            {
                byte commandCode;
                try
                {
                    while (!shuttingdownToken.IsCancellationRequested)
                    {
                        commandCode = binaryReader.ReadByte();

                        lastStreamWorkingTime = DateTime.Now;

                        if (commandCode <= 127) //Private channel data
                        {
                            int length = GetInt32FromBytes(commandCode, binaryReader.ReadByte(), binaryReader.ReadByte(), binaryReader.ReadByte());
                            OnPrivateMessageReceived(length, binaryReader);
                        }
                        else if (commandCode == 254) //Ping
                        {
                            OnPingReceived();
                        }
                        else if (commandCode == 253) //Pong
                        {
                            //Do nothing
                        }
                        else if (commandCode == 130) //Add or update client with virtual host setting
                        {
                            var clientId = binaryReader.ReadGuid();
                            OnAddOrUpdateClientReceived(clientId, binaryReader);
                        }
                        else if (commandCode == 129) //Add or update client without virtual host setting
                        {
                            var clientId = binaryReader.ReadGuid();
                            OnAddOrUpdateClientReceived(clientId);
                        }
                        else if (commandCode == 131) //Remove
                        {
                            var clientId = binaryReader.ReadGuid();
                            OnRemoveClientReceived(clientId);
                        }
                        else if (commandCode == 128) //Hello
                        {
                            OnHelloReceived();
                        }
                        else if (commandCode == 255) //Link closed
                        {
                            binaryReader.Close();
                            StopProcessing(true);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!shuttingdownToken.IsCancellationRequested) //Or, it is closed by terminating reading process.
                    {
                        if (ConnectionErrorOccurred != null)
                        {
                            ConnectionExceptionEventArgs e = new ConnectionExceptionEventArgs(ex, true, false);
                            ConnectionErrorOccurred(this, e);
                        }
                        StopProcessing(true);
                    }
                }
            }

            AdapterStopped?.Invoke(this, EventArgs.Empty);
        }
 void OnAdapterConnectionErrorOccurred(object sender, ConnectionExceptionEventArgs e)
 {
     var adapter = (IRemoteHubAdapter<byte[]>)sender;
     ConnectionErrorOccurredInternal(this, new ConnectionExceptionWithAdapterEventArgs(e, adapter));
 }
Beispiel #4
0
 private void RedisAdapter_ConnectionErrorOccurred(object sender, ConnectionExceptionEventArgs e)
 {
     FromAdapter_ConnectionErrorOccurred?.Invoke(this, e);
 }
 /// <summary>
 /// Initializes an instance of ConnectionExceptionWithAdapterEventArgs.
 /// </summary>
 /// <param name="e">The argument passed by <see cref="IRemoteHubAdapter.ConnectionErrorOccurred"/>.</param>
 /// <param name="remoteHubAdapter">RemoteHub Adapter instance which throw the exception.</param>
 public ConnectionExceptionWithAdapterEventArgs(ConnectionExceptionEventArgs e, IRemoteHubAdapter <byte[]> remoteHubAdapter)
     : base(e.Exception, e.IsFatal, e.IsRetried)
 {
     Adapter = remoteHubAdapter;
 }