Skip to content

Commit

Permalink
.NET SDK Resource Provider:'Billing' (Azure#5682)
Browse files Browse the repository at this point in the history
REST Spec PR 'Azure/azure-rest-api-specs#5546'
REST Spec PR Author 'asarkar84'
REST Spec PR Last commit
  • Loading branch information
adxsdknet authored and dsgouda committed Apr 4, 2019
1 parent cf773fc commit b81f596
Show file tree
Hide file tree
Showing 18 changed files with 1,755 additions and 322 deletions.
433 changes: 433 additions & 0 deletions src/SDKs/Billing/Management.Billing/Generated/AgreementsOperations.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// <auto-generated>
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>

namespace Microsoft.Azure.Management.Billing
{
using Microsoft.Rest;
using Microsoft.Rest.Azure;
using Models;
using System.Threading;
using System.Threading.Tasks;

/// <summary>
/// Extension methods for AgreementsOperations.
/// </summary>
public static partial class AgreementsOperationsExtensions
{
/// <summary>
/// Lists all agreements for a billing account.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='billingAccountName'>
/// billing Account Id.
/// </param>
/// <param name='expand'>
/// May be used to expand the participants.
/// </param>
public static AgreementListResult ListByBillingAccountName(this IAgreementsOperations operations, string billingAccountName, string expand = default(string))
{
return operations.ListByBillingAccountNameAsync(billingAccountName, expand).GetAwaiter().GetResult();
}

/// <summary>
/// Lists all agreements for a billing account.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='billingAccountName'>
/// billing Account Id.
/// </param>
/// <param name='expand'>
/// May be used to expand the participants.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static async Task<AgreementListResult> ListByBillingAccountNameAsync(this IAgreementsOperations operations, string billingAccountName, string expand = default(string), CancellationToken cancellationToken = default(CancellationToken))
{
using (var _result = await operations.ListByBillingAccountNameWithHttpMessagesAsync(billingAccountName, expand, null, cancellationToken).ConfigureAwait(false))
{
return _result.Body;
}
}

/// <summary>
/// Get the agreement by name.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='billingAccountName'>
/// billing Account Id.
/// </param>
/// <param name='agreementName'>
/// Agreement Id.
/// </param>
/// <param name='expand'>
/// May be used to expand the participants.
/// </param>
public static Agreement Get(this IAgreementsOperations operations, string billingAccountName, string agreementName, string expand = default(string))
{
return operations.GetAsync(billingAccountName, agreementName, expand).GetAwaiter().GetResult();
}

/// <summary>
/// Get the agreement by name.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='billingAccountName'>
/// billing Account Id.
/// </param>
/// <param name='agreementName'>
/// Agreement Id.
/// </param>
/// <param name='expand'>
/// May be used to expand the participants.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static async Task<Agreement> GetAsync(this IAgreementsOperations operations, string billingAccountName, string agreementName, string expand = default(string), CancellationToken cancellationToken = default(CancellationToken))
{
using (var _result = await operations.GetWithHttpMessagesAsync(billingAccountName, agreementName, expand, null, cancellationToken).ConfigureAwait(false))
{
return _result.Body;
}
}

}
}
241 changes: 18 additions & 223 deletions src/SDKs/Billing/Management.Billing/Generated/BillingManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ public partial class BillingManagementClient : ServiceClient<BillingManagementCl
/// </summary>
public virtual ITransactionsByBillingAccountOperations TransactionsByBillingAccount { get; private set; }

/// <summary>
/// Gets the ITransactionsByBillingProfileOperations.
/// </summary>
public virtual ITransactionsByBillingProfileOperations TransactionsByBillingProfile { get; private set; }

/// <summary>
/// Gets the ITransactionsByInvoiceSectionOperations.
/// </summary>
public virtual ITransactionsByInvoiceSectionOperations TransactionsByInvoiceSection { get; private set; }

/// <summary>
/// Gets the IPolicyOperations.
/// </summary>
Expand Down Expand Up @@ -273,6 +283,11 @@ public partial class BillingManagementClient : ServiceClient<BillingManagementCl
/// </summary>
public virtual IBillingProfileBillingRoleAssignmentOperations BillingProfileBillingRoleAssignment { get; private set; }

/// <summary>
/// Gets the IAgreementsOperations.
/// </summary>
public virtual IAgreementsOperations Agreements { get; private set; }

/// <summary>
/// Initializes a new instance of the BillingManagementClient class.
/// </summary>
Expand Down Expand Up @@ -539,6 +554,8 @@ private void Initialize()
ProductsByInvoiceSection = new ProductsByInvoiceSectionOperations(this);
Products = new ProductsOperations(this);
TransactionsByBillingAccount = new TransactionsByBillingAccountOperations(this);
TransactionsByBillingProfile = new TransactionsByBillingProfileOperations(this);
TransactionsByInvoiceSection = new TransactionsByInvoiceSectionOperations(this);
Policy = new PolicyOperations(this);
BillingProperty = new BillingPropertyOperations(this);
Transfers = new TransfersOperations(this);
Expand All @@ -553,6 +570,7 @@ private void Initialize()
BillingAccountBillingRoleAssignment = new BillingAccountBillingRoleAssignmentOperations(this);
InvoiceSectionBillingRoleAssignment = new InvoiceSectionBillingRoleAssignmentOperations(this);
BillingProfileBillingRoleAssignment = new BillingProfileBillingRoleAssignmentOperations(this);
Agreements = new AgreementsOperations(this);
BaseUri = new System.Uri("https://management.azure.com");
ApiVersion = "2018-11-01-preview";
AcceptLanguage = "en-US";
Expand Down Expand Up @@ -588,229 +606,6 @@ private void Initialize()
DeserializationSettings.Converters.Add(new TransformationJsonConverter());
DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
}
/// <summary>
/// Lists the transactions by billingProfileName for given start date and end
/// date.
/// <see href="https://docs.microsoft.com/en-us/rest/api/consumption/" />
/// </summary>
/// <param name='billingAccountName'>
/// billing Account Id.
/// </param>
/// <param name='billingProfileName'>
/// Billing Profile Id.
/// </param>
/// <param name='startDate'>
/// Start date
/// </param>
/// <param name='endDate'>
/// End date
/// </param>
/// <param name='filter'>
/// May be used to filter by transaction kind. The filter supports 'eq', 'lt',
/// 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or
/// 'not'. Tag filter is a key value pair string where key and value is
/// separated by a colon (:).
/// </param>
/// <param name='customHeaders'>
/// Headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <exception cref="ErrorResponseException">
/// Thrown when the operation returned an invalid status code
/// </exception>
/// <exception cref="SerializationException">
/// Thrown when unable to deserialize the response
/// </exception>
/// <exception cref="ValidationException">
/// Thrown when a required parameter is null
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Thrown when a required parameter is null
/// </exception>
/// <return>
/// A response object containing the response body and response headers.
/// </return>
public async Task<AzureOperationResponse<TransactionsListResult>> TransactionsByBillingProfileWithHttpMessagesAsync(string billingAccountName, string billingProfileName, string startDate, string endDate, string filter = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (billingAccountName == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "billingAccountName");
}
if (billingProfileName == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "billingProfileName");
}
if (ApiVersion == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "this.ApiVersion");
}
if (startDate == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "startDate");
}
if (endDate == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "endDate");
}
// Tracing
bool _shouldTrace = ServiceClientTracing.IsEnabled;
string _invocationId = null;
if (_shouldTrace)
{
_invocationId = ServiceClientTracing.NextInvocationId.ToString();
Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
tracingParameters.Add("billingAccountName", billingAccountName);
tracingParameters.Add("billingProfileName", billingProfileName);
tracingParameters.Add("startDate", startDate);
tracingParameters.Add("endDate", endDate);
tracingParameters.Add("filter", filter);
tracingParameters.Add("cancellationToken", cancellationToken);
ServiceClientTracing.Enter(_invocationId, this, "TransactionsByBillingProfile", tracingParameters);
}
// Construct URL
var _baseUrl = BaseUri.AbsoluteUri;
var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/transactions").ToString();
_url = _url.Replace("{billingAccountName}", System.Uri.EscapeDataString(billingAccountName));
_url = _url.Replace("{billingProfileName}", System.Uri.EscapeDataString(billingProfileName));
List<string> _queryParameters = new List<string>();
if (ApiVersion != null)
{
_queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(ApiVersion)));
}
if (startDate != null)
{
_queryParameters.Add(string.Format("startDate={0}", System.Uri.EscapeDataString(startDate)));
}
if (endDate != null)
{
_queryParameters.Add(string.Format("endDate={0}", System.Uri.EscapeDataString(endDate)));
}
if (filter != null)
{
_queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter)));
}
if (_queryParameters.Count > 0)
{
_url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
}
// Create HTTP transport objects
var _httpRequest = new HttpRequestMessage();
HttpResponseMessage _httpResponse = null;
_httpRequest.Method = new HttpMethod("GET");
_httpRequest.RequestUri = new System.Uri(_url);
// Set Headers
if (GenerateClientRequestId != null && GenerateClientRequestId.Value)
{
_httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString());
}
if (AcceptLanguage != null)
{
if (_httpRequest.Headers.Contains("accept-language"))
{
_httpRequest.Headers.Remove("accept-language");
}
_httpRequest.Headers.TryAddWithoutValidation("accept-language", AcceptLanguage);
}


