/// <inheritdoc />
        public async override Task <BigQueryRoutine> GetRoutineAsync(RoutineReference routineReference, GetRoutineOptions options = null, CancellationToken cancellationToken = default)
        {
            var request  = CreateGetRoutineRequest(routineReference, options);
            var resource = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false);

            return(new BigQueryRoutine(this, resource));
        }
        private GetRequest CreateGetRoutineRequest(RoutineReference routineReference, GetRoutineOptions options)
        {
            GaxPreconditions.CheckNotNull(routineReference, nameof(routineReference));

            var request = Service.Routines.Get(routineReference.ProjectId, routineReference.DatasetId, routineReference.RoutineId);

            options?.ModifyRequest(request);
            RetryHandler.MarkAsRetriable(request);
            request.PrettyPrint = PrettyPrint;
            return(request);
        }
        /// <inheritdoc />
        public override BigQueryRoutine GetRoutine(RoutineReference routineReference, GetRoutineOptions options = null)
        {
            var request  = CreateGetRoutineRequest(routineReference, options);
            var resource = request.Execute();

            return(new BigQueryRoutine(this, resource));
        }
        /// <inheritdoc />
        public override BigQueryRoutine GetOrCreateRoutine(RoutineReference routineReference, Routine resource, GetRoutineOptions getOptions = null, CreateRoutineOptions createOptions = null)
        {
            CheckResourceReference(routineReference, resource);

            try
            {
                return(GetRoutine(routineReference, getOptions));
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
            {
                try
                {
                    return(CreateRoutine(routineReference, resource, createOptions));
                }
                catch (GoogleApiException ex2) when(ex2.HttpStatusCode == HttpStatusCode.Conflict)
                {
                    return(GetRoutine(routineReference, getOptions));
                }
            }
        }
        /// <inheritdoc />
        public async override Task <BigQueryRoutine> GetOrCreateRoutineAsync(RoutineReference routineReference, Routine resource, GetRoutineOptions getOptions = null, CreateRoutineOptions createOptions = null, CancellationToken cancellationToken = default)
        {
            CheckResourceReference(routineReference, resource);

            try
            {
                return(await GetRoutineAsync(routineReference, getOptions, cancellationToken).ConfigureAwait(false));
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
            {
                try
                {
                    return(await CreateRoutineAsync(routineReference, resource, createOptions, cancellationToken).ConfigureAwait(false));
                }
                catch (GoogleApiException ex2) when(ex2.HttpStatusCode == HttpStatusCode.Conflict)
                {
                    return(await GetRoutineAsync(routineReference, getOptions, cancellationToken).ConfigureAwait(false));
                }
            }
        }
 /// <summary>
 /// Asynchronously retrieves the specified routine.
 /// This method just creates a <see cref="RoutineReference"/> and delegates to <see cref="GetRoutineAsync(RoutineReference, GetRoutineOptions, CancellationToken)"/>.
 /// </summary>
 /// <param name="projectId">The project ID. Must not be null.</param>
 /// <param name="datasetId">The dataset ID. Must not be null.</param>
 /// <param name="routineId">The routine ID. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the requested routine.</returns>
 public virtual Task <BigQueryRoutine> GetRoutineAsync(string projectId, string datasetId, string routineId, GetRoutineOptions options = null, CancellationToken cancellationToken = default) =>
 GetRoutineAsync(GetRoutineReference(projectId, datasetId, routineId), options, cancellationToken);
 /// <summary>
 /// Asynchronously retrieves the specified routine.
 /// </summary>
 /// <param name="routineReference">A fully-qualified identifier for the routine. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the requested routine.</returns>
 public virtual Task <BigQueryRoutine> GetRoutineAsync(RoutineReference routineReference, GetRoutineOptions options = null, CancellationToken cancellationToken = default) =>
 throw new NotImplementedException();
 /// <summary>
 /// Retrieves the specified routine.
 /// </summary>
 /// <param name="routineReference">A fully-qualified identifier for the routine. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The requested routine.</returns>
 public virtual BigQueryRoutine GetRoutine(RoutineReference routineReference, GetRoutineOptions options = null) =>
 throw new NotImplementedException();
 /// <summary>
 /// Retrieves the specified routine.
 /// This method just creates a <see cref="RoutineReference"/> and delegates to <see cref="GetRoutine(RoutineReference, GetRoutineOptions)"/>.
 /// </summary>
 /// <param name="projectId">The project ID. Must not be null.</param>
 /// <param name="datasetId">The dataset ID. Must not be null.</param>
 /// <param name="routineId">The routine ID. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The requested routine.</returns>
 public virtual BigQueryRoutine GetRoutine(string projectId, string datasetId, string routineId, GetRoutineOptions options = null) =>
 GetRoutine(GetRoutineReference(projectId, datasetId, routineId), options);
 /// <summary>
 /// Asynchronously attempts to fetch the specified routine, creating it if it doesn't exist.
 /// This method just creates a <see cref="RoutineReference"/> and delegates to <see cref="GetOrCreateRoutineAsync(RoutineReference, Routine, GetRoutineOptions, CreateRoutineOptions, CancellationToken)"/>.
 /// </summary>
 /// <param name="projectId">The project ID. Must not be null.</param>
 /// <param name="datasetId">The dataset ID. Must not be null.</param>
 /// <param name="routineId">The routine ID. Must not be null.</param>
 /// <param name="resource">The routine resource representation to use for the creation. Must not be null. If this routine's <see cref="Routine.RoutineReference"/> is specified, then it must be the same as the one obtained from the other parameters, else it will be set to the one obtained from the other parameters.</param>
 /// <param name="getOptions">The options for the "get" operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="createOptions">The options for the "create" operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the existing or new routine.</returns>
 public virtual Task <BigQueryRoutine> GetOrCreateRoutineAsync(string projectId, string datasetId, string routineId, Routine resource, GetRoutineOptions getOptions = null, CreateRoutineOptions createOptions = null, CancellationToken cancellationToken = default) =>
 GetOrCreateRoutineAsync(GetRoutineReference(projectId, datasetId, routineId), resource, getOptions, createOptions, cancellationToken);
 /// <summary>
 /// Attempts to fetch the specified routine, creating it if it doesn't exist.
 /// </summary>
 /// <param name="routineReference">A fully-qualified identifier for the routine. Must not be null.</param>
 /// <param name="resource">The routine resource representation to use for the creation. Must not be null. If this routine's <see cref="Routine.RoutineReference"/> is specified, then it must be the same as the one obtained from the other parameters, else it will be set to the one obtained from the other parameters.</param>
 /// <param name="getOptions">The options for the "get" operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="createOptions">The options for the "create" operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The existing or new routine.</returns>
 public virtual BigQueryRoutine GetOrCreateRoutine(RoutineReference routineReference, Routine resource, GetRoutineOptions getOptions = null, CreateRoutineOptions createOptions = null) =>
 throw new NotImplementedException();
 /// <summary>
 /// Attempts to fetch the specified routine, creating it if it doesn't exist.
 /// This method just creates a <see cref="RoutineReference"/> and delegates to <see cref="GetOrCreateRoutine(RoutineReference, Routine, GetRoutineOptions, CreateRoutineOptions)"/>.
 /// </summary>
 /// <param name="projectId">The project ID. Must not be null.</param>
 /// <param name="datasetId">The dataset ID. Must not be null.</param>
 /// <param name="routineId">The routine ID. Must not be null.</param>
 /// <param name="resource">The routine resource representation to use for the creation. Must not be null. If this routine's <see cref="Routine.RoutineReference"/> is specified, then it must be the same as the one obtained from the other parameters, else it will be set to the one obtained from the other parameters.</param>
 /// <param name="getOptions">The options for the "get" operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="createOptions">The options for the "create" operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The existing or new routine.</returns>
 public virtual BigQueryRoutine GetOrCreateRoutine(string projectId, string datasetId, string routineId, Routine resource, GetRoutineOptions getOptions = null, CreateRoutineOptions createOptions = null) =>
 GetOrCreateRoutine(GetRoutineReference(projectId, datasetId, routineId), resource, getOptions, createOptions);