Assets/Watson/Scripts/Services/DocumentConversion/DocumentConversion.cs
/// <summary>
/// Convert document to use in other Watson services.
/// </summary>
/// <param name="callback"></param>
/// <param name="documentPath"></param>
/// <param name="conversionTarget"></param>
/// <param name="data"></param>
/// <returns></returns>
Convert document to use in other Watson services.
Convert document to use in other Watson services .
public bool ConvertDocument(OnConvertDocument callback, string documentPath, string conversionTarget = ConversionTarget.ANSWER_UNITS, string data = null)
        {
            if (callback == null)
                throw new ArgumentNullException("callback");
            if (string.IsNullOrEmpty(documentPath))
                throw new ArgumentNullException("A document path is needed to convert document.");
            if (string.IsNullOrEmpty(conversionTarget))
                throw new ArgumentNullException("A conversion target is needed to convert document.");
            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, FUNCTION_CONVERT_DOCUMENT);
            if (connector == null)
                return false;
            ConvertDocumentRequest req = new ConvertDocumentRequest();
            req.Callback = callback;
            req.OnResponse = ConvertDocumentResponse;
            req.Data = data;
            req.ConversionTarget = conversionTarget;
            req.Parameters["version"] = Version.DOCUMENT_CONVERSION;
            byte[] documentData = null;
            if (documentPath != default(string))
            {
                if (LoadFile != null)
                {
                    documentData = LoadFile(documentPath);
                }
                else
                {
#if !UNITY_WEBPLAYER
                    documentData = File.ReadAllBytes(documentPath);
#endif
                }
                if (documentData == null)
                    Log.Error("DocumentConversion", "Failed to upload {0}!", documentPath);
            }
            if (documentData != null)
            {
                req.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                req.Forms = new Dictionary<string, RESTConnector.Form>();
                req.Forms["file"] = new RESTConnector.Form(documentData);
                req.Forms["config"] = new RESTConnector.Form(conversionTarget.ToString());
            }
            return connector.Send(req);
        }
public bool ConvertDocument ( OnConvertDocument callback , string documentPath , string conversionTarget = ConversionTarget . ANSWER_UNITS , string data = null ) { if ( callback == null ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( documentPath ) ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( conversionTarget ) ) throw new ArgumentNullException ( " " ) ; RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , FUNCTION_CONVERT_DOCUMENT ) ; if ( connector == null ) return false ; ConvertDocumentRequest req = new ConvertDocumentRequest ( ) ; req . Callback = callback ; req . OnResponse = ConvertDocumentResponse ; req . Data = data ; req . ConversionTarget = conversionTarget ; req . Parameters [ " " ] = Version . DOCUMENT_CONVERSION ; byte [ ] documentData = null ; if ( documentPath != default ( string ) ) { if ( LoadFile != null ) { documentData = LoadFile ( documentPath ) ; } else { if ! UNITY_WEBPLAYER documentData = File . ReadAllBytes ( documentPath ) ; endif } if ( documentData == null ) Log . Error ( " " , " " , documentPath ) ; } if ( documentData != null ) { req . Headers [ " " ] = " " ; req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ; req . Forms [ " " ] = new RESTConnector . Form ( documentData ) ; req . Forms [ " " ] = new RESTConnector . Form ( conversionTarget . ToString ( ) ) ; } return connector . Send ( req ) ; }
Convert document to use in other Watson services.
Convert document to use in other Watson services .
None
callback
OnConvertDocument
None
documentPath
string
None
conversionTarget
string
None
data
string
None