Skip to content

Commit bdb89da

Browse files
authored
Merge pull request #12 from heyanlong/revert-11-master
Revert "远程IP无法解析"
2 parents d2c0e8c + 745af6a commit bdb89da

File tree

2 files changed

+5
-76
lines changed

2 files changed

+5
-76
lines changed

NebulaNet/GraphClient.cs

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
using Thrift;
55
using Thrift.Protocol;
66
using Thrift.Transport.Client;
7-
using System.Net;
8-
using System.Collections.Generic;
9-
using System.Linq;
10-
using System.Reflection;
11-
using Nebula.Common;
12-
using System.Threading;
137

148
namespace NebulaNet
159
{
@@ -23,23 +17,18 @@ public class GraphClient
2317
public GraphClient(string ip, int port)
2418
{
2519
var tConfiguration = new TConfiguration();
20+
socketTransport = new TSocketTransport(ip, port, tConfiguration);
2621

27-
if (IPAddress.TryParse(ip, out IPAddress iPAddress))
28-
socketTransport = new TSocketTransport(iPAddress, port, tConfiguration);
29-
else
30-
socketTransport = new TSocketTransport(ip, port, tConfiguration);
31-
32-
socketTransport.OpenAsync(default).Wait();
22+
socketTransport.OpenAsync(default);
3323

3424
protocolProtocol = new TBinaryProtocol(socketTransport);
3525

3626
Client = new GraphService.Client(protocolProtocol);
3727
}
28+
3829
public void Authenticate(string user, string passwd)
3930
{
40-
41-
var authResponse = Client.authenticate(System.Text.Encoding.ASCII.GetBytes(user), System.Text.Encoding.ASCII.GetBytes(passwd)).Result;
42-
31+
var authResponse = Client.authenticate(System.Text.Encoding.Default.GetBytes(user), System.Text.Encoding.Default.GetBytes(passwd)).Result;
4332
if (authResponse.Error_code != 0)
4433
{
4534
throw new Exception("error auth!");
@@ -55,42 +44,12 @@ public async Task<ExecutionResponse> Execute(string statement)
5544
var executionResponse = await Client.execute(sessionId, System.Text.Encoding.Default.GetBytes(statement));
5645
if (executionResponse.Error_code != 0)
5746
{
58-
throw new Exception(System.Text.Encoding.UTF8.GetString(executionResponse.Error_msg) + statement + " execute failed.");
47+
throw new Exception(System.Text.Encoding.ASCII.GetString(executionResponse.Error_msg) + statement + " execute failed.");
5948
}
6049

6150
return executionResponse;
6251
}
6352

64-
public async Task<List<T>> Execute<T>(string statement) where T : class
65-
{
66-
var executionResponse = await Execute(statement);
67-
if (executionResponse.Data == null)
68-
return default;
69-
70-
//获取列名
71-
var columnNames = executionResponse.Data.Column_names
72-
.Select(x => System.Text.Encoding.UTF8.GetString(x).ToLower()).ToArray();
73-
74-
//查找可用属性和数据索引
75-
var indexAndProps = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance)//BindingFlags.IgnoreCase
76-
.Select(x => new { Index= Array.IndexOf(columnNames,x.Name.ToLower()),Prop=x })
77-
.Where(x => x.Index >= 0);
78-
79-
//映射对象
80-
var result = new List<T>();
81-
foreach (var row in executionResponse.Data.Rows)
82-
{
83-
var o = Activator.CreateInstance<T>();
84-
foreach (var item in indexAndProps)
85-
{
86-
item.Prop.SetValue(o, row.Values[item.Index].GetValue(item.Prop.PropertyType));
87-
}
88-
result.Add(o);
89-
}
90-
91-
return result;
92-
}
93-
9453
public async Task SignOff()
9554
{
9655
await Client.signout(sessionId);

NebulaNet/NebulaNetExtensions.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)