1- using System ;
2- using System . Linq ;
3- using System . Threading . Tasks ;
1+ using System . Threading . Tasks ;
42using Newtonsoft . Json ;
53
6- namespace Neo4j . Driver . Tests . TestBackend
7- {
8- internal class ResultConsume : IProtocolObject
9- {
10- public ResultConsumeType data { get ; set ; } = new ResultConsumeType ( ) ;
11- [ JsonIgnore ]
12- public IRecord Records { get ; set ; }
13- [ JsonIgnore ]
14- public IResultSummary Summary { get ; set ; }
15-
16- public class ResultConsumeType
17- {
18- public string resultId { get ; set ; }
19- }
20-
21- public override async Task Process ( )
22- {
23- Summary = await ( ( Result ) ObjManager . GetObject ( data . resultId ) ) . ConsumeResults ( ) . ConfigureAwait ( false ) ;
24- }
25-
26- public override string Respond ( )
27- {
28- return new ProtocolResponse ( "Summary" , new
29- {
30- query = GetQuery ( Summary ) ,
31- queryType = GetQueryTypeAsStringCode ( Summary ) ,
32- plan = GetPlan ( Summary ) ,
33- notifications = CreateNotificationList ( ) ,
34- database = Summary . Database ? . Name ,
35- serverInfo = GetServerInfo ( Summary ) ,
36- counters = GetCountersFromSummary ( Summary ) ,
37- profile = MapToProfilePlan ( Summary . Profile ) ,
38- resultAvailableAfter = GetTotalMilliseconds ( Summary . ResultAvailableAfter ) ,
39- resultConsumedAfter = GetTotalMilliseconds ( Summary . ResultConsumedAfter )
40- } ) . Encode ( ) ;
41- }
42-
43- private static long ? GetTotalMilliseconds ( TimeSpan timespan )
44- {
45- return timespan . TotalMilliseconds >= 0L
46- ? ( long ) timespan . TotalMilliseconds
47- : default ( long ? ) ;
48- }
49-
50- private static object GetQuery ( IResultSummary summary )
51- {
52- return summary ? . Query == null
53- ? null
54- : new
55- {
56- text = summary . Query . Text ,
57- parameters = summary . Query . Parameters
58- . Select ( x => new { x . Key , Value = NativeToCypher . Convert ( x . Value ) } )
59- . ToDictionary ( x => x . Key , x => x . Value )
60- } ;
61- }
62-
63- private static string GetQueryTypeAsStringCode ( IResultSummary summary )
64- {
65- return summary ? . QueryType switch
66- {
67- QueryType . ReadOnly => "r" ,
68- QueryType . ReadWrite => "rw" ,
69- QueryType . WriteOnly => "w" ,
70- QueryType . SchemaWrite => "s" ,
71- QueryType . Unknown => null ,
72- _ => throw new ArgumentOutOfRangeException ( )
73- } ;
74- }
75-
76- private static object GetPlan ( IResultSummary summary )
77- {
78- return summary ? . Plan == null
79- ? null
80- : MapToPlanJson ( summary . Plan ) ;
81- }
4+ namespace Neo4j . Driver . Tests . TestBackend ;
825
83- private static object GetServerInfo ( IResultSummary summary )
84- {
85- return summary ? . Server == null
86- ? null
87- : new
88- {
89- protocolVersion = summary . Server . ProtocolVersion ,
90- agent = summary . Server . Agent
91- } ;
92- }
93-
94- private static object GetCountersFromSummary ( IResultSummary summary )
95- {
96- return new
97- {
98- constraintsAdded = summary . Counters . ConstraintsAdded ,
99- constraintsRemoved = summary . Counters . ConstraintsRemoved ,
100- nodesCreated = summary . Counters . NodesCreated ,
101- nodesDeleted = summary . Counters . NodesDeleted ,
102- relationshipsCreated = summary . Counters . RelationshipsCreated ,
103- relationshipsDeleted = summary . Counters . RelationshipsDeleted ,
104- propertiesSet = summary . Counters . PropertiesSet ,
105- labelsAdded = summary . Counters . LabelsAdded ,
106- labelsRemoved = summary . Counters . LabelsRemoved ,
107- indexesAdded = summary . Counters . IndexesAdded ,
108- indexesRemoved = summary . Counters . IndexesRemoved ,
109- systemUpdates = summary . Counters . SystemUpdates ,
110- containsUpdates = summary . Counters . ContainsUpdates ,
111- containsSystemUpdates = summary . Counters . ContainsSystemUpdates ,
112- } ;
113- }
114-
115- private static object MapToProfilePlan ( IProfiledPlan plan )
116- {
117- if ( plan == null )
118- return null ;
119-
120- if ( plan . HasPageCacheStats )
121- return new
122- {
123- args = plan . Arguments ,
124- operatorType = plan . OperatorType ,
125- children = plan . Children . Select ( MapToProfilePlan ) . ToList ( ) ,
126- identifiers = plan . Identifiers ,
127- time = plan . Time ,
128- pageCacheHitRatio = plan . PageCacheHitRatio ,
129- pageCacheMisses = plan . PageCacheMisses ,
130- pageCacheHits = plan . PageCacheHits ,
131- rows = plan . Records ,
132- dbHits = plan . DbHits ,
133- } ;
134-
135- return new
136- {
137- args = plan . Arguments ,
138- operatorType = plan . OperatorType ,
139- children = plan . Children . Select ( MapToProfilePlan ) . ToList ( ) ,
140- identifiers = plan . Identifiers ,
141- rows = plan . Records ,
142- dbHits = plan . DbHits ,
143- } ;
144- }
145-
146- private static object MapToPlanJson ( IPlan plan )
147- {
148- return new
149- {
150- args = plan . Arguments ,
151- operatorType = plan . OperatorType ,
152- children = plan . Children . Select ( MapToPlanJson ) . ToList ( ) ,
153- identifiers = plan . Identifiers
154- } ;
155- }
6+ internal class ResultConsume : IProtocolObject
7+ {
8+ public ResultConsume . ResultConsumeType data { get ; set ; } = new ResultConsume . ResultConsumeType ( ) ;
9+ [ JsonIgnore ]
10+ public IRecord Records { get ; set ; }
11+ [ JsonIgnore ]
12+ public IResultSummary Summary { get ; set ; }
13+
14+ public class ResultConsumeType
15+ {
16+ public string resultId { get ; set ; }
17+ }
15618
157- private object CreateNotificationList ( )
158- {
159- if ( Summary ? . Notifications == null )
160- return null ;
161- if ( Summary ? . Notifications ? . All ( x => x . Position == null ) ?? false )
162- {
163- return Summary ? . Notifications . Select ( x => new
164- {
165- severity = x . Severity ,
166- description = x . Description ,
167- code = x . Code ,
168- title = x . Title ,
169- } ) . ToList ( ) ;
170- }
19+ public override async Task Process ( )
20+ {
21+ Summary = await ( ( Result ) ObjManager . GetObject ( data . resultId ) ) . ConsumeResults ( ) . ConfigureAwait ( false ) ;
22+ }
17123
172- return Summary ? . Notifications . Select ( x => new
173- {
174- severity = x . Severity ,
175- description = x . Description ,
176- code = x . Code ,
177- title = x . Title ,
178- position = x . Position == null
179- ? null
180- : new
181- {
182- column = x . Position . Column ,
183- offset = x . Position . Offset ,
184- line = x . Position . Line
185- }
186- } ) . ToList ( ) ;
187- }
24+ public override string Respond ( )
25+ {
26+ return new ProtocolResponse ( "Summary" , SummaryJsonSerializer . SerializeToRaw ( Summary ) ) . Encode ( ) ;
18827 }
189- }
28+ }
0 commit comments