コード例 #1
0
        private void OnGetWorkspacesResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DataModels.Workspaces workspaces = new DataModels.Workspaces();
            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 = workspaces;
                    r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Conversation", "GetWorkspaces Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((GetWorkspacesReq)req).Callback != null)
            {
                ((GetWorkspacesReq)req).Callback(resp.Success ? workspaces : null);
            }
        }
コード例 #2
0
 private void OnDeleteModelResponse(RESTConnector.Request req, RESTConnector.Response resp)
 {
     if (((DeleteModelRequest)req).Callback != null)
     {
         ((DeleteModelRequest)req).Callback(resp.Success, ((DeleteModelRequest)req).Data);
     }
 }
コード例 #3
0
        private void OnAskQuestionResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            Response response = null;

            if (resp.Success)
            {
                try
                {
                    response = ProcessAskResp(resp.Data);
                    if (m_QuestionCache != null && response != null)
                    {
                        m_QuestionCache.Save(((AskQuestionReq)req).QuestionID, resp.Data);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Natural Language Classifier", "GetClassifiers Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((AskQuestionReq)req).Callback != null)
            {
                if (resp.Success && response != null)
                {
                    response.question.questionId = ((AskQuestionReq)req).QuestionID;
                    ((AskQuestionReq)req).Callback(response.question);
                }
                else
                {
                    ((AskQuestionReq)req).Callback(null);
                }
            }
        }
コード例 #4
0
        private void OnAnalyzeResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            AnalysisResults analysisResults = new AnalysisResults();

            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 = analysisResults;
                    r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Discovery", "OnAnalyzeResponse Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((AnalyzeRequest)req).Callback != null)
            {
                ((AnalyzeRequest)req).Callback(resp.Success ? analysisResults : null, ((AnalyzeRequest)req).Data);
            }
        }
コード例 #5
0
        private void OnTranslateDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DetailedResponse <DocumentStatus> response = new DetailedResponse <DocumentStatus>();

            foreach (KeyValuePair <string, string> kvp in resp.Headers)
            {
                response.Headers.Add(kvp.Key, kvp.Value);
            }
            response.StatusCode = resp.HttpResponseCode;

            try
            {
                string json = Encoding.UTF8.GetString(resp.Data);
                response.Result   = JsonConvert.DeserializeObject <DocumentStatus>(json);
                response.Response = json;
            }
            catch (Exception e)
            {
                Log.Error("LanguageTranslatorService.OnTranslateDocumentResponse()", "Exception: {0}", e.ToString());
                resp.Success = false;
            }

            if (((RequestObject <DocumentStatus>)req).Callback != null)
            {
                ((RequestObject <DocumentStatus>)req).Callback(response, resp.Error);
            }
        }
コード例 #6
0
ファイル: Conversation.cs プロジェクト: ScalpelApp/Alpha003
        private void MessageResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            object dataObject = null;
            string data       = "";

            if (resp.Success)
            {
                try
                {
                    //  For deserializing into a generic object
                    data       = Encoding.UTF8.GetString(resp.Data);
                    dataObject = Json.Deserialize(data);
                }
                catch (Exception e)
                {
                    Log.Error("Conversation", "MessageResp Exception: {0}", e.ToString());
                    data         = e.Message;
                    resp.Success = false;
                }
            }

            string customData = ((MessageReq)req).Data;

            if (((MessageReq)req).Callback != null)
            {
                ((MessageReq)req).Callback(resp.Success ? dataObject : null, !string.IsNullOrEmpty(customData) ? customData : data.ToString());
            }
        }
コード例 #7
0
        private void GetDilemmaResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DilemmasResponse response = new DilemmasResponse();

            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 = response;
                    r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("TradeoffAnalytics", "GetDilemmaResponse Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((GetDilemmaRequest)req).Callback != null)
            {
                ((GetDilemmaRequest)req).Callback(resp.Success ? response : null);
            }
        }
