/// <summary> /// Records a response as bayeux message, while only 'data' part of the message is given. /// It will try to parse data and put as IJSonMutableObject, or if parsing fails, it will put it /// just as string value of the field. /// </summary> public RecordedDataSourceResponse RecordBayeuxData(string name, int internalStatus, string channel, string data) { if (string.IsNullOrEmpty(channel)) { throw new ArgumentNullException("channel"); } var response = new RecordedBayeuxDataSourceResponse(name); var bayeuxMessage = CreateEmptyBayeuxResponse(internalStatus, channel); if (string.IsNullOrEmpty(data)) { bayeuxMessage.SetValue("data", data); } else { try { var reader = new JSonReader(data); bayeuxMessage.SetValue("data", reader.ReadAsJSonMutableObject()); } catch (Exception ex) { DebugLog.WriteBayeuxLine("Parsing of 'data' for RecordedBayeuxDataSourceResponse failed!"); DebugLog.WriteBayeuxException(ex); bayeuxMessage.SetValue("data", data); } } response.AsJSon = bayeuxMessage; Record(response); return(response); }
/// <summary> /// Records a response as bayeux message. /// </summary> public RecordedBayeuxDataSourceResponse RecordBayeux(string name, string messageAsJSon) { var reader = new JSonReader(messageAsJSon); var response = new RecordedBayeuxDataSourceResponse(name); response.AsJSon = reader.ReadAsJSonMutableObject(); Record(response); return(response); }
/// <summary> /// Records a response as bayeux message. /// </summary> public RecordedBayeuxDataSourceResponse RecordBayeux(string name, IJSonObject messageAsJSon) { if (messageAsJSon == null) { throw new ArgumentNullException("messageAsJSon"); } var response = new RecordedBayeuxDataSourceResponse(name); response.AsJSon = messageAsJSon; Record(response); return(response); }
/// <summary> /// Records a response as bayeux message, while only 'data' part of the message is given. /// </summary> public RecordedDataSourceResponse RecordBayeuxData(string name, int internalStatus, string channel, IJSonObject data) { if (string.IsNullOrEmpty(channel)) { throw new ArgumentNullException("channel"); } var response = new RecordedBayeuxDataSourceResponse(name); var bayeuxMessage = CreateEmptyBayeuxResponse(internalStatus, channel); bayeuxMessage.SetValue("data", data); response.AsJSon = bayeuxMessage; Record(response); return(response); }
/// <summary> /// Method called just before allowing externals to select a response. /// </summary> protected override void InternalPreSelectResponse(RecordedDataSourceSelectorEventArgs e) { if (!AllowMatchingByChannel) { return; } var request = ConvertToJSon(e); // do nothing: if (request == null || !request.IsEnumerable) { return; } var channel = RecordedBayeuxDataSourceResponse.GetChannel(request); if (string.IsNullOrEmpty(channel)) { return; } // select matching response by channel: foreach (var response in e.Responses) { var bayeuxResponse = response as RecordedBayeuxDataSourceResponse; if (bayeuxResponse != null) { if (string.Compare(channel, bayeuxResponse.Channel, StringComparison.OrdinalIgnoreCase) == 0) { e.SelectedResponse = bayeuxResponse; DebugLog.WriteBayeuxLine(string.Concat("Selected response for channel: '", channel, "'")); return; } } } }
/// <summary> /// Records a response as bayeux message, while only 'data' part of the message is given. /// It will try to parse data and put as IJSonMutableObject, or if parsing fails, it will put it /// just as string value of the field. /// </summary> public RecordedDataSourceResponse RecordBayeuxData(string name, int internalStatus, string channel, string data) { if (string.IsNullOrEmpty(channel)) throw new ArgumentNullException("channel"); var response = new RecordedBayeuxDataSourceResponse(name); var bayeuxMessage = CreateEmptyBayeuxResponse(internalStatus, channel); if (string.IsNullOrEmpty(data)) { bayeuxMessage.SetValue("data", data); } else { try { var reader = new JSonReader(data); bayeuxMessage.SetValue("data", reader.ReadAsJSonMutableObject()); } catch (Exception ex) { DebugLog.WriteBayeuxLine("Parsing of 'data' for RecordedBayeuxDataSourceResponse failed!"); DebugLog.WriteBayeuxException(ex); bayeuxMessage.SetValue("data", data); } } response.AsJSon = bayeuxMessage; Record(response); return response; }
/// <summary> /// Records a response as bayeux message, while only 'data' part of the message is given. /// </summary> public RecordedDataSourceResponse RecordBayeuxData(string name, int internalStatus, string channel, IJSonObject data) { if (string.IsNullOrEmpty(channel)) throw new ArgumentNullException("channel"); var response = new RecordedBayeuxDataSourceResponse(name); var bayeuxMessage = CreateEmptyBayeuxResponse(internalStatus, channel); bayeuxMessage.SetValue("data", data); response.AsJSon = bayeuxMessage; Record(response); return response; }
/// <summary> /// Records a response as bayeux message. /// </summary> public RecordedBayeuxDataSourceResponse RecordBayeux(string name, IJSonObject messageAsJSon) { if (messageAsJSon == null) throw new ArgumentNullException("messageAsJSon"); var response = new RecordedBayeuxDataSourceResponse(name); response.AsJSon = messageAsJSon; Record(response); return response; }
/// <summary> /// Records a response as bayeux message. /// </summary> public RecordedBayeuxDataSourceResponse RecordBayeux(string name, string messageAsJSon) { var reader = new JSonReader(messageAsJSon); var response = new RecordedBayeuxDataSourceResponse(name); response.AsJSon = reader.ReadAsJSonMutableObject(); Record(response); return response; }