//public async Task CallZomeFunctionAsync(string id, string instanceId, string zome, string function, ZomeFunctionCallBack callback, object paramsObject, bool autoConvertFieldsToHCStandard = false, bool matchIdToInstanceZomeFuncInCallback = true, bool cachReturnData = false)
        public async Task CallZomeFunctionAsync(string id, string instanceId, string zome, string function, ZomeFunctionCallBack callback, object paramsObject, bool matchIdToInstanceZomeFuncInCallback = true, bool cachReturnData = false)
        {
            Logger.Log("CallZomeFunctionAsync ENTER", LogType.Debug);
            _cacheZomeReturnDataLookup[id] = cachReturnData;

            if (cachReturnData)
            {
                if (_zomeReturnDataLookup.ContainsKey(id))
                {
                    Logger.Log("Caching Enabled so returning data from cach...", LogType.Warn);
                    Logger.Log(string.Concat("Id: ", _zomeReturnDataLookup[id].Id, ", Instance: ", _zomeReturnDataLookup[id].Instance, ", Zome: ", _zomeReturnDataLookup[id].Zome, ", Zome Function: ", _zomeReturnDataLookup[id].ZomeFunction, ", Is Zome Call Successful: ", _zomeReturnDataLookup[id].IsCallSuccessful ? "True" : "False", ", Raw Zome Return Data: ", _zomeReturnDataLookup[id].RawZomeReturnData, ", Zome Return Data: ", _zomeReturnDataLookup[id].ZomeReturnData, ", JSON Raw Data: ", _zomeReturnDataLookup[id].RawJSONData), LogType.Info);

                    if (callback != null)
                    {
                        callback.DynamicInvoke(this, _zomeReturnDataLookup[id]);
                    }

                    OnZomeFunctionCallBack?.Invoke(this, _zomeReturnDataLookup[id]);
                    Logger.Log("CallZomeFunctionAsync EXIT", LogType.Debug);
                    return;
                }
            }

            if (matchIdToInstanceZomeFuncInCallback)
            {
                _instanceLookup[id] = instanceId;
                _zomeLookup[id]     = zome;
                _funcLookup[id]     = function;
            }

            if (callback != null)
            {
                _callbackLookup[id] = callback;
            }


            //if (autoConvertFieldsToHCStandard)
            //{
            //    string json = JsonConvert.SerializeObject(paramsObject);
            //    JObject data = JObject.Parse(json);
            //    //data.Next.Replace(new JToken()

            //    data.SelectToken("instance_stats.test-instance.number_delayed_validations").ToString()),
            //}

            await SendMessageAsync(JsonConvert.SerializeObject(
                                       new
            {
                jsonrpc = "2.0",
                id,
                method  = "call",
                @params = new { instance_id = instanceId, zome, function, args = paramsObject }
                //@params = new { instance_id = instanceId, zome, function, @params = paramsObject }
            }
                                       ));

            Logger.Log("CallZomeFunctionAsync EXIT", LogType.Debug);
        }
コード例 #2
0
        public async Task CallZomeFunctionAsync(string id, string instanceId, string zome, string function, ZomeFunctionCallBack callback, object paramsObject, bool matchIdToInstanceZomeFuncInCallback = true, bool cachReturnData = false)
        {
            Logger.Log("CallZomeFunctionAsync ENTER", LogType.Debug);
            _cacheZomeReturnDataLookup[id] = cachReturnData;

            if (cachReturnData)
            {
                if (_zomeReturnDataLookup.ContainsKey(id))
                {
                    Logger.Log("Caching Enabled so returning data from cach...", LogType.Warn);
                    Logger.Log(string.Concat("Id: ", _zomeReturnDataLookup[id].Id, ", Instance: ", _zomeReturnDataLookup[id].Instance, ", Zome: ", _zomeReturnDataLookup[id].Zome, ", Zome Function: ", _zomeReturnDataLookup[id].ZomeFunction, ", Is Zome Call Successful: ", _zomeReturnDataLookup[id].IsCallSuccessful ? "True" : "False", ", Raw Zome Return Data: ", _zomeReturnDataLookup[id].RawZomeReturnData, ", Zome Return Data: ", _zomeReturnDataLookup[id].ZomeReturnData, ", JSON Raw Data: ", _zomeReturnDataLookup[id].RawJSONData), LogType.Info);

                    if (callback != null)
                    {
                        callback.DynamicInvoke(this, _zomeReturnDataLookup[id]);
                    }

                    OnZomeFunctionCallBack?.Invoke(this, _zomeReturnDataLookup[id]);
                    Logger.Log("CallZomeFunctionAsync EXIT", LogType.Debug);
                    return;
                }
            }

            if (matchIdToInstanceZomeFuncInCallback)
            {
                _instanceLookup[id] = instanceId;
                _zomeLookup[id]     = zome;
                _funcLookup[id]     = function;
            }

            if (callback != null)
            {
                _callbackLookup[id] = callback;
            }

            await SendMessageAsync(JsonConvert.SerializeObject(
                                       new
            {
                jsonrpc = "2.0",
                id,
                method  = "call",
                @params = new { instance_id = instanceId, zome, function, @params = paramsObject }
            }
                                       ));

            Logger.Log("CallZomeFunctionAsync EXIT", LogType.Debug);
        }