private void OnGetClassifiersResp(RESTConnector.Request req, RESTConnector.Response resp) { GetClassifiersTopLevelBrief classifiers = new GetClassifiersTopLevelBrief(); if (resp.Success) { try { fsData data = null; fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); object obj = classifiers; r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } } catch (Exception e) { Log.Error("VisualRecognition", "GetClassifiers Exception: {0}", e.ToString()); resp.Success = false; } } if (((GetClassifiersReq)req).Callback != null) { ((GetClassifiersReq)req).Callback(resp.Success ? classifiers : null); } }
private void OnCheckServices(GetClassifiersTopLevelBrief classifiers) { if (m_Callback != null) { if (classifiers != null) { if (classifiers.classifiers != null) { if (classifiers.classifiers.Length > 0) { // Check first five classifiers - too many classifiers currently! int numClassifiers = (classifiers.classifiers.Length > 5) ? 5 : classifiers.classifiers.Length; for (int i = 0; i < numClassifiers; i++) { if (!m_Service.GetClassifier(classifiers.classifiers[i].classifier_id, OnCheckService)) { Log.Debug("VisualRecognition", "Failed to call GetClassifier()"); } else { m_GetClassifierCount += 1; } } } else { if (m_Callback != null && m_Callback.Target != null) { m_Callback(SERVICE_ID, true); // no classifiers to check, just return success then.. } } } else { Log.Debug("VisualRecognition", "Classifiers.classifiers is null!"); } } else { Log.Debug("VisualRecognition", "Classifiers in null!"); } } else { if (m_Callback != null && m_Callback.Target != null) { m_Callback(SERVICE_ID, false); } } }
private void OnGetClassifiers(GetClassifiersTopLevelBrief classifiers) { bool bFound = false; foreach (var c in classifiers.classifiers) { if (c.name.ToLower().StartsWith(ClassifierName.ToLower())) { bFound = Service.GetClassifier(c.classifier_id, OnGetClassifier); break; } } if (!bFound) { Log.Warning("VisualRecognition", "Failed to find classifier {0}", ClassifierName); Callback(null); } }