Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 3
0
 /// <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;
 }
Ejemplo n.º 4
0
 /// <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));
        }
Ejemplo n.º 7
0
        /// <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;
        }
Ejemplo n.º 8
0
        /// <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;
        }
Ejemplo n.º 10
0
        /// <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();
        }
Ejemplo n.º 12
0
        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);
                }
            }
        }
Ejemplo n.º 13
0
 /// <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);
 }
Ejemplo n.º 14
0
        /// <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);
        }
Ejemplo n.º 16
0
 /// <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);
 }