コード例 #8
0
        private void OnRegisterEmbodiment(RESTConnector.Request req, RESTConnector.Response resp)
        {
            RegisterEmbodimentReq ereq = req as RegisterEmbodimentReq;

            if (resp.Success)
            {
                try {
                    IDictionary json         = Json.Deserialize(Encoding.UTF8.GetString(resp.Data)) as IDictionary;
                    string      embodimentId = json["_id"] as string;
                    string      token        = json["embodimentToken"] as string;

                    if (ereq.Callback != null)
                    {
                        ereq.Callback(token, embodimentId);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("TopicClient", "OnRegisterEmbodiment Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (!resp.Success && ereq.Callback != null)
            {
                ereq.Callback(null, null);
            }
        }
コード例 #9
0
        private void OnGetClassifierResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            GetClassifiersPerClassifierVerbose classifier = new GetClassifiersPerClassifierVerbose();

            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 = classifier;
                    r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Visual Recognition", "GetClassifier Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((GetClassifierReq)req).Callback != null)
            {
                ((GetClassifierReq)req).Callback(resp.Success ? classifier : null);
            }
        }
コード例 #10
0
ファイル: TextToSpeech.cs プロジェクト: hoverbird/unity-sdk
        private void ToSpeechResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            ToSpeechRequest speechReq = req as ToSpeechRequest;

            if (speechReq == null)
            {
                throw new WatsonException("Wrong type of request object.");
            }

            Log.Debug("TextToSpeech", "Request completed in {0} seconds.", resp.ElapsedTime);

            AudioClip clip = resp.Success ? ProcessResponse(speechReq.TextId, resp.Data) : null;

            if (clip == null)
            {
                Log.Error("TextToSpeech", "Request Failed: {0}", resp.Error);
            }
            if (m_SpeechCache != null && clip != null)
            {
                m_SpeechCache.Save(speechReq.TextId, resp.Data);
            }

            if (speechReq.Callback != null)
            {
                speechReq.Callback(clip);
            }
        }
コード例 #11
0
        private void GetModelResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            TranslationModel model = new TranslationModel();

            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 = model;
                    r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("NLC", "GetModel Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((GetModelReq)req).Callback != null)
            {
                ((GetModelReq)req).Callback(resp.Success ? model : null);
            }
        }
コード例 #12
0
        private void OnDownloadDialogResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DownloadDialogReq downloadReq = req as DownloadDialogReq;

            if (downloadReq == null)
            {
                throw new WatsonException("Unexpected type.");
            }

            if (resp.Success)
            {
                try {
                    if (SaveFile != null)
                    {
                        SaveFile(downloadReq.DialogFileName, resp.Data);
                    }
                    else
                    {
                                                #if !UNITY_WEBPLAYER
                        File.WriteAllBytes(downloadReq.DialogFileName, resp.Data);
                                                #endif
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Dialog", "Caught exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((DownloadDialogReq)req).Callback != null)
            {
                ((DownloadDialogReq)req).Callback(resp.Success);
            }
        }
コード例 #13
0
        private void OnIdentifyResponse(RESTConnector.Request r, RESTConnector.Response resp)
        {
            IdentifyReq req = r as IdentifyReq;

            if (req == null)
            {
                throw new WatsonException("Unexpected Request type.");
            }

            if (resp.Success)
            {
                if (req.Callback != null)
                {
                    req.Callback(Encoding.UTF8.GetString(resp.Data));
                }
            }
            else
            {
                Log.Error("Translate", "Identify() failed: {0}", resp.Error);
                if (req.Callback != null)
                {
                    req.Callback(null);
                }
            }
        }
コード例 #14
0
        private void GetLanguagesResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            Languages langs = new Languages();

            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 = langs;
                    r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Natural Language Classifier", "GetLanguages Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((GetLanguagesReq)req).Callback != null)
            {
                ((GetLanguagesReq)req).Callback(resp.Success ? langs : null);
            }
        }
コード例 #15
0
        private void OnRefreshIamTokenResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DetailedResponse <IamTokenData> response = new DetailedResponse <IamTokenData> ();

            response.Result = new IamTokenData();
            foreach (KeyValuePair <string, string> kvp in resp.Headers)
            {
                response.Headers.Add(kvp.Key, kvp.Value);
            }
            response.StatusCode = resp.HttpResponseCode;

            try {
                string json = Encoding.UTF8.GetString(resp.Data);
                response.Result   = JsonConvert.DeserializeObject <IamTokenData> (json);
                response.Response = json;
            } catch (Exception e) {
                Log.Error("Credentials.OnRefreshIamTokenResponse()", "Exception: {0}", e.ToString());
                resp.Success = false;
            }

            if (((RefreshIamTokenRequest)req).Callback != null)
            {
                ((RefreshIamTokenRequest)req).Callback(response, resp.Error);
            }
        }
