/// <summary> /// Sends asynchronously long-polling request again. /// </summary> protected void ReconnectLongPollingConnection(bool resetFailures) { if (resetFailures) { _longPollingConnecFailures = 0; } else { _longPollingConnecFailures++; } // try to reconnect, if possible: if (IsLongPolling && State == BayeuxConnectionState.Connected) { BayeuxRequest message = LongPollingRequest; string dataToSend; string requestMethod; lock (_syncObject) { requestMethod = message.RequestMethod; dataToSend = SerializeRequest(message); } _httpLongPollingConnection.SendRequestAsync(null, dataToSend, requestMethod, HttpDataSourceResponseType.AsString); } }
/// <summary> /// Sends a bayeux message to the server with the ability to override the JSON returned by request object itself /// with the one specified as raw JSON data. /// </summary> public void Send(BayeuxRequest message, string overrideWithJSonData, bool asynchronous) { if (message == null) { throw new ArgumentNullException("message"); } string dataToSend = overrideWithJSonData; lock (_syncObject) { if (_request != null) { if (_httpConnection.IsActive) { _httpConnection.Cancel(); // this is a sync operation, which should cause the _request to be nulled ... } _request = null; } if (_request != null) { throw new InvalidOperationException("Can't start new request, when current has not been finished/cancelled"); } if (string.IsNullOrEmpty(message.ClientID)) { message.ClientID = ClientID; } _request = message; // serialize JSON data as text message if not provided as parameter: if (string.IsNullOrEmpty(overrideWithJSonData)) { dataToSend = SerializeRequest(message); } } if (asynchronous) { _httpConnection.SendRequestAsync(null, dataToSend, message.RequestMethod, HttpDataSourceResponseType.AsString); } else { _httpConnection.SendRequest(null, dataToSend, message.RequestMethod, HttpDataSourceResponseType.AsString); } }