From d9490624527d8d297ec1f728e00f3af7b817033c Mon Sep 17 00:00:00 2001 From: xleili Date: Tue, 13 Sep 2022 16:39:22 +0800 Subject: [PATCH] docs(cloud):C# suppply cloud in/out doc and fix ivavalid path --- docs/en/09-data-out/_sub_cs.mdx | 2 +- .../csharp/cloud-example/cloud-example.sln | 80 ++++----- .../csharp/cloud-example/inout/Program.cs | 153 +++++++++--------- .../csharp/cloud-example/inout/inout.csproj | 22 +-- 4 files changed, 125 insertions(+), 132 deletions(-) diff --git a/docs/en/09-data-out/_sub_cs.mdx b/docs/en/09-data-out/_sub_cs.mdx index 694970e7eb..a09e91422b 100644 --- a/docs/en/09-data-out/_sub_cs.mdx +++ b/docs/en/09-data-out/_sub_cs.mdx @@ -1,3 +1,3 @@ ```csharp -// {{#include docs/examples/csharp/SubscribeDemo.cs}} +{{#include docs/examples/csharp/native-example/SubscribeDemo.cs}} ``` \ No newline at end of file diff --git a/docs/examples/csharp/cloud-example/cloud-example.sln b/docs/examples/csharp/cloud-example/cloud-example.sln index 39ee563bbb..43f3fb77b9 100644 --- a/docs/examples/csharp/cloud-example/cloud-example.sln +++ b/docs/examples/csharp/cloud-example/cloud-example.sln @@ -1,40 +1,40 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30114.105 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "connect", "connect\connect.csproj", "{4006CF0C-17BE-4508-9682-A85298F8C92D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "usage", "usage\usage.csproj", "{243C420F-FC47-4F21-B81E-83CDE91F2D47}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stmt", "stmt\stmt.csproj", "{B6907CB6-41CB-4644-AEE1-551456EADE12}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "inout", "inout\inout.csproj", "{058C3864-CF33-459D-B1A7-F7E1C6AED452}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4006CF0C-17BE-4508-9682-A85298F8C92D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4006CF0C-17BE-4508-9682-A85298F8C92D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4006CF0C-17BE-4508-9682-A85298F8C92D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4006CF0C-17BE-4508-9682-A85298F8C92D}.Release|Any CPU.Build.0 = Release|Any CPU - {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Debug|Any CPU.Build.0 = Debug|Any CPU - {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Release|Any CPU.ActiveCfg = Release|Any CPU - {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Release|Any CPU.Build.0 = Release|Any CPU - {B6907CB6-41CB-4644-AEE1-551456EADE12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B6907CB6-41CB-4644-AEE1-551456EADE12}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B6907CB6-41CB-4644-AEE1-551456EADE12}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B6907CB6-41CB-4644-AEE1-551456EADE12}.Release|Any CPU.Build.0 = Release|Any CPU - {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Debug|Any CPU.Build.0 = Debug|Any CPU - {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Release|Any CPU.ActiveCfg = Release|Any CPU - {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "connect", "connect\connect.csproj", "{4006CF0C-17BE-4508-9682-A85298F8C92D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "usage", "usage\usage.csproj", "{243C420F-FC47-4F21-B81E-83CDE91F2D47}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stmt", "stmt\stmt.csproj", "{B6907CB6-41CB-4644-AEE1-551456EADE12}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "inout", "inout\inout.csproj", "{058C3864-CF33-459D-B1A7-F7E1C6AED452}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4006CF0C-17BE-4508-9682-A85298F8C92D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4006CF0C-17BE-4508-9682-A85298F8C92D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4006CF0C-17BE-4508-9682-A85298F8C92D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4006CF0C-17BE-4508-9682-A85298F8C92D}.Release|Any CPU.Build.0 = Release|Any CPU + {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Release|Any CPU.Build.0 = Release|Any CPU + {B6907CB6-41CB-4644-AEE1-551456EADE12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B6907CB6-41CB-4644-AEE1-551456EADE12}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B6907CB6-41CB-4644-AEE1-551456EADE12}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B6907CB6-41CB-4644-AEE1-551456EADE12}.Release|Any CPU.Build.0 = Release|Any CPU + {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Debug|Any CPU.Build.0 = Debug|Any CPU + {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Release|Any CPU.ActiveCfg = Release|Any CPU + {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/docs/examples/csharp/cloud-example/inout/Program.cs b/docs/examples/csharp/cloud-example/inout/Program.cs index d82d3440d9..140db0f0f0 100644 --- a/docs/examples/csharp/cloud-example/inout/Program.cs +++ b/docs/examples/csharp/cloud-example/inout/Program.cs @@ -1,81 +1,74 @@ -using System; -using TDengineDriver; -using TDengineWS.Impl; -using System.Collections.Generic; - -namespace Cloud.Examples -{ - public class InOutExample - { - static void Main(string[] args) - { - string dsn = Environment.GetEnvironmentVariable("TDENGINE_CLOUD_DSN"); - IntPtr conn = LibTaosWS.WSConnectWithDSN(dsn); - if (conn != IntPtr.Zero) - { - - try - { - // ANCHOR: insert - string createTable = "CREATE STABLE if not exists test.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"; - string insertData = "INSERT INTO test.d1001 USING test.meters TAGS('California.SanFrancisco', 1) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000)" + - "test.d1002 USING test.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)" + - "test.d1003 USING test.meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)" + - "test.d1004 USING test.meters TAGS('California.LosAngeles', 4) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) "; - - // create database under database named 'test' - IntPtr res = LibTaosWS.WSQuery(conn, createTable); - ValidQueryExecution(res); - // Free the query result every time when used up it. - LibTaosWS.WSFreeResult(res); - - // insert data into the table created in previous step. - res = LibTaosWS.WSQuery(conn, insertData); - ValidQueryExecution(res); - // Free the query result every time when used up it. - LibTaosWS.WSFreeResult(res); - // ANCHOR: query - void ValidQueryExecution(IntPtr res) - { - int code = LibTaosWS.WSErrorNo(res); - if (code != 0) - { - throw new Exception($"execute SQL failed: reason: {LibTaosWS.WSErrorStr(res)}, code:{code}"); - } - } - // ANCHOR_END: insert - string selectTable = "select * from test.meters"; - IntPtr res = LibTaosWS.WSQueryTimeout(conn, selectTable, 5000); - ValidQueryExecution(res); - - // get meta info of the retrieved data as List - List metas = LibTaosWS.WSGetFields(res); - - // get data of the retrieved data as List. - List dataSet = LibTaosWS.WSGetData(res); - - // Free the query result every time when used up it. - LibTaosWS.WSFreeResult(res); - // ANCHOR_END: query - } - finally - { - // close connect - LibTaosWS.WSClose(conn); - } - } - else - { - throw new Exception($"get connection failed,reason:{LibTaosWS.WSErrorStr(conn)},code:{LibTaosWS.WSErrorNo(conn)}"); - } - sum(1, 2); - void sum(int i, int j) - { - Console.WriteLine("{0} + {1} = {2}", i, j, i + j); - } - - - } - - } +using System; +using TDengineDriver; +using TDengineWS.Impl; +using System.Collections.Generic; + +namespace Cloud.Examples +{ + public class InOutExample + { + static void Main(string[] args) + { + string dsn = Environment.GetEnvironmentVariable("TDENGINE_CLOUD_DSN"); + IntPtr conn = LibTaosWS.WSConnectWithDSN(dsn); + if (conn != IntPtr.Zero) + { + + try + { + // ANCHOR: insert + string createTable = "CREATE STABLE if not exists test.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"; + string insertData = "INSERT INTO test.d1001 USING test.meters TAGS('California.SanFrancisco', 1) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000)" + + "test.d1002 USING test.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)" + + "test.d1003 USING test.meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)" + + "test.d1004 USING test.meters TAGS('California.LosAngeles', 4) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) "; + + // create database under database named 'test' + IntPtr res = LibTaosWS.WSQuery(conn, createTable); + ValidQueryExecution(res); + // Free the query result every time when used up it. + LibTaosWS.WSFreeResult(res); + + // insert data into the table created in previous step. + res = LibTaosWS.WSQuery(conn, insertData); + ValidQueryExecution(res); + // Free the query result every time when used up it. + LibTaosWS.WSFreeResult(res); + // ANCHOR: query + void ValidQueryExecution(IntPtr res) + { + int code = LibTaosWS.WSErrorNo(res); + if (code != 0) + { + throw new Exception($"execute SQL failed: reason: {LibTaosWS.WSErrorStr(res)}, code:{code}"); + } + } + // ANCHOR_END: insert + string selectTable = "select * from test.meters"; + res = LibTaosWS.WSQueryTimeout(conn, selectTable, 5000); + ValidQueryExecution(res); + + // get meta info of the retrieved data as List + List metas = LibTaosWS.WSGetFields(res); + + // get data of the retrieved data as List. + List dataSet = LibTaosWS.WSGetData(res); + + // Free the query result every time when used up it. + LibTaosWS.WSFreeResult(res); + // ANCHOR_END: query + } + finally + { + // close connect + LibTaosWS.WSClose(conn); + } + } + else + { + throw new Exception($"get connection failed,reason:{LibTaosWS.WSErrorStr(conn)},code:{LibTaosWS.WSErrorNo(conn)}"); + } + } + + } } \ No newline at end of file diff --git a/docs/examples/csharp/cloud-example/inout/inout.csproj b/docs/examples/csharp/cloud-example/inout/inout.csproj index 757d36dc10..34951dc761 100644 --- a/docs/examples/csharp/cloud-example/inout/inout.csproj +++ b/docs/examples/csharp/cloud-example/inout/inout.csproj @@ -1,13 +1,13 @@ - - - - Exe - net5.0 - enable - - + + + + Exe + net5.0 + enable + + - - - + + + -- GitLab