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 cdcb96f  GEODE-4347: Add dotnet ContinuousQuery example (#355)
cdcb96f is described below

commit cdcb96f277b3a65a522eb53e2bedf378d7d757f7
Author: Blake Bender <[email protected]>
AuthorDate: Fri Sep 21 16:55:30 2018 +0000

    GEODE-4347: Add dotnet ContinuousQuery example (#355)
    
    - Create new project directory
    - Add ContinuousQueryCs to dotnet examples CMakeLists
    
    Co-authored-by: Blake Bender <[email protected]>
---
 examples/dotnet/CMakeLists.txt                    |  3 +
 examples/dotnet/CMakeLists.txt.in                 |  1 +
 examples/dotnet/ContinuousQueryCs/MyCqListener.cs | 68 +++++++++++++++++
 examples/dotnet/ContinuousQueryCs/Order.cs        | 71 ++++++++++++++++++
 examples/dotnet/ContinuousQueryCs/Program.cs      | 91 +++++++++++++++++++++++
 examples/dotnet/ContinuousQueryCs/README.md       | 30 ++++++++
 examples/dotnet/ContinuousQueryCs/startserver.ps1 | 39 ++++++++++
 examples/dotnet/ContinuousQueryCs/stopserver.ps1  | 39 ++++++++++
 examples/dotnet/PdxSerializableCs/README.md       | 12 +--
 examples/dotnet/RemoteQueryCs/README.md           | 21 +++---
 10 files changed, 360 insertions(+), 15 deletions(-)

diff --git a/examples/dotnet/CMakeLists.txt b/examples/dotnet/CMakeLists.txt
index e727310..e50ff75 100644
--- a/examples/dotnet/CMakeLists.txt
+++ b/examples/dotnet/CMakeLists.txt
@@ -50,6 +50,9 @@ endfunction()
 add_example(NAME AuthInitialize
        SOURCE ExampleAuthInitialize.cs Program.cs)
 
+add_example(NAME ContinuousQueryCs 
+       SOURCE Order.cs MyCqListener.cs Program.cs)
+
 add_example(NAME DataSerializableCs
        SOURCE Order.cs Program.cs)
 
diff --git a/examples/dotnet/CMakeLists.txt.in 
b/examples/dotnet/CMakeLists.txt.in
index 53a2998..5035bec 100644
--- a/examples/dotnet/CMakeLists.txt.in
+++ b/examples/dotnet/CMakeLists.txt.in
@@ -18,6 +18,7 @@ cmake_minimum_required(VERSION 3.10)
 project(@[email protected] LANGUAGES NONE)
 
 add_subdirectory(AuthInitialize)
+add_subdirectory(ContinuousQueryCs)
 add_subdirectory(DataSerializableCs)
 add_subdirectory(PdxAutoSerializer)
 add_subdirectory(PdxSerializableCs)
diff --git a/examples/dotnet/ContinuousQueryCs/MyCqListener.cs 
b/examples/dotnet/ContinuousQueryCs/MyCqListener.cs
new file mode 100644
index 0000000..d61c065
--- /dev/null
+++ b/examples/dotnet/ContinuousQueryCs/MyCqListener.cs
@@ -0,0 +1,68 @@
+/*
+* 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 Apache.Geode.Client;
+
+namespace Apache.Geode.Examples.ContinuousQuery
+{
+    public class MyCqListener<TKey, TResult> : ICqListener<TKey, TResult>
+    {
+        public virtual void OnEvent(CqEvent<TKey, TResult> ev)
+        {
+            Order val = ev.getNewValue() as Order;
+            TKey key = ev.getKey();
+            string operationType = "UNKNOWN";
+
+            switch (ev.getQueryOperation())
+            {
+                case CqOperation.OP_TYPE_CREATE:
+                    operationType = "CREATE";
+                    break;
+                case CqOperation.OP_TYPE_UPDATE:
+                    operationType = "UPDATE";
+                    break;
+                case CqOperation.OP_TYPE_DESTROY:
+                    operationType = "DESTROY";
+                    break;
+                default:
+                    Console.WriteLine("Unexpected operation encountered {0}", 
ev.getQueryOperation());
+                    break;
+            }
+
+            if (val != null)
+            {
+                Console.WriteLine("MyCqListener::OnEvent({0}) called with key 
{1}, value {2}", operationType, key, val.ToString());
+            }
+            else
+            {
+                Console.WriteLine("MyCqListener::OnEvent({0}) called with key 
{1}, value null", operationType, key);
+            }
+        }
+
+        public virtual void OnError(CqEvent<TKey, TResult> ev)
+        {
+            Console.WriteLine("MyCqListener::OnError called");
+        }
+
+        public virtual void Close()
+        {
+            Console.WriteLine("MyCqListener::close called");
+        }
+    }
+}
diff --git a/examples/dotnet/ContinuousQueryCs/Order.cs 
b/examples/dotnet/ContinuousQueryCs/Order.cs
new file mode 100644
index 0000000..ecb5875
--- /dev/null
+++ b/examples/dotnet/ContinuousQueryCs/Order.cs
@@ -0,0 +1,71 @@
+/*
+* 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 Apache.Geode.Client;
+using System;
+
+namespace Apache.Geode.Examples.ContinuousQuery
+{
+    public class Order : IPdxSerializable
+    {
+        private const string ORDER_ID_KEY_ = "order_id";
+        private const string NAME_KEY_ = "name";
+        private const string QUANTITY_KEY_ = "quantity";
+
+        public long OrderId { get; set; }
+        public string Name { get; set; }
+        public short Quantity { get; set; }
+
+        // A default constructor is required for deserialization
+        public Order() { }
+
+        public Order(int orderId, string name, short quantity)
+        {
+            OrderId = orderId;
+            Name = name;
+            Quantity = quantity;
+        }
+
+        public override string ToString()
+        {
+            return string.Format("Order: [{0}, {1}, {2}]", OrderId, Name, 
Quantity);
+        }
+
+        public void ToData(IPdxWriter output)
+        {
+            output.WriteLong(ORDER_ID_KEY_, OrderId);
+            output.MarkIdentityField(ORDER_ID_KEY_);
+
+            output.WriteString(NAME_KEY_, Name);
+            output.MarkIdentityField(NAME_KEY_);
+
+            output.WriteInt(QUANTITY_KEY_, Quantity);
+            output.MarkIdentityField(QUANTITY_KEY_);
+        }
+
+        public void FromData(IPdxReader input)
+        {
+            OrderId = input.ReadLong(ORDER_ID_KEY_);
+            Name = input.ReadString(NAME_KEY_);
+            Quantity = (short)input.ReadInt(QUANTITY_KEY_);
+        }
+
+        public static IPdxSerializable CreateDeserializable()
+        {
+            return new Order();
+        }
+    }
+}
diff --git a/examples/dotnet/ContinuousQueryCs/Program.cs 
b/examples/dotnet/ContinuousQueryCs/Program.cs
new file mode 100644
index 0000000..41b3d33
--- /dev/null
+++ b/examples/dotnet/ContinuousQueryCs/Program.cs
@@ -0,0 +1,91 @@
+/*
+* 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 Apache.Geode.Client;
+
+namespace Apache.Geode.Examples.ContinuousQuery
+{
+    public class Program
+    {
+        public static void Main(string[] args)
+        {
+            var cacheFactory = new CacheFactory()
+                .Set("log-level", "none");
+            var cache = cacheFactory.Create();
+
+            Console.WriteLine("Registering for data serialization");
+
+            cache.TypeRegistry.RegisterPdxType(Order.CreateDeserializable);
+
+            var poolFactory = cache.GetPoolFactory()
+                .AddLocator("localhost", 10334);
+            var pool = poolFactory
+              .SetSubscriptionEnabled(true)
+              .Create("pool");
+
+            var regionFactory = cache.CreateRegionFactory(RegionShortcut.PROXY)
+                .SetPoolName("pool");
+            var orderRegion = regionFactory.Create<string, 
Order>("example_orderobject");
+
+            var queryService = pool.GetQueryService();
+
+            var cqAttributesFactory = new CqAttributesFactory<string, Order>();
+
+            var cqListener = new MyCqListener<string, Order>();
+
+            cqAttributesFactory.AddCqListener(cqListener);
+
+            var cqAttributes = cqAttributesFactory.Create();
+            try {
+              var query = queryService.NewCq("MyCq", "SELECT * FROM 
/example_orderobject WHERE quantity > 30", cqAttributes, false);
+
+              Console.WriteLine("Executing continuous query");
+              query.Execute();
+            
+              Console.WriteLine("Create orders");
+              var order1 = new Order(1, "product x", 23);
+              var order2 = new Order(2, "product y", 37);
+              var order3 = new Order(3, "product z", 1);
+              var order4 = new Order(4, "product z", 102);
+              var order5 = new Order(5, "product x", 17);
+              var order6 = new Order(6, "product z", 42);
+            
+              Console.WriteLine("Putting and changing Order objects in the 
region");
+              orderRegion.Put("Order1", order1);
+              orderRegion.Put("Order2", order2);
+              orderRegion.Put("Order3", order3);
+              orderRegion.Put("Order4", order4);
+              orderRegion.Put("Order5", order5);
+              orderRegion.Put("Order6", order6);
+            
+              orderRegion.Put("Order2", new Order(2, "product y", 45));
+              orderRegion.Put("Order2", new Order(2, "product y", 29));
+              orderRegion.Remove("Order6");
+
+              System.Threading.Thread.Sleep(2000);
+
+              query.Stop();
+              query.Close();
+            } catch (IllegalStateException ex) {
+              Console.WriteLine(ex.Message);
+            }
+         
+            cache.Close();
+        }
+    }
+}
diff --git a/examples/dotnet/ContinuousQueryCs/README.md 
b/examples/dotnet/ContinuousQueryCs/README.md
new file mode 100644
index 0000000..d544412
--- /dev/null
+++ b/examples/dotnet/ContinuousQueryCs/README.md
@@ -0,0 +1,30 @@
+# ContinuousQuery Example
+This is a simple example showing how to execute a continuous query on a Goede 
region.
+
+## Prerequisites
+* Install [Apache Geode](https://geode.apache.org)
+* Build and install [Apache Geode 
Native](https://github.com/apache/geode-native)
+
+## Running
+* Start Geode Server and create region.
+  ```
+  gfsh>start locator --name=locator
+  gfsh>start server --name=server
+  gfsh>create region --name=example_orderobject --type=PARTITION
+  ```
+* Execute `ContinuousQueryCS.exe`
+  
+  output:
+  ```
+  Registering for data serialization
+  Executing continuous query
+  Create orders
+  Putting and changing Order objects in the region
+  MyCqListener::OnEvent(CREATE) called with key Order2, value Order: [2, 
product y, 37]
+  MyCqListener::OnEvent(CREATE) called with key Order4, value Order: [4, 
product z, 102]
+  MyCqListener::OnEvent(CREATE) called with key Order6, value Order: [6, 
product z, 42]
+  MyCqListener::OnEvent(UPDATE) called with key Order2, value Order: [2, 
product y, 45]
+  MyCqListener::OnEvent(DESTROY) called with key Order2, value Order: [2, 
product y, 29]
+  MyCqListener::OnEvent(DESTROY) called with key Order6, value null
+  MyCqListener::close called
+  ```
diff --git a/examples/dotnet/ContinuousQueryCs/startserver.ps1 
b/examples/dotnet/ContinuousQueryCs/startserver.ps1
new file mode 100644
index 0000000..c3d5735
--- /dev/null
+++ b/examples/dotnet/ContinuousQueryCs/startserver.ps1
@@ -0,0 +1,39 @@
+# 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.
+
+$GFSH_PATH = ""
+if (Get-Command gfsh -ErrorAction SilentlyContinue)
+{
+    $GFSH_PATH = "gfsh"
+}
+else
+{
+    if (-not (Test-Path env:GEODE_HOME))
+    {
+        Write-Host "Could not find gfsh.  Please set the GEODE_HOME path. e.g. 
"
+        Write-Host "(Powershell) `$env:GEODE_HOME = <path to Geode>"
+        Write-Host " OR"
+        Write-Host "(Command-line) set %GEODE_HOME% = <path to Geode>"
+    }
+    else
+    {
+        $GFSH_PATH = "$env:GEODE_HOME\bin\gfsh.bat"
+    }
+}
+
+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=example_orderobject 
--type=PARTITION'"
+}
\ No newline at end of file
diff --git a/examples/dotnet/ContinuousQueryCs/stopserver.ps1 
b/examples/dotnet/ContinuousQueryCs/stopserver.ps1
new file mode 100644
index 0000000..a95b7a7
--- /dev/null
+++ b/examples/dotnet/ContinuousQueryCs/stopserver.ps1
@@ -0,0 +1,39 @@
+# 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.
+
+$GFSH_PATH = ""
+if (Get-Command gfsh -ErrorAction SilentlyContinue)
+{
+    $GFSH_PATH = "gfsh"
+}
+else
+{
+    if (-not (Test-Path env:GEODE_HOME))
+    {
+        Write-Host "Could not find gfsh.  Please set the GEODE_HOME path. e.g. 
"
+        Write-Host "(Powershell) `$env:GEODE_HOME = <path to Geode>"
+        Write-Host " OR"
+        Write-Host "(Command-line) set %GEODE_HOME% = <path to Geode>"
+    }
+    else
+    {
+        $GFSH_PATH = "$env:GEODE_HOME\bin\gfsh.bat"
+    }
+}
+
+if ($GFSH_PATH -ne "")
+{
+   Invoke-Expression "$GFSH_PATH -e 'connect' -e 'destroy region 
--name=example_orderobject' -e 'stop server --name=server' -e 'stop locator 
--name=locator'"
+}
\ No newline at end of file
diff --git a/examples/dotnet/PdxSerializableCs/README.md 
b/examples/dotnet/PdxSerializableCs/README.md
index bbe7ecd..4859e84 100644
--- a/examples/dotnet/PdxSerializableCs/README.md
+++ b/examples/dotnet/PdxSerializableCs/README.md
@@ -1,5 +1,5 @@
-# PdxAutoSerializer Example
-This is a simple example showing how to register for auto-serialization of 
custom objects using the ReflectionBasedAutoSerializer class.
+# PdxSerializable Example
+This is a simple example showing how to register for serialization of custom 
objects using the IPDXSerializable class.
 
 ## Prerequisites
 * Install [Apache Geode](https://geode.apache.org)
@@ -12,13 +12,13 @@ This is a simple example showing how to register for 
auto-serialization of custo
   gfsh>start server --name=server
   gfsh>create region --name=example_orderobject --type=PARTITION
   ```
-* Execute `PdxAutoSerializer.exe`.
+* Execute `PdxSerializableCs.exe`.
   
   output:
   ```
-  Registering for reflection-based auto serialization
+  Registering for data serialization
   Storing order object in the region
-  order to put is Order: [65, Vox AC30, 11]
+  order to put is Order: [65, Donuts, 12]
   Successfully put order, getting now...
-  Order key: 65 = Order: [65, Vox AC30, 11]
+  Order key: 65 = Order: [65, Donuts, 12]
   ```
diff --git a/examples/dotnet/RemoteQueryCs/README.md 
b/examples/dotnet/RemoteQueryCs/README.md
index bbe7ecd..89b2b94 100644
--- a/examples/dotnet/RemoteQueryCs/README.md
+++ b/examples/dotnet/RemoteQueryCs/README.md
@@ -1,5 +1,5 @@
-# PdxAutoSerializer Example
-This is a simple example showing how to register for auto-serialization of 
custom objects using the ReflectionBasedAutoSerializer class.
+# RemoteQuery Example
+This is a simple example showing how to execute a query on a remote region.
 
 ## Prerequisites
 * Install [Apache Geode](https://geode.apache.org)
@@ -10,15 +10,18 @@ This is a simple example showing how to register for 
auto-serialization of custo
   ```
   gfsh>start locator --name=locator
   gfsh>start server --name=server
-  gfsh>create region --name=example_orderobject --type=PARTITION
+  gfsh>create region --name=custom_orders --type=PARTITION
   ```
-* Execute `PdxAutoSerializer.exe`.
+* Execute `RemoteQueryCs.exe`.
   
   output:
   ```
-  Registering for reflection-based auto serialization
-  Storing order object in the region
-  order to put is Order: [65, Vox AC30, 11]
-  Successfully put order, getting now...
-  Order key: 65 = Order: [65, Vox AC30, 11]
+  Registering for data serialization
+  Create orders
+  Storing orders in the region
+  Getting the orders from the region
+  The following orders have a quantity greater than 30:
+  Order: [6, product z, 42]
+  Order: [4, product z, 102]
+  Order: [2, product y, 37]
   ```

Reply via email to