Exemplo n.º 1
0
        /// <summary>
        /// Gets a classifier by classifierId.
        /// </summary>
        /// <returns><c>true</c>, if classifier was gotten, <c>false</c> otherwise.</returns>
        /// <param name="classifierId">Classifier identifier.</param>
        /// <param name="callback">Callback.</param>
        public bool GetClassifier(string classifierId, OnGetClassifier callback)
        {
            if (string.IsNullOrEmpty(classifierId))
            {
                throw new ArgumentNullException("classifierId");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (string.IsNullOrEmpty(mp_ApiKey))
            {
                mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
            }
            if (string.IsNullOrEmpty(mp_ApiKey))
            {
                throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
            }

            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_CLASSIFIERS + "/" + classifierId);

            if (connector == null)
            {
                return(false);
            }

            GetClassifierReq req = new GetClassifierReq();

            req.Callback = callback;
            req.Parameters["api_key"] = mp_ApiKey;
            req.Parameters["version"] = VisualRecognitionVersion.Version;
            req.OnResponse            = OnGetClassifierResp;

            return(connector.Send(req));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a specific classifer.
        /// </summary>
        /// <param name="classifierId">The ID of the classifier to get.</param>
        /// <param name="callback">The callback to invoke with the Classifier object.</param>
        /// <returns>Returns true if the request is submitted.</returns>
        public bool GetClassifier(string classifierId, OnGetClassifier callback)
        {
            if (string.IsNullOrEmpty(classifierId))
            {
                throw new ArgumentNullException("classifierId");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/classifiers/" + classifierId);

            if (connector == null)
            {
                return(false);
            }

            GetClassifierReq req = new GetClassifierReq();

            req.Callback   = callback;
            req.OnResponse = OnGetClassifierResp;

            return(connector.Send(req));
        }