private void OnGetModels(ListModelsResults modelsData, string customData)
 {
     if (m_Callback != null)
     {
         m_Callback(SERVICE_ID, modelsData != null);
     }
 }
        private void OnGetModelsResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            ListModelsResults modelData = new ListModelsResults();

            if (resp.Success)
            {
                try
                {
                    fsData   data = null;
                    fsResult r    = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);

                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }

                    object obj = modelData;
                    r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Discovery", "OnGetModelssResponse Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((GetModelsRequest)req).Callback != null)
            {
                ((GetModelsRequest)req).Callback(resp.Success ? modelData : null, ((GetModelsRequest)req).Data);
            }
        }
Example #3
0
        private void OnGetModelsResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            ListModelsResults           result     = new ListModelsResults();
            fsData                      data       = null;
            Dictionary <string, object> customData = ((GetModelsRequest)req).CustomData;

            customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers);

            if (resp.Success)
            {
                try
                {
                    fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);

                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }

                    object obj = result;
                    r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }

                    customData.Add("json", data);
                }
                catch (Exception e)
                {
                    Log.Error("Discovery.OnGetModelsResponse()", "OnGetModelssResponse Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (resp.Success)
            {
                if (((GetModelsRequest)req).SuccessCallback != null)
                {
                    ((GetModelsRequest)req).SuccessCallback(result, customData);
                }
            }
            else
            {
                if (((GetModelsRequest)req).FailCallback != null)
                {
                    ((GetModelsRequest)req).FailCallback(resp.Error, customData);
                }
            }
        }