コード例 #16
0
        private void OnRecognizeResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            RecognizeRequest recognizeReq = req as RecognizeRequest;

            if (recognizeReq == null)
            {
                throw new WatsonException("Unexpected request type.");
            }

            SpeechResultList result = null;

            if (resp.Success)
            {
                result = ParseRecognizeResponse(resp.Data);
                if (result == null)
                {
                    Log.Error("SpeechToText", "Failed to parse json response: {0}",
                              resp.Data != null ? Encoding.UTF8.GetString(resp.Data) : "");
                }
                else
                {
                    Log.Status("SpeechToText", "Received Recognize Response, Elapsed Time: {0}, Results: {1}",
                               resp.ElapsedTime, result.Results.Length);
                }
            }
            else
            {
                Log.Error("SpeechToText", "Recognize Error: {0}", resp.Error);
            }

            if (recognizeReq.Callback != null)
            {
                recognizeReq.Callback(result);
            }
        }
コード例 #17
0
        private void OnGetCombinedCallResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            CombinedCallData combinedCallData = new CombinedCallData();

            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 = combinedCallData;
                    r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("AlchemyAPI", "OnGetCombinedCallResponse Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((GetCombinedCallRequest)req).Callback != null)
            {
                ((GetCombinedCallRequest)req).Callback(resp.Success ? combinedCallData : null, ((GetCombinedCallRequest)req).Data);
            }
        }
コード例 #18
0
 private void OnDeleteDialogResp(RESTConnector.Request req, RESTConnector.Response resp)
 {
     if (((DeleteDialogReq)req).Callback != null)
     {
         ((DeleteDialogReq)req).Callback(resp.Success);
     }
 }
コード例 #19
0
        private void DeleteModelResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            string customData = ((DeleteModelReq)req).Data;

            if (((DeleteModelReq)req).Callback != null)
            {
                ((DeleteModelReq)req).Callback(resp.Success, customData);
            }
        }
コード例 #20
0
        private void OnRecognizeTextResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            TextRecogTopLevelMultiple text = null;

            if (resp.Success)
            {
                text = ProcessRecognizeTextResult(resp.Data);
            }

            if (((RecognizeTextReq)req).Callback != null)
            {
                ((RecognizeTextReq)req).Callback(text);
            }
        }
コード例 #21
0
        private void OnClassifyResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            ClassifyTopLevelMultiple classify = null;

            if (resp.Success)
            {
                classify = ProcessClassifyResult(resp.Data);
            }

            if (((ClassifyReq)req).Callback != null)
            {
                ((ClassifyReq)req).Callback(classify);
            }
        }
コード例 #22
0
        private void OnDetectFacesResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            FacesTopLevelMultiple faces = null;

            if (resp.Success)
            {
                faces = ProcessDetectFaceResult(resp.Data);
            }

            if (((DetectFacesReq)req).Callback != null)
            {
                ((DetectFacesReq)req).Callback(faces);
            }
        }
コード例 #23
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);
                }
            }
        }
コード例 #24
0
        private void OnClassifyResp(RESTConnector.Request req, RESTConnector.Response resp)
        {
            ClassifyResult result = new ClassifyResult();;
            fsData         data   = null;
            Dictionary <string, object> customData = ((ClassifyReq)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("NaturalLanguageClassifier.OnTrainClassifierResp()", "GetClassifiers Exception: {0}", e.ToString());
                }
            }

            if (resp.Success)
            {
                if (((ClassifyReq)req).SuccessCallback != null)
                {
                    ((ClassifyReq)req).SuccessCallback(result, customData);
                }
            }
            else
            {
                if (((ClassifyReq)req).FailCallback != null)
                {
                    ((ClassifyReq)req).FailCallback(resp.Error, customData);
                }
            }
        }
コード例 #25
0
        private void GetDilemmaResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DilemmasResponse            result     = new DilemmasResponse();
            fsData                      data       = null;
            Dictionary <string, object> customData = ((GetDilemmaRequest)req).CustomData;

            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("TradeoffAnalytics.GetDilemmaResponse()", "GetDilemmaResponse Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (resp.Success)
            {
                if (((GetDilemmaRequest)req).SuccessCallback != null)
                {
                    ((GetDilemmaRequest)req).SuccessCallback(result, customData);
                }
            }
            else
            {
                if (((GetDilemmaRequest)req).FailCallback != null)
                {
                    ((GetDilemmaRequest)req).FailCallback(resp.Error, customData);
                }
            }
        }
