/// <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); } }
/// <summary> /// Stops listening for asynchronous data. /// </summary> public void StopLongPolling() { if (IsLongPolling) { _longPollingRequest = null; _longPolling = false; _httpLongPollingConnection.Cancel(); } }