Skip to content

Commit 77a6944

Browse files
committed
update
1 parent c5d4b4d commit 77a6944

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

.vs/dolphindb_csharpapi/v15/.suo

21 KB
Binary file not shown.

dolphindb_csharpapi/DBConnection.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,15 @@ public virtual IEntity run(string script, ProgressListener listener)
398398
msg = @in.readLine();
399399
if (!msg.Equals("OK"))
400400
{
401-
throw new IOException(msg);
401+
if (ServerExceptionUtils.isNotLogin(msg))
402+
{
403+
if (userId.Length > 0 && password.Length > 0) login();
404+
}
405+
else
406+
{
407+
throw new IOException(msg);
408+
}
409+
402410
}
403411

404412
if (numObject == 0)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace dolphindb
7+
{
8+
class ServerExceptionUtils
9+
{
10+
public static bool isNotLogin(string exMsg)
11+
{
12+
return exMsg.Contains(string.Format("<{0}>",ServerException.NotAuthenticated.ToString()));
13+
}
14+
}
15+
16+
enum ServerException
17+
{
18+
NotAuthenticated
19+
}
20+
}

dolphindb_csharpapi/dolphindb_csharpapi.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<Compile Include="io\ProgressListener.cs" />
127127
<Compile Include="Properties\AssemblyInfo.cs" />
128128
<Compile Include="RSAUtils.cs" />
129+
<Compile Include="ServerExceptionUtils.cs" />
129130
<Compile Include="streaming\AbstractClient.cs" />
130131
<Compile Include="streaming\BasicMessage.cs" />
131132
<Compile Include="streaming\Deamon.cs" />

dolphindb_csharpapi_test/DBConnection_test.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace dolphindb_csharpapi_test
1717
[TestClass]
1818
public class DBConnection_test
1919
{
20-
private readonly string SERVER = "115.239.209.189";
21-
private readonly int PORT = 18531;
20+
private readonly string SERVER = "192.168.1.201";
21+
private readonly int PORT = 8848;
2222
private readonly string USER = "admin";
2323
private readonly string PASSWORD = "123456";
2424

@@ -33,6 +33,8 @@ public void Test_chinese_Table()
3333
Assert.AreEqual("备注1", ((BasicString)bt.getColumn("备注").get(0)).getString());
3434
DataTable dt = bt.toDataTable();
3535
Assert.AreEqual("备注10", dt.Rows[9]["备注"].ToString());
36+
37+
3638
}
3739

3840
[TestMethod]
@@ -377,6 +379,8 @@ public void Test_run_return_vector_float()
377379
DBConnection db = new DBConnection();
378380
db.connect(SERVER, PORT);
379381
IVector v = (BasicFloatVector)db.run("1.123f 2.2234f 3.4567f");
382+
383+
BasicDateTimeVector v1 = new BasicDateTimeVector(1);
380384
Assert.IsTrue(v.isVector());
381385
Assert.AreEqual(3, v.rows());
382386
Assert.AreEqual(2.2234, Math.Round(((BasicFloat)v.get(1)).getValue(), 4));
@@ -1608,5 +1612,20 @@ public void Test_FirstLineIsEmpty()
16081612
Assert.AreEqual(2, re.getValue());
16091613
}
16101614

1615+
[TestMethod]
1616+
public void Test_ReLogin()
1617+
{
1618+
DBConnection db = new DBConnection();
1619+
db.connect(SERVER, PORT, USER, PASSWORD);
1620+
1621+
db.run(@"if(existsDatabase('dfs://db1')) dropDatabase('dfs://db1')
1622+
db = database('dfs://db1', VALUE, 1..10)
1623+
t = table(1..100 as id)
1624+
db.createPartitionedTable(t,'t1', 'id')");
1625+
db.run("logout()");
1626+
db.run("exec count(*) from loadTable('dfs://db1','t1')");
1627+
BasicInt re = (BasicInt)db.run("exec count(*) from loadTable('dfs://db1','t1')");
1628+
Assert.AreEqual(0, re.getValue());
1629+
}
16111630
}
16121631
}

0 commit comments

Comments
 (0)