ติดตามความคืบหน้าการแปลงเอกสาร

ติดตามความคืบหน้าการแปลงเอกสาร

Aspose.Email มีฟีเจอร์เพื่อการติดตามความคืบหน้าการแปลงเอกสาร สำหรับสิ่งนี้ API มีให้ SaveOptions.CustomProgressHandler. ซึ่งเป็นเมธอดที่จัดการเหตุการณ์ความคืบหน้า ประเภทของเหตุการณ์ความคืบหน้าถูกแทนด้วย ProgressEventType enumeration. enumeration ProgressEventType มีสมาชิกต่อไปนี้.

  • MimeStructureCreated: เหตุการณ์นี้แจ้งว่าโครงสร้าง MIME ถูกสร้างขึ้น.
  • MimePartSaved: เหตุการณ์นี้แจ้งว่าการบันทึกส่วน MIME หนึ่งเสร็จสิ้น.
  • SavedToStream: เหตุการณ์นี้แจ้งว่าทุกส่วนของ MIME ถูกบันทึกลงสตรีมแล้ว.

โค้ดตัวอย่างต่อไปนี้แสดงการใช้ SaveOptions.CustomProgressHandler และ enumeration ProgressEventType เพื่อติดตามความคืบหน้าการแปลงเอกสาร.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
public static void main(String[] args) {
    // The path to the resource directory.
    String dataDir = "data/";

    MailMessage msg = MailMessage.load(dataDir + "test.eml");

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    EmlSaveOptions opt = new EmlSaveOptions(MailMessageSaveType.getEmlFormat());
    opt.setCustomProgressHandler(new ConversionProgressEventHandler() {
        public void invoke(ProgressEventHandlerInfo info) {
            showEmlConversionProgress(info);
        }
    });

    msg.save(bos, opt);
}

private static void showEmlConversionProgress(ProgressEventHandlerInfo info) {
    switch (info.getEventType()) {
        case ProgressEventType.MimeStructureCreated:
            System.out.println("MimeStructureCreated - TotalMimePartCount: " + info.getTotalMimePartCount());
            System.out.println("MimeStructureCreated - SavedMimePartCount: " + info.getSavedMimePartCount());
            break;
        case ProgressEventType.MimePartSaved:
            System.out.println("MimePartSaved - TotalMimePartCount: " + info.getTotalMimePartCount());
            System.out.println("MimePartSaved - SavedMimePartCount: " + info.getSavedMimePartCount());
            break;
        case ProgressEventType.SavedToStream:
            System.out.println("SavedToStream - TotalMimePartCount: " + info.getTotalMimePartCount());
            System.out.println("SavedToStream - SavedMimePartCount: " + info.getSavedMimePartCount());
            break;
    }
}