From 78ac5ee1314b0a4b77865826da56c591d6ace7c5 Mon Sep 17 00:00:00 2001
From: xiaolei li <85657333+xleili@users.noreply.github.com>
Date: Tue, 20 Sep 2022 18:23:39 +0800
Subject: [PATCH] docs(diver):C# add docs with WebSocket (#16950)
* docs(diver):C# add docs with WebSocket
* docs(driver):C# docs update with commnets
---
docs/examples/csharp/.gitignore | 10 +-
docs/examples/csharp/wsConnect/Program.cs | 25 ++++
.../csharp/wsConnect/wsConnect.csproj | 13 ++
docs/examples/csharp/wsInsert/Program.cs | 58 +++++++++
docs/examples/csharp/wsInsert/wsInsert.csproj | 13 ++
docs/examples/csharp/wsQuery/Program.cs | 74 +++++++++++
docs/examples/csharp/wsQuery/wsQuery.csproj | 13 ++
docs/examples/csharp/wsStmt/Program.cs | 95 ++++++++++++++
docs/examples/csharp/wsStmt/wsStmt.csproj | 13 ++
docs/zh/07-develop/01-connect/_connect_cs.mdx | 6 +-
docs/zh/08-connector/40-csharp.mdx | 120 +++++++++++++++++-
11 files changed, 431 insertions(+), 9 deletions(-)
create mode 100644 docs/examples/csharp/wsConnect/Program.cs
create mode 100644 docs/examples/csharp/wsConnect/wsConnect.csproj
create mode 100644 docs/examples/csharp/wsInsert/Program.cs
create mode 100644 docs/examples/csharp/wsInsert/wsInsert.csproj
create mode 100644 docs/examples/csharp/wsQuery/Program.cs
create mode 100644 docs/examples/csharp/wsQuery/wsQuery.csproj
create mode 100644 docs/examples/csharp/wsStmt/Program.cs
create mode 100644 docs/examples/csharp/wsStmt/wsStmt.csproj
diff --git a/docs/examples/csharp/.gitignore b/docs/examples/csharp/.gitignore
index b3aff79f37..694da603b9 100644
--- a/docs/examples/csharp/.gitignore
+++ b/docs/examples/csharp/.gitignore
@@ -1,4 +1,12 @@
bin
obj
.vs
-*.sln
\ No newline at end of file
+*.sln
+wsConnect/obj
+wsInsert/obj
+wsQuery/obj
+wsStmt/obj
+wsConnect/bin
+wsInsert/bin
+wsQuery/bin
+wsStmt/bin
\ No newline at end of file
diff --git a/docs/examples/csharp/wsConnect/Program.cs b/docs/examples/csharp/wsConnect/Program.cs
new file mode 100644
index 0000000000..2e89372c3e
--- /dev/null
+++ b/docs/examples/csharp/wsConnect/Program.cs
@@ -0,0 +1,25 @@
+using System;
+using TDengineWS.Impl;
+
+namespace Examples
+{
+ public class WSConnExample
+ {
+ static void Main(string[] args)
+ {
+ string DSN = "ws://root:taosdata@127.0.0.1:6041/test";
+ IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN);
+ if (wsConn == IntPtr.Zero)
+ {
+ throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}");
+ }
+ else
+ {
+ Console.WriteLine("Establish connect success.");
+ }
+
+ // close connection.
+ LibTaosWS.WSClose(wsConn);
+ }
+ }
+}
\ No newline at end of file
diff --git a/docs/examples/csharp/wsConnect/wsConnect.csproj b/docs/examples/csharp/wsConnect/wsConnect.csproj
new file mode 100644
index 0000000000..34951dc761
--- /dev/null
+++ b/docs/examples/csharp/wsConnect/wsConnect.csproj
@@ -0,0 +1,13 @@
+
+
+
+ Exe
+ net5.0
+ enable
+
+
+
+
+
+
+
diff --git a/docs/examples/csharp/wsInsert/Program.cs b/docs/examples/csharp/wsInsert/Program.cs
new file mode 100644
index 0000000000..4ff830b437
--- /dev/null
+++ b/docs/examples/csharp/wsInsert/Program.cs
@@ -0,0 +1,58 @@
+using System;
+using TDengineWS.Impl;
+
+namespace Examples
+{
+ public class WSInsertExample
+ {
+ static void Main(string[] args)
+ {
+ string DSN = "ws://root:taosdata@127.0.0.1:6041/test";
+ IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN);
+
+ // Assert if connection is validate
+ if (wsConn == IntPtr.Zero)
+ {
+ throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}");
+ }
+ else
+ {
+ Console.WriteLine("Establish connect success.");
+ }
+
+ string createTable = "CREATE STABLE test.meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);";
+ string insert = "INSERT INTO test.d1001 USING test.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)" +
+ "test.d1002 USING test.meters TAGS('California.SanFrancisco', 3) VALUES('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)" +
+ "test.d1003 USING test.meters TAGS('California.LosAngeles', 2) VALUES('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000) " +
+ "test.d1004 USING test.meters TAGS('California.LosAngeles', 3) VALUES('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000)('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
+
+ IntPtr wsRes = LibTaosWS.WSQuery(wsConn, createTable);
+ ValidInsert("create table", wsRes);
+ LibTaosWS.WSFreeResult(wsRes);
+
+ wsRes = LibTaosWS.WSQuery(wsConn, insert);
+ ValidInsert("insert data", wsRes);
+ LibTaosWS.WSFreeResult(wsRes);
+
+ // close connection.
+ LibTaosWS.WSClose(wsConn);
+ }
+
+ static void ValidInsert(string desc, IntPtr wsRes)
+ {
+ int code = LibTaosWS.WSErrorNo(wsRes);
+ if (code != 0)
+ {
+ throw new Exception($"execute SQL failed: reason: {LibTaosWS.WSErrorStr(wsRes)}, code:{code}");
+ }
+ else
+ {
+ Console.WriteLine("{0} success affect {2} rows, cost {1} nanoseconds", desc, LibTaosWS.WSTakeTiming(wsRes),LibTaosWS.WSAffectRows(wsRes));
+ }
+ }
+ }
+
+}
+// Establish connect success.
+// create table success affect 0 rows, cost 3717542 nanoseconds
+// insert data success affect 8 rows, cost 2613637 nanoseconds
\ No newline at end of file
diff --git a/docs/examples/csharp/wsInsert/wsInsert.csproj b/docs/examples/csharp/wsInsert/wsInsert.csproj
new file mode 100644
index 0000000000..34951dc761
--- /dev/null
+++ b/docs/examples/csharp/wsInsert/wsInsert.csproj
@@ -0,0 +1,13 @@
+
+
+
+ Exe
+ net5.0
+ enable
+
+
+
+
+
+
+
diff --git a/docs/examples/csharp/wsQuery/Program.cs b/docs/examples/csharp/wsQuery/Program.cs
new file mode 100644
index 0000000000..bf3cf2bbe2
--- /dev/null
+++ b/docs/examples/csharp/wsQuery/Program.cs
@@ -0,0 +1,74 @@
+using System;
+using TDengineWS.Impl;
+using System.Collections.Generic;
+using TDengineDriver;
+
+namespace Examples
+{
+ public class WSQueryExample
+ {
+ static void Main(string[] args)
+ {
+ string DSN = "ws://root:taosdata@127.0.0.1:6041/test";
+ IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN);
+ if (wsConn == IntPtr.Zero)
+ {
+ throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}");
+ }
+ else
+ {
+ Console.WriteLine("Establish connect success.");
+ }
+
+ string select = "select * from test.meters";
+
+ // optional:wsRes = LibTaosWS.WSQuery(wsConn, select);
+ IntPtr wsRes = LibTaosWS.WSQueryTimeout(wsConn, select, 1);
+ // Assert if query execute success.
+ int code = LibTaosWS.WSErrorNo(wsRes);
+ if (code != 0)
+ {
+ throw new Exception($"execute SQL failed: reason: {LibTaosWS.WSErrorStr(wsRes)}, code:{code}");
+ }
+
+ // get meta data
+ List metas = LibTaosWS.WSGetFields(wsRes);
+ // get retrieved data
+ List