protected override void ReadOptionalFields(IJSonObject input) { // reset field values: SupportedConnectionTypes = BayeuxConnectionTypes.None; // read additional data: if (input.Contains("supportedConnectionTypes")) { IJSonObject supportedTypes = input["supportedConnectionTypes"]; if (supportedTypes == null) { throw new MissingMemberException("Missing 'supportedConnectionTypes' field"); } if (!supportedTypes.IsArray) { throw new FormatException("Expected supportedConnectionTypes to be an array"); } BayeuxConnectionTypes types = BayeuxConnectionTypes.None; foreach (IJSonObject connectionType in supportedTypes.ArrayItems) { types |= BayeuxConnectionTypesHelper.Parse(connectionType.StringValue); } } }
protected override void WriteOptionalFields(IJSonWriter output) { // create basic JSON representation of Bayeux message: // { // ... - parent inserted fields // supportedConnectionTypes: "xxx", // version: "1.0", // minimumVersion: "1.0", // ext: "xxx" // } if (Version != null) { output.WriteMember("version", Version.ToString()); } if (MinimumVersion != null) { output.WriteMember("minimumVersion", MinimumVersion.ToString()); } output.WriteMember("supportedConnectionTypes"); output.WriteArrayBegin(); foreach (string type in BayeuxConnectionTypesHelper.ToCollection(SupportedConnectionTypes)) { output.WriteValue(type); } output.WriteArrayEnd(); }
/// <summary> /// Records bayeux-handshake response. /// </summary> public RecordedBayeuxDataSourceResponse RecordBayeuxHandshake(BayeuxConnectionTypes connectionTypes) { var responseJSonText = "{\"supportedConnectionTypes\":[\"" + string.Join(", ", BayeuxConnectionTypesHelper.ToCollection(connectionTypes)) + "\"],\"ext\":{\"token\":\"xxx\"},\"successful\":true,\"authSuccessful\":true,\"clientId\":\"xxx\",\"advice\":{\"reconnect\":\"retry\"},\"version\":\"1.0\",\"channel\":\"/meta/handshake\",\"minimumVersion\":\"1.0\"}"; return(RecordBayeux("Handshake", responseJSonText)); }
protected override void WriteOptionalFields(IJSonWriter output) { output.WriteMember("supportedConnectionTypes"); output.WriteArrayBegin(); foreach (string type in BayeuxConnectionTypesHelper.ToCollection(SupportedConnectionTypes)) { output.WriteValue(type); } output.WriteArrayEnd(); }
protected override void WriteOptionalFields(IJSonWriter output) { output.WriteMember("connectionType", BayeuxConnectionTypesHelper.ToString(ConnectionType)); }