1+ #pragma warning disable CS1591
2+
3+ using Microsoft . Xrm . Sdk ;
4+ using System ;
5+ using System . Collections . Generic ;
6+ using System . Linq ;
7+ using System . Text ;
8+ using System . Threading . Tasks ;
9+
10+ namespace Microsoft . PowerPlatform . Dataverse . Client . Extensions
11+ {
12+ public class AsyncStatusResponse
13+ {
14+ /// <summary>
15+ /// Status of the system job.
16+ /// </summary>
17+ public enum AsyncStatusResponse_statecode
18+ {
19+ Ready = 0 ,
20+ Suspended = 1 ,
21+ Locked = 2 ,
22+ Completed = 3 ,
23+ FailedParse = 999
24+ }
25+
26+ /// <summary>
27+ /// Reason for the status of the system job.
28+ /// </summary>
29+ public enum AsyncStatusResponse_statuscode
30+ {
31+ WaitingForResources = 0 ,
32+ Waiting = 10 ,
33+ InProgress = 20 ,
34+ Pausing = 21 ,
35+ Canceling = 22 ,
36+ Succeeded = 30 ,
37+ Failed = 31 ,
38+ Canceled = 32 ,
39+ FailedParse = 999
40+ }
41+
42+ /// <summary>
43+ /// Raw entity returned from the operation status poll.
44+ /// </summary>
45+ public Entity RetrievedEntity { get ; set ; }
46+
47+ /// <summary>
48+ /// Operation Id.
49+ /// </summary>
50+ public Guid AsyncOperationId
51+ {
52+ get
53+ {
54+ if ( RetrievedEntity != null )
55+ return RetrievedEntity . Id ;
56+ else
57+ return Guid . Empty ;
58+ }
59+ }
60+
61+ /// <summary>
62+ /// Name of the Operation
63+ /// </summary>
64+ public string OperationName
65+ {
66+ get
67+ {
68+ if ( RetrievedEntity != null )
69+ return RetrievedEntity . Attributes . ContainsKey ( "name" ) ? RetrievedEntity . GetAttributeValue < string > ( "name" ) : string . Empty ;
70+ else
71+ return string . Empty ;
72+ }
73+ }
74+
75+ /// <summary>
76+ /// Type of the Operation <see href="https://learn.microsoft.com/power-apps/developer/data-platform/reference/entities/asyncoperation#operationtype-choicesoptions"/>
77+ /// </summary>
78+ public string OperationType
79+ {
80+ get
81+ {
82+ if ( RetrievedEntity != null )
83+ return RetrievedEntity . Attributes . ContainsKey ( "operationtype" ) ? RetrievedEntity . FormattedValues [ "operationtype" ] : string . Empty ;
84+ else
85+ return string . Empty ;
86+ }
87+ }
88+
89+ /// <summary>
90+ /// User readable message, if available.
91+ /// </summary>
92+ public string FriendlyMessage
93+ {
94+ get
95+ {
96+ if ( RetrievedEntity != null )
97+ return RetrievedEntity . Attributes . ContainsKey ( "friendlymessage" ) ? RetrievedEntity . GetAttributeValue < string > ( "friendlymessage" ) : string . Empty ;
98+ else
99+ return string . Empty ;
100+ }
101+ }
102+
103+ /// <summary>
104+ /// System message, if available
105+ /// </summary>
106+ public string Message
107+ {
108+ get
109+ {
110+ if ( RetrievedEntity != null )
111+ return RetrievedEntity . Attributes . ContainsKey ( "message" ) ? RetrievedEntity . GetAttributeValue < string > ( "message" ) : string . Empty ;
112+ else
113+ return string . Empty ;
114+ }
115+ }
116+
117+ /// <summary>
118+ /// Correlation id
119+ /// </summary>
120+ public Guid CorrlationId
121+ {
122+ get
123+ {
124+ if ( RetrievedEntity != null )
125+ return RetrievedEntity . Attributes . ContainsKey ( "correlationid" ) ? RetrievedEntity . GetAttributeValue < Guid > ( "correlationid" ) : Guid . Empty ;
126+ else
127+ return Guid . Empty ;
128+ }
129+ }
130+
131+ /// <summary>
132+ /// Operation Status Code.
133+ /// </summary>
134+ public AsyncStatusResponse_statuscode StatusCode { get ; internal set ; }
135+
136+ /// <summary>
137+ /// Localized text version of Status code, if available
138+ /// </summary>
139+ public string StatusCode_Localized {
140+ get
141+ {
142+ if ( RetrievedEntity != null )
143+ return RetrievedEntity . Attributes . ContainsKey ( "statuscode" ) ? RetrievedEntity . FormattedValues [ "statuscode" ] : string . Empty ;
144+ else
145+ return string . Empty ;
146+ }
147+ }
148+
149+ /// <summary>
150+ /// Operation State code
151+ /// </summary>
152+ public AsyncStatusResponse_statecode State { get ; internal set ; }
153+
154+ /// <summary>
155+ /// Localized text version of state code text, if available
156+ /// </summary>
157+ public string State_Localized
158+ {
159+ get
160+ {
161+ if ( RetrievedEntity != null )
162+ return RetrievedEntity . Attributes . ContainsKey ( "statecode" ) ? RetrievedEntity . FormattedValues [ "statecode" ] : string . Empty ;
163+ else
164+ return string . Empty ;
165+ }
166+ }
167+
168+ /// <summary>
169+ /// Creates an AsyncStatusResponse Object
170+ /// </summary>
171+ /// <param name="asyncOperationResponses"></param>
172+ internal AsyncStatusResponse ( EntityCollection asyncOperationResponses )
173+ {
174+ // parse the Async Operation type.
175+ if ( asyncOperationResponses == null )
176+ {
177+ // Do something Result is null.
178+
179+ }
180+ else if ( asyncOperationResponses != null && ! asyncOperationResponses . Entities . Any ( ) ) {
181+ // Do something ( no records )
182+ } else
183+ {
184+ // not null and have records.
185+ this . RetrievedEntity = asyncOperationResponses . Entities . First ( ) ; // get first entity.
186+ // Parse state and status
187+ OptionSetValue ostatecode = RetrievedEntity . Attributes . ContainsKey ( "statecode" ) ? RetrievedEntity . GetAttributeValue < OptionSetValue > ( "statecode" ) : new OptionSetValue ( - 1 ) ;
188+ try
189+ {
190+ State = ( AsyncStatusResponse_statecode ) ostatecode . Value ;
191+ }
192+ catch
193+ {
194+ State = AsyncStatusResponse_statecode . FailedParse ;
195+ }
196+
197+ OptionSetValue ostatuscode = RetrievedEntity . Attributes . ContainsKey ( "statuscode" ) ? RetrievedEntity . GetAttributeValue < OptionSetValue > ( "statuscode" ) : new OptionSetValue ( - 1 ) ;
198+ try
199+ {
200+ StatusCode = ( AsyncStatusResponse_statuscode ) ostatuscode . Value ;
201+ }
202+ catch
203+ {
204+ StatusCode = AsyncStatusResponse_statuscode . FailedParse ;
205+ }
206+
207+ }
208+ }
209+
210+ }
211+ }
212+ #pragma warning restore CS1591
0 commit comments