public void StartSending(IParserStruct structure, string messageId) { try { switch (structure.Id) { case 7: case 8: case 12: case 13: case 14: _BUFFER_SIZE = 40 * 1024; break; default: _BUFFER_SIZE = 1024; break; } byte[] body = new byte[_BUFFER_SIZE]; structure.WriteBytes(body, 0); _channel.BasicPublish("", messageId, null, body); } catch (Exception ex) { //InvokeLog("EXCEPTION: StartSending : " + ex.Message); } return; }
public void BeginSend(IParserStruct structure, AsyncCallback callback, SocketsType socketType) { lock (_sendSync) { if (Disposed || _closed) { //Debug.WriteLine(string.Format("[SocketClient] Can't BeginSend cause Disposed='{0}' or Close='{1}'", Disposed,_closed)); InvokeOnException(new Exception(string.Format("[SocketClient] Can't BeginSend cause Disposed='{0}' or Close='{1}'", Disposed, _closed)), true); return; } structure.WriteBytes(_bufferForSend, _offsetForSend); //we add 8 bytes to strcuture length, cause every structure has a header created //from 2 Int32 fields //Structue.Length - reports the length of structure itself, without header try { SocketError error; if (socketType == SocketsType.History) { _socketHistory.BeginSend(_bufferForSend, _offsetForSend, structure.Length + 8, SocketFlags.None, out error, callback, this); } else if (socketType == SocketsType.RealTime) { _socketRT.BeginSend(_bufferForSend, _offsetForSend, structure.Length + 8, SocketFlags.None, out error, callback, this); } else { _socket.BeginSend(_bufferForSend, _offsetForSend, structure.Length + 8, SocketFlags.None, out error, callback, this); } if (error != SocketError.Success) { InvokeLog("[SocketClient] ERROR: " + error.ToString()); //Debug.WriteLine(string.Format("[SocketClient] Can't begin cause of error '{0}'", error)); if (error == SocketError.ConnectionReset || error == SocketError.ConnectionAborted || error == SocketError.NotConnected || error == SocketError.ConnectionRefused) { InvokeOnException(new Exception("Connection Closed - " + error), true); } } } catch (Exception exception) { //Debug.WriteLine(string.Format("[SocketClient] {0}", exception.Message)); if (!StandaloneUsage) { throw; } InvokeOnException(exception, true); } } }