コード例 #1
0
        public void getData(string simId, string key, GetDataRequestSuccessDelegate successDelegate, GetDataRequestErrorDelegate errorDelegate)
        {
            string dataReturnString = ExternalCalls.getKeyPairSessionStorage(simId, key);

            // returns json string defined as below

            /*
             *  var response =
             *  {
             *      success: true,
             *      key: javaKey,
             *      value: null,
             *      exists: false
             *  };
             */

            // Parse return string from external call
            JObject jObject = JsonConvert.DeserializeObject <JObject>(dataReturnString);

            JProperty propSuccess = jObject.Property("success");
            //JProperty propKey = jObject.Property("key");
            JProperty propValue  = jObject.Property("value");
            JProperty propExists = jObject.Property("exists");

            bool success = propSuccess.Value.ToObject <bool>();


            Message.GetDataResponse getDataResponse = new Message.GetDataResponse();
            getDataResponse.handshake = Transporter.getInstance().getHandshake();
            getDataResponse.simId     = simId;
            getDataResponse.key       = key;
            getDataResponse.value     = null;
            getDataResponse.exists    = propExists.ToObject <bool>();

            if (success == true)
            {
                getDataResponse.responseType = "success";
            }
            else
            {
                getDataResponse.responseType = "error";
            }

            if (propValue.Value != null)
            {
                getDataResponse.value = propValue.Value.ToObject <string>();
            }

            if (success == true)
            {
                successDelegate(getDataResponse);
            }
            else
            {
                errorDelegate(getDataResponse);
            }
        }
コード例 #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);
        }
コード例 #3
0
 public SimCapiQueuedGetRequest(GetDataRequestSuccessDelegate successDelegate, GetDataRequestErrorDelegate errorDelegate)
 {
     this.successDelegate = successDelegate;
     this.errorDelegate   = errorDelegate;
 }
コード例 #4
0
 public SimCapiGetRequestCallback(GetDataRequestSuccessDelegate successDelegate, GetDataRequestErrorDelegate errorDelegate)
 {
     this.successDelegate = successDelegate;
     this.errorDelegate   = errorDelegate;
 }
コード例 #5
0
 /// <summary>
 /// Returns a persisent value.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="onSuccess"></param>
 /// <param name="onError"></param>
 public void Get(string key, GetDataRequestSuccessDelegate onSuccess, GetDataRequestErrorDelegate onError)
 {
     Sim.Capi.Transporter.getDataRequest(Capi.SIM_ID, key, onSuccess, onError);
 }