This is an automated email from the ASF dual-hosted git repository.

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3893a26  GEODE-6211: Add dotnet transaction example (#438)
3893a26 is described below

commit 3893a260e7db82ebcdc13ccea2c5a0ca86d73784
Author: Blake Bender <[email protected]>
AuthorDate: Tue Feb 19 13:41:23 2019 -0800

    GEODE-6211: Add dotnet transaction example (#438)
    
    - GEODE-6211: Rename dotnet example directories to match cpp example dirs
    - Prefix example project names with 'dotnet-' or 'cpp-' to differentiate 
for Windows
    
    Co-authored-by: Michael Oleske <[email protected]>
    Co-authored-by: Jacob Barrett <[email protected]>
---
 examples/cpp/CMakeLists.txt.cpp_example.in         |  2 +-
 examples/dotnet/CMakeLists.txt                     |  3 +
 examples/dotnet/CMakeLists.txt.dotnet_example.in   |  2 +-
 examples/dotnet/CMakeLists.txt.in                  |  1 +
 .../ExampleAuthInitialize.cs                       |  0
 .../{AuthInitialize => authiniialize}/Program.cs   |  0
 .../{AuthInitialize => authiniialize}/README.md    |  0
 .../startserver.ps1                                |  0
 .../stopserver.ps1                                 |  0
 .../MyCqListener.cs                                |  0
 .../Order.cs                                       |  0
 .../Program.cs                                     |  0
 .../README.md                                      |  0
 .../startserver.ps1                                |  0
 .../stopserver.ps1                                 |  0
 .../Order.cs                                       |  0
 .../Program.cs                                     |  0
 .../README.md                                      |  0
 .../startserver.ps1                                |  0
 .../stopserver.ps1                                 |  0
 .../Order.cs                                       |  0
 .../Program.cs                                     |  0
 .../README.md                                      |  0
 .../startserver.ps1                                |  0
 .../stopserver.ps1                                 |  0
 .../Order.cs                                       |  0
 .../Program.cs                                     |  0
 .../README.md                                      |  0
 .../startserver.ps1                                |  0
 .../stopserver.ps1                                 |  0
 .../{PutGetRemove => put-get-remove}/Program.cs    |  0
 .../{PutGetRemove => put-get-remove}/README.md     |  0
 .../startserver.ps1                                |  0
 .../stopserver.ps1                                 |  0
 .../{RemoteQueryCs => remotequery}/CMakeLists.txt  |  0
 .../dotnet/{RemoteQueryCs => remotequery}/Order.cs |  0
 .../{RemoteQueryCs => remotequery}/Program.cs      |  0
 .../{RemoteQueryCs => remotequery}/README.md       |  0
 .../{RemoteQueryCs => remotequery}/startserver.ps1 |  0
 .../{RemoteQueryCs => remotequery}/stopserver.ps1  |  0
 examples/dotnet/transaction/Program.cs             | 90 ++++++++++++++++++++++
 examples/dotnet/transaction/README.md              | 59 ++++++++++++++
 .../{RemoteQueryCs => transaction}/startserver.ps1 |  2 +-
 .../{RemoteQueryCs => transaction}/stopserver.ps1  |  2 +-
 44 files changed, 157 insertions(+), 4 deletions(-)

diff --git a/examples/cpp/CMakeLists.txt.cpp_example.in 
b/examples/cpp/CMakeLists.txt.cpp_example.in
index 0e90284..2f251ab 100644
--- a/examples/cpp/CMakeLists.txt.cpp_example.in
+++ b/examples/cpp/CMakeLists.txt.cpp_example.in
@@ -15,7 +15,7 @@
 
 cmake_minimum_required(VERSION 3.5)
 
-project(@ADD_EXAMPLE_NAME@ LANGUAGES CXX)
+project(cpp-@ADD_EXAMPLE_NAME@ LANGUAGES CXX)
 
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake)
 set(CMAKE_CXX_STANDARD 11)
diff --git a/examples/dotnet/CMakeLists.txt b/examples/dotnet/CMakeLists.txt
index aeedcb7..14dc8fb 100644
--- a/examples/dotnet/CMakeLists.txt
+++ b/examples/dotnet/CMakeLists.txt
@@ -69,3 +69,6 @@ add_example(NAME PutGetRemove
 
 add_example(NAME RemoteQueryCs 
        SOURCE Order.cs Program.cs)
+
+add_example(NAME TransactionCs
+       SOURCE Program.cs)
diff --git a/examples/dotnet/CMakeLists.txt.dotnet_example.in 
b/examples/dotnet/CMakeLists.txt.dotnet_example.in
index cabc6aa..82ab10c 100644
--- a/examples/dotnet/CMakeLists.txt.dotnet_example.in
+++ b/examples/dotnet/CMakeLists.txt.dotnet_example.in
@@ -15,7 +15,7 @@
 
 cmake_minimum_required(VERSION 3.10)
 
-project(@ADD_EXAMPLE_NAME@ LANGUAGES CSharp)
+project(dotnet-@ADD_EXAMPLE_NAME@ LANGUAGES CSharp)
 
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake)
 
diff --git a/examples/dotnet/CMakeLists.txt.in 
b/examples/dotnet/CMakeLists.txt.in
index 2257e75..2e5b88a 100644
--- a/examples/dotnet/CMakeLists.txt.in
+++ b/examples/dotnet/CMakeLists.txt.in
@@ -25,4 +25,5 @@ add_subdirectory(PdxAutoSerializer)
 add_subdirectory(PdxSerializableCs)
 add_subdirectory(PutGetRemove)
 add_subdirectory(RemoteQueryCs)
+add_subdirectory(TransactionCs)
 
diff --git a/examples/dotnet/AuthInitialize/ExampleAuthInitialize.cs 
b/examples/dotnet/authiniialize/ExampleAuthInitialize.cs
similarity index 100%
rename from examples/dotnet/AuthInitialize/ExampleAuthInitialize.cs
rename to examples/dotnet/authiniialize/ExampleAuthInitialize.cs
diff --git a/examples/dotnet/AuthInitialize/Program.cs 
b/examples/dotnet/authiniialize/Program.cs
similarity index 100%
rename from examples/dotnet/AuthInitialize/Program.cs
rename to examples/dotnet/authiniialize/Program.cs
diff --git a/examples/dotnet/AuthInitialize/README.md 
b/examples/dotnet/authiniialize/README.md
similarity index 100%
rename from examples/dotnet/AuthInitialize/README.md
rename to examples/dotnet/authiniialize/README.md
diff --git a/examples/dotnet/AuthInitialize/startserver.ps1 
b/examples/dotnet/authiniialize/startserver.ps1
similarity index 100%
rename from examples/dotnet/AuthInitialize/startserver.ps1
rename to examples/dotnet/authiniialize/startserver.ps1
diff --git a/examples/dotnet/AuthInitialize/stopserver.ps1 
b/examples/dotnet/authiniialize/stopserver.ps1
similarity index 100%
rename from examples/dotnet/AuthInitialize/stopserver.ps1
rename to examples/dotnet/authiniialize/stopserver.ps1
diff --git a/examples/dotnet/ContinuousQueryCs/MyCqListener.cs 
b/examples/dotnet/continuousquery/MyCqListener.cs
similarity index 100%
rename from examples/dotnet/ContinuousQueryCs/MyCqListener.cs
rename to examples/dotnet/continuousquery/MyCqListener.cs
diff --git a/examples/dotnet/ContinuousQueryCs/Order.cs 
b/examples/dotnet/continuousquery/Order.cs
similarity index 100%
rename from examples/dotnet/ContinuousQueryCs/Order.cs
rename to examples/dotnet/continuousquery/Order.cs
diff --git a/examples/dotnet/ContinuousQueryCs/Program.cs 
b/examples/dotnet/continuousquery/Program.cs
similarity index 100%
rename from examples/dotnet/ContinuousQueryCs/Program.cs
rename to examples/dotnet/continuousquery/Program.cs
diff --git a/examples/dotnet/ContinuousQueryCs/README.md 
b/examples/dotnet/continuousquery/README.md
similarity index 100%
rename from examples/dotnet/ContinuousQueryCs/README.md
rename to examples/dotnet/continuousquery/README.md
diff --git a/examples/dotnet/PdxSerializableCs/startserver.ps1 
b/examples/dotnet/continuousquery/startserver.ps1
similarity index 100%
rename from examples/dotnet/PdxSerializableCs/startserver.ps1
rename to examples/dotnet/continuousquery/startserver.ps1
diff --git a/examples/dotnet/PdxSerializableCs/stopserver.ps1 
b/examples/dotnet/continuousquery/stopserver.ps1
similarity index 100%
rename from examples/dotnet/PdxSerializableCs/stopserver.ps1
rename to examples/dotnet/continuousquery/stopserver.ps1
diff --git a/examples/dotnet/DataSerializableCs/Order.cs 
b/examples/dotnet/dataserializable/Order.cs
similarity index 100%
rename from examples/dotnet/DataSerializableCs/Order.cs
rename to examples/dotnet/dataserializable/Order.cs
diff --git a/examples/dotnet/DataSerializableCs/Program.cs 
b/examples/dotnet/dataserializable/Program.cs
similarity index 100%
rename from examples/dotnet/DataSerializableCs/Program.cs
rename to examples/dotnet/dataserializable/Program.cs
diff --git a/examples/dotnet/DataSerializableCs/README.md 
b/examples/dotnet/dataserializable/README.md
similarity index 100%
rename from examples/dotnet/DataSerializableCs/README.md
rename to examples/dotnet/dataserializable/README.md
diff --git a/examples/dotnet/PdxAutoSerializer/startserver.ps1 
b/examples/dotnet/dataserializable/startserver.ps1
similarity index 100%
rename from examples/dotnet/PdxAutoSerializer/startserver.ps1
rename to examples/dotnet/dataserializable/startserver.ps1
diff --git a/examples/dotnet/PdxAutoSerializer/stopserver.ps1 
b/examples/dotnet/dataserializable/stopserver.ps1
similarity index 100%
rename from examples/dotnet/PdxAutoSerializer/stopserver.ps1
rename to examples/dotnet/dataserializable/stopserver.ps1
diff --git a/examples/dotnet/PdxAutoSerializer/Order.cs 
b/examples/dotnet/pdxautoserializable/Order.cs
similarity index 100%
rename from examples/dotnet/PdxAutoSerializer/Order.cs
rename to examples/dotnet/pdxautoserializable/Order.cs
diff --git a/examples/dotnet/PdxAutoSerializer/Program.cs 
b/examples/dotnet/pdxautoserializable/Program.cs
similarity index 100%
rename from examples/dotnet/PdxAutoSerializer/Program.cs
rename to examples/dotnet/pdxautoserializable/Program.cs
diff --git a/examples/dotnet/PdxAutoSerializer/README.md 
b/examples/dotnet/pdxautoserializable/README.md
similarity index 100%
rename from examples/dotnet/PdxAutoSerializer/README.md
rename to examples/dotnet/pdxautoserializable/README.md
diff --git a/examples/dotnet/DataSerializableCs/startserver.ps1 
b/examples/dotnet/pdxautoserializable/startserver.ps1
similarity index 100%
rename from examples/dotnet/DataSerializableCs/startserver.ps1
rename to examples/dotnet/pdxautoserializable/startserver.ps1
diff --git a/examples/dotnet/DataSerializableCs/stopserver.ps1 
b/examples/dotnet/pdxautoserializable/stopserver.ps1
similarity index 100%
rename from examples/dotnet/DataSerializableCs/stopserver.ps1
rename to examples/dotnet/pdxautoserializable/stopserver.ps1
diff --git a/examples/dotnet/PdxSerializableCs/Order.cs 
b/examples/dotnet/pdxserializable/Order.cs
similarity index 100%
rename from examples/dotnet/PdxSerializableCs/Order.cs
rename to examples/dotnet/pdxserializable/Order.cs
diff --git a/examples/dotnet/PdxSerializableCs/Program.cs 
b/examples/dotnet/pdxserializable/Program.cs
similarity index 100%
rename from examples/dotnet/PdxSerializableCs/Program.cs
rename to examples/dotnet/pdxserializable/Program.cs
diff --git a/examples/dotnet/PdxSerializableCs/README.md 
b/examples/dotnet/pdxserializable/README.md
similarity index 100%
rename from examples/dotnet/PdxSerializableCs/README.md
rename to examples/dotnet/pdxserializable/README.md
diff --git a/examples/dotnet/ContinuousQueryCs/startserver.ps1 
b/examples/dotnet/pdxserializable/startserver.ps1
similarity index 100%
rename from examples/dotnet/ContinuousQueryCs/startserver.ps1
rename to examples/dotnet/pdxserializable/startserver.ps1
diff --git a/examples/dotnet/ContinuousQueryCs/stopserver.ps1 
b/examples/dotnet/pdxserializable/stopserver.ps1
similarity index 100%
rename from examples/dotnet/ContinuousQueryCs/stopserver.ps1
rename to examples/dotnet/pdxserializable/stopserver.ps1
diff --git a/examples/dotnet/PutGetRemove/Program.cs 
b/examples/dotnet/put-get-remove/Program.cs
similarity index 100%
rename from examples/dotnet/PutGetRemove/Program.cs
rename to examples/dotnet/put-get-remove/Program.cs
diff --git a/examples/dotnet/PutGetRemove/README.md 
b/examples/dotnet/put-get-remove/README.md
similarity index 100%
rename from examples/dotnet/PutGetRemove/README.md
rename to examples/dotnet/put-get-remove/README.md
diff --git a/examples/dotnet/PutGetRemove/startserver.ps1 
b/examples/dotnet/put-get-remove/startserver.ps1
similarity index 100%
rename from examples/dotnet/PutGetRemove/startserver.ps1
rename to examples/dotnet/put-get-remove/startserver.ps1
diff --git a/examples/dotnet/PutGetRemove/stopserver.ps1 
b/examples/dotnet/put-get-remove/stopserver.ps1
similarity index 100%
rename from examples/dotnet/PutGetRemove/stopserver.ps1
rename to examples/dotnet/put-get-remove/stopserver.ps1
diff --git a/examples/dotnet/RemoteQueryCs/CMakeLists.txt 
b/examples/dotnet/remotequery/CMakeLists.txt
similarity index 100%
rename from examples/dotnet/RemoteQueryCs/CMakeLists.txt
rename to examples/dotnet/remotequery/CMakeLists.txt
diff --git a/examples/dotnet/RemoteQueryCs/Order.cs 
b/examples/dotnet/remotequery/Order.cs
similarity index 100%
rename from examples/dotnet/RemoteQueryCs/Order.cs
rename to examples/dotnet/remotequery/Order.cs
diff --git a/examples/dotnet/RemoteQueryCs/Program.cs 
b/examples/dotnet/remotequery/Program.cs
similarity index 100%
rename from examples/dotnet/RemoteQueryCs/Program.cs
rename to examples/dotnet/remotequery/Program.cs
diff --git a/examples/dotnet/RemoteQueryCs/README.md 
b/examples/dotnet/remotequery/README.md
similarity index 100%
rename from examples/dotnet/RemoteQueryCs/README.md
rename to examples/dotnet/remotequery/README.md
diff --git a/examples/dotnet/RemoteQueryCs/startserver.ps1 
b/examples/dotnet/remotequery/startserver.ps1
similarity index 100%
copy from examples/dotnet/RemoteQueryCs/startserver.ps1
copy to examples/dotnet/remotequery/startserver.ps1
diff --git a/examples/dotnet/RemoteQueryCs/stopserver.ps1 
b/examples/dotnet/remotequery/stopserver.ps1
similarity index 100%
copy from examples/dotnet/RemoteQueryCs/stopserver.ps1
copy to examples/dotnet/remotequery/stopserver.ps1
diff --git a/examples/dotnet/transaction/Program.cs 
b/examples/dotnet/transaction/Program.cs
new file mode 100644
index 0000000..b8ccdf4
--- /dev/null
+++ b/examples/dotnet/transaction/Program.cs
@@ -0,0 +1,90 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using Apache.Geode.Client;
+
+namespace Apache.Geode.Examples.Transaction
+{
+  class Program
+  {
+    private static readonly List<string> keys = new List<string> {
+      "Key1",
+      "Key2",
+      "Key3",
+      "Key4",
+      "Key5",
+      "Key6",
+      "Key7",
+      "Key8",
+      "Key9",
+      "Key10"
+    };
+
+    private static readonly Random getRandom = new Random();
+
+    private static int getValueFromExternalSystem() {
+      var value = getRandom.Next(20);
+      if (value == 0)
+      {
+        throw new Exception("failed to get from external system");
+      }
+      return value;
+    }
+
+    static void Main(string[] args)
+    {
+      var cache = new CacheFactory()
+          .Set("log-level", "none").Create();
+
+      var poolFactory = cache.GetPoolFactory()
+          .AddLocator("localhost", 10334);
+      
+      Console.WriteLine("Created cache");
+
+      poolFactory.Create("pool");
+
+      var regionFactory = cache.CreateRegionFactory(RegionShortcut.PROXY)
+          .SetPoolName("pool");
+      var region = regionFactory.Create<string, int>("exampleRegion");
+
+      Console.WriteLine("Created region 'exampleRegion'");
+
+      var retries = 5;
+      while(retries-- > 0)
+      {
+        try 
+        {
+          cache.CacheTransactionManager.Begin();
+          foreach(var key in keys)
+          {
+            var value = getValueFromExternalSystem();
+            region.Put(key, value);
+          }
+          cache.CacheTransactionManager.Commit();
+          Console.WriteLine("Committed transaction - exiting");
+          break;
+        } catch
+        {
+          cache.CacheTransactionManager.Rollback();
+          Console.WriteLine("Rolled back transaction - retrying({0})", 
retries);
+        }
+      }
+    }
+  }
+}
diff --git a/examples/dotnet/transaction/README.md 
b/examples/dotnet/transaction/README.md
new file mode 100644
index 0000000..682f1dc
--- /dev/null
+++ b/examples/dotnet/transaction/README.md
@@ -0,0 +1,59 @@
+# Transaction example
+This is a very simple example showing how to use TransactionManager.  This 
example shows
+how to begin a transaction, commit a transaction, and rollback a transaction 
while showing
+exception handling.  We commit two keys and rollback adding a third key and 
destroying an
+existing key while showing how to handle exceptions.
+
+## Prerequisites
+* An installation of Apache Geode.
+* Apache Geode Native, built and installed.
+* Apache Geode Native examples, built and installed.
+
+## Running
+1. Set the current directory to the `TransactionCs` directory in your example 
workspace.
+
+  ```
+  $ cd workspace/examples/dotnet/TransactionCs
+  ```
+
+1. Run the `startserver.ps1` script to start the Geode server, create a 
region, and populate the region with sample data.
+
+  ```
+  $ sh ./startserver.ps1
+  /Users/user/geode/bin/gfsh
+
+  (1) Executing - start locator --name=locator
+  ...
+  (2) Executing - start server --name=server
+  ...
+  (3) Executing - create region --name=exampleRegion --type=PARTITION
+
+  Member | Status
+  ------ | ----------------------------------------------
+  server | Region "/exampleRegion" created on "server"
+  ```
+
+1. Execute `TransactionCs`:
+
+  ```
+  $ build/TransactionCs
+    Created cache
+    Created region 'exampleRegion'
+    Rolled back transaction - retrying(4)
+    Rolled back transaction - retrying(3)
+    Rolled back transaction - retrying(2)
+    Committed transaction - exiting
+  ```
+
+1. Stop the server
+
+  ```
+  $ sh ./stopserver.ps1
+  /Users/user/geode/bin/gfsh
+  (1) Executing - connect
+  ...
+  (2) Executing - stop server --name=server
+  ...
+  (3) Executing - stop locator --name=locator
+  ....
+  ```
diff --git a/examples/dotnet/RemoteQueryCs/startserver.ps1 
b/examples/dotnet/transaction/startserver.ps1
similarity index 95%
rename from examples/dotnet/RemoteQueryCs/startserver.ps1
rename to examples/dotnet/transaction/startserver.ps1
index 4c5c849..e8fed8b 100644
--- a/examples/dotnet/RemoteQueryCs/startserver.ps1
+++ b/examples/dotnet/transaction/startserver.ps1
@@ -35,5 +35,5 @@ else
 
 if ($GFSH_PATH -ne "")
 {
-   Invoke-Expression "$GFSH_PATH -e 'start locator --name=locator 
--dir=$PSScriptRoot\locator' -e 'start server --name=server 
--dir=$PSScriptRoot\server' -e 'create region --name=custom_orders 
--type=PARTITION'"
+   Invoke-Expression "$GFSH_PATH -e 'start locator --name=locator 
--dir=$PSScriptRoot\locator' -e 'start server --name=server 
--dir=$PSScriptRoot\server' -e 'create region --name=exampleRegion 
--type=PARTITION'"
 }
\ No newline at end of file
diff --git a/examples/dotnet/RemoteQueryCs/stopserver.ps1 
b/examples/dotnet/transaction/stopserver.ps1
similarity index 95%
rename from examples/dotnet/RemoteQueryCs/stopserver.ps1
rename to examples/dotnet/transaction/stopserver.ps1
index 5ac5117..0d435a2 100644
--- a/examples/dotnet/RemoteQueryCs/stopserver.ps1
+++ b/examples/dotnet/transaction/stopserver.ps1
@@ -35,5 +35,5 @@ else
 
 if ($GFSH_PATH -ne "")
 {
-   Invoke-Expression "$GFSH_PATH -e 'connect' -e 'destroy region 
--name=custom_orders' -e 'stop server --name=server' -e 'stop locator 
--name=locator'"
+   Invoke-Expression "$GFSH_PATH -e 'connect' -e 'destroy region 
--name=exampleRegion' -e 'stop server --name=server' -e 'stop locator 
--name=locator'"
 }
\ No newline at end of file

Reply via email to