1- using BotSharp . Abstraction . Rules . Models ;
1+ using BotSharp . Abstraction . Graph . Models ;
22
33namespace BotSharp . Abstraction . Rules ;
44
5- public class RuleGraph
5+ public class FlowGraph
66{
77 private string _id = Guid . NewGuid ( ) . ToString ( ) ;
8- private List < RuleNode > _nodes = [ ] ;
9- private List < RuleEdge > _edges = [ ] ;
8+ private List < FlowNode > _nodes = [ ] ;
9+ private List < FlowEdge > _edges = [ ] ;
1010
11- public RuleGraph ( )
11+ public FlowGraph ( )
1212 {
1313 _id = Guid . NewGuid ( ) . ToString ( ) ;
1414 _nodes = [ ] ;
1515 _edges = [ ] ;
1616 }
1717
18- public static RuleGraph Init ( )
18+ public static FlowGraph Init ( )
1919 {
20- return new RuleGraph ( ) ;
20+ return new FlowGraph ( ) ;
2121 }
2222
23- public RuleNode ? GetRootNode ( string ? name = null )
23+ public FlowNode ? GetRootNode ( string ? name = null )
2424 {
2525 if ( ! string . IsNullOrEmpty ( name ) )
2626 {
@@ -30,7 +30,7 @@ public static RuleGraph Init()
3030 return _nodes . FirstOrDefault ( x => x . Type . IsEqualTo ( "root" ) || x . Type . IsEqualTo ( "start" ) ) ;
3131 }
3232
33- public ( RuleNode ? Node , IEnumerable < RuleEdge > IncomingEdges , IEnumerable < RuleEdge > OutgoingEdges ) GetNode ( string id )
33+ public ( FlowNode ? Node , IEnumerable < FlowEdge > IncomingEdges , IEnumerable < FlowEdge > OutgoingEdges ) GetNode ( string id )
3434 {
3535 var node = _nodes . FirstOrDefault ( x => x . Id . IsEqualTo ( id ) ) ;
3636 if ( node == null )
@@ -55,12 +55,12 @@ public string GetGraphId()
5555 return _id ;
5656 }
5757
58- public IEnumerable < RuleNode > GetNodes ( Func < RuleNode , bool > ? filter = null )
58+ public IEnumerable < FlowNode > GetNodes ( Func < FlowNode , bool > ? filter = null )
5959 {
6060 return filter == null ? [ .. _nodes ] : [ .. _nodes . Where ( filter ) ] ;
6161 }
6262
63- public IEnumerable < RuleEdge > GetEdges ( Func < RuleEdge , bool > ? filter = null )
63+ public IEnumerable < FlowEdge > GetEdges ( Func < FlowEdge , bool > ? filter = null )
6464 {
6565 return filter == null ? [ .. _edges ] : [ .. _edges . Where ( filter ) ] ;
6666 }
@@ -70,17 +70,17 @@ public void SetGraphId(string id)
7070 _id = id ;
7171 }
7272
73- public void SetNodes ( IEnumerable < RuleNode > nodes )
73+ public void SetNodes ( IEnumerable < FlowNode > nodes )
7474 {
7575 _nodes = [ .. nodes ? . ToList ( ) ?? [ ] ] ;
7676 }
7777
78- public void SetEdges ( IEnumerable < RuleEdge > edges )
78+ public void SetEdges ( IEnumerable < FlowEdge > edges )
7979 {
8080 _edges = [ .. edges ? . ToList ( ) ?? [ ] ] ;
8181 }
8282
83- public void AddNode ( RuleNode node )
83+ public void AddNode ( FlowNode node )
8484 {
8585 var found = _nodes . Exists ( x => x . Id . IsEqualTo ( node . Id ) ) ;
8686 if ( ! found )
@@ -89,7 +89,7 @@ public void AddNode(RuleNode node)
8989 }
9090 }
9191
92- public void AddEdge ( RuleNode from , RuleNode to , EdgeItemPayload payload )
92+ public void AddEdge ( FlowNode from , FlowNode to , EdgeItemPayload payload )
9393 {
9494 var sourceFound = _nodes . Exists ( x => x . Id . IsEqualTo ( from . Id ) ) ;
9595 var targetFound = _nodes . Exists ( x => x . Id . IsEqualTo ( to . Id ) ) ;
@@ -107,7 +107,7 @@ public void AddEdge(RuleNode from, RuleNode to, EdgeItemPayload payload)
107107
108108 if ( ! edgeFound )
109109 {
110- _edges . Add ( new RuleEdge ( from , to )
110+ _edges . Add ( new FlowEdge ( from , to )
111111 {
112112 Id = payload . Id ,
113113 Name = payload . Name ,
@@ -121,7 +121,7 @@ public void AddEdge(RuleNode from, RuleNode to, EdgeItemPayload payload)
121121 }
122122 }
123123
124- public IEnumerable < ( RuleNode , RuleEdge ) > GetParentNodes ( RuleNode node , bool ascending = false )
124+ public IEnumerable < ( FlowNode , FlowEdge ) > GetParentNodes ( FlowNode node , bool ascending = false )
125125 {
126126 var filtered = _edges . Where ( e => e . To != null && e . To . Id . IsEqualTo ( node . Id ) ) ;
127127 var ordered = ascending
@@ -131,7 +131,7 @@ public void AddEdge(RuleNode from, RuleNode to, EdgeItemPayload payload)
131131 return ordered . Select ( e => ( e . From , e ) ) . ToList ( ) ;
132132 }
133133
134- public IEnumerable < ( RuleNode , RuleEdge ) > GetChildrenNodes ( RuleNode node , bool ascending = false )
134+ public IEnumerable < ( FlowNode , FlowEdge ) > GetChildrenNodes ( FlowNode node , bool ascending = false )
135135 {
136136 var filtered = _edges . Where ( e => e . From != null && e . From . Id . IsEqualTo ( node . Id ) ) ;
137137 var ordered = ascending
@@ -141,7 +141,7 @@ public void AddEdge(RuleNode from, RuleNode to, EdgeItemPayload payload)
141141 return ordered . Select ( e => ( e . To , e ) ) . ToList ( ) ;
142142 }
143143
144- public RuleGraphInfo GetGraphInfo ( )
144+ public FlowGraphInfo GetGraphInfo ( )
145145 {
146146 return new ( )
147147 {
@@ -157,9 +157,9 @@ public void Clear()
157157 _edges = [ ] ;
158158 }
159159
160- public static RuleGraph FromGraphInfo ( RuleGraphInfo graphInfo )
160+ public static FlowGraph FromGraphInfo ( FlowGraphInfo graphInfo )
161161 {
162- var graph = new RuleGraph ( ) ;
162+ var graph = new FlowGraph ( ) ;
163163 graph . SetGraphId ( graphInfo . GraphId . IfNullOrEmptyAs ( Guid . NewGuid ( ) . ToString ( ) ) ! ) ;
164164 graph . SetNodes ( graphInfo . Nodes ) ;
165165 graph . SetEdges ( graphInfo . Edges ) ;
@@ -172,11 +172,12 @@ public override string ToString()
172172 }
173173}
174174
175- public class RuleNode : GraphItem
175+ public class FlowNode : GraphItem
176176{
177177 /// <summary>
178178 /// Node type: root, criteria, action, etc.
179179 /// </summary>
180+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
180181 public override string Type { get ; set ; } = "action" ;
181182
182183 /// <summary>
@@ -199,22 +200,22 @@ public override string ToString()
199200 }
200201}
201202
202- public class RuleEdge : GraphItem
203+ public class FlowEdge : GraphItem
203204{
204205 /// <summary>
205206 /// Edge type: is_next, etc.
206207 /// </summary>
207208 public override string Type { get ; set ; } = "next" ;
208209
209- public RuleNode From { get ; set ; }
210- public RuleNode To { get ; set ; }
210+ public FlowNode From { get ; set ; }
211+ public FlowNode To { get ; set ; }
211212
212- public RuleEdge ( ) : base ( )
213+ public FlowEdge ( ) : base ( )
213214 {
214-
215+
215216 }
216217
217- public RuleEdge ( RuleNode from , RuleNode to ) : base ( )
218+ public FlowEdge ( FlowNode from , FlowNode to ) : base ( )
218219 {
219220 Id = Guid . NewGuid ( ) . ToString ( ) ;
220221 From = from ;
@@ -229,15 +230,28 @@ public override string ToString()
229230
230231public class GraphItem
231232{
233+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
232234 public virtual string Id { get ; set ; } = Guid . NewGuid ( ) . ToString ( ) ;
235+
236+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
233237 public virtual string Name { get ; set ; } = null ! ;
238+
239+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
234240 public virtual string Type { get ; set ; } = null ! ;
241+
242+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
235243 public virtual IEnumerable < string > Labels { get ; set ; } = [ ] ;
236244 public virtual double Weight { get ; set ; } = 1.0 ;
245+
246+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
237247 public virtual string ? Description { get ; set ; }
248+
249+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
238250 public virtual Dictionary < string , string ? > Config { get ; set ; } = [ ] ;
239251
240252 private string ? _alias ;
253+
254+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
241255 public virtual string Alias
242256 {
243257 get => string . IsNullOrEmpty ( _alias ) ? Name : _alias ;
@@ -265,9 +279,11 @@ public class EdgeItemPayload : GraphItem
265279
266280}
267281
268- public class RuleGraphInfo
282+ public class FlowGraphInfo
269283{
284+ [ JsonPropertyName ( "graph_id" ) ]
285+ [ JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingNull ) ]
270286 public string GraphId { get ; set ; }
271- public IEnumerable < RuleNode > Nodes { get ; set ; } = [ ] ;
272- public IEnumerable < RuleEdge > Edges { get ; set ; } = [ ] ;
287+ public IEnumerable < FlowNode > Nodes { get ; set ; } = [ ] ;
288+ public IEnumerable < FlowEdge > Edges { get ; set ; } = [ ] ;
273289}
0 commit comments