Das Notes Forum

Domino 9 und frühere Versionen => ND6: Entwicklung => Thema gestartet von: TMC am 30.01.05 - 12:32:41

Titel: Lotus Script - Ausführung durch User abbrechen lassen
Beitrag von: TMC am 30.01.05 - 12:32:41
Hi,

wenn eine Script-Ausführung sehr lange braucht (u.U. mehrere Minuten), würde ich gerne den User abbrechen lassen können, und dann einen "Roll-Back" ausführen.

Beispiel: XML-Export von mehreren Dokumenten, die sehr groß sind.
Kann jeder auch mal selber probieren: Mal eine 20 MB große PDF-Datei im Designer in eine Maske attachen. Dann Maske speichern und Menü: DXL Utilities.. / Exporter.
Das kann dauern........

Schön wäre eben eine Msgbox oder sowas, die im Vordergrund erscheint, während das Script läuft. Drückt der User auf Abbrechen, dann führt man eben einen Roll-Back aus (z.B. nicht vollständig erstellte Dateien wieder entfernen).

Hat da wer von Euch einen Tipp? Hmm, vielleicht über NotesAPI?


Danke,
Matthias
Titel: Re: Lotus Script - Ausführung durch User abbrechen lassen
Beitrag von: animate am 30.01.05 - 13:14:14
vielleicht hilft dir diese Diskussion (http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/00b01c0239d66fa485256f3d00051405?OpenDocument) weiter. Insbesondere diese Antowrt (http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/00b01c0239d66fa485256f3d00051405?OpenDocument) samt Download-Link.

Oder aber auch eine Option, die die Benutzerin wählen lässt, ob sie Attachments exportieren möchte oder nicht.
Titel: Re: Lotus Script - Ausführung durch User abbrechen lassen
Beitrag von: TMC am 30.01.05 - 14:23:51
Ah, danke Thomas, das klingt gut:

Zitat
FileGuard - Use Delete method to handle aborts

Whenever you declare a class, you can define a Delete method that executes on an object of that class when it's deallocated.  This happens whenever the memory is freed, whether it's because the object has gone out of scope from the function it was declared in, or because the script aborted with an error, or by Ctrl+Break, for whatever other reason.
For instance, the simple class below is useful when writing to files to make sure that you don't leave a file open if the user aborts.  This class provides a method of obtaining a file handle that provides insurance that the script can't abort and leave the file open.  To use it, you could have code like this:
Dim FG1 As New FileGuard
outfile% = FG1.Handle
Open "C:\TEMP\DUMP.TXT" For Output As outfile%
Dim FG2 As New FileGuard
infile% = FG2.Handle
Open "\\RAGAMUFFIN\ARGH\NASTY.DAT" For Input As infile%
...
If the user aborts while the files are still open, Notes will automatically deallocate the storage of the FG1 and FG2 objects, but since those objects are of a class that has a Delete method, it will first execute that method on each of them, which closes the file whose file number they have stored in their data properties.
Note: you must open a file using the returned file handle from the Handle method, before you allocate another instance of FileGuard, or else they will get the same file number. Since Freefile returns the number of the first file handle that's not yet in use, calling it twice without using the result of the first call to open a file, returns the same value again.
The Terminate event of a script can also be used for this kind of cleanup, but that requires that all the variables be declared globally. The object-oriented technique lets you localize the cleanup code to the place to the subroutine that works with the file.The code:
Class FileGuard
     filenumber As Integer
     isopen As Integer
     
     Public Property Get Handle
          Handle = filenumber
     End Property
     
     Sub New()
          filenumber = Freefile( )
          isopen = True
     End Sub
     
     Sub Close
          If isopen Then
               On Error Resume Next
               Close filenumber
               isopen = False
          End If
     End Sub
     
     Sub Delete
          Me.Close
     End Sub
End Class



Oder aber auch eine Option, die die Benutzerin wählen lässt, ob sie Attachments exportieren möchte oder nicht.

Hmm, hier speziell (NotesDXLExporter.Export(doc)) müsste ich dann aber wohl mit dem SAX-Parser arbeiten oder? Ich habe jetzt nicht gesehen, dass ich dem NotesDXLExporter eine Property mitgeben kann, um Attachments nicht zu berücksichtigen. Die könnte man zwar dann danach rauswerfen, aber was auch sehr lange dauert, ist z.B. nur das Auslesen in eines Docs via DXLExporter in ein String.
Titel: Re: Lotus Script - Ausführung durch User abbrechen lassen
Beitrag von: TMC am 30.01.05 - 14:46:19
Oder aber auch eine Option, die die Benutzerin wählen lässt, ob sie Attachments exportieren möchte oder nicht.

Hmm, hier speziell (NotesDXLExporter.Export(doc)) müsste ich dann aber wohl mit dem SAX-Parser arbeiten oder? Ich habe jetzt nicht gesehen, dass ich dem NotesDXLExporter eine Property mitgeben kann, um Attachments nicht zu berücksichtigen. Die könnte man zwar dann danach rauswerfen, aber was auch sehr lange dauert, ist z.B. nur das Auslesen in eines Docs via DXLExporter in ein String.

Nein, geht einfacher  ;D
Einfach vom NotesDocument(doc) alle Attachments rauswerfen (Call NotesEmbeddedObject.Remove), bevor man den Export startet, dann geht's rasend schnell trotz 20 MB Attachment.