taosdata / TDengine

High-performance, scalable time-series database designed for Industrial IoT (IIoT) scenarios
https://tdengine.com
GNU Affero General Public License v3.0
23.39k stars 4.86k forks source link

Can support c#? #55

Closed windjmj closed 5 years ago

windjmj commented 5 years ago

Thank you for the code.If the TDengine can support c# ,it will perfect.

masterchen commented 5 years ago

Well, i have the same questions, is it possible to call TDEngine via C++ lib from C# application ?@windjmj

hjxilinx commented 5 years ago

We will provide the C# and library for windows soon. Please wait for a few weeks.

HuarenYu commented 5 years ago

Restfull api is an alternative choice

masterchen commented 5 years ago

yep,restful api indeed can meet your requirment, but cannt subscribe ,right?

codedever commented 5 years ago

If the TDengine can support C# for dotnet core platform, it will be better, after all, dotnet core is the future.

maikebing commented 5 years ago

https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos

maikebing commented 5 years ago
string database = "db_" + DateTime.Now.ToString("yyyyMMddHHmmss");
 var builder = new TaosConnectionStringBuilder()
    {
        DataSource = "http://td.gitclub.cn/rest/sql",
        DataBase = database,
        // Token = "cm9vdDp0YW9zZGF0YQ=="
        Username="root",
        Password= "taosdata"
    };
using (var connection = new TaosConnection(builder.ConnectionString))
{
    connection.Open();
    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 int);").ExecuteNonQuery());
    Console.WriteLine("insert into t values  {0}  ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ms")}', 10);").ExecuteNonQuery());
    Console.WriteLine("insert into t values  {0} ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss.ms")}', 20);").ExecuteNonQuery());
    var cmd_select = connection.CreateCommand();
    cmd_select.CommandText = $"select * from {database}.t";
    var reader = cmd_select.ExecuteReader();
    List<Dictionary<string, object>> valuePairs = new List<Dictionary<string, object>>();
    while (reader.Read())
    {
        Dictionary<string, object> pairs = new Dictionary<string, object>();
        for (int i = 0; i < reader.FieldCount; i++)
        {
            pairs.Add(reader.GetName(i), reader.GetValue(i));
        }
        valuePairs.Add(pairs);
    }
    Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(valuePairs));
    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());
    Console.ReadKey();
    connection.Close();
}
codedever commented 5 years ago

OK, restful api to ef.core is the first step, we still need more reliable and more efficient connection api from official.

maikebing commented 5 years ago
///Specify the name of the database
string database = "db_" + DateTime.Now.ToString("yyyyMMddHHmmss");
var builder = new TaosConnectionStringBuilder()
{
    DataSource = "http://td.gitclub.cn/rest/sql",
    DataBase = database,
    Username = "root",
    Password = "taosdata"
};
//Example for ADO.Net 
using (var connection = new TaosConnection(builder.ConnectionString))
{
    connection.Open();
    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 int);").ExecuteNonQuery());
    Console.WriteLine("insert into t values  {0}  ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ms")}', 10);").ExecuteNonQuery());
    Console.WriteLine("insert into t values  {0} ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss.ms")}', 20);").ExecuteNonQuery());
    Console.WriteLine("==================================================================");
    var cmd_select = connection.CreateCommand();
    cmd_select.CommandText = $"select * from {database}.t";
    var reader = cmd_select.ExecuteReader();
    ConsoleTableBuilder.From(reader.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine();
    Console.WriteLine("==================================================================");
    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.Close();
}
//Example for  Entity Framework Core  
using (var context = new TaosContext(new DbContextOptionsBuilder()
                                        .UseTaos(builder.ConnectionString).Options))
{
    Console.WriteLine("EnsureCreated");
    context.Database.EnsureCreated();
    for (int i = 0; i < 10; i++)
    {
        var rd = new Random();
        context.sensor.Add(new sensor() { ts = DateTime.Now.AddMilliseconds(i), degree = rd.NextDouble(), pm25 = rd.Next(0, 1000) });
    }
    Console.WriteLine("SaveChanges.....");
    context.SaveChanges();
    Console.WriteLine("==================================================================");
    Console.WriteLine("Search   pm25>0");
    var f = from s in context.sensor where s.pm25 > 0 select s;
    var ary = f.ToArray();
    ConsoleTableBuilder.From(ary.ToList()).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine();
    Console.WriteLine("==================================================================");
    context.Database.EnsureDeleted();
}
}
hzcheng commented 5 years ago

51