예제 #1
0
        /// <summary>
        /// Copy a custom model stored in this resource (the source) to the user specified
        /// target Form Recognizer resource.
        /// </summary>
        /// <param name="modelId">Model identifier of the model to copy to the target Form Recognizer resource.</param>
        /// <param name="target">A <see cref="CopyAuthorization"/> with the copy authorization to the target Form Recognizer resource.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <returns>A <see cref="CopyModelOperation"/> to wait on this long-running operation.  Its <see cref="CopyModelOperation.Value"/> upon successful
        /// completion will contain meta-data about the model copied.</returns>
        public virtual CopyModelOperation StartCopyModel(string modelId, CopyAuthorization target, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(modelId, nameof(modelId));
            Argument.AssertNotNull(target, nameof(target));

            using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormTrainingClient)}.{nameof(StartCopyModel)}");
            scope.Start();

            try
            {
                Guid guid    = ClientCommon.ValidateModelId(modelId, nameof(modelId));
                var  request = new CopyRequest(target.ResourceId,
                                               target.Region,
                                               new CopyAuthorizationResult(target.ModelId, target.AccessToken, target.ExpiresOn.ToUnixTimeSeconds()));

                Response response = ServiceClient.CopyCustomModel(guid, request, cancellationToken);
                string   location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

                return(new CopyModelOperation(ServiceClient, Diagnostics, location, target.ModelId));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
예제 #2
0
        public virtual CopyModelOperation StartCopyModel(string modelId, CopyAuthorization target, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(modelId, nameof(modelId));
            Argument.AssertNotNull(target, nameof(target));

            Guid guid    = ClientCommon.ValidateModelId(modelId, nameof(modelId));
            var  request = new CopyRequest(target.ResourceId,
                                           target.Region,
                                           new CopyAuthorizationResult(target.ModelId, target.AccessToken, target.ExpiresOn /*.ToUnixTimeSeconds()*/));

            ResponseWithHeaders <ServiceCopyCustomModelHeaders> response = ServiceClient.CopyCustomModel(guid, request, cancellationToken);

            return(new CopyModelOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, target.ModelId));
        }