Beispiel #1
0
        void handleGetDataResponse(Message.GetDataResponse getDataResponse)
        {
            if (getDataResponse.handshake.authToken != _handshake.authToken)
            {
                return;
            }

            SimCapiGetRequestCallback requestCallBack = _getRequests[getDataResponse.simId][getDataResponse.key];

            if (getDataResponse.responseType == "success" && requestCallBack.successDelegate != null)
            {
                requestCallBack.successDelegate(getDataResponse);
            }
            else if (getDataResponse.responseType == "error" && requestCallBack.errorDelegate != null)
            {
                requestCallBack.errorDelegate(getDataResponse);
            }

            SimCapiQueuedGetRequest queuedGetRequest = requestCallBack.queuedGetRequest;

            _getRequests[getDataResponse.simId].Remove(getDataResponse.key);

            if (queuedGetRequest != null)
            {
                getDataRequest(getDataResponse.simId, getDataResponse.key, queuedGetRequest.successDelegate, queuedGetRequest.errorDelegate);
            }
        }
Beispiel #2
0
        public bool getDataRequest(string simId, string key, GetDataRequestSuccessDelegate successDelegate, GetDataRequestErrorDelegate errorDelegate)
        {
            if (simId == null)
            {
                throw new System.Exception("getDataRequest() called with null simId!");
            }

            if (key == null)
            {
                throw new System.Exception("getDataRequest() called with null key!");
            }

            // Use local data fallback
            if (!ExternalCalls.isInIFrame() || ExternalCalls.isInAuthor())
            {
                _simCapiLocalData.getData(simId, key, successDelegate, errorDelegate);
                return(true);
            }

            // Make sure dictionary exists for simId
            if (_getRequests.ContainsKey(simId) == false)
            {
                _getRequests[simId] = new Dictionary <string, SimCapiGetRequestCallback>();
            }


            // getRequest in progress, add to queue
            if (_getRequests[simId].ContainsKey(key) == true)
            {
                _getRequests[simId][key].queuedGetRequest = new SimCapiQueuedGetRequest(successDelegate, errorDelegate);
                return(false);
            }

            _getRequests[simId][key] = new SimCapiGetRequestCallback(successDelegate, errorDelegate);

            string jsonString = SimCapiJsonMaker.create_GET_DATA_REQUEST(_handshake, key, simId);

            if (_handshake.authToken == null)
            {
                _pendingMessagesForHandshake.Add(jsonString);
            }
            else
            {
                sendMessage(jsonString);
            }

            return(true);
        }