Neo4jClient Node/Relationship Class 约定
Neo4jClient Node/Relationship Class conventions
使用 Neo4jClient 时,properties/methods 的 node/relationship class 是否有标准的命名约定?
我正在关注此 link Neo4jClient - Retrieving relationship from Cypher query 以建立我的关系 class
然而,我的关系有一些属性,尽管关系有它,但我无法获得任何价值。在调试我的代码时,我意识到在创建关系对象时没有从关系中检索到某些属性。
这是我的关系class
public class Creates
{
private string _raw;
private int _sourcePort;
private string _image;
private int _DestinationPort;
private int _eventcode;
private string _name;
private string _src_ip;
private int _src_port;
private string _dvc;
private int _signature_ID;
private string _dest_ip;
private string _computer;
private string _sourceType;
private int _recordID;
private int _processID;
private DateTime _time;
private int _dest_port;
public string Raw { get { return _raw; } set { _raw = value; } }
public int SourcePort { get { return _sourcePort; } set { _sourcePort = value; } }
public string Image { get { return _image; } set { _image = value; } }
public int DestinationPort { get { return _DestinationPort; } set { _DestinationPort = value; } }
public int Eventcode { get { return _eventcode; } set { _eventcode = value; } }
public string Name { get { return _name; } set { _name = value; } }
public string Src_ip { get { return _src_ip; } set { _src_ip = value; } }
public int Src_port { get { return _src_port; } set { _src_port = value; } }
public string DVC { get { return _dvc; } set { _dvc = value; } }
public int Signature_ID { get { return _signature_ID; } set { _signature_ID = value; } }
public string Dest_ip { get { return _dest_ip; } set { _dest_ip = value; } }
public string Computer { get { return _computer; } set { _computer = value; } }
public string SourceType { get { return _sourceType; } set { _sourceType = value; } }
public int RecordID { get { return _recordID; } set { _recordID = value; } }
public int ProcessID { get { return _processID; } set { _processID = value; } }
public DateTime Indextime { get { return _time; } set { _time = value; } }
public int Dest_port { get { return _dest_port; } set { _dest_port = value; } }
}
这是另一个class
public class ProcessConnectedIP
{
public Neo4jClient.RelationshipInstance<Pivot> bindto { get; set; }
public Neo4jClient.Node<LogEvent> bindip { get; set; }
public Neo4jClient.RelationshipInstance<Pivot> connectto { get; set; }
public Neo4jClient.Node<LogEvent> connectip { get; set; }
}
这是我用来获取关系对象的 neo4jclient 查询
public IEnumerable<ProcessConnectedIP> GetConnectedIPs(string nodeName)
{
try
{
var result =
this.client.Cypher.Match("(sourceNode:Process{name:{nameParam}})-[b:Bind_IP]->(bind:IP_Address)-[c:Connect_IP]->(connect:IP_Address)")
.WithParam("nameParam", nodeName)
.Where("b.dest_ip = c.dest_ip")
.AndWhere("c.Image=~{imageParam}")
.WithParam("imageParam", $".*" + nodeName + ".*")
.Return((b, bind, c, connect) => new ProcessConnectedIP
{
bindto = b.As<RelationshipInstance<Creates>>(),
bindip = bind.As<Node<LogEvent>>(),
connectto = c.As<RelationshipInstance<Creates>>(),
connectip = connect.As<Node<LogEvent>>()
})
.Results;
return result;
}catch(Exception ex)
{
Console.WriteLine("GetConnectedIPs: Error Msg: " + ex.Message);
return null;
}
}
这是读取结果的方法
public void MyMethod(string name)
{
IEnumerable<ProcessConnectedIP> result = clientDAL.GetConnectedIPs(name);
if(result != null)
{
var results = result.ToList();
Console.WriteLine(results.Count());
foreach (ProcessConnectedIP item in results)
{
Console.WriteLine(item.Data.Src_ip);
Console.WriteLine(item.bindto.StartNodeReference.Id);
Console.WriteLine(item.bindto.EndNodeReference.Id);
Console.WriteLine(item.connectto.StartNodeReference.Id);
Console.WriteLine(item.connectto.EndNodeReference.Id);
Node<LogEvent> ans = item.bindip;
LogEvent log = ans.Data;
Console.WriteLine(log.Name);
Node<LogEvent> ans1 = item.connectip;
LogEvent log1 = ans1.Data;
Console.WriteLine(log1.Name);
}
}
}
不知何故,我只能用 src_ip/src_port/dest_ip/dest_port 值填充关系对象。其余都是空的。
有什么可能的原因吗?我在属性名称上玩过 upper/lower 个案例,但它似乎不起作用。
这是我正在处理的图表部分
这是关系属性示例:
_raw: Some XML dataSourcePort: 49767Image: C:\Windows\explorer.exeDestinationPort: 443EventCode: 3Name: Bind
IPsrc_ip: 172.10.10.104dvc: COMPUTER-NAMEsrc_port:
49767signature_id: 3dest_ip: 172.10.10.11Computer:
COMPUTRE-NAME_sourcetype:
XmlWinEventLog:Microsoft-Windows-Sysmon/OperationalRecordID:
13405621ProcessId: 7184_time: 2017-08-28T15:15:39+08:00dest_port: 443
我不完全确定您的 Creates
class 是如何填充的,尤其是那些字段 - 因为您的 Src_port
属性 与 src_port
在您提供的示例中(区分大小写)。
我认为最好还是回到超级简单的版本。 Neo4jClient 会将您的属性映射到 Relationship 中的属性,只要它们具有相同的名称(并且区分大小写)。
所以从一个新的 Creates
class 开始(并使用自动属性 - 这会让您的生活变得更轻松!)
public class Creates
{
public string Computer { get; set; }
}
运行 你的查询,看看你是否得到结果,然后继续添加与你希望返回的名称和类型相匹配的属性(int
,string
等等)
看来我必须以小写形式提供 neo4j node/relationship 属性 名称并且在 属性 名称的开头没有特殊字符,以便上述代码工作.
该图表不是我一开始创建的,因此我必须根据给定的内容进行处理。我必须让创建图表的开发人员创建小写节点才能使上述工作正常进行。
使用 Neo4jClient 时,properties/methods 的 node/relationship class 是否有标准的命名约定?
我正在关注此 link Neo4jClient - Retrieving relationship from Cypher query 以建立我的关系 class
然而,我的关系有一些属性,尽管关系有它,但我无法获得任何价值。在调试我的代码时,我意识到在创建关系对象时没有从关系中检索到某些属性。
这是我的关系class
public class Creates
{
private string _raw;
private int _sourcePort;
private string _image;
private int _DestinationPort;
private int _eventcode;
private string _name;
private string _src_ip;
private int _src_port;
private string _dvc;
private int _signature_ID;
private string _dest_ip;
private string _computer;
private string _sourceType;
private int _recordID;
private int _processID;
private DateTime _time;
private int _dest_port;
public string Raw { get { return _raw; } set { _raw = value; } }
public int SourcePort { get { return _sourcePort; } set { _sourcePort = value; } }
public string Image { get { return _image; } set { _image = value; } }
public int DestinationPort { get { return _DestinationPort; } set { _DestinationPort = value; } }
public int Eventcode { get { return _eventcode; } set { _eventcode = value; } }
public string Name { get { return _name; } set { _name = value; } }
public string Src_ip { get { return _src_ip; } set { _src_ip = value; } }
public int Src_port { get { return _src_port; } set { _src_port = value; } }
public string DVC { get { return _dvc; } set { _dvc = value; } }
public int Signature_ID { get { return _signature_ID; } set { _signature_ID = value; } }
public string Dest_ip { get { return _dest_ip; } set { _dest_ip = value; } }
public string Computer { get { return _computer; } set { _computer = value; } }
public string SourceType { get { return _sourceType; } set { _sourceType = value; } }
public int RecordID { get { return _recordID; } set { _recordID = value; } }
public int ProcessID { get { return _processID; } set { _processID = value; } }
public DateTime Indextime { get { return _time; } set { _time = value; } }
public int Dest_port { get { return _dest_port; } set { _dest_port = value; } }
}
这是另一个class
public class ProcessConnectedIP
{
public Neo4jClient.RelationshipInstance<Pivot> bindto { get; set; }
public Neo4jClient.Node<LogEvent> bindip { get; set; }
public Neo4jClient.RelationshipInstance<Pivot> connectto { get; set; }
public Neo4jClient.Node<LogEvent> connectip { get; set; }
}
这是我用来获取关系对象的 neo4jclient 查询
public IEnumerable<ProcessConnectedIP> GetConnectedIPs(string nodeName)
{
try
{
var result =
this.client.Cypher.Match("(sourceNode:Process{name:{nameParam}})-[b:Bind_IP]->(bind:IP_Address)-[c:Connect_IP]->(connect:IP_Address)")
.WithParam("nameParam", nodeName)
.Where("b.dest_ip = c.dest_ip")
.AndWhere("c.Image=~{imageParam}")
.WithParam("imageParam", $".*" + nodeName + ".*")
.Return((b, bind, c, connect) => new ProcessConnectedIP
{
bindto = b.As<RelationshipInstance<Creates>>(),
bindip = bind.As<Node<LogEvent>>(),
connectto = c.As<RelationshipInstance<Creates>>(),
connectip = connect.As<Node<LogEvent>>()
})
.Results;
return result;
}catch(Exception ex)
{
Console.WriteLine("GetConnectedIPs: Error Msg: " + ex.Message);
return null;
}
}
这是读取结果的方法
public void MyMethod(string name)
{
IEnumerable<ProcessConnectedIP> result = clientDAL.GetConnectedIPs(name);
if(result != null)
{
var results = result.ToList();
Console.WriteLine(results.Count());
foreach (ProcessConnectedIP item in results)
{
Console.WriteLine(item.Data.Src_ip);
Console.WriteLine(item.bindto.StartNodeReference.Id);
Console.WriteLine(item.bindto.EndNodeReference.Id);
Console.WriteLine(item.connectto.StartNodeReference.Id);
Console.WriteLine(item.connectto.EndNodeReference.Id);
Node<LogEvent> ans = item.bindip;
LogEvent log = ans.Data;
Console.WriteLine(log.Name);
Node<LogEvent> ans1 = item.connectip;
LogEvent log1 = ans1.Data;
Console.WriteLine(log1.Name);
}
}
}
不知何故,我只能用 src_ip/src_port/dest_ip/dest_port 值填充关系对象。其余都是空的。
有什么可能的原因吗?我在属性名称上玩过 upper/lower 个案例,但它似乎不起作用。
这是我正在处理的图表部分
这是关系属性示例:
_raw: Some XML dataSourcePort: 49767Image: C:\Windows\explorer.exeDestinationPort: 443EventCode: 3Name: Bind IPsrc_ip: 172.10.10.104dvc: COMPUTER-NAMEsrc_port: 49767signature_id: 3dest_ip: 172.10.10.11Computer: COMPUTRE-NAME_sourcetype: XmlWinEventLog:Microsoft-Windows-Sysmon/OperationalRecordID: 13405621ProcessId: 7184_time: 2017-08-28T15:15:39+08:00dest_port: 443
我不完全确定您的 Creates
class 是如何填充的,尤其是那些字段 - 因为您的 Src_port
属性 与 src_port
在您提供的示例中(区分大小写)。
我认为最好还是回到超级简单的版本。 Neo4jClient 会将您的属性映射到 Relationship 中的属性,只要它们具有相同的名称(并且区分大小写)。
所以从一个新的 Creates
class 开始(并使用自动属性 - 这会让您的生活变得更轻松!)
public class Creates
{
public string Computer { get; set; }
}
运行 你的查询,看看你是否得到结果,然后继续添加与你希望返回的名称和类型相匹配的属性(int
,string
等等)
看来我必须以小写形式提供 neo4j node/relationship 属性 名称并且在 属性 名称的开头没有特殊字符,以便上述代码工作.
该图表不是我一开始创建的,因此我必须根据给定的内容进行处理。我必须让创建图表的开发人员创建小写节点才能使上述工作正常进行。