Skip to content

Commit

Permalink
去掉注释
Browse files Browse the repository at this point in the history
  • Loading branch information
maikebing committed Nov 18, 2022
1 parent edff6c1 commit 8325bfa
Showing 1 changed file with 110 additions and 110 deletions.
220 changes: 110 additions & 110 deletions src/Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,116 +31,116 @@ static void Main(string[] args)
Port = 6030

};
////Example for ADO.Net
//using (var connection = new TaosConnection(builder.ConnectionString))
//{
// connection.Open();
// Console.WriteLine("ServerVersion:{0}", connection.ServerVersion);
// connection.DatabaseExists(database);
// Console.WriteLine("create {0} {1}", database, connection.CreateCommand($"create database {database};").ExecuteNonQuery());
// Console.WriteLine("create table t {0} {1}", database, connection.CreateCommand($"create table {database}.t (ts timestamp, cdata binary(255));").ExecuteNonQuery());
// Console.WriteLine("insert into t values {0} ", connection.CreateCommand($"insert into {database}.t values ({(long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds)}, 10);").ExecuteNonQuery());
// Console.WriteLine("create {0} {1}", database, connection.CreateCommand($"use {database};").ExecuteNonQuery());

// Console.WriteLine("单表插入一行数据 {0} ", connection.CreateCommand($"insert into {database}.t values ({(long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds)}, 10);").ExecuteNonQuery());
// Thread.Sleep(100);
// Console.WriteLine("单表插入多行数据 {0} ", connection.CreateCommand($"insert into {database}.t values ({(long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds)}, 101) ({(long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds + 1)}, 992);").ExecuteNonQuery());
// connection.ChangeDatabase(database);
// BindParamBatch(connection);

// Console.WriteLine("insert into t values {0} ", connection.CreateCommand($"insert into {database}.t values ({(long)(DateTime.Now.AddMonths(-1).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds)}, 20);").ExecuteNonQuery());
// var cmd_select = connection.CreateCommand();
// cmd_select.CommandText = $"select * from {database}.t;";
// var reader = cmd_select.ExecuteReader();

// int index = reader.GetOrdinal("cdata");
// if (reader.Read())
// {
// var ts = reader.GetDateTime("ts");
// }
// Console.WriteLine($"cdata index at {index}");
// Console.WriteLine(cmd_select.CommandText);
// Console.WriteLine("");
// ConsoleTableBuilder.From(reader.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine();

// connection.ChangeDatabase(database);
// Console.WriteLine("");
// connection.CreateCommand($"CREATE TABLE datas (reportTime timestamp, type int, bufferedEnd bool, address nchar(64), parameter nchar(64), `value` nchar(64)) TAGS (boxCode nchar(64), machineId int);").ExecuteNonQuery();
// connection.CreateCommand($"INSERT INTO data_history_67 USING datas TAGS ('mongo', 67) values ( 1608173534840, 2 ,false ,'Channel1.窑.烟囱温度', '烟囱温度' ,'122.00' );").ExecuteNonQuery();
// var cmd_datas = connection.CreateCommand();
// cmd_datas.CommandText = $"SELECT reportTime,type,bufferedEnd,address,parameter,`value` FROM {database}.data_history_67 LIMIT 100";
// var readerdatas = cmd_datas.ExecuteReader();
// Console.WriteLine(cmd_datas.CommandText);
// Console.WriteLine("");
// ConsoleTableBuilder.From(readerdatas.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.Default).ExportAndWriteLine();
// Console.WriteLine("");

