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); } } }
/// <summary> /// Converts <see cref="BayeuxConnectionTypes"/> flag fields into a collection of strings. /// </summary> public static string[] ToCollection(BayeuxConnectionTypes types) { var result = new List <string>(); if ((types & BayeuxConnectionTypes.LongPolling) == BayeuxConnectionTypes.LongPolling) { result.Add("long-polling"); } if ((types & BayeuxConnectionTypes.CallbackPolling) == BayeuxConnectionTypes.CallbackPolling) { result.Add("callback-polling"); } if ((types & BayeuxConnectionTypes.Iframe) == BayeuxConnectionTypes.Iframe) { result.Add("iframe"); } if ((types & BayeuxConnectionTypes.Flash) == BayeuxConnectionTypes.Flash) { result.Add("flash"); } if ((types & BayeuxConnectionTypes.RequestResponse) == BayeuxConnectionTypes.RequestResponse) { result.Add("request-response"); } return(result.ToArray()); }
/// <summary> /// Init constructor. /// </summary> public HandshakeRequest(BayeuxConnectionTypes supportedConnectionTypes, IJSonWritable data, IJSonWritable ext) : base(MetaChannel, data, ext) { Version = new Version(1, 0); MinimumVersion = Version; SupportedConnectionTypes = supportedConnectionTypes; }
/// <summary> /// Init constructor. /// </summary> public HandshakeRequest(BayeuxConnectionTypes supportedConnectionTypes, IJSonWritable data, IJSonWritable ext) : base (MetaChannel, data, ext) { Version = new Version(1, 0); MinimumVersion = Version; SupportedConnectionTypes = supportedConnectionTypes; }
/// <summary> /// Converts the <see cref="BayeuxConnectionTypes"/> value into a string. /// If it is a combination of few values, then 'null' will be returned. /// </summary> public static string ToString(BayeuxConnectionTypes type) { if (type == BayeuxConnectionTypes.LongPolling) { return("long-polling"); } if (type == BayeuxConnectionTypes.CallbackPolling) { return("callback-polling"); } if (type == BayeuxConnectionTypes.Iframe) { return("iframe"); } if (type == BayeuxConnectionTypes.Flash) { return("flash"); } if (type == BayeuxConnectionTypes.RequestResponse) { return("request-response"); } return(null); }
/// <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)); }
/// <summary> /// Init constructor. /// </summary> public ConnectRequest(string clientID, BayeuxConnectionTypes connectionType, IJSonWritable data, IJSonWritable ext) : base (MetaChannel, data, ext) { if (string.IsNullOrEmpty(clientID)) throw new ArgumentException("ClientID can not be empty", "clientID"); ClientID = clientID; ConnectionType = connectionType; }
/// <summary> /// Init constructor. /// </summary> public ConnectRequest(string clientID, BayeuxConnectionTypes connectionType, IJSonWritable data, IJSonWritable ext) : base(MetaChannel, data, ext) { if (string.IsNullOrEmpty(clientID)) { throw new ArgumentException("ClientID can not be empty", "clientID"); } ClientID = clientID; ConnectionType = connectionType; }
/// <summary> /// Converts the <see cref="BayeuxConnectionTypes"/> value into a string. /// If it is a combination of few values, then 'null' will be returned. /// </summary> public static string ToString(BayeuxConnectionTypes type) { if (type == BayeuxConnectionTypes.LongPolling) return "long-polling"; if (type == BayeuxConnectionTypes.CallbackPolling) return "callback-polling"; if (type == BayeuxConnectionTypes.Iframe) return "iframe"; if (type == BayeuxConnectionTypes.Flash) return "flash"; if (type == BayeuxConnectionTypes.RequestResponse) return "request-response"; return null; }
/// <summary> /// Sends handshake request to the server. /// </summary> public void Handshake(BayeuxConnectionTypes supportedConnectionTypes, IJSonWritable data, IJSonWritable ext, bool asynchronous) { // if there is another Handshake request executed in background, try to cancel it first: if (_state == BayeuxConnectionState.Connecting) { Cancel(); // <-- this should reset the state to Disconnected! } if (_state != BayeuxConnectionState.Disconnected) { throw new InvalidOperationException("Connecting or already connected to bayeux server! Disconnect first"); } _state = BayeuxConnectionState.Connecting; SendRequest(new HandshakeRequest(supportedConnectionTypes, data, ext), asynchronous); }
/// <summary> /// Converts <see cref="BayeuxConnectionTypes"/> flag fields into a collection of strings. /// </summary> public static string[] ToCollection(BayeuxConnectionTypes types) { var result = new List<string>(); if ((types & BayeuxConnectionTypes.LongPolling) == BayeuxConnectionTypes.LongPolling) result.Add("long-polling"); if ((types & BayeuxConnectionTypes.CallbackPolling) == BayeuxConnectionTypes.CallbackPolling) result.Add("callback-polling"); if ((types & BayeuxConnectionTypes.Iframe) == BayeuxConnectionTypes.Iframe) result.Add("iframe"); if ((types & BayeuxConnectionTypes.Flash) == BayeuxConnectionTypes.Flash) result.Add("flash"); if ((types & BayeuxConnectionTypes.RequestResponse) == BayeuxConnectionTypes.RequestResponse) result.Add("request-response"); return result.ToArray(); }
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); } } }
/// <summary> /// Sends handshake request to the server. /// </summary> public void Handshake(BayeuxConnectionTypes supportedConnectionTypes, IJSonWritable data, string userName, string password, bool asynchronous) { Handshake(supportedConnectionTypes, data, new BayeuxHandshakeExtension(userName, password), asynchronous); }
/// <summary> /// Sends handshake request to the server. /// </summary> public void Handshake(BayeuxConnectionTypes supportedConnectionTypes, IJSonWritable data, IJSonWritable ext, bool asynchronous) { // if there is another Handshake request executed in background, try to cancel it first: if (_state == BayeuxConnectionState.Connecting) Cancel(); // <-- this should reset the state to Disconnected! if (_state != BayeuxConnectionState.Disconnected) throw new InvalidOperationException("Connecting or already connected to bayeux server! Disconnect first"); _state = BayeuxConnectionState.Connecting; SendRequest(new HandshakeRequest(supportedConnectionTypes, data, ext), asynchronous); }
/// <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); }