Skip to content

Commit

Permalink
Remove duplication in DataPlaneRestClient/RestClient (#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
chamons authored Jun 4, 2021
1 parent a5a7a52 commit 7effb48
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 61 deletions.
6 changes: 3 additions & 3 deletions src/AutoRest.CSharp/Common/Output/Models/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected virtual Dictionary<ServiceRequest, RestClientMethod> EnsureNormalMetho
return requestMethods;
}

protected virtual Dictionary<ServiceRequest, RestClientMethod> EnsureGetNextPageMethods()
protected Dictionary<ServiceRequest, RestClientMethod> EnsureGetNextPageMethods()
{
var nextPageMethods = new Dictionary<ServiceRequest, RestClientMethod>();
foreach (var operation in OperationGroup.Operations)
Expand Down Expand Up @@ -177,13 +177,13 @@ protected static RestClientMethod BuildNextPageMethod(RestClientMethod method, O
operation);
}

public virtual RestClientMethod? GetNextOperationMethod(ServiceRequest request)
public RestClientMethod? GetNextOperationMethod(ServiceRequest request)
{
_nextPageMethods.TryGetValue(request, out RestClientMethod? value);
return value;
}

public virtual RestClientMethod GetOperationMethod(ServiceRequest request)
public RestClientMethod GetOperationMethod(ServiceRequest request)
{
return _requestMethods[request];
}
Expand Down
58 changes: 0 additions & 58 deletions src/AutoRest.CSharp/DataPlane/Output/DataPlaneRestClient.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using AutoRest.CSharp.Generation.Types;
using AutoRest.CSharp.Input;
using AutoRest.CSharp.Output.Models.Requests;
using AutoRest.CSharp.Output.Models.Responses;
using AutoRest.CSharp.Output.Models.Serialization;
using AutoRest.CSharp.Output.Models.Shared;
using AutoRest.CSharp.Output.Models.Types;
using AutoRest.CSharp.Utilities;
using Azure.Core;
using Request = AutoRest.CSharp.Output.Models.Requests.Request;
using StatusCodes = AutoRest.CSharp.Output.Models.Responses.StatusCodes;

namespace AutoRest.CSharp.Output.Models
{
internal class DataPlaneRestClient : RestClient
{
private CachedDictionary<ServiceRequest, RestClientMethod> _requestMethods;
private CachedDictionary<ServiceRequest, RestClientMethod> _nextPageMethods;
private BuildContext<DataPlaneOutputLibrary> _context;

public DataPlaneRestClient(OperationGroup operationGroup, BuildContext<DataPlaneOutputLibrary> context)
: base(operationGroup, context, context.Library.FindClient(operationGroup)?.Declaration?.Name)
{
_context = context;
_requestMethods = new CachedDictionary<ServiceRequest, RestClientMethod> (EnsureNormalMethods);
_nextPageMethods = new CachedDictionary<ServiceRequest, RestClientMethod> (EnsureGetNextPageMethods);
}

protected override Dictionary<ServiceRequest, RestClientMethod> EnsureNormalMethods()
Expand All @@ -53,49 +39,5 @@ protected override Dictionary<ServiceRequest, RestClientMethod> EnsureNormalMeth

return requestMethods;
}

protected override Dictionary<ServiceRequest, RestClientMethod> EnsureGetNextPageMethods()
{
var nextPageMethods = new Dictionary<ServiceRequest, RestClientMethod>();
foreach (var operation in OperationGroup.Operations)
{
var paging = operation.Language.Default.Paging;
if (paging == null)
{
continue;
}
foreach (var serviceRequest in operation.Requests)
{
RestClientMethod? nextMethod = null;
if (paging.NextLinkOperation != null)
{
nextMethod = GetOperationMethod(paging.NextLinkOperation.Requests.Single());
}
else if (paging.NextLinkName != null)
{
var method = GetOperationMethod(serviceRequest);
nextMethod = BuildNextPageMethod(method, operation);
}

if (nextMethod != null)
{
nextPageMethods.Add(serviceRequest, nextMethod);
}
}
}

return nextPageMethods;
}

public override RestClientMethod? GetNextOperationMethod(ServiceRequest request)
{
_nextPageMethods.TryGetValue(request, out RestClientMethod? value);
return value;
}

public override RestClientMethod GetOperationMethod(ServiceRequest request)
{
return _requestMethods[request];
}
}
}

0 comments on commit 7effb48

Please sign in to comment.