// Console.WriteLine("CREATE TABLE meters ", connection.CreateCommand($"CREATE TABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupdId int);").ExecuteNonQuery());
// Console.WriteLine("CREATE TABLE d1001 ", connection.CreateCommand($"CREATE TABLE d1001 USING meters TAGS (\"Beijing.Chaoyang\", 2);").ExecuteNonQuery());
// Console.WriteLine("INSERT INTO d1001 ", connection.CreateCommand($"INSERT INTO d1001 USING METERS TAGS(\"Beijng.Chaoyang\", 2) VALUES(now, 10.2, 219, 0.32);").ExecuteNonQuery());
// Console.WriteLine("DROP TABLE {0} {1}", database, connection.CreateCommand($"DROP TABLE {database}.t;").ExecuteNonQuery());
// Console.WriteLine("DROP DATABASE {0} {1}", database, connection.CreateCommand($"DROP DATABASE {database};").ExecuteNonQuery());
// connection.CreateCommand("DROP DATABASE IF EXISTS IoTSharp").ExecuteNonQuery();
// connection.CreateCommand("CREATE DATABASE IoTSharp KEEP 365d;").ExecuteNonQuery();
// connection.ChangeDatabase("IoTSharp");
// connection.CreateCommand("CREATE TABLE IF NOT EXISTS telemetrydata (ts timestamp,value_type tinyint, value_boolean bool, value_string binary(10240), value_long bigint,value_datetime timestamp,value_double double) TAGS (deviceid binary(32),keyname binary(64));").ExecuteNonQuery();
// var devid1 = $"{Guid.NewGuid():N}";
// var devid2 = $"{Guid.NewGuid():N}";
// var devid3 = $"{Guid.NewGuid():N}";
// var devid4 = $"{Guid.NewGuid():N}";
// DateTime dt = DateTime.Now;
// UploadTelemetryData(connection, devid1, "1#air-compressor-two-level-discharge-temperature", 1000);
// UploadTelemetryData(connection, devid2, "1#air-compressor-load-rate", 1000);
// Console.WriteLine("");
// Console.WriteLine("");
// Console.WriteLine("");
// DateTime dt2 = DateTime.Now;
// UploadTelemetryDataPool(connection, devid3, "1#air-compressor-two-level-discharge-temperature1", 1000);
// UploadTelemetryDataPool(connection, devid4, "1#air-compressor-load-rate1", 1000);
// var t1 = DateTime.Now.Subtract(dt).TotalSeconds;
// var t2 = DateTime.Now.Subtract(dt2).TotalSeconds;
// Console.WriteLine("Done");
// Thread.Sleep(TimeSpan.FromSeconds(1));
// Console.WriteLine($"UploadTelemetryData 耗时:{t1}");
// Console.WriteLine($"UploadTelemetryDataPool 耗时:{t2}");
// Thread.Sleep(TimeSpan.FromSeconds(2));
// var reader2 = connection.CreateCommand("select last_row(*) from telemetrydata group by deviceid,keyname ;").ExecuteReader();
// ConsoleTableBuilder.From(reader2.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.Default).ExportAndWriteLine();
// var reader3 = connection.CreateCommand("select * from telemetrydata;").ExecuteReader();
// List<string> list = new List<string>();
// while (reader3.Read())
// {
// list.Add(reader3.GetString("keyname"));
// }

// var k = list.GroupBy(e => e);
// var dic = k.ToDictionary(en => en.Key, en => en.ToList());
// dic.Keys.ToList().ForEach(k =>
// {
// Console.WriteLine(k);
// ConsoleTableBuilder.From(dic[k]).WithFormat(ConsoleTableBuilderFormat.Default).ExportAndWriteLine(TableAligntment.Center);
// });



// BulkInsertLines(connection);

// BulkInsertJsonString(connection);

// BulkInsertByJsonAndTags(connection);

// BulkInsertWithJson_BuildJson(connection);

// Console.WriteLine("DROP DATABASE IoTSharp", database, connection.CreateCommand($"DROP DATABASE IoTSharp;").ExecuteNonQuery());



// connection.Close();



