Example #1
0
        private void ProcessResponse(JToken response)
        {
            var messages = response as JArray;

            if (messages == null)
            {
                Tracer.Write(ReactConstants.Tag, "Empty JavaScript Queue");
                return;
            }

            var moduleIds   = messages[0].ToObject <int[]>();
            var methodIds   = messages[1].ToObject <int[]>();
            var paramsArray = messages[2] as JArray;

            if (moduleIds == null || methodIds == null || paramsArray == null ||
                moduleIds.Length != methodIds.Length || moduleIds.Length != paramsArray.Count)
            {
                throw new InvalidOperationException("Unexpected React batch response.");
            }

            _nativeModulesQueueThread.RunOnQueue(() =>
            {
                for (var i = 0; i < moduleIds.Length; ++i)
                {
                    var moduleId = moduleIds[i];
                    var methodId = methodIds[i];
                    var args     = (JArray)paramsArray[i];

                    _reactCallback.Invoke(moduleId, methodId, args);
                }
                ;

                _reactCallback.OnBatchComplete();
            });
        }
        private void ProcessResponse(JToken response)
        {
            if (response == null || response.Type == JTokenType.Null || response.Type == JTokenType.Undefined)
            {
                return;
            }

            var messages = response as JArray;

            if (messages == null)
            {
                throw new InvalidOperationException(
                          "Did not get valid calls back from JavaScript. Message type: " + response.Type);
            }

            if (messages.Count < 3)
            {
                throw new InvalidOperationException(
                          "Did not get valid calls back from JavaScript. Message count: " + messages.Count);
            }

            var moduleIds   = messages[0] as JArray;
            var methodIds   = messages[1] as JArray;
            var paramsArray = messages[2] as JArray;

            if (moduleIds == null || methodIds == null || paramsArray == null ||
                moduleIds.Count != methodIds.Count || moduleIds.Count != paramsArray.Count)
            {
                throw new InvalidOperationException(
                          "Did not get valid calls back from JavaScript. JSON: " + response);
            }

            _nativeModulesQueueThread.RunOnQueue(() =>
            {
                Log.Info(ReactConstants.Tag, $">>> _nativeModulesQueueThread.RunOnQueue moduleIds.Count={moduleIds.Count}");
                for (var i = 0; i < moduleIds.Count; ++i)
                {
                    var moduleId = moduleIds[i].Value <int>();
                    var methodId = methodIds[i].Value <int>();
                    var args     = (JArray)paramsArray[i];
                    Log.Info(ReactConstants.Tag, $">>> moduleIds={moduleId} methodId={methodId} args={args}");
                    _reactCallback.Invoke(moduleId, methodId, args);
                }
                ;

                // TODO: confirm ?
                if (0 != moduleIds.Count)
                {
                    _reactCallback.OnBatchComplete();
                }
            });
        }
Example #3
0
        private void ProcessResponse(JToken response)
        {
            if (response == null || response.Type == JTokenType.Null || response.Type == JTokenType.Undefined)
            {
                return;
            }

            var messages = response as JArray;

            if (messages == null)
            {
                throw new InvalidOperationException(
                          "Did not get valid calls back from JavaScript. Message type: " + response.Type);
            }

            if (messages.Count < 3)
            {
                throw new InvalidOperationException(
                          "Did not get valid calls back from JavaScript. Message count: " + messages.Count);
            }

            var moduleIds   = messages[0] as JArray;
            var methodIds   = messages[1] as JArray;
            var paramsArray = messages[2] as JArray;

            if (moduleIds == null || methodIds == null || paramsArray == null ||
                moduleIds.Count != methodIds.Count || moduleIds.Count != paramsArray.Count)
            {
                throw new InvalidOperationException(
                          "Did not get valid calls back from JavaScript. JSON: " + response);
            }

            _nativeModulesQueueThread.Dispatch(() =>
            {
                for (var i = 0; i < moduleIds.Count; ++i)
                {
                    var moduleId = moduleIds[i].Value <int>();
                    var methodId = methodIds[i].Value <int>();
                    var args     = (JArray)paramsArray[i];

                    _reactCallback.Invoke(moduleId, methodId, args);
                }
                ;

                _reactCallback.OnBatchComplete();
            });
        }