-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathadvanced-features.st
More file actions
177 lines (138 loc) · 4.59 KB
/
advanced-features.st
File metadata and controls
177 lines (138 loc) · 4.59 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"============================================
Advanced Features Example
Demonstrates advanced bridge features like
custom command handlers and caching
============================================"
| bridge command result handler |
"Get the shared bridge instance"
bridge := GSScriptingStepTalkBridge sharedBridge.
Transcript show: 'Advanced Bridge Features'; cr.
Transcript show: '======================='; cr; cr.
"Example 1: Custom command handler"
Transcript show: 'Example 1: Custom Command Handler'; cr.
"Create a block that handles custom commands"
handler := [:cmd |
Transcript show: 'Custom handler invoked for command: ',
cmd asString; cr.
'Custom result from StepTalk'.
].
"Register the handler"
bridge
registerCommandHandler: handler
forCommand: 'myCustomCommand'
inSuite: 'CustomSuite'.
Transcript show: 'Registered custom command handler'; cr; cr.
"Example 2: Multiple specifier types"
Transcript show: 'Example 2: Using Multiple Specifier Types'; cr.
"Middle specifier"
| middleSpec |
middleSpec := bridge
createSpecifier: 'middle'
inContainer: nil
forKey: 'documents'
withValue: nil.
Transcript show: 'Created middle specifier'; cr.
"Random specifier"
| randomSpec |
randomSpec := bridge
createSpecifier: 'random'
inContainer: nil
forKey: 'documents'
withValue: nil.
Transcript show: 'Created random specifier'; cr; cr.
"Example 3: Relative specifiers"
Transcript show: 'Example 3: Relative Specifiers'; cr.
| baseSpec relativeSpec |
baseSpec := bridge
createSpecifier: 'name'
inContainer: nil
forKey: 'documents'
withValue: 'MyDocument'.
relativeSpec := bridge
createSpecifier: 'relative'
inContainer: nil
forKey: 'documents'
withValue: (Dictionary new
at: 'base' put: baseSpec;
at: 'position' put: 'after';
yourself).
Transcript show: 'Created relative specifier (document after MyDocument)'; cr; cr.
"Example 4: UniqueID specifier"
Transcript show: 'Example 4: UniqueID Specifier'; cr.
| uidSpec |
uidSpec := bridge
createSpecifier: 'uniqueID'
inContainer: nil
forKey: 'documents'
withValue: 'DOC-12345'.
Transcript show: 'Created uniqueID specifier'; cr; cr.
"Example 5: Complex command with multiple arguments"
Transcript show: 'Example 5: Complex Command Arguments'; cr.
| locationSpec |
locationSpec := bridge
createSpecifier: 'position'
inContainer: nil
forKey: 'documents'
withValue: 'end'.
properties := Dictionary new
at: 'name' put: 'NewDocument';
at: 'modified' put: false;
at: 'visible' put: true;
yourself.
result := bridge
executeCommand: 'create'
forSuite: 'CoreSuite'
withArguments: (Dictionary new
at: 'ObjectClass' put: 'document';
at: 'Location' put: locationSpec;
at: 'WithProperties' put: properties;
yourself).
Transcript show: 'Created document with complex arguments'; cr; cr.
"Example 6: Batch operations"
Transcript show: 'Example 6: Batch Operations'; cr.
| docs |
docs := Array new: 5.
1 to: 5 do: [:i |
| docName |
docName := 'Document', i asString.
docs at: i put: (bridge
createObject: 'document'
atLocation: nil
withProperties: (Dictionary new
at: 'name' put: docName;
yourself)).
Transcript show: 'Created ', docName; cr.
].
Transcript show: 'Created 5 documents in batch'; cr; cr.
"Example 7: Query and filter"
Transcript show: 'Example 7: Querying Objects'; cr.
count := bridge countObjects: 'document' inContainer: nil.
Transcript show: 'Total documents: ', count asString; cr.
"Get all documents (this would need a whose specifier in real use)"
Transcript show: 'To filter, use NSWhoseSpecifier in production'; cr; cr.
"Example 8: Clear cache"
Transcript show: 'Example 8: Cache Management'; cr.
bridge clearCache.
Transcript show: 'Cleared bridge cache'; cr; cr.
"Example 9: Error handling patterns"
Transcript show: 'Example 9: Robust Error Handling'; cr.
[
command := bridge
createCommand: 'get'
forSuite: 'CoreSuite'
withArguments: nil.
result := command executeCommand.
(command scriptErrorNumber = 0)
ifTrue: [
Transcript show: 'Success: ', result asString; cr.
]
ifFalse: [
Transcript show: 'Error ',
command scriptErrorNumber asString,
': ',
command scriptErrorString; cr.
].
] on: Error do: [:ex |
Transcript show: 'Exception caught: ', ex messageText; cr.
].
Transcript cr; show: 'Advanced examples complete!'; cr.