コード例 #26
0
        private void ConvertDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            ConvertedDocument response = new ConvertedDocument();
            fsData            data     = null;
            fsResult          r;

            if (resp.Success)
            {
                if ((req as ConvertDocumentRequest).ConversionTarget == ConversionTarget.Answerunits)
                {
                    try
                    {
                        r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
                        if (!r.Succeeded)
                        {
                            throw new WatsonException(r.FormattedMessages);
                        }

                        object obj = response;
                        r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
                        if (!r.Succeeded)
                        {
                            throw new WatsonException(r.FormattedMessages);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("DocumentConversion", "ConvertDocumentResponse Exception: {0}", e.ToString());
                        resp.Success = false;
                    }
                }
                else if ((req as ConvertDocumentRequest).ConversionTarget == ConversionTarget.NormalizedHtml)
                {
                    response.htmlContent = System.Text.Encoding.Default.GetString(resp.Data);
                }
                else if ((req as ConvertDocumentRequest).ConversionTarget == ConversionTarget.NormalizedText)
                {
                    response.textContent = System.Text.Encoding.Default.GetString(resp.Data);
                }
            }

            if (((ConvertDocumentRequest)req).Callback != null)
            {
                ((ConvertDocumentRequest)req).Callback(resp.Success ? response : null, ((ConvertDocumentRequest)req).Data);
            }
        }
コード例 #27
0
        private void OnGetTranslatedDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DetailedResponse <byte[]> response = new DetailedResponse <byte[]>();

            foreach (KeyValuePair <string, string> kvp in resp.Headers)
            {
                response.Headers.Add(kvp.Key, kvp.Value);
            }
            response.StatusCode = resp.HttpResponseCode;

            response.Result = resp.Data;

            if (((RequestObject <byte[]>)req).Callback != null)
            {
                ((RequestObject <byte[]>)req).Callback(response, resp.Error);
            }
        }
コード例 #28
0
        private void OnProfileAsCsvResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DetailedResponse <System.IO.MemoryStream> response = new DetailedResponse <System.IO.MemoryStream>();

            foreach (KeyValuePair <string, string> kvp in resp.Headers)
            {
                response.Headers.Add(kvp.Key, kvp.Value);
            }
            response.StatusCode = resp.HttpResponseCode;

            response.Result = new System.IO.MemoryStream(resp.Data);

            if (((RequestObject <System.IO.MemoryStream>)req).Callback != null)
            {
                ((RequestObject <System.IO.MemoryStream>)req).Callback(response, resp.Error);
            }
        }
コード例 #29
0
        private void OnRefreshIamTokenResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            DetailedResponse <IamTokenData> response = new DetailedResponse <IamTokenData>();

            response.Result = new IamTokenData();
            fsData data = null;

            foreach (KeyValuePair <string, string> kvp in resp.Headers)
            {
                response.Headers.Add(kvp.Key, kvp.Value);
            }

            if (resp.Success)
            {
                try
                {
                    fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
                    if (!r.Succeeded)
                    {
                        throw new IBMException(r.FormattedMessages);
                    }

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

                    response.Response = data.ToString();
                }
                catch (Exception e)
                {
                    Log.Error("TokenManager.OnRefreshTokenResponse()", "Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (((RefreshIamTokenRequest)req).Callback != null)
            {
                ((RefreshIamTokenRequest)req).Callback(response, resp.Error);
            }
        }
コード例 #30
0
        private void OnIdentifyResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            IdentifyReq identifyRequest = req as IdentifyReq;

            if (identifyRequest == null)
            {
                throw new WatsonException("Unexpected Request type.");
            }

            string identifiedLanguages;

            if (resp.Success)
            {
                identifiedLanguages = Encoding.UTF8.GetString(resp.Data);
                string customData = identifyRequest.Data;
                if (((IdentifyReq)req).Callback != null)
                {
                    ((IdentifyReq)req).Callback(resp.Success ? identifiedLanguages : null, (!string.IsNullOrEmpty(customData) ? customData : identifiedLanguages));
                }
            }
        }