├── courgette.log
├── docker-compose.override.yml
├── docs
├── assets
│ ├── 1.png
│ ├── 2.png
│ └── 3.png
├── time_profile_zh.pdf
├── Apache IoTDB C#客户端介绍 (6).pdf
├── bytebuffer_zh.md
├── C#原生接口.md
├── session_pool_zh.md
└── API.md
├── .gitmodules
├── src
├── Apache.IoTDB.Data
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── IoTDBResult.cs
│ ├── Apache.IoTDB.Data.csproj
│ ├── IoTDBFactory.cs
│ ├── IoTDBException.cs
│ ├── DataReaderExtensions.cs
│ └── IoTDBTransaction.cs
└── Apache.IoTDB
│ ├── Rpc
│ └── Generated
│ │ ├── TSConnectionType.cs
│ │ ├── TConsensusGroupType.cs
│ │ ├── TSProtocolVersion.cs
│ │ ├── TRegionMigrateFailedType.cs
│ │ ├── common.Extensions.cs
│ │ ├── TSeriesPartitionSlot.cs
│ │ ├── TSCloseSessionReq.cs
│ │ ├── TTimePartitionSlot.cs
│ │ ├── TConsensusGroupId.cs
│ │ ├── TEndPoint.cs
│ │ ├── TNodeResource.cs
│ │ ├── TSCancelOperationReq.cs
│ │ ├── TSGetOperationStatusReq.cs
│ │ ├── TSConnectionInfoResp.cs
│ │ ├── TSchemaNode.cs
│ │ ├── TSSetTimeZoneReq.cs
│ │ ├── TSyncTransportMetaInfo.cs
│ │ ├── TFile.cs
│ │ ├── TSDropSchemaTemplateReq.cs
│ │ ├── TSGetTimeZoneResp.cs
│ │ ├── TDataNodeConfiguration.cs
│ │ ├── TSExecuteBatchStatementReq.cs
│ │ ├── TFilesResp.cs
│ │ ├── TSetTTLReq.cs
│ │ ├── TSPruneSchemaTemplateReq.cs
│ │ ├── TRegionReplicaSet.cs
│ │ └── TFlushReq.cs
│ ├── Apache.IoTDB.csproj
│ ├── Client.cs
│ ├── Template
│ ├── TemplateNode.cs
│ ├── InternalNode.cs
│ ├── MeasurementNode.cs
│ └── Template.cs
│ ├── Utils.cs
│ ├── IoTDBConstants.cs
│ ├── DataStructure
│ ├── GetSubArray.cs
│ ├── ArrayExtensions.cs
│ ├── BitMap.cs
│ └── ByteBuffer.cs
│ └── ConcurrentClientQueue.cs
├── samples
└── Apache.IoTDB.Samples
│ ├── Properties
│ └── launchSettings.json
│ ├── Program.cs
│ ├── Dockerfile
│ ├── Apache.IoTDB.Samples.csproj
│ └── SessionPoolTest.Template.cs
├── tests
├── Apache.IoTDB.Tests
│ ├── Tests.cs
│ └── Apache.IoTDB.Tests.csproj
└── Apache.IoTDB.Integration.Tests
│ ├── Tests.cs
│ └── Apache.IoTDB.Integration.Tests.csproj
├── launchSettings.json
├── .dockerignore
├── docker-compose.dcproj
├── .github
└── workflows
│ ├── dotnet.yml
│ └── e2e.yml
├── .gitignore
├── docker-compose.yml
├── README_ZH.md
├── README.md
└── PUBLISH.md
/courgette.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docker-compose.override.yml:
--------------------------------------------------------------------------------
1 | version: '3.4'
2 |
--------------------------------------------------------------------------------
/docs/assets/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eedalong/Apache-IoTDB-Client-CSharp/HEAD/docs/assets/1.png
--------------------------------------------------------------------------------
/docs/assets/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eedalong/Apache-IoTDB-Client-CSharp/HEAD/docs/assets/2.png
--------------------------------------------------------------------------------
/docs/assets/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eedalong/Apache-IoTDB-Client-CSharp/HEAD/docs/assets/3.png
--------------------------------------------------------------------------------
/docs/time_profile_zh.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eedalong/Apache-IoTDB-Client-CSharp/HEAD/docs/time_profile_zh.pdf
--------------------------------------------------------------------------------
/docs/Apache IoTDB C#客户端介绍 (6).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eedalong/Apache-IoTDB-Client-CSharp/HEAD/docs/Apache IoTDB C#客户端介绍 (6).pdf
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "Apache-IoTDB-Client-CSharp-UserCase"]
2 | path = Apache-IoTDB-Client-CSharp-UserCase
3 | url = git@github.com:eedalong/Apache-IoTDB-Client-CSharp-UserCase.git
4 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB.Data/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.CompilerServices;
4 | using System.Text;
5 | [assembly: InternalsVisibleTo("Apache.IoTDB.Tests")]
6 |
--------------------------------------------------------------------------------
/samples/Apache.IoTDB.Samples/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "Apache.IoTDB.Samples": {
4 | "commandName": "Project"
5 | },
6 | "Docker": {
7 | "commandName": "Docker"
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/tests/Apache.IoTDB.Tests/Tests.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 |
3 | namespace Apache.IoTDB.Tests
4 | {
5 | public class Tests
6 | {
7 | [SetUp]
8 | public void Setup()
9 | {
10 | }
11 |
12 | [Test]
13 | public void Test1()
14 | {
15 | Assert.Pass();
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/tests/Apache.IoTDB.Integration.Tests/Tests.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 |
3 | namespace Apache.IoTDB.Integration.Tests
4 | {
5 | public class Tests
6 | {
7 | [SetUp]
8 | public void Setup()
9 | {
10 | }
11 |
12 | [Test]
13 | public void Test1()
14 | {
15 | Assert.Pass();
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/src/Apache.IoTDB.Data/IoTDBResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Apache.IoTDB.Data
6 | {
7 | public class IoTDBErrorResult
8 | {
9 |
10 | public int Code { get; set; }
11 | ///
12 | ///
13 | ///
14 | public string Error { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "Docker Compose": {
4 | "commandName": "DockerCompose",
5 | "commandVersion": "1.0",
6 | "composeLaunchAction": "None",
7 | "composeLaunchServiceName": "apache.iotdb.samples",
8 | "serviceActions": {
9 | "apache.iotdb.samples": "StartDebugging",
10 | "iotdb": "StartWithoutDebugging"
11 | }
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | **/.classpath
2 | **/.dockerignore
3 | **/.env
4 | **/.git
5 | **/.gitignore
6 | **/.project
7 | **/.settings
8 | **/.toolstarget
9 | **/.vs
10 | **/.vscode
11 | **/*.*proj.user
12 | **/*.dbmdl
13 | **/*.jfm
14 | **/azds.yaml
15 | **/bin
16 | **/charts
17 | **/docker-compose*
18 | **/Dockerfile*
19 | **/node_modules
20 | **/npm-debug.log
21 | **/obj
22 | **/secrets.dev.yaml
23 | **/values.dev.yaml
24 | LICENSE
25 | README.md
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Rpc/Generated/TSConnectionType.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Autogenerated by Thrift Compiler (0.14.2)
3 | *
4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | * @generated
6 | */
7 |
8 | #pragma warning disable IDE0079 // remove unnecessary pragmas
9 | #pragma warning disable IDE1006 // parts of the code use IDL spelling
10 |
11 | public enum TSConnectionType
12 | {
13 | THRIFT_BASED = 0,
14 | MQTT_BASED = 1,
15 | INTERNAL = 2,
16 | }
17 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Rpc/Generated/TConsensusGroupType.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Autogenerated by Thrift Compiler (0.14.2)
3 | *
4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | * @generated
6 | */
7 |
8 | #pragma warning disable IDE0079 // remove unnecessary pragmas
9 | #pragma warning disable IDE1006 // parts of the code use IDL spelling
10 |
11 | public enum TConsensusGroupType
12 | {
13 | ConfigNodeRegion = 0,
14 | DataRegion = 1,
15 | SchemaRegion = 2,
16 | }
17 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Rpc/Generated/TSProtocolVersion.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Autogenerated by Thrift Compiler (0.14.2)
3 | *
4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | * @generated
6 | */
7 |
8 | #pragma warning disable IDE0079 // remove unnecessary pragmas
9 | #pragma warning disable IDE1006 // parts of the code use IDL spelling
10 |
11 | public enum TSProtocolVersion
12 | {
13 | IOTDB_SERVICE_PROTOCOL_V1 = 0,
14 | IOTDB_SERVICE_PROTOCOL_V2 = 1,
15 | IOTDB_SERVICE_PROTOCOL_V3 = 2,
16 | }
17 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Apache.IoTDB.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0;net6.0;netstandard2.1;netstandard2.0;net461
5 | latest
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Rpc/Generated/TRegionMigrateFailedType.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Autogenerated by Thrift Compiler (0.14.2)
3 | *
4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | * @generated
6 | */
7 |
8 | #pragma warning disable IDE0079 // remove unnecessary pragmas
9 | #pragma warning disable IDE1006 // parts of the code use IDL spelling
10 |
11 | public enum TRegionMigrateFailedType
12 | {
13 | AddPeerFailed = 0,
14 | RemovePeerFailed = 1,
15 | RemoveConsensusGroupFailed = 2,
16 | DeleteRegionFailed = 3,
17 | CreateRegionFailed = 4,
18 | }
19 |
--------------------------------------------------------------------------------
/docker-compose.dcproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 2.1
5 | Linux
6 | 4d457769-80cb-401f-9155-c3125c04facd
7 |
8 |
9 |
10 | docker-compose.yml
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Client.cs:
--------------------------------------------------------------------------------
1 | using Thrift.Transport;
2 |
3 | namespace Apache.IoTDB
4 | {
5 | public class Client
6 | {
7 | public IClientRPCService.Client ServiceClient { get; }
8 | public long SessionId { get; }
9 | public long StatementId { get; }
10 | public TFramedTransport Transport { get; }
11 |
12 | public Client(IClientRPCService.Client client, long sessionId, long statementId, TFramedTransport transport)
13 | {
14 | ServiceClient = client;
15 | SessionId = sessionId;
16 | StatementId = statementId;
17 | Transport = transport;
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/tests/Apache.IoTDB.Tests/Apache.IoTDB.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/Apache.IoTDB.Integration.Tests/Apache.IoTDB.Integration.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.github/workflows/dotnet.yml:
--------------------------------------------------------------------------------
1 | name: .NET
2 |
3 | on:
4 | push:
5 | branches: [ main, dev/* ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Setup .NET
17 | uses: actions/setup-dotnet@v1
18 | with:
19 | dotnet-version: 6.0.x
20 | - name: Restore dependencies
21 | run: dotnet restore "src/Apache.IoTDB/Apache.IoTDB.csproj"
22 | - name: Build
23 | run: dotnet build --no-restore "src/Apache.IoTDB/Apache.IoTDB.csproj"
24 | - name: Test
25 | run: dotnet test --no-build --verbosity normal "tests/Apache.IoTDB.Tests/Apache.IoTDB.Tests.csproj"
26 |
--------------------------------------------------------------------------------
/samples/Apache.IoTDB.Samples/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 | using NLog.Extensions.Logging;
3 | using System;
4 | using System.Threading.Tasks;
5 |
6 | namespace Apache.IoTDB.Samples
7 | {
8 | public static class Program
9 | {
10 | public static async Task Main(string[] args)
11 | {
12 | var sessionPoolTest = new SessionPoolTest("iotdb");
13 | await sessionPoolTest.Test() ;
14 | }
15 |
16 | public static void OpenDebugMode(this SessionPool session)
17 | {
18 | session.OpenDebugMode(builder =>
19 | {
20 | builder.AddConsole();
21 | builder.AddNLog();
22 | });
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/.github/workflows/e2e.yml:
--------------------------------------------------------------------------------
1 | name: E2E Tests
2 |
3 | on:
4 | push:
5 | branches: [ main, dev/* ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 |
11 | build:
12 | name: e2e test
13 | runs-on: ${{ matrix.os }}
14 | strategy:
15 | matrix:
16 | os: [ubuntu-latest]
17 | steps:
18 |
19 | - name: Check out code into the CSharp module directory
20 | uses: actions/checkout@v2
21 |
22 | - name: Set Docker & Run Test
23 | run: |
24 | docker network create --subnet 172.18.0.0/24 iotdb-network && docker-compose -f docker-compose.yml up --build --abort-on-container-exit --remove-orphans
25 |
26 | - name: Clean IoTDB & Shut Down Docker
27 | run: |
28 | docker-compose -f docker-compose.yml down
29 |
--------------------------------------------------------------------------------
/samples/Apache.IoTDB.Samples/Dockerfile:
--------------------------------------------------------------------------------
1 | #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
2 |
3 | FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
4 | WORKDIR /app
5 |
6 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
7 | WORKDIR /src
8 | COPY ["samples/Apache.IoTDB.Samples/Apache.IoTDB.Samples.csproj", "samples/Apache.IoTDB.Samples/"]
9 | COPY ["src/Apache.IoTDB/Apache.IoTDB.csproj", "src/Apache.IoTDB/"]
10 | COPY ["src/Apache.IoTDB.Data/Apache.IoTDB.Data.csproj", "src/Apache.IoTDB.Data/"]
11 | RUN dotnet restore "samples/Apache.IoTDB.Samples/Apache.IoTDB.Samples.csproj"
12 | COPY . .
13 | WORKDIR "/src/samples/Apache.IoTDB.Samples"
14 | RUN dotnet build "Apache.IoTDB.Samples.csproj" -c Release -o /app/build
15 |
16 | FROM build AS publish
17 | RUN dotnet publish "Apache.IoTDB.Samples.csproj" -c Release -o /app/publish
18 |
19 | FROM base AS final
20 | WORKDIR /app
21 | COPY --from=publish /app/publish .
22 | ENTRYPOINT ["dotnet", "Apache.IoTDB.Samples.dll"]
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Template/TemplateNode.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using Apache.IoTDB.DataStructure;
4 | namespace Apache.IoTDB
5 | {
6 | public abstract class TemplateNode
7 | {
8 | private string name;
9 | public TemplateNode(string name)
10 | {
11 | this.name = name;
12 | }
13 | public string Name
14 | {
15 | get
16 | {
17 | return name;
18 | }
19 | }
20 |
21 | public virtual Dictionary getChildren()
22 | {
23 | return null;
24 | }
25 |
26 | public virtual void addChild(TemplateNode node) { }
27 | public virtual void deleteChild(TemplateNode node) { }
28 | public virtual bool isMeasurement()
29 | {
30 | return false;
31 | }
32 | public virtual bool isShareTime()
33 | {
34 | return false;
35 | }
36 | public virtual byte[] ToBytes()
37 | {
38 | return null;
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Apache.IoTDB.Data/Apache.IoTDB.Data.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Apache.IoTDB.Data
5 | $(AssemblyName)
6 | Apache.IoTDB.Data
7 |
8 | IoTDB implementation of the System.Data.Common provider model.
9 | Commonly Used Types:
10 | Apache.IoTDB.Data.IoTDBCommand
11 | Apache.IoTDB.Data.IoTDBConnection
12 | Apache.IoTDB.Data.IoTDBConnectionStringBuilder
13 | Apache.IoTDB.Data.IoTDBDataReader
14 | Apache.IoTDB.Data.IoTDBException
15 | Apache.IoTDB.Data.IoTDBFactory
16 | Apache.IoTDB.Data.IoTDBParameter
17 | Apache.IoTDB.Data.IoTDBTransaction
18 |
19 | net5.0;net6.0;netstandard2.1;netstandard2.0;net461
20 | 10
21 | Apache.IoTDB.Data是一个IoTDB的ADO.Net 提供器。这将允许你通过.Net访问IoTDB数据库。
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Utils.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace Apache.IoTDB
5 | {
6 | public class Utils
7 | {
8 | public bool IsSorted(IList collection)
9 | {
10 | for (var i = 1; i < collection.Count; i++)
11 | {
12 | if (collection[i] < collection[i - 1])
13 | {
14 | return false;
15 | }
16 | }
17 |
18 | return true;
19 | }
20 |
21 | public int VerifySuccess(TSStatus status, int successCode, int redirectRecommendCode)
22 | {
23 | if (status.__isset.subStatus)
24 | {
25 | if (status.SubStatus.Any(subStatus => VerifySuccess(subStatus, successCode, redirectRecommendCode) != 0))
26 | {
27 | return -1;
28 | }
29 |
30 | return 0;
31 | }
32 |
33 | if (status.Code == successCode || status.Code == redirectRecommendCode)
34 | {
35 | return 0;
36 | }
37 |
38 | return -1;
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/samples/Apache.IoTDB.Samples/Apache.IoTDB.Samples.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | Linux
7 | ..\..
8 |
9 |
10 |
11 | default
12 |
13 |
14 |
15 | default
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # User-specific files
2 | *.rsuser
3 | *.suo
4 | *.user
5 | *.userosscache
6 | *.sln.docstates
7 | **/tmp
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Dd]ebugPublic/
12 | [Rr]elease/
13 | [Rr]eleases/
14 | x64/
15 | x86/
16 | [Ww][Ii][Nn]32/
17 | [Aa][Rr][Mm]/
18 | [Aa][Rr][Mm]64/
19 | bld/
20 | [Bb]in/
21 | [Oo]bj/
22 | [Ll]og/
23 | [Ll]ogs/
24 |
25 | # MSTest test Results
26 | [Tt]est[Rr]esult*/
27 | [Bb]uild[Ll]og.*
28 |
29 | # NUnit
30 | *.VisualState.xml
31 | TestResult.xml
32 | nunit-*.xml
33 |
34 | # Build Results of an ATL Project
35 | [Dd]ebugPS/
36 | [Rr]eleasePS/
37 | dlldata.c
38 |
39 | # .NET Core
40 | project.lock.json
41 | project.fragment.lock.json
42 | artifacts/
43 |
44 | # StyleCop
45 | StyleCopReport.xml
46 |
47 |
48 | # ReSharper is a .NET coding add-in
49 | _ReSharper*/
50 | *.[Rr]e[Ss]harper
51 | *.DotSettings.user
52 |
53 | # DotCover is a Code Coverage Tool
54 | *.dotCove
55 |
56 | # Click-Once directory
57 | publish/
58 |
59 | ### VisualStudioCode ###
60 | .vscode/*
61 | !.vscode/settings.json
62 | !.vscode/tasks.json
63 | !.vscode/launch.json
64 | !.vscode/extensions.json
65 | *.code-workspace
66 |
67 |
68 | ### Rider ###
69 | .idea
70 | /.vs/Apache.IoTDB/FileContentIndex
71 | /.vs/ProjectEvaluation
72 | /.vs/Apache.IoTDB
73 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Template/InternalNode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Thrift;
4 |
5 | namespace Apache.IoTDB
6 | {
7 | public class InternalNode : TemplateNode
8 | {
9 | private Dictionary children;
10 | private bool shareTime;
11 | public InternalNode(string name, bool shareTime) : base(name)
12 | {
13 | this.children = new Dictionary();
14 | this.shareTime = shareTime;
15 | }
16 | public override void addChild(TemplateNode node)
17 | {
18 | if (this.children.ContainsKey(node.Name))
19 | {
20 | throw new Exception("Duplicated child of node in template.");
21 | }
22 | this.children.Add(node.Name, node);
23 | }
24 |
25 | public override void deleteChild(TemplateNode node)
26 | {
27 | if (this.children.ContainsKey(node.Name))
28 | {
29 | this.children.Remove(node.Name);
30 | }
31 | }
32 |
33 | public override Dictionary getChildren()
34 | {
35 | return this.children;
36 | }
37 | public override bool isShareTime()
38 | {
39 | return this.shareTime;
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Apache.IoTDB/Template/MeasurementNode.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using Apache.IoTDB;
3 | using Apache.IoTDB.DataStructure;
4 |
5 | namespace Apache.IoTDB
6 | {
7 | public class MeasurementNode : TemplateNode
8 | {
9 | private TSDataType dataType;
10 | private TSEncoding encoding;
11 | private Compressor compressor;
12 | public MeasurementNode(string name, TSDataType dataType, TSEncoding encoding, Compressor compressor) : base(name)
13 | {
14 | this.dataType = dataType;
15 | this.encoding = encoding;
16 | this.compressor = compressor;
17 | }
18 | public override bool isMeasurement()
19 | {
20 | return true;
21 | }
22 | public TSDataType DataType
23 | {
24 | get
25 | {
26 | return dataType;
27 | }
28 | }
29 | public TSEncoding Encoding
30 | {
31 | get
32 | {
33 | return encoding;
34 | }
35 | }
36 | public Compressor Compressor
37 | {
38 | get
39 | {
40 | return compressor;
41 | }
42 | }
43 |
44 | public override byte[] ToBytes()
45 | {
46 | var buffer = new ByteBuffer();
47 | buffer.AddStr(this.Name);
48 | buffer.AddByte((byte)this.DataType);
49 | buffer.AddByte((byte)this.Encoding);
50 | buffer.AddByte((byte)this.Compressor);
51 | return buffer.GetBuffer();
52 | }
53 |
54 |
55 |
56 | }
57 | }
--------------------------------------------------------------------------------
/src/Apache.IoTDB.Data/IoTDBFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Common;
2 |
3 | namespace Apache.IoTDB.Data
4 | {
5 | ///
6 | /// Creates instances of various Maikebing.Data.IoTDB classes.
7 | ///
8 | public class IoTDBFactory : DbProviderFactory
9 | {
10 | private IoTDBFactory()
11 | {
12 | }
13 |
14 | ///
15 | /// The singleton instance.
16 | ///
17 | public static readonly IoTDBFactory Instance = new IoTDBFactory();
18 |
19 | ///
20 | /// Creates a new command.
21 | ///
22 | /// The new command.
23 | public override DbCommand CreateCommand()
24 | => new IoTDBCommand();
25 |
26 | ///
27 | /// Creates a new connection.
28 | ///
29 | /// The new connection.
30 | public override DbConnection CreateConnection()
31 | => new IoTDBConnection();
32 |
33 | ///
34 | /// Creates a new connection string builder.
35 | ///
36 | /// The new connection string builder.
37 | public override DbConnectionStringBuilder CreateConnectionStringBuilder()
38 | => new IoTDBConnectionStringBuilder();
39 |
40 | ///
41 | /// Creates a new parameter.
42 | ///
43 | /// The new parameter.
44 | public override DbParameter CreateParameter()
45 | => new IoTDBParameter();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3.4'
2 |
3 | services:
4 | apache.iotdb.samples:
5 | image: ${DOCKER_REGISTRY-}apacheiotdbsamples
6 | depends_on:
7 | iotdb:
8 | condition: service_healthy
9 | links:
10 | - iotdb
11 | build:
12 | context: .
13 | dockerfile: samples/Apache.IoTDB.Samples/Dockerfile
14 | networks:
15 | iotdb-network:
16 | ipv4_address: 172.18.0.2
17 |
18 | iotdb:
19 | image: apache/iotdb:1.0.0-datanode
20 | restart: always
21 | container_name: iotdb-dn-1
22 | depends_on:
23 | iotdb-confignode-1:
24 | condition: service_healthy
25 | healthcheck:
26 | test: ["CMD", "ls", "/iotdb/data"]
27 | interval: 3s
28 | timeout: 5s
29 | retries: 30
30 | start_period: 30s
31 | ports:
32 | - 6667:6667
33 | networks:
34 | iotdb-network:
35 | ipv4_address: 172.18.0.3
36 | environment:
37 | - dn_rpc_address=iotdb
38 | - dn_internal_address=iotdb
39 | - dn_target_config_node_list=iotdb-confignode-1:22277
40 |
41 | iotdb-confignode-1:
42 | image: apache/iotdb:1.0.0-confignode
43 | restart: always
44 | container_name: iotdb-cn-1
45 | healthcheck:
46 | test: ["CMD", "ls", "/iotdb/data"]
47 | interval: 3s
48 | timeout: 5s
49 | retries: 30
50 | start_period: 30s
51 | networks:
52 | iotdb-network:
53 | ipv4_address: 172.18.0.4
54 | environment:
55 | - cn_internal_address=iotdb-confignode-1
56 | - cn_target_config_node_list=iotdb-confignode-1:22277
57 |
58 |
59 | networks:
60 | iotdb-network:
61 | external: true
--------------------------------------------------------------------------------
/src/Apache.IoTDB/IoTDBConstants.cs:
--------------------------------------------------------------------------------
1 | namespace Apache.IoTDB
2 | {
3 | public enum TSDataType
4 | {
5 | BOOLEAN,
6 | INT32,
7 | INT64,
8 | FLOAT,
9 | DOUBLE,
10 | TEXT,
11 |
12 | // default value must be 0
13 | NONE
14 | }
15 |
16 | public enum TSEncoding
17 | {
18 | PLAIN,
19 | PLAIN_DICTIONARY,
20 | RLE,
21 | DIFF,
22 | TS_2DIFF,
23 | BITMAP,
24 | GORILLA_V1,
25 | REGULAR,
26 | GORILLA,
27 |
28 | // default value must be 0
29 | NONE
30 | }
31 |
32 | public enum Compressor
33 | {
34 | UNCOMPRESSED,
35 | SNAPPY,
36 | GZIP,
37 | LZO,
38 | SDT,
39 | PAA,
40 | PLA,
41 | LZ4
42 | }
43 | public enum TemplateQueryType
44 | {
45 | COUNT_MEASUREMENTS,
46 | IS_MEASUREMENT,
47 | PATH_EXIST,
48 | SHOW_MEASUREMENTS,
49 | SHOW_TEMPLATES,
50 | SHOW_SET_TEMPLATES,
51 | SHOW_USING_TEMPLATES
52 | }
53 | public class TsFileConstant
54 | {
55 |
56 | public static string TSFILE_SUFFIX = ".tsfile";
57 | public static string TSFILE_HOME = "TSFILE_HOME";
58 | public static string TSFILE_CONF = "TSFILE_CONF";
59 | public static string PATH_ROOT = "root";
60 | public static string TMP_SUFFIX = "tmp";
61 | public static string PATH_SEPARATOR = ".";
62 | public static char PATH_SEPARATOR_CHAR = '.';
63 | public static string PATH_SEPARATER_NO_REGEX = "\\.";
64 | public static char DOUBLE_QUOTE = '"';
65 |
66 | public static byte TIME_COLUMN_MASK = (byte)0x80;
67 | public static byte VALUE_COLUMN_MASK = (byte)0x40;
68 |
69 | private TsFileConstant() { }
70 | }
71 | }
--------------------------------------------------------------------------------
/src/Apache.IoTDB/DataStructure/GetSubArray.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 | #if NET461_OR_GREATER || NETSTANDARD2_0
5 | //https://github.com/bgrainger/IndexRange
6 | //https://gist.github.com/bgrainger/fb2c18659c2cdfce494c82a8c4803360
7 |
8 | namespace System.Runtime.CompilerServices
9 | {
10 | internal static class RuntimeHelpers
11 | {
12 | ///
13 | /// Slices the specified array using the specified range.
14 | ///
15 | public static T[] GetSubArray(T[] array, Range range)
16 | {
17 | if (array == null)
18 | {
19 | throw new ArgumentNullException();
20 | }
21 |
22 | (int offset, int length) = range.GetOffsetAndLength(array.Length);
23 |
24 | if (default(T)! != null || typeof(T[]) == array.GetType()) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
25 | {
26 | // We know the type of the array to be exactly T[].
27 |
28 | if (length == 0)
29 | {
30 | return Array.Empty();
31 | }
32 |
33 | var dest = new T[length];
34 | Array.Copy(array, offset, dest, 0, length);
35 | return dest;
36 | }
37 | else
38 | {
39 | // The array is actually a U[] where U:T.
40 | T[] dest = (T[])Array.CreateInstance(array.GetType().GetElementType()!, length);
41 | Array.Copy(array, offset, dest, 0, length);
42 | return dest;
43 | }
44 | }
45 | }
46 | }
47 | #endif
--------------------------------------------------------------------------------
/README_ZH.md:
--------------------------------------------------------------------------------
1 |
21 | [English](./README.md) | [中文](./README_ZH.md)
22 |
23 | # Apache IoTDB C#语言客户端
24 |
25 | ## 概览
26 |
27 | 本仓库是Apache IoTDB的C#语言客户端,与其他语言支持相同语义的用户接口。
28 |
29 | Apache IoTDB website: https://iotdb.apache.org
30 |
31 | Apache IoTDB Github: https://github.com/apache/iotdb
32 |
33 | ## 如何安装
34 | ### 从NuGet Package安装
35 |
36 | 我们为CSharp用户准备了NuGet包,用户可直接通过.NET CLI进行客户端安装,[NuGet包链接如下](https://www.nuget.org/packages/Apache.IoTDB/),命令行中运行如下命令即可完成安装
37 |
38 | ```sh
39 | dotnet add package Apache.IoTDB
40 | ```
41 |
42 | 请注意,`Apache.IoTDB`这个包仅支持大于`.net framework 4.6.1`的版本。
43 | ## 环境准备
44 |
45 | .NET SDK Version >= 5.0
46 | .NET Framework >= 4.6.1
47 |
48 | ## 如何使用 (快速上手)
49 | 用户可参考[使用样例](https://github.com/eedalong/Apache-IoTDB-Client-CSharp-UserCase)中的测试代码了解各个接口使用方式
50 |
51 |
52 | ## iotdb-client-csharp的开发者环境要求
53 | .NET SDK Version >= 5.0
54 | .NET Framework >= 4.6.1
55 | ApacheThrift >= 0.14.1
56 | NLog >= 4.7.9
57 |
58 |
59 | ### 操作系统
60 |
61 | * Linux、Macos或其他类unix系统
62 | * Windows+bash(WSL、cygwin、Git Bash)
63 |
64 | ### 命令行工具
65 |
66 | ## 在 nuget.org 上发布你自己的客户端
67 | 你可以在这个[文档](./PUBLISH.md)中找到如何发布
--------------------------------------------------------------------------------
/docs/bytebuffer_zh.md:
--------------------------------------------------------------------------------
1 | ## IoTDB CSharp Client ByteBuffer实现介绍
2 | 在进行`RowRecords`以及`Tablet`的插入时,我们需要对多行RowRecord和Tablet进行序列化以进行发送。客户端中的序列化实现主要依赖于ByteBuffer完成。接下来我们介绍ByteBuffer的实现细节。本文包含如下几点内容:
3 | - 序列化的协议
4 | - C#与Java的大小端的差异
5 | - ByteBuffer内存倍增算法
6 |
7 | ### 一、序列化协议
8 | 客户端向IoTDB服务器发送的序列化数据总体应该包含两个信息。
9 | - 数据类型
10 | - 数据本身
11 |
12 | 其中对于`字符串`的序列化时,我们需要再加入字符串的长度信息。即一个字符串的序列化完整结果为:
13 |
14 | [类型][长度][数据内容]
15 | 接下来我们分别介绍`RowRecord`、`Tablet`的序列化方式
16 |
17 | #### 1.1 RowRecord
18 | 我们对RowRecord进行序列化时,`伪代码`如下:
19 |
20 | public byte[] value_to_bytes(List data_types, List values){
21 | ByteBuffer buffer = new ByteBuffer(values.Count);
22 | for(int i = 0;i < data_types.Count(); i++){
23 | buffer.add_type((data_types[i]);
24 | buffer.add_val(values[i]);
25 | }
26 | }
27 |
28 | 对于其序列化的结果格式如下:
29 |
30 | [数据类型1][数据1][数据类型2][数据2]...[数据类型N][数据N]
31 | 其中数据类型为自定义的`Enum`变量,分别如下:
32 |
33 | public enum TSDataType{BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT, NONE};
34 |
35 | #### 1.2. Tablet序列化
36 | 使用`Tabelt`进行数据插入时有如下限制:
37 |
38 | 限制:Tablet中数据不能有空值
39 | 由于向 `IoTDB`服务器发送`Tablet`数据插入请求时会携带`行数`, `列数`, `列数据类型`,所以`Tabelt`序列化时我们不需要加入数据类型信息。`Tablet`是`按照列进行序列化`,这是因为后端可以通过行数得知出当前列的元素个数,同时根据列类型来对数据进行解析。
40 |
41 | ## CSharp与Java序列化数据时的大小端差异
42 | 由于Java序列化默认大端协议,而CSharp序列化默认得到小端序列。所以我们在CSharp中序列化数据之后,需要对数据进行反转这样后端才可以正常解析。同时当我们从后端获取到序列化的结果时(如`SessionDataset`),我们也需要对获得的数据进行反转以解析内容。这其中特例便是字符串的序列化,CSharp中对字符串的序列化结果为大端序,所以序列化字符串或者接收到字符串序列化结果时,不需要反转序列结果。
43 |
44 | ## ByteBuffer内存倍增法
45 | 拥有数万行的Tablet的序列化结果可能有上百兆,为了能够高效的实现大`Tablet`的序列化,我们对ByteBuffer使用`内存倍增法`的策略来减少序列化过程中对于内存的申请和释放。即当当前的buffer的长度不足以放下序列化结果时,我们将当前buffer的内存`至少`扩增2倍。这极大的减少了内存的申请释放次数,加速了大Tablet的序列化速度。
46 |
47 | private void extend_buffer(int space_need){
48 | if(write_pos + space_need >= total_length){
49 | total_length = max(space_need, total_length);
50 | byte[] new_buffer = new byte[total_length * 2];
51 | buffer.CopyTo(new_buffer, 0);
52 | buffer = new_buffer;
53 | total_length = 2 * total_length;
54 | }
55 | }
56 | 同时在序列化`Tablet`时,我们首先根据Tablet的`行数`,`列数`以及每一列的数据类型估计当前`Tablet`序列化结果所需要的内存大小,并在初始化时进行内存的申请。这进一步的减少了内存的申请释放频率。
57 |
58 | 通过上述的策略,我们在一个有`20000`行的Tablet上进行测试时,序列化速度相比Naive数组长度动态生长实现算法具有约35倍的性能加速。
59 |
60 |
--------------------------------------------------------------------------------
/src/Apache.IoTDB/ConcurrentClientQueue.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Collections.Generic;
4 | using System.Diagnostics;
5 | using System.Threading;
6 |
7 | namespace Apache.IoTDB
8 | {
9 | public class ConcurrentClientQueue
10 | {
11 | public ConcurrentQueue ClientQueue { get; }
12 |
13 | public ConcurrentClientQueue(List clients)
14 | {
15 | ClientQueue = new ConcurrentQueue(clients);
16 | }
17 | public ConcurrentClientQueue()
18 | {
19 | ClientQueue = new ConcurrentQueue();
20 | }
21 | public void Add(Client client) => Return(client);
22 |
23 | public void Return(Client client)
24 | {
25 | Monitor.Enter(ClientQueue);
26 | ClientQueue.Enqueue(client);
27 | Monitor.PulseAll(ClientQueue); // wake up all threads waiting on the queue, refresh the waiting time
28 | Monitor.Exit(ClientQueue);
29 | Thread.Sleep(0);
30 | }
31 | int _ref = 0;
32 | public void AddRef()
33 | {
34 | lock (this)
35 | {
36 | _ref++;
37 | }
38 | }
39 | public int GetRef()
40 | {
41 | return _ref;
42 | }
43 | public void RemoveRef()
44 | {
45 | lock (this)
46 | {
47 | _ref--;
48 | }
49 | }
50 | public int Timeout { get; set; } = 10;
51 | public Client Take()
52 | {
53 | Client client = null;
54 | Monitor.Enter(ClientQueue);
55 | while(true){
56 | bool timeout = false;
57 | if (ClientQueue.IsEmpty)
58 | {
59 | timeout = !Monitor.Wait(ClientQueue, TimeSpan.FromSeconds(Timeout));
60 | }
61 | ClientQueue.TryDequeue(out client);
62 |
63 | if(client != null || timeout){
64 | break;
65 | }
66 | }
67 | Monitor.Exit(ClientQueue);
68 | if (client == null)
69 | {
70 | throw new TimeoutException($"Connection pool is empty and wait time out({Timeout}s)!");
71 | }
72 | return client;
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/src/Apache.IoTDB.Data/IoTDBException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data.Common;
3 |
4 |
5 | namespace Apache.IoTDB.Data
6 | {
7 | ///
8 | /// Represents a IoTDB error.
9 | ///
10 | public class IoTDBException : DbException
11 | {
12 | IoTDBErrorResult _IoTDBError;
13 |
14 | public IoTDBException(IoTDBErrorResult IoTDBError) : base(IoTDBError.Error, null)
15 | {
16 | _IoTDBError = IoTDBError;
17 | base.HResult = _IoTDBError.Code;
18 | }
19 |
20 | public IoTDBException(IoTDBErrorResult IoTDBError, Exception ex) : base(IoTDBError.Error, ex)
21 | {
22 | _IoTDBError = IoTDBError;
23 | base.HResult = _IoTDBError.Code;
24 | }
25 |
26 |
27 |
28 |
29 |
30 | public override string Message => _IoTDBError?.Error;
31 | public override int ErrorCode => (int) _IoTDBError?.Code;
32 | ///
33 | /// Throws an exception with a specific IoTDB error code value.
34 | ///
35 | /// The IoTDB error code corresponding to the desired exception.
36 | /// A handle to database connection.
37 | ///
38 | /// No exception is thrown for non-error result codes.
39 | ///
40 | public static void ThrowExceptionForRC(string _commandText, IoTDBErrorResult IoTDBError)
41 | {
42 | var te = new IoTDBException(IoTDBError);
43 | te.Data.Add("commandText", _commandText);
44 | throw te;
45 | }
46 | public static void ThrowExceptionForRC( IoTDBErrorResult IoTDBError)
47 | {
48 | var te = new IoTDBException(IoTDBError);
49 | throw te;
50 | }
51 | public static void ThrowExceptionForRC(IntPtr _IoTDB)
52 | {
53 | var te = new IoTDBException(new IoTDBErrorResult() { });
54 | throw te;
55 | }
56 | public static void ThrowExceptionForRC(int code, string message, Exception ex)
57 | {
58 | var te = new IoTDBException(new IoTDBErrorResult() { Code = code, Error = message }, ex);
59 | throw te;
60 | }
61 | public static void ThrowExceptionForRC(int code, string message)
62 | {
63 | var te = new IoTDBException(new IoTDBErrorResult() { Code = code, Error = message });
64 | throw te;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
21 | [English](./README.md) | [中文](./README_ZH.md)
22 |
23 | # Apache IoTDB Client for C#
24 |
25 | ## Overview
26 |
27 | This is the C# client of Apache IoTDB.
28 |
29 | [Apache IoTDB](https://iotdb.apache.org) (Internet of Things Database) is a data management system for time series data, which can provide users specific services, such as, data collection, storage and analysis. Due to its light weight structure, high performance and usable features together with its seamless integration with the Hadoop and Spark ecology, IoTDB meets the requirements of massive dataset storage, high throughput data input, and complex data analysis in the industrial IoT field.
30 |
31 | Apache IoTDB website: https://iotdb.apache.org
32 | Apache IoTDB Github: https://github.com/apache/iotdb
33 |
34 | ## Installation
35 |
36 | ### Install from NuGet Package
37 |
38 | We have prepared Nuget Package for C# users. Users can directly install the client through .NET CLI. [The link of our NuGet Package is here](https://www.nuget.org/packages/Apache.IoTDB/). Run the following command in the command line to complete installation
39 |
40 | ```sh
41 | dotnet add package Apache.IoTDB
42 | ```
43 |
44 | Note that the `Apache.IoTDB` package only supports versions greater than `.net framework 4.6.1`.(#starting-from-net-framework-4x).
45 |
46 | ## Prerequisites
47 |
48 | .NET SDK Version >= 5.0
49 | .NET Framework >= 4.6.1
50 |
51 | ## How to Use the Client (Quick Start)
52 |
53 | Users can refer to the test code in [tests](https://github.com/eedalong/Apache-IoTDB-Client-CSharp-UserCase) to understand the usage mode of each interface.
54 |
55 | ## Developer environment requirements for iotdb-client-csharp
56 |
57 | ```
58 | .NET SDK Version >= 5.0
59 | .NET Framework >= 4.6.1
60 | ApacheThrift >= 0.14.1
61 | NLog >= 4.7.9
62 | ```
63 |
64 | ### OS
65 |
66 | * Linux, Macos or other unix-like OS
67 | * Windows+bash(WSL, cygwin, Git Bash)
68 |
69 | ### Command Line Tools
70 |
71 | ## Publish your own client on nuget.org
72 | You can find out how to publish from this [doc](./PUBLISH.md).
--------------------------------------------------------------------------------
/src/Apache.IoTDB/DataStructure/ArrayExtensions.cs:
--------------------------------------------------------------------------------
1 | #if NET461_OR_GREATER || NETSTANDARD2_0
2 | //https://github.com/Grax32/ArrayExtensions/blob/master/docs/index.md
3 |
4 | using System;
5 | namespace Grax32.Extensions
6 | {
7 | public static class ArrayExtensions
8 | {
9 | public static void Fill(this T[] destinationArray, T value)
10 | {
11 | if (destinationArray == null)
12 | {
13 | throw new ArgumentNullException(nameof(destinationArray));
14 | }
15 |
16 | destinationArray[0] = value;
17 | FillInternal(destinationArray, 1);
18 | }
19 |
20 | public static void Fill(this T[] destinationArray, T[] values)
21 | {
22 | if (destinationArray == null)
23 | {
24 | throw new ArgumentNullException(nameof(destinationArray));
25 | }
26 |
27 | var copyLength = values.Length;
28 | var destinationArrayLength = destinationArray.Length;
29 |
30 | if (copyLength == 0)
31 | {
32 | throw new ArgumentException("Parameter must contain at least one value.", nameof(values));
33 | }
34 |
35 | if (copyLength > destinationArrayLength)
36 | {
37 | // value to copy is longer than destination,
38 | // so fill destination with first part of value
39 | Array.Copy(values, destinationArray, destinationArrayLength);
40 | return;
41 | }
42 |
43 | Array.Copy(values, destinationArray, copyLength);
44 |
45 | FillInternal(destinationArray, copyLength);
46 | }
47 |
48 | private static void FillInternal(this T[] destinationArray, int copyLength)
49 | {
50 | var destinationArrayLength = destinationArray.Length;
51 | var destinationArrayHalfLength = destinationArrayLength / 2;
52 |
53 | // looping copy from beginning of array to current position
54 | // doubling copy length with each pass
55 | for (; copyLength < destinationArrayHalfLength; copyLength *= 2)
56 | {
57 | Array.Copy(
58 | sourceArray: destinationArray,
59 | sourceIndex: 0,
60 | destinationArray: destinationArray,
61 | destinationIndex: copyLength,
62 | length: copyLength);
63 | }
64 |
65 | // we're past halfway, meaning only a single copy remains
66 | // exactly fill remainder of array
67 | Array.Copy(
68 | sourceArray: destinationArray,
69 | sourceIndex: 0,
70 | destinationArray: destinationArray,
71 | destinationIndex: copyLength,
72 | length: destinationArrayLength - copyLength);
73 | }
74 | }
75 | }
76 | #endif
--------------------------------------------------------------------------------
/src/Apache.IoTDB.Data/DataReaderExtensions.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel.DataAnnotations.Schema;
5 | using System.Data;
6 | using System.Data.Common;
7 | using System.Linq;
8 | using System.Runtime.InteropServices;
9 | using System.Text;
10 |
11 | namespace Apache.IoTDB.Data
12 | {
13 | public static class DataReaderExtensions
14 | {
15 | public static SessionPool CreateSession(this IoTDBConnectionStringBuilder db)
16 | {
17 | return new SessionPool(db.DataSource, db.Port, db.Username, db.Password, db.FetchSize, db.ZoneId, db.PoolSize,db.Compression,db.TimeOut);
18 | }
19 |
20 | public static List ToObject(this IDataReader dataReader)
21 | {
22 | List jArray = new List();
23 | try
24 | {
25 | var t = typeof(T);
26 | var pots = t.GetProperties();
27 | while (dataReader.Read())
28 | {
29 | T jObject = Activator.CreateInstance();
30 | for (int i = 0; i < dataReader.FieldCount; i++)
31 | {
32 | try
33 | {
34 | string strKey = dataReader.GetName(i);
35 | if (dataReader[i] != DBNull.Value)
36 | {
37 | var pr = from p in pots where (p.Name == strKey || p.ColumnNameIs(strKey)) && p.CanWrite select p;
38 | if (pr.Any())
39 | {
40 | var pi = pr.FirstOrDefault();
41 | pi.SetValue(jObject, Convert.ChangeType(dataReader[i], pi.PropertyType));
42 | }
43 | }
44 | }
45 | catch (Exception)
46 | {
47 |
48 | }
49 | }
50 | jArray.Add(jObject);
51 | }
52 | }
53 | catch (Exception ex)
54 | {
55 | IoTDBException.ThrowExceptionForRC(-10002, $"ToObject<{nameof(T)}> Error", ex);
56 | }
57 | return jArray;
58 | }
59 |
60 | internal static bool ColumnNameIs(this System.Reflection.PropertyInfo p, string strKey)
61 | {
62 | return (p.IsDefined(typeof(ColumnAttribute), true) && (p.GetCustomAttributes(typeof(ColumnAttribute), true) as ColumnAttribute[])?.FirstOrDefault().Name == strKey);
63 | }
64 |
65 |
66 | public static DataTable ToDataTable(this IDataReader reader)
67 | {
68 | var dt = new DataTable();
69 | try
70 | {
71 |
72 | dt.Load(reader, LoadOption.OverwriteChanges, (object sender, FillErrorEventArgs e) =>
73 | {
74 |
75 | });
76 | }
77 | catch (Exception)
78 | {
79 |
80 |
81 | }
82 | return dt;
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/docs/C#原生接口.md:
--------------------------------------------------------------------------------
1 | # C# 原生接口
2 |
3 | ## 依赖
4 |
5 | - .NET SDK >= 5.0 或 .NET Framework 4.x
6 | - ApacheThrift >= 0.14.1
7 | - NLog >= 4.7.9
8 |
9 | ## 安装
10 |
11 | 您可以使用 NuGet Package Manager, .NET CLI等工具来安装,以 .NET CLI为例
12 |
13 | 如果您使用的是.NET 5.0 或者更高版本的SDK,输入如下命令即可安装最新的NuGet包
14 |
15 | ```
16 | dotnet add package Apache.IoTDB
17 | ```
18 |
19 | 为了适配 .NET Framework 4.x,我们单独构建了一个NuGet包,如果您使用的是.NET Framework 4.x,输入如下命令即可安装最新的包
20 |
21 | ```bash
22 | dotnet add package Apache.IoTDB.framework
23 | ```
24 |
25 | 如果您想安装更早版本的客户端,只需要指定版本即可
26 |
27 | ```bash
28 | # 安装0.12.1.2版本的客户端
29 | dotnet add package Apache.IoTDB --version 0.12.1.2
30 | ```
31 |
32 | ## 基本接口说明
33 |
34 | Session接口在语义上和其他语言客户端相同
35 |
36 | ```c#
37 | // 参数定义
38 | string host = "localhost";
39 | int port = 6667;
40 | int pool_size = 2;
41 |
42 | // 初始化session
43 | var session_pool = new SessionPool(host, port, pool_size);
44 |
45 | // 开启session
46 | await session_pool.Open(false);
47 |
48 | // 创建时间序列
49 | await session_pool.CreateTimeSeries("root.test_group.test_device.ts1", TSDataType.TEXT, TSEncoding.PLAIN, Compressor.UNCOMPRESSED);
50 | await session_pool.CreateTimeSeries("root.test_group.test_device.ts2", TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.UNCOMPRESSED);
51 | await session_pool.CreateTimeSeries("root.test_group.test_device.ts3", TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED);
52 |
53 | // 插入record
54 | var measures = new List{"ts1", "ts2", "ts3"};
55 | var values = new List