//}
UseTaosEFCore(builder);
//Example for ADO.Net
using (var connection = new TaosConnection(builder.ConnectionString))
{
connection.Open();
Console.WriteLine("ServerVersion:{0}", connection.ServerVersion);
connection.DatabaseExists(database);
Console.WriteLine("create {0} {1}", database, connection.CreateCommand($"create database {database};").ExecuteNonQuery());
Console.WriteLine("create table t {0} {1}", database, connection.CreateCommand($"create table {database}.t (ts timestamp, cdata binary(255));").ExecuteNonQuery());
Console.WriteLine("insert into t values {0} ", connection.CreateCommand($"insert into {database}.t values ({(long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds)}, 10);").ExecuteNonQuery());
Console.WriteLine("create {0} {1}", database, connection.CreateCommand($"use {database};").ExecuteNonQuery());

Console.WriteLine("单表插入一行数据 {0} ", connection.CreateCommand($"insert into {database}.t values ({(long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds)}, 10);").ExecuteNonQuery());
Thread.Sleep(100);
Console.WriteLine("单表插入多行数据 {0} ", connection.CreateCommand($"insert into {database}.t values ({(long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds)}, 101) ({(long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds + 1)}, 992);").ExecuteNonQuery());
connection.ChangeDatabase(database);
BindParamBatch(connection);

Console.WriteLine("insert into t values {0} ", connection.CreateCommand($"insert into {database}.t values ({(long)(DateTime.Now.AddMonths(-1).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds)}, 20);").ExecuteNonQuery());
var cmd_select = connection.CreateCommand();
cmd_select.CommandText = $"select * from {database}.t;";
var reader = cmd_select.ExecuteReader();

int index = reader.GetOrdinal("cdata");
if (reader.Read())
{
var ts = reader.GetDateTime("ts");
}
Console.WriteLine($"cdata index at {index}");
Console.WriteLine(cmd_select.CommandText);
Console.WriteLine("");
ConsoleTableBuilder.From(reader.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine();

connection.ChangeDatabase(database);
Console.WriteLine("");
connection.CreateCommand($"CREATE TABLE datas (reportTime timestamp, type int, bufferedEnd bool, address nchar(64), parameter nchar(64), `value` nchar(64)) TAGS (boxCode nchar(64), machineId int);").ExecuteNonQuery();
connection.CreateCommand($"INSERT INTO data_history_67 USING datas TAGS ('mongo', 67) values ( 1608173534840, 2 ,false ,'Channel1.窑.烟囱温度', '烟囱温度' ,'122.00' );").ExecuteNonQuery();
var cmd_datas = connection.CreateCommand();
cmd_datas.CommandText = $"SELECT reportTime,type,bufferedEnd,address,parameter,`value` FROM {database}.data_history_67 LIMIT 100";
var readerdatas = cmd_datas.ExecuteReader();
Console.WriteLine(cmd_datas.CommandText);
Console.WriteLine("");
ConsoleTableBuilder.From(readerdatas.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.Default).ExportAndWriteLine();
Console.WriteLine("");

Console.WriteLine("CREATE TABLE meters ", connection.CreateCommand($"CREATE TABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupdId int);").ExecuteNonQuery());
Console.WriteLine("CREATE TABLE d1001 ", connection.CreateCommand($"CREATE TABLE d1001 USING meters TAGS (\"Beijing.Chaoyang\", 2);").ExecuteNonQuery());
Console.WriteLine("INSERT INTO d1001 ", connection.CreateCommand($"INSERT INTO d1001 USING METERS TAGS(\"Beijng.Chaoyang\", 2) VALUES(now, 10.2, 219, 0.32);").ExecuteNonQuery());
Console.WriteLine("DROP TABLE {0} {1}", database, connection.CreateCommand($"DROP TABLE {database}.t;").ExecuteNonQuery());
Console.WriteLine("DROP DATABASE {0} {1}", database, connection.CreateCommand($"DROP DATABASE {database};").ExecuteNonQuery());
connection.CreateCommand("DROP DATABASE IF EXISTS IoTSharp").ExecuteNonQuery();
connection.CreateCommand("CREATE DATABASE IoTSharp KEEP 365d;").ExecuteNonQuery();
connection.ChangeDatabase("IoTSharp");
connection.CreateCommand("CREATE TABLE IF NOT EXISTS telemetrydata (ts timestamp,value_type tinyint, value_boolean bool, value_string binary(10240), value_long bigint,value_datetime timestamp,value_double double) TAGS (deviceid binary(32),keyname binary(64));").ExecuteNonQuery();
var devid1 = $"{Guid.NewGuid():N}";
var devid2 = $"{Guid.NewGuid():N}";
var devid3 = $"{Guid.NewGuid():N}";
var devid4 = $"{Guid.NewGuid():N}";
DateTime dt = DateTime.Now;
UploadTelemetryData(connection, devid1, "1#air-compressor-two-level-discharge-temperature", 1000);
UploadTelemetryData(connection, devid2, "1#air-compressor-load-rate", 1000);
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
DateTime dt2 = DateTime.Now;
UploadTelemetryDataPool(connection, devid3, "1#air-compressor-two-level-discharge-temperature1", 1000);
UploadTelemetryDataPool(connection, devid4, "1#air-compressor-load-rate1", 1000);
var t1 = DateTime.Now.Subtract(dt).TotalSeconds;
var t2 = DateTime.Now.Subtract(dt2).TotalSeconds;
Console.WriteLine("Done");
Thread.Sleep(TimeSpan.FromSeconds(1));
Console.WriteLine($"UploadTelemetryData 耗时:{t1}");
Console.WriteLine($"UploadTelemetryDataPool 耗时:{t2}");
Thread.Sleep(TimeSpan.FromSeconds(2));
var reader2 = connection.CreateCommand("select last_row(*) from telemetrydata group by deviceid,keyname ;").ExecuteReader();
ConsoleTableBuilder.From(reader2.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.Default).ExportAndWriteLine();
var reader3 = connection.CreateCommand("select * from telemetrydata;").ExecuteReader();
List<string> list = new List<string>();
while (reader3.Read())
{
list.Add(reader3.GetString("keyname"));
}

var k = list.GroupBy(e => e);
var dic = k.ToDictionary(en => en.Key, en => en.ToList());
dic.Keys.ToList().ForEach(k =>
{
Console.WriteLine(k);
ConsoleTableBuilder.From(dic[k]).WithFormat(ConsoleTableBuilderFormat.Default).ExportAndWriteLine(TableAligntment.Center);
});



BulkInsertLines(connection);

BulkInsertJsonString(connection);

BulkInsertByJsonAndTags(connection);

BulkInsertWithJson_BuildJson(connection);

Console.WriteLine("DROP DATABASE IoTSharp", database, connection.CreateCommand($"DROP DATABASE IoTSharp;").ExecuteNonQuery());



connection.Close();



}
UseTaosEFCore(builder);

}

Expand Down

0 comments on commit 8325bfa

Please sign in to comment.