-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystemWatcher.apln
47 lines (42 loc) · 1.55 KB
/
FileSystemWatcher.apln
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
:Namespace FileSystemWatcher
(⎕IO ⎕ML)←1 1
∇ WatchEvent(obj args);nargs
⍝ Callback for System.IO.FileSystemWatcher instance
⍝ Passes info on to ⎕SE.Link.Notify for processing
{}2501⌶0 ⍝ kill thread on exit
nargs←⊂819⌶⍕args.ChangeType ⍝ type: created|changed|deleted|renamed
nargs,←⊂args.FullPath
:If 0≠⎕NC⊂'args.OldFullPath'
nargs,←⊂args.OldFullPath
:EndIf
{}⎕SE.Link.Notify nargs
∇
∇ r←Watch args;⎕USING;path;filter;watcher
⍝ args: path filter
⎕USING←',System.dll'
watcher←⎕NEW System.IO.FileSystemWatcher
watcher.(Path Filter)←args
watcher.(onChanged onCreated onDeleted onRenamed)←⊂'WatchEvent'
watcher.IncludeSubdirectories←1
watcher.EnableRaisingEvents←1
r←⎕NEW Disposable watcher ⍝ wrap a destructor around it
∇
:Class Disposable
:Field Public Object
∇ make ref
:Access Public
:Implements Constructor
Object←ref
∇
∇ do_dispose ref
:Trap 0
ref.Dispose
:EndTrap
∇
∇ dispose;tid
:Implements Destructor
Object.EnableRaisingEvents←0
tid←do_dispose&Object
∇
:EndClass
:EndNamespace