private void OnSocketData(object sender, SocketEventArgs e)
{
try
{
BaseFrame frame = this.serializer.Deserialize(e.BinaryData);
if (this.OnFrameReceived != null)
{
this.OnFrameReceived(this, new FrameEventArgs(frame));
}
try
{
if (frame is DataFrame)
{
this.ProcessDataFrame((DataFrame)frame);
}
else if (frame is ControlFrame)
{
this.ProcessControlFrame((ControlFrame)frame);
}
else
{
throw new InvalidOperationException("Unsupported frame type");
}
}
catch (Exception streamError)
{
if (streamError is ProtocolExeption || this.OnStreamError == null)
{
throw;
}
this.OnStreamError(this, new StreamErrorEventArgs(this.streamsStore.GetStreamById(frame.StreamId), streamError));
}
}
catch (Exception protocolError)
{
if (this.OnError != null)
{
this.OnError(this, new ProtocolErrorEventArgs(protocolError));
}
}
}