@@ -152,27 +152,203 @@ command:
152
152
```
153
153
msbuild /t:clean Coherence.msbuild
154
154
```
155
- The
155
+
156
156
# <a name =" started " ></a >CLI Hello Coherence Example
157
- Note: You can skipt this section for now till the Hello Coherence console example is available.
158
- ## Build the example
159
- The Hello Coherence example is in the examples\Hello directory.
157
+ The following example illustrates starting a storage enabled Coherence server, followed by running the HelloCoherence console application. The HelloCoherence application inserts and retrieves data from the Coherence server.
158
+
159
+ ## Build HelloCoherence
160
+ 1 . Using dotnet-cli to create a HelloCoherence console application:
161
+ ```
162
+ dotnet new console -name "HelloCoherence"
163
+ ```
164
+ 1 . Add the following references to the HelloCoherence.csproj (provide the Coherence.Core.dll location in the ` <HintPath> ` ):
165
+ ```
166
+ <ItemGroup>
167
+ <Reference Include="Coherence.Core, Version=14.1.1.4, Culture=neutral, PublicKeyToken=0ada89708fdf1f9a, processorArchitecture=MSIL">
168
+ <HintPath>Coherence.Core.dll</HintPath>
169
+ </Reference>
170
+ <PackageReference Include="Common.Logging" Version="3.4.1" />
171
+ <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
172
+ </ItemGroup>
173
+ ```
174
+ Also include any Coherence configuration files you may have.
175
+
176
+ 1 . Replace Program.cs code with the following source:
177
+ ```
178
+ /*
179
+ * Copyright (c) 2000, 2022, Oracle and/or its affiliates.
180
+ *
181
+ * Licensed under the Universal Permissive License v 1.0 as shown at
182
+ * http://oss.oracle.com/licenses/upl.
183
+ */
184
+ using System;
185
+ using Tangosol.Net;
186
+ using Tangosol.Net.Cache;
187
+ using Tangosol.Run.Xml;
188
+ namespace Hello
189
+ {
190
+ class Program
191
+ {
192
+ static void Main(string[] args)
193
+ {
194
+ // Display title as the C# console Coherence app and
195
+ // show user the valid commands:
196
+ Console.WriteLine("Coherence for .NET Extend Client");
197
+ Console.WriteLine("The following are the available cache operations:");
198
+ Console.WriteLine("\tcache <cacheName> - specify a cache name to use");
199
+ Console.WriteLine("\tput <key> <value> - put a <key, value> pair into the cache");
200
+ Console.WriteLine("\tget <key> - get the value of a given key from the cache");
201
+ Console.WriteLine("\tremove <key> - remove an entry of the given key from the cache");
202
+ Console.WriteLine("\tlist - list all the entries in the cache");
203
+ Console.WriteLine("\tsize - get the size of the cache");
204
+ Console.WriteLine("\tbye - exit the console");
205
+ Console.WriteLine();
206
+ Console.Write("Map (?): ");
207
+
208
+ // Declare variabs.
209
+ String cacheName = null;
210
+ INamedCache namedCache = null;
211
+ String op = Console.ReadLine().ToLower();
212
+ String[] opList = op.Split();
213
+
214
+ // Processing cache operations.
215
+ while (opList[0].CompareTo("bye") != 0)
216
+ {
217
+ String key;
218
+ String value;
219
+
220
+ if (!opList[0].Equals("cache") && namedCache == null)
221
+ {
222
+ Console.WriteLine("No named cache. Please specify a named cache to use.");
223
+ }
224
+ else
225
+ {
226
+ switch (opList[0])
227
+ {
228
+ case "cache":
229
+ if (opList.Length < 2)
230
+ {
231
+ Console.WriteLine("No cache name. Please specify a cache name to use.");
232
+ }
233
+ else
234
+ {
235
+ cacheName = opList[1];
236
+ namedCache = CacheFactory.GetCache(cacheName);
237
+ }
238
+ break;
239
+
240
+ case "put":
241
+ if (opList.Length < 3)
242
+ {
243
+ Console.WriteLine("No key/value pair. Please specify the key and value to be put into the cache.");
244
+ }
245
+ else
246
+ {
247
+ key = opList[1];
248
+ value = opList[2];
249
+ namedCache[key] = value;
250
+ }
251
+ break;
252
+
253
+ case "get":
254
+ if (opList.Length < 2)
255
+ {
256
+ Console.WriteLine("No key. Please specify the key to get.");
257
+ }
258
+ else
259
+ {
260
+ key = opList[1];
261
+ var result = namedCache[key];
262
+ Console.WriteLine(result == null ? "NULL" : namedCache[key]);
263
+ }
264
+ break;
265
+
266
+ case "remove":
267
+ if (opList.Length < 2)
268
+ {
269
+ Console.WriteLine("No key. Please specify the key to remove.");
270
+ }
271
+ else
272
+ {
273
+ key = opList[1];
274
+ namedCache.Remove(key);
275
+ }
276
+ break;
277
+
278
+ case "list":
279
+ foreach (ICacheEntry entry in namedCache.Entries)
280
+ {
281
+ Console.WriteLine(entry.Key + " = " + entry.Value);
282
+ }
283
+ break;
284
+
285
+ case "size":
286
+ Console.WriteLine(namedCache.Count);
287
+ break;
288
+
289
+ default:
290
+ Console.WriteLine("Valid operations are: cache, put, get, remove, list, size, and bye.");
291
+ break;
292
+ }
293
+ }
294
+
295
+ Console.WriteLine("");
296
+ if (namedCache == null)
297
+ {
298
+ Console.Write("Map (?): ");
299
+ }
300
+ else
301
+ {
302
+ Console.Write("Map (" + cacheName + "): ");
303
+ }
304
+
305
+ // Read cache operation
306
+ op = Console.ReadLine().ToLower();
307
+ opList = op.Split();
308
+ }
309
+ }
310
+ }
311
+ }
312
+ ```
313
+
314
+ By default, you need to provide a POF configure file, pof-config.xml, in the TargetFramework directory. Below are a sample pof-config.xml file:
315
+
316
+ ```
317
+ <?xml version="1.0"?>
318
+ <!--
319
+ Copyright (c) 2000, 2020, Oracle and/or its affiliates.
320
+
321
+ Licensed under the Universal Permissive License v 1.0 as shown at
322
+ http://oss.oracle.com/licenses/upl.
323
+ -->
324
+ <pof-config xmlns="http://schemas.tangosol.com/pof">
325
+ <user-type-list>
326
+ <!-- include all "standard" Coherence POF user types -->
327
+ <include>assembly://Coherence.Core/Tangosol.Config/coherence-pof-config.xml</include>
328
+
329
+ <!-- include all application POF user types -->
330
+ </user-type-list>
331
+ </pof-config>
160
332
```
161
- cd examples\Hello
162
- msbuild /t:clean /t:build
333
+
334
+ 4 . Build the HelloCoherence project
335
+ ```
336
+ dotnet build
163
337
```
164
338
165
339
## Start a Coherence server
166
340
167
341
```
168
- "%JAVA_HOME%\bin\java" -Dcoherence.pof.enabled=true -Dcoherence.cacheconfig=Resources\server-cache-config.xml -jar coherence.jar
342
+ "%JAVA_HOME%\bin\java" -Dcoherence.pof.enabled=true -Dcoherence.log.level=9 -jar coherence.jar
169
343
```
170
344
171
345
## Run the Hello Coherence example
172
346
173
347
``` shell script
174
- cd examples\H ello\H ello\b in\D ebug
175
- Hello.exe
348
+ dotnet run
349
+ ```
350
+
351
+ ```
176
352
Coherence for .NET Extend Client
177
353
The following are the available cache operations:
178
354
cache <cacheName> - specify a cache name to use
@@ -203,8 +379,13 @@ english = Hello
203
379
spanish = Hola
204
380
205
381
Map (welcomes): bye
382
+ ```
206
383
207
- Hello.exe
384
+ ```
385
+ dotnet run
386
+ ```
387
+
388
+ ```
208
389
Coherence for .NET Extend Client
209
390
The following are the available cache operations:
210
391
cache <cacheName> - specify a cache name to use
0 commit comments