@@ -31,7 +31,7 @@ namespace Azure.Generator.Management.Providers
3131 /// </summary>
3232 internal class ResourceClientProvider : TypeProvider
3333 {
34- private IReadOnlyCollection < InputOperation > _resourceOperations ;
34+ private IReadOnlyCollection < InputServiceMethod > _resourceServiceMethods ;
3535 private readonly IReadOnlyList < string > _contextualParameters ;
3636 private bool _isSingleton ;
3737
@@ -52,8 +52,8 @@ public ResourceClientProvider(InputClient inputClient)
5252 SpecName = resourceModel . Name ;
5353
5454 // We should be able to assume that all operations in the resource client are for the same resource
55- var requestPath = new RequestPath ( inputClient . Operations . First ( ) . Path ) ;
56- _resourceOperations = inputClient . Operations ;
55+ var requestPath = new RequestPath ( inputClient . Methods . First ( ) . Operation . Path ) ;
56+ _resourceServiceMethods = inputClient . Methods ;
5757 ResourceData = ManagementClientGenerator . Instance . TypeFactory . CreateModel ( resourceModel ) ! ;
5858 _clientProvider = ManagementClientGenerator . Instance . TypeFactory . CreateClient ( inputClient ) ! ;
5959
@@ -203,36 +203,36 @@ protected MethodProvider BuildValidateResourceIdMethod()
203203 protected override MethodProvider [ ] BuildMethods ( )
204204 {
205205 var operationMethods = new List < MethodProvider > ( ) ;
206- foreach ( var operation in _resourceOperations )
206+ foreach ( var method in _resourceServiceMethods )
207207 {
208- var convenienceMethod = GetCorrespondingConvenienceMethod ( operation , false ) ;
208+ var convenienceMethod = GetCorrespondingConvenienceMethod ( method . Operation , false ) ;
209209 // exclude the List operations for resource, they will be in ResourceCollection
210210 var returnType = convenienceMethod . Signature . ReturnType ! ;
211- if ( ( returnType . IsFrameworkType && returnType . IsList ) || operation . Paging ? . ItemPropertySegments . Any ( ) == true )
211+ if ( ( returnType . IsFrameworkType && returnType . IsList ) || ( method is InputPagingServiceMethod pagingMethod && pagingMethod . PagingMetadata . ItemPropertySegments . Any ( ) == true ) )
212212 {
213213 continue ;
214214 }
215215
216216 // only update for non-singleton resource
217- var isUpdateOnly = operation . HttpMethod == HttpMethod . Put . ToString ( ) && ! _isSingleton ;
218- operationMethods . Add ( BuildOperationMethod ( operation , convenienceMethod , false , isUpdateOnly ) ) ;
219- var asyncConvenienceMethod = GetCorrespondingConvenienceMethod ( operation , true ) ;
220- operationMethods . Add ( BuildOperationMethod ( operation , asyncConvenienceMethod , true , isUpdateOnly ) ) ;
217+ var isUpdateOnly = method . Operation . HttpMethod == HttpMethod . Put . ToString ( ) && ! _isSingleton ;
218+ operationMethods . Add ( BuildOperationMethod ( method , convenienceMethod , false , isUpdateOnly ) ) ;
219+ var asyncConvenienceMethod = GetCorrespondingConvenienceMethod ( method . Operation , true ) ;
220+ operationMethods . Add ( BuildOperationMethod ( method , asyncConvenienceMethod , true , isUpdateOnly ) ) ;
221221 }
222222
223223 return [ BuildValidateResourceIdMethod ( ) , .. operationMethods ] ;
224224 }
225225
226- private MethodProvider BuildOperationMethod ( InputOperation operation , MethodProvider convenienceMethod , bool isAsync , bool isUpdateOnly = false )
226+ private MethodProvider BuildOperationMethod ( InputServiceMethod method , MethodProvider convenienceMethod , bool isAsync , bool isUpdateOnly = false )
227227 {
228- var isLongRunning = operation . LongRunning != null ;
228+ var operation = method . Operation ;
229229 var signature = new MethodSignature (
230230 isUpdateOnly ? ( isAsync ? "UpdateAsync" : "Update" ) : convenienceMethod . Signature . Name ,
231231 isUpdateOnly ? $ "Update a { SpecName } " : convenienceMethod . Signature . Description ,
232232 convenienceMethod . Signature . Modifiers ,
233- GetOperationMethodReturnType ( isAsync , isLongRunning , operation . Responses , out var isGeneric ) ,
233+ GetOperationMethodReturnType ( isAsync , method is InputLongRunningServiceMethod || method is InputLongRunningPagingServiceMethod , operation . Responses , out var isGeneric ) ,
234234 convenienceMethod . Signature . ReturnDescription ,
235- GetOperationMethodParameters ( convenienceMethod , isLongRunning ) ,
235+ GetOperationMethodParameters ( convenienceMethod , method is InputLongRunningServiceMethod ) ,
236236 convenienceMethod . Signature . Attributes ,
237237 convenienceMethod . Signature . GenericArguments ,
238238 convenienceMethod . Signature . GenericParameterConstraints ,
@@ -244,7 +244,7 @@ private MethodProvider BuildOperationMethod(InputOperation operation, MethodProv
244244 UsingDeclare ( "scope" , typeof ( DiagnosticScope ) , _clientDiagonosticsField . Invoke ( nameof ( ClientDiagnostics . CreateScope ) , [ Literal ( $ "{ Type . Namespace } .{ operation . Name } ") ] ) , out var scopeVariable ) ,
245245 scopeVariable . Invoke ( nameof ( DiagnosticScope . Start ) ) . Terminate ( ) ,
246246 new TryCatchFinallyStatement
247- ( BuildOperationMethodTryStatement ( convenienceMethod , isAsync , isLongRunning , operation , isGeneric ) , Catch ( Declare < Exception > ( "e" , out var exceptionVarialble ) , [ scopeVariable . Invoke ( nameof ( DiagnosticScope . Failed ) , exceptionVarialble ) . Terminate ( ) , Throw ( ) ] ) )
247+ ( BuildOperationMethodTryStatement ( convenienceMethod , isAsync , method , isGeneric ) , Catch ( Declare < Exception > ( "e" , out var exceptionVarialble ) , [ scopeVariable . Invoke ( nameof ( DiagnosticScope . Failed ) , exceptionVarialble ) . Terminate ( ) , Throw ( ) ] ) )
248248 } ;
249249
250250 return new MethodProvider ( signature , bodyStatements , this ) ;
@@ -287,8 +287,9 @@ protected CSharpType GetOperationMethodReturnType(bool isAsync, bool isLongRunni
287287 return isAsync ? new CSharpType ( typeof ( Task < > ) , new CSharpType ( typeof ( Response < > ) , Type ) ) : new CSharpType ( typeof ( Response < > ) , Type ) ;
288288 }
289289
290- private TryStatement BuildOperationMethodTryStatement ( MethodProvider convenienceMethod , bool isAsync , bool isLongRunning , InputOperation operation , bool isGeneric )
290+ private TryStatement BuildOperationMethodTryStatement ( MethodProvider convenienceMethod , bool isAsync , InputServiceMethod method , bool isGeneric )
291291 {
292+ var operation = method . Operation ;
292293 var cancellationToken = convenienceMethod . Signature . Parameters . Single ( p => p . Type . Equals ( typeof ( CancellationToken ) ) ) ;
293294 var tryStatement = new TryStatement ( ) ;
294295 var contextDeclaration = Declare ( "context" , typeof ( RequestContext ) , New . Instance ( typeof ( RequestContext ) , new Dictionary < ValueExpression , ValueExpression > { { Identifier ( nameof ( RequestContext . CancellationToken ) ) , cancellationToken } } ) , out var contextVariable ) ;
@@ -311,10 +312,20 @@ private TryStatement BuildOperationMethodTryStatement(MethodProvider convenience
311312 tryStatement . Add ( responseDeclaration ) ;
312313 }
313314
314- if ( isLongRunning )
315+ if ( method is InputLongRunningServiceMethod || method is InputLongRunningPagingServiceMethod )
315316 {
317+ OperationFinalStateVia finalStateVia = OperationFinalStateVia . Location ;
318+ if ( method is InputLongRunningServiceMethod lroMethod )
319+ {
320+ finalStateVia = ( OperationFinalStateVia ) lroMethod . LongRunningServiceMetadata . FinalStateVia ;
321+ }
322+ else if ( method is InputLongRunningPagingServiceMethod lroPagingMethod )
323+ {
324+ finalStateVia = ( OperationFinalStateVia ) lroPagingMethod . LongRunningServiceMetadata . FinalStateVia ;
325+ }
326+
316327 var armOperationType = ! isGeneric ? ManagementClientGenerator . Instance . OutputLibrary . ArmOperation . Type : ManagementClientGenerator . Instance . OutputLibrary . GenericArmOperation . Type . MakeGenericType ( [ Type ] ) ;
317- ValueExpression [ ] armOperationArguments = [ _clientDiagonosticsField , This . Property ( "Pipeline" ) , messageVariable . Property ( "Request" ) , isGeneric ? responseVariable . Invoke ( "GetRawResponse" ) : responseVariable , Static ( typeof ( OperationFinalStateVia ) ) . Property ( ( ( OperationFinalStateVia ) operation . LongRunning ! . FinalStateVia ) . ToString ( ) ) ] ;
328+ ValueExpression [ ] armOperationArguments = [ _clientDiagonosticsField , This . Property ( "Pipeline" ) , messageVariable . Property ( "Request" ) , isGeneric ? responseVariable . Invoke ( "GetRawResponse" ) : responseVariable , Static ( typeof ( OperationFinalStateVia ) ) . Property ( finalStateVia . ToString ( ) ) ] ;
318329 var operationDeclaration = Declare ( "operation" , armOperationType , New . Instance ( armOperationType , isGeneric ? [ New . Instance ( Source . Type , This . Property ( "Client" ) ) , .. armOperationArguments ] : armOperationArguments ) , out var operationVariable ) ;
319330
320331 tryStatement . Add ( operationDeclaration ) ;
0 commit comments