if (customHeaders != null)
{
foreach(var _header in customHeaders)
{
if (_httpRequest.Headers.Contains(_header.Key))
{
_httpRequest.Headers.Remove(_header.Key);
}
_httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
}
}

// Serialize Request
string _requestContent = null;
// Set Credentials
if (Credentials != null)
{
cancellationToken.ThrowIfCancellationRequested();
await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
}
// Send Request
if (_shouldTrace)
{
ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
}
cancellationToken.ThrowIfCancellationRequested();
_httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
if (_shouldTrace)
{
ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
}
HttpStatusCode _statusCode = _httpResponse.StatusCode;
cancellationToken.ThrowIfCancellationRequested();
string _responseContent = null;
if ((int)_statusCode != 200)
{
var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
try
{
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, DeserializationSettings);
if (_errorBody != null)
{
ex.Body = _errorBody;
}
}
catch (JsonException)
{
// Ignore the exception
}
ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
if (_shouldTrace)
{
ServiceClientTracing.Error(_invocationId, ex);
}
_httpRequest.Dispose();
if (_httpResponse != null)
{
_httpResponse.Dispose();
}
throw ex;
}
// Create Result
var _result = new AzureOperationResponse<TransactionsListResult>();
_result.Request = _httpRequest;
_result.Response = _httpResponse;
if (_httpResponse.Headers.Contains("x-ms-request-id"))
{
_result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
}
// Deserialize Response
if ((int)_statusCode == 200)
{
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
try
{
_result.Body = SafeJsonConvert.DeserializeObject<TransactionsListResult>(_responseContent, DeserializationSettings);
}
catch (JsonException ex)
{
_httpRequest.Dispose();
if (_httpResponse != null)
{
_httpResponse.Dispose();
}
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
}
}
if (_shouldTrace)
{
ServiceClientTracing.Exit(_invocationId, _result);
}
return _result;
}

/// <summary>
/// Cancel product by product id
/// </summary>
Expand Down
Loading

0 comments on commit b81f596

Please sign in to comment.