コード例 #1
0
 void OnConvertDocument(ConvertedDocument documentConversionData, string data)
 {
     if (m_Callback != null)
     {
         m_Callback(SERVICE_ID, documentConversionData != null);
     }
 }
コード例 #2
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);
            }
        }
コード例 #3
0
        private void ConvertDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            ConvertedDocument           result = new ConvertedDocument();
            fsData                      data   = null;
            fsResult                    r;
            Dictionary <string, object> customData = ((ConvertDocumentRequest)req).CustomData;

            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 = 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("DocumentConversion.ConvertDocumentResponse()", "ConvertDocumentResponse Exception: {0}", e.ToString());
                        resp.Success = false;
                    }
                }
                else if ((req as ConvertDocumentRequest).ConversionTarget == ConversionTarget.NormalizedHtml)
                {
#if NETFX_CORE
                    result.htmlContent = System.Text.Encoding.GetEncoding(0).GetString(resp.Data);
#else
                    result.htmlContent = System.Text.Encoding.Default.GetString(resp.Data);
#endif
                    customData.Add("json", data);
                }
                else if ((req as ConvertDocumentRequest).ConversionTarget == ConversionTarget.NormalizedText)
                {
#if NETFX_CORE
                    result.textContent = System.Text.Encoding.GetEncoding(0).GetString(resp.Data);
#else
                    result.textContent = System.Text.Encoding.Default.GetString(resp.Data);
#endif
                    customData.Add("json", data);
                }
            }

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