Search in sources :

Example 11 with ConvertException

use of com.herewhite.sdk.domain.ConvertException in project whiteboard-android by netless-io.

the class ProjectorQuery method startProgressLoop.

private void startProgressLoop() {
    long timeLimit = startTime + timeout;
    try {
        status = ConverterStatus.Checking;
        while (System.currentTimeMillis() < timeLimit) {
            checkProgress();
            if (status != ConverterStatus.Checking) {
                return;
            }
            Thread.sleep(interval);
        }
        onFailure(new ConvertException(ConvertErrorCode.CheckTimeout));
        status = ConverterStatus.Timeout;
    } catch (ConvertException e) {
        onFailure(e);
        status = ConverterStatus.Fail;
    } catch (InterruptedException ignored) {
        onFailure(new ConvertException(ConvertErrorCode.ConvertFail));
        status = ConverterStatus.Fail;
    }
}
Also used : ConvertException(com.herewhite.sdk.domain.ConvertException)

Example 12 with ConvertException

use of com.herewhite.sdk.domain.ConvertException in project whiteboard-android by netless-io.

the class RoomActivity method staticConvert.

public void staticConvert(MenuItem item) {
    Converter c = new Converter(this.token);
    c.startConvertTask("https://white-cn-edge-doc-convert.oss-cn-hangzhou.aliyuncs.com/LightWaves.pdf", Converter.ConvertType.Static, new ConverterCallbacks() {

        @Override
        public void onFailure(ConvertException e) {
            logAction(e.getMessage());
        }

        @Override
        public void onFinish(ConvertedFiles ppt, ConversionInfo convertInfo) {
            mRoom.putScenes("/static", ppt.getScenes(), 0);
            mRoom.setScenePath("/static/1");
            logAction(convertInfo.toString());
        }

        @Override
        public void onProgress(Double progress, ConversionInfo convertInfo) {
            logAction(String.valueOf(progress));
        }
    });
    // ConvertV5
    ConverterV5.Builder builder = new ConverterV5.Builder();
    ConverterV5 converter = builder.setResource("https://white-cn-edge-doc-convert.oss-cn-hangzhou.aliyuncs.com/LightWaves.pdf").setType(ConvertType.Static).setScale(1.5).setOutputFormat(ImageFormat.JPEG).setSdkToken(demoAPI.getSdkToken()).setTaskUuid(null).setTaskToken(null).setCallback(new ConverterCallbacks() {

        @Override
        public void onProgress(Double progress, ConversionInfo convertInfo) {
        }

        @Override
        public void onFinish(ConvertedFiles ppt, ConversionInfo convertInfo) {
        }

        @Override
        public void onFailure(ConvertException e) {
        }
    }).build();
    converter.startConvertTask();
}
Also used : ConvertException(com.herewhite.sdk.domain.ConvertException) MapBuilder(com.herewhite.demo.utils.MapBuilder) Converter(com.herewhite.sdk.Converter) ConverterCallbacks(com.herewhite.sdk.ConverterCallbacks) ConvertedFiles(com.herewhite.sdk.domain.ConvertedFiles) ConversionInfo(com.herewhite.sdk.domain.ConversionInfo) ConverterV5(com.herewhite.sdk.converter.ConverterV5)

Example 13 with ConvertException

use of com.herewhite.sdk.domain.ConvertException in project whiteboard-android by netless-io.

the class Converter method polling.

private void polling(String taskId, ConvertType type, final ConvertCallback callbacks) {
    boolean canCheck = this.status == ConverterStatus.Timeout || this.status == ConverterStatus.CheckingFail || this.status == ConverterStatus.GetDynamicFail;
    if (this.status != ConverterStatus.Created && !canCheck) {
        return;
    }
    final Converter that = this;
    Date expireDate = new Date(this.beginDate.getTime() + this.timeout);
    while (converting && expireDate.after(new Date())) {
        final CountDownLatch latch = new CountDownLatch(1);
        that.status = ConverterStatus.Checking;
        checkProgress(taskId, type, new CheckCallback() {

            @Override
            public void onCheckResponse(ConversionInfo info) {
                ConversionInfo.ServerConversionStatus status = info.getConvertStatus();
                if (status == ConversionInfo.ServerConversionStatus.Fail || status == ConversionInfo.ServerConversionStatus.NotFound) {
                    converting = false;
                    that.status = ConverterStatus.Fail;
                    ConvertErrorCode code = status == ConversionInfo.ServerConversionStatus.Fail ? ConvertErrorCode.ConvertFail : ConvertErrorCode.NotFound;
                    ConvertException e = new ConvertException(code, info.getReason());
                    callbacks.onConvertFailure(e);
                } else if (status == ConversionInfo.ServerConversionStatus.Finished) {
                    // 成功时,可能还要额外获取动态 ppt 内容,不直接设置状态
                    converting = false;
                    callbacks.onConvertFinish(info);
                } else {
                    that.status = ConverterStatus.WaitingForNextCheck;
                    callbacks.onConvertProgress(info.getConvertedPercentage(), info);
                }
                try {
                    Thread.sleep(interval);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                latch.countDown();
            }

            @Override
            public void onCheckFailure(Exception e) {
                ConvertException exp = new ConvertException(ConvertErrorCode.CheckFail);
                callbacks.onConvertFailure(exp);
                converting = false;
                latch.countDown();
            }
        });
        try {
            latch.await();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (this.status == ConverterStatus.WaitingForNextCheck) {
        this.status = ConverterStatus.Timeout;
        ConvertException exp = new ConvertException(ConvertErrorCode.CheckTimeout);
        callbacks.onConvertFailure(exp);
    }
}
Also used : ConvertException(com.herewhite.sdk.domain.ConvertException) ConvertErrorCode(com.herewhite.sdk.domain.ConvertErrorCode) ConversionInfo(com.herewhite.sdk.domain.ConversionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date) IOException(java.io.IOException) ConvertException(com.herewhite.sdk.domain.ConvertException)

Aggregations

ConvertException (com.herewhite.sdk.domain.ConvertException)13 ConversionInfo (com.herewhite.sdk.domain.ConversionInfo)9 IOException (java.io.IOException)6 ConverterCallbacks (com.herewhite.sdk.ConverterCallbacks)5 ConvertedFiles (com.herewhite.sdk.domain.ConvertedFiles)5 Call (okhttp3.Call)5 Response (okhttp3.Response)5 Converter (com.herewhite.sdk.Converter)4 Request (okhttp3.Request)4 JsonObject (com.google.gson.JsonObject)3 MapBuilder (com.herewhite.demo.utils.MapBuilder)3 ConverterV5 (com.herewhite.sdk.converter.ConverterV5)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ConvertErrorCode (com.herewhite.sdk.domain.ConvertErrorCode)2 Date (java.util.Date)2 Callback (okhttp3.Callback)2 HashMap (java.util.HashMap)1 RequestBody (okhttp3.RequestBody)1