Apache-IoTDB-Client-CSharp-UserCase/Program.cs (89 lines of code) (raw):

using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Apache.IoTDB; using Apache.IoTDB.DataStructure; namespace Apache.IoTDB.UserCase { class Program { static string host = "localhost"; static int port = 6667; static int pool_size = 2; static async Task OpenAndCloseSessionPool() { var session_pool = new SessionPool(host, port, pool_size); await session_pool.Open(false); if (session_pool.IsOpen()) { Console.WriteLine("SessionPool open success"); } else { Console.WriteLine("SessionPool open failed"); } await session_pool.Close(); } static async Task CreateTimeseries() { var session_pool = new SessionPool(host, port, pool_size); await session_pool.Open(false); await session_pool.DeleteStorageGroupAsync("root.ln.wf01.wt01"); var status = await session_pool.CreateTimeSeries("root.ln.wf01.wt01.status", TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); status = await session_pool.CreateTimeSeries("root.ln.wf01.wt01.temperature", TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); status = await session_pool.CreateTimeSeries("root.ln.wf01.wt01.hardware", TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); await session_pool.Close(); } static async Task InsertRecord() { var session_pool = new SessionPool(host, port, pool_size); await session_pool.Open(false); long timestamp = 1; var values = new List<object> { true, (double)1.1, "test" }; var measures = new List<string> { "status", "temperature", "hardware" }; var rowRecord = new RowRecord(timestamp, values, measures); var status = await session_pool.InsertRecordAsync("root.ln.wf01.wt01", rowRecord); await session_pool.Close(); } static async Task InsertTablet() { var session_pool = new SessionPool(host, port, pool_size); await session_pool.Open(false); var device_id = "root.ln.wf01.wt01"; var measurement_lst = new List<string> { "status", "temperature", "hardware" }; var value_lst = new List<List<object>> { new() {true, (double)1.1, "test"}, new() {false, (double)2.2, "test2"}, new() {true, (double)3.3, "test3"} }; var timestamp_lst = new List<long> { 1, 2, 3 }; var datatype_lst = new List<TSDataType> { TSDataType.BOOLEAN, TSDataType.DOUBLE, TSDataType.TEXT }; var tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); var status = await session_pool.InsertTabletAsync(tablet); await session_pool.Close(); } static async Task ExecuteQueryStatement() { var session_pool = new SessionPool(host, port, pool_size); await session_pool.Open(false); var res = await session_pool.ExecuteQueryStatementAsync("select * from root.ln.wf01.wt01"); res.ShowTableNames(); while (res.HasNext()) { Console.WriteLine(res.Next()); } await res.Close(); await session_pool.Close(); } static async Task Main(string[] args) { await OpenAndCloseSessionPool(); await CreateTimeseries(); await InsertRecord(); await InsertTablet(); await ExecuteQueryStatement(); } } }