Skip to content

Commit 6d57ab6

Browse files
committed
update src with build date 2022.05.20
1 parent 565e453 commit 6d57ab6

File tree

132 files changed

+21874
-861
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+21874
-861
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ To run DolphinDB script in C#:
6060
conn.run("<SCRIPT>");
6161
```
6262

63-
Note that the maximum allowed length of the script is 65,535 bytes.
64-
6563
If the script contains only one statement, such as an expression, DolphinDB returns the result of the statement. If the script contains more than one statement, the result of the last statement will be returned. If the script contains an error or there is a network problem, it throws an IOException.
6664

6765
### 4. Call DolphinDB functions
@@ -245,7 +243,7 @@ public void test_save_TableInsert(string[] strArray, int[] intArray, long[] tsAr
245243
}
246244
```
247245

248-
The example above uses partial application in DolphinDB to embed a table in `tableInsert{sharedTable}` as a function. For details about partial application, please refer to [Partial Application Documentation](https://www.dolphindb.com/help/PartialApplication.html).
246+
The example above uses partial application in DolphinDB to embed a table in `tableInsert{sharedTable}` as a function. For details about partial application, please refer to [Partial Application Documentation](https://www.dolphindb.com/help/Functionalprogramming/PartialApplication.html).
249247

250248
##### 7.1.3 Use function `tableInsert` to save a table object
251249
```
@@ -344,7 +342,7 @@ C# API provides objects that correspond to DolphinDB data types. They are usuall
344342
The majority of DolphinDB data types can be constructed from corresponding C# data types. For examples, INT in DolphinDB from 'new BasicInt(4)', DOUBLE in DolphinDB from 'new BasicDouble(1.23)'. The following DolphinDB data types, however, need to be constructed in different ways:
345343
- CHAR type: as the CHAR type in DolphinDB is stored as a byte, we can use the BasicByte type to construct CHAR in C# API, for example 'new BasicByte((byte)'c')'.
346344
- SYMBOL type: the SYMBOL type in DolphinDB is stored as INT to improve the efficiency of storage and query of strings. C# doesn't have this data type, so C# API does not provide BasicSymbol. SYMBOL type can be processed directly with BasicString.
347-
- Temporal types: temporal data types are stored as INT or LONG in DolphinDB. DolphinDB provides 9 temporal data types: date, month, time, minute, second, datetime, timestamp, nanotime and nanotimestamp. For detailed description, please refer to [DolphinDB Temporal Type and Conversion] (https://www.dolphindb.com/help/TemporalTypeandConversion.html). Since C# also provides data types such as LocalDate, LocalTime, LocalDateTime and YearMonth, C# API provides conversion functions in the Utils class between all C# temporal types and INT or LONG.
345+
- Temporal types: temporal data types are stored as INT or LONG in DolphinDB. DolphinDB provides 9 temporal data types: date, month, time, minute, second, datetime, timestamp, nanotime and nanotimestamp. For detailed description, please refer to [DolphinDB Temporal Type and Conversion](https://www.dolphindb.com/help/DataManipulation/TemporalObjects/TemporalTypeandConversion.html). Since C# also provides data types such as LocalDate, LocalTime, LocalDateTime and YearMonth, C# API provides conversion functions in the Utils class between all C# temporal types and INT or LONG.
348346

349347
The following script shows the correspondence between DolphinDB temporal types and C# native temporal types:
350348

README_CN.md

Lines changed: 414 additions & 59 deletions
Large diffs are not rendered by default.

bin/dolphindb_csharpapi.dll

-173 KB
Binary file not shown.

dolphindb_csharpapi.sln

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26430.15
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dolphindb_csharpapi", "dolphindb_csharpapi\dolphindb_csharpapi.csproj", "{F744DA92-D9F2-49BB-9783-F89E825CB307}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dolphindb_csharpapi", "src\dolphindb_csharpapi.csproj", "{F744DA92-D9F2-49BB-9783-F89E825CB307}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dolphindb_csharpapi_test", "dolphindb_csharpapi_test\dolphindb_csharpapi_test.csproj", "{9297EF6F-E380-423B-BA64-FE2907226FF8}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dolphindb_csharpapi_test", "test\dolphindb_csharpapi_test.csproj", "{9297EF6F-E380-423B-BA64-FE2907226FF8}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "longTimeTask", "longTimeTask\longTimeTask.csproj", "{AA834560-396D-42E6-9D5D-9DE41AA1482F}"
911
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -41,8 +43,23 @@ Global
4143
{9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x64.Build.0 = Release|Any CPU
4244
{9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x86.ActiveCfg = Release|Any CPU
4345
{9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x86.Build.0 = Release|Any CPU
46+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Debug|x64.ActiveCfg = Debug|Any CPU
49+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Debug|x64.Build.0 = Debug|Any CPU
50+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Debug|x86.ActiveCfg = Debug|Any CPU
51+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Debug|x86.Build.0 = Debug|Any CPU
52+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Release|x64.ActiveCfg = Release|Any CPU
55+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Release|x64.Build.0 = Release|Any CPU
56+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Release|x86.ActiveCfg = Release|Any CPU
57+
{AA834560-396D-42E6-9D5D-9DE41AA1482F}.Release|x86.Build.0 = Release|Any CPU
4458
EndGlobalSection
4559
GlobalSection(SolutionProperties) = preSolution
4660
HideSolutionNode = FALSE
4761
EndGlobalSection
62+
GlobalSection(ExtensibilityGlobals) = postSolution
63+
SolutionGuid = {BD8FB1DE-3841-4F68-A643-A686A14E10BC}
64+
EndGlobalSection
4865
EndGlobal

examples/DFSTableWriting.cs

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
using dolphindb;
2+
using dolphindb.data;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
7+
public class DFSTableWriting
8+
{
9+
private static DBConnection conn;
10+
public static string HOST = "localhost";
11+
public static int PORT = 8848;
12+
13+
private BasicTable createBasicTable()
14+
{
15+
List<string> colNames = new List<string>();
16+
colNames.Add("cbool");
17+
colNames.Add("cchar");
18+
colNames.Add("cshort");
19+
colNames.Add("cint");
20+
colNames.Add("clong");
21+
colNames.Add("cdate");
22+
colNames.Add("cmonth");
23+
colNames.Add("ctime");
24+
colNames.Add("cminute");
25+
colNames.Add("csecond");
26+
colNames.Add("cdatetime");
27+
colNames.Add("ctimestamp");
28+
colNames.Add("cnanotime");
29+
colNames.Add("cnanotimestamp");
30+
colNames.Add("cfloat");
31+
colNames.Add("cdouble");
32+
colNames.Add("csymbol");
33+
colNames.Add("cstring");
34+
List<IVector> cols = new List<IVector>();
35+
36+
37+
//boolean
38+
byte[] vbool = new byte[] { 1, 0 };
39+
BasicBooleanVector bbv = new BasicBooleanVector(vbool);
40+
cols.Add(bbv);
41+
//char
42+
byte[] vchar = new byte[] { (byte)'c', (byte)'a' };
43+
BasicByteVector bcv = new BasicByteVector(vchar);
44+
cols.Add(bcv);
45+
//cshort
46+
short[] vshort = new short[] { 32767, 29 };
47+
BasicShortVector bshv = new BasicShortVector(vshort);
48+
cols.Add(bshv);
49+
//cint
50+
int[] vint = new int[] { 2147483647, 483647 };
51+
BasicIntVector bintv = new BasicIntVector(vint);
52+
cols.Add(bintv);
53+
//clong
54+
long[] vlong = new long[] { 2147483647, 483647 };
55+
BasicLongVector blongv = new BasicLongVector(vlong);
56+
cols.Add(blongv);
57+
//cdate
58+
int[] vdate = new int[] { Utils.countDays(new DateTime(2018,2,14)), Utils.countDays(new DateTime(2018,8,15)) };
59+
BasicDateVector bdatev = new BasicDateVector(vdate);
60+
cols.Add(bdatev);
61+
//cmonth
62+
int[] vmonth = new int[] { Utils.countMonths(new DateTime(2018,2,6)), Utils.countMonths(new DateTime(2018,8,11)) };
63+
BasicMonthVector bmonthv = new BasicMonthVector(vmonth);
64+
cols.Add(bmonthv);
65+
//ctime
66+
int[] vtime = new int[] { Utils.countMilliseconds(16, 46, 05, 123), Utils.countMilliseconds(18, 32, 05, 321) };
67+
BasicTimeVector btimev = new BasicTimeVector(vtime);
68+
cols.Add(btimev);
69+
//cminute
70+
int[] vminute = new int[] { Utils.countMinutes(new TimeSpan(16,30,00)), Utils.countMinutes(new TimeSpan(9,30,00)) };
71+
BasicMinuteVector bminutev = new BasicMinuteVector(vminute);
72+
cols.Add(bminutev);
73+
//csecond
74+
int[] vsecond = new int[] { Utils.countSeconds(new TimeSpan(16,30,00)), Utils.countSeconds(new TimeSpan(16, 30, 50)) };
75+
BasicSecondVector bsecondv = new BasicSecondVector(vsecond);
76+
cols.Add(bsecondv);
77+
//cdatetime
78+
int[] vdatetime = new int[] { Utils.countSeconds(new DateTime(2018, 9, 8, 9, 30, 01)), Utils.countSeconds(new DateTime(2018, 11, 8, 16, 30, 01)) };
79+
BasicDateTimeVector bdatetimev = new BasicDateTimeVector(vdatetime);
80+
cols.Add(bdatetimev);
81+
//ctimestamp
82+
long[] vtimestamp = new long[] { Utils.countMilliseconds(2018, 11, 12, 9, 30, 01, 123), Utils.countMilliseconds(2018, 11, 12, 16, 30, 01, 123) };
83+
BasicTimestampVector btimestampv = new BasicTimestampVector(vtimestamp);
84+
cols.Add(btimestampv);
85+
//cnanotime
86+
long[] vnanotime = new long[] { Utils.countNanoseconds(new TimeSpan(9, 30, 05, 1234567)), Utils.countNanoseconds(new TimeSpan(16, 30, 05, 9876543)) };
87+
BasicNanoTimeVector bnanotimev = new BasicNanoTimeVector(vnanotime);
88+
cols.Add(bnanotimev);
89+
//cnanotimestamp
90+
long[] vnanotimestamp = new long[] { Utils.countNanoseconds(new DateTime(2018, 11, 12, 9, 30, 05, 123)), Utils.countNanoseconds(new DateTime(2018, 11, 13, 16, 30, 05, 987)) };
91+
BasicNanoTimestampVector bnanotimestampv = new BasicNanoTimestampVector(vnanotimestamp);
92+
cols.Add(bnanotimestampv);
93+
//cfloat
94+
float[] vfloat = new float[] { 2147.483647f, 483.647f };
95+
BasicFloatVector bfloatv = new BasicFloatVector(vfloat);
96+
cols.Add(bfloatv);
97+
//cdouble
98+
double[] vdouble = new double[] { 214.7483647, 48.3647 };
99+
BasicDoubleVector bdoublev = new BasicDoubleVector(vdouble);
100+
cols.Add(bdoublev);
101+
//csymbol
102+
String[] vsymbol = new String[] { "GOOG", "MS" };
103+
BasicStringVector bsymbolv = new BasicStringVector(vsymbol);
104+
cols.Add(bsymbolv);
105+
//cstring
106+
String[] vstring = new String[] { "", "test string" };
107+
BasicStringVector bstringv = new BasicStringVector(vstring);
108+
cols.Add(bstringv);
109+
BasicTable t1 = new BasicTable(colNames, cols);
110+
return t1;
111+
}
112+
113+
public void writeDfsTable()
114+
{
115+
BasicTable table1 = createBasicTable();
116+
conn.login("admin", "123456", false);
117+
conn.run("t = table(10000:0,`cbool`cchar`cshort`cint`clong`cdate`cmonth`ctime`cminute`csecond`cdatetime`ctimestamp`cnanotime`cnanotimestamp`cfloat`cdouble`csymbol`cstring,[BOOL,CHAR,SHORT,INT,LONG,DATE,MONTH,TIME,MINUTE,SECOND,DATETIME,TIMESTAMP,NANOTIME,NANOTIMESTAMP,FLOAT,DOUBLE,SYMBOL,STRING])\n");
118+
conn.run("if(existsDatabase('dfs://testDatabase')){dropDatabase('dfs://testDatabase')}");
119+
conn.run("db = database('dfs://testDatabase',RANGE,2018.01.01..2018.12.31)");
120+
conn.run("db.createPartitionedTable(t,'tb1','cdate')");
121+
conn.run("def saveData(data){ loadTable('dfs://testDatabase','tb1').tableInsert(data)}");
122+
List<IEntity> args = new List<IEntity>(1);
123+
args.Add(table1);
124+
conn.run("saveData", args);
125+
BasicTable dt = (BasicTable)conn.run("select * from loadTable('dfs://testDatabase','tb1')");
126+
if (dt.rows() != 2) {
127+
Console.WriteLine("failed");
128+
}
129+
}
130+
131+
132+
public static void Main(string[] args)
133+
{
134+
conn = new DBConnection();
135+
if (args.Length == 2)
136+
{
137+
try
138+
{
139+
HOST = args[0];
140+
PORT = int.Parse(args[1]);
141+
}
142+
catch (Exception)
143+
{
144+
Console.WriteLine("Wrong arguments");
145+
}
146+
}
147+
else if (args.Length != 2 && args.Length != 0)
148+
{
149+
Console.WriteLine("wrong arguments");
150+
return;
151+
}
152+
try
153+
{
154+
conn.connect(HOST, PORT);
155+
}
156+
catch (IOException e)
157+
{
158+
Console.WriteLine("Connection error");
159+
Console.WriteLine(e.ToString());
160+
Console.Write(e.StackTrace);
161+
}
162+
try
163+
{
164+
(new DFSTableWriting()).writeDfsTable();
165+
}
166+
catch (IOException)
167+
{
168+
Console.WriteLine("Writing error");
169+
}
170+
}
171+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using dolphindb.data;
4+
using dolphindb;
5+
using dolphindb.route;
6+
7+
namespace DolphinDB
8+
{
9+
class DFSTableWritingMultiThread
10+
{
11+
static void Main(string[] args)
12+
{
13+
IDBConnectionPool pool = new ExclusiveDBConnectionPool("localhost", 8848, "admin", "123456", 5, true, true);
14+
IDBTask conn = new BasicDBTask("dbPath = \"dfs://demohash\";if(existsDatabase(dbPath)) dropDatabase(dbPath); db = database(dbPath, HASH,[STRING, 2]);t= table(100:0,`id`value,[STRING,INT]);pt=db.createPartitionedTable(t,`pt,`id);");
15+
pool.execute(conn);
16+
17+
18+
PartitionedTableAppender appender = new PartitionedTableAppender("dfs://demohash", "pt", "id", pool);
19+
List<String> colNames = new List<String>(2);
20+
colNames.Add("id");
21+
colNames.Add("value");
22+
List<IVector> cols = new List<IVector>(2);
23+
BasicStringVector id = new BasicStringVector(3);
24+
id.setString(0, "ORCA");
25+
id.setString(1, "YHOO");
26+
id.setString(2, "Ford");
27+
cols.Add(id);
28+
29+
BasicIntVector value = new BasicIntVector(3);
30+
value.setInt(0, 10);
31+
value.setInt(1, 11);
32+
value.setInt(2, 12);
33+
cols.Add(value);
34+
35+
int res = appender.append(new BasicTable(colNames, cols));
36+
}
37+
}
38+
}

examples/README_CN.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## DolphinDB C# API例子
2+
3+
### 1. 概述
4+
目前已有2个C# API的例子,如下表所示:
5+
6+
| 例子主题 | 文件名称 |
7+
|:-------------- |:-------------|
8+
|数据库写入|DFSTableWriting.cs|
9+
|流数据写入和订阅|StreamingData.cs|
10+
11+
本文下面对每个例子分别进行简单的说明,包括运行和使用帮助等。
12+
### 2. 数据库写入例子
13+
14+
本例实现了用C# API往分布式数据库写入数据的功能。例子中的目标数据库是一个按日期分区的分布式数据库。
15+
16+
#### 2.1 代码说明
17+
主要有2个函数:
18+
* createBasicTable函数 : 定义写入的数据,该函数创建了一个本地的表对象BasicTable。
19+
* writeDfsTable函数 : 通过API在DolphinDB创建待写入的分布式表,并用`run("tableInsert",args)`函数将C#端的BasicTable上传和写入分布式表。
20+
#### 2.2 运行
21+
将代码编译成xxx.exe 执行
22+
```
23+
xxx.exe [serverIP] [serverPort]
24+
```
25+
若不传入serverIP和serverPort参数,默认serverIP="localhost",serverPort==8848
26+
27+
### 3. 流数据写入和订阅例子
28+
C# API提供了ThreadedClient、ThreadPooledClient和PollingClient三种订阅模式订阅流表的数据。三种模式的主要区别在于收取数据的方式:
29+
30+
ThreadedClient单线程执行,并且对收到的消息直接执行用户定义的handler函数进行处理;
31+
32+
ThreadPooledClient多线程执行,对收到的消息进行多线程并行调用用户定义的handler函数进行处理;
33+
34+
PollingClient返回一个消息队列,用户可以通过轮询队列的方式获取和处理数据。
35+
36+
在本例流数据订阅的源代码中,选择用ThreadedClient,PollingClient两种方式。ThreadPooledClient可以参照ThreadedClient使用方式。
37+
38+
#### 3.1 代码说明
39+
本例实现了流数据表的写入和流数据订阅的功能,订阅服务端发布的数据并在C#应用端打印出来,主要有5个函数和类如下:
40+
* createStreamTable函数 :用于在DolphinDB中创建流数据表。
41+
* pollingClient类 :用PollingClient订阅模式订阅流表的数据,并在主线程中获取的数据展示出来。
42+
* ThreadedClient类 :用ThreadedClient订阅模式订阅流表的数据。
43+
* SampleMessageHandler类 : 处理ThreadedClient订阅的流表数据,将获取的数据展示出来。
44+
45+
#### 3.2 运行
46+
将代码编译成xxx.exe 执行
47+
```
48+
xxx.exe [serverIP] [serverPort] [subscribePort] [subscribeMethod]
49+
```
50+
subscribeMethod有2个选项:
51+
* 'T',用ThreadedClient开启订阅。
52+
* 'P',用PollingClient开启订阅。
53+
54+
若不传入参数,默认serverIP="localhost",serverPort==8848,subscribePort=8892,subscribeMethod='P'.
55+
56+
程序运行之后,Server端流表被创建,客户端处于等待流数据的状态。在DolphinDB 服务端运行以下脚本发布数据(持续100秒):
57+
```
58+
for(x in 0:1000){
59+
time =time(now())
60+
sym= rand(`S`M`MS`GO, 1)
61+
qty= rand(1000..2000,1)
62+
price = rand(2335.34,1)
63+
insert into Trades values(x, time,sym, qty, price)
64+
sleep(100)
65+
}
66+
```
67+
在PollingClient订阅时,若需要中途停止订阅,可以向流表写入 id = -1的记录,示例程序会停止运行
68+
```
69+
insert into Trades values(-1,time(now()),`a, 0, 0)
70+
```

0 commit comments

Comments
 (0)