/// <summary> /// Initializes a new instance of the <see cref="AnalyzeHealthcareEntitiesOperation"/> class. /// </summary> /// <param name="serviceClient">The client for communicating with the Text Analytics Azure Cognitive Service through its REST API.</param> /// <param name="diagnostics">The client diagnostics for exception creation in case of failure.</param> /// <param name="operationLocation">The address of the long-running operation. It can be obtained from the response headers upon starting the operation.</param> /// <param name="idToIndexMap"></param> /// <param name="showStats"></param> internal AnalyzeHealthcareEntitiesOperation(ServiceClient serviceClient, ClientDiagnostics diagnostics, string operationLocation, IDictionary <string, int> idToIndexMap, bool?showStats = default) { _serviceClient = serviceClient; _diagnostics = diagnostics; _idToIndexMap = idToIndexMap; _showStats = showStats; _operationInternal = new(_diagnostics, this, rawResponse : null); _jobId = operationLocation.Split('/').Last().Split('?')[0]; Id = OperationContinuationToken.Serialize(_jobId, idToIndexMap, showStats); }
/// <summary> /// Initializes a new instance of the <see cref="AnalyzeHealthcareEntitiesOperation"/> class. /// </summary> /// <param name="serviceClient">The client for communicating with the Text Analytics Azure Cognitive Service through its REST API.</param> /// <param name="diagnostics">The client diagnostics for exception creation in case of failure.</param> /// <param name="operationLocation">The address of the long-running operation. It can be obtained from the response headers upon starting the operation.</param> /// <param name="idToIndexMap"></param> /// <param name="showStats"></param> internal AnalyzeHealthcareEntitiesOperation(TextAnalyticsRestClient serviceClient, ClientDiagnostics diagnostics, string operationLocation, IDictionary <string, int> idToIndexMap, bool?showStats = default) { _serviceClient = serviceClient; _diagnostics = diagnostics; _idToIndexMap = idToIndexMap; _showStats = showStats; _operationInternal = new(_diagnostics, this, rawResponse : null); // TODO: Add validation here // https://github.com/Azure/azure-sdk-for-net/issues/11505 _jobId = operationLocation.Split('/').Last(); Id = OperationContinuationToken.Serialize(_jobId, idToIndexMap, showStats); }
/// <exception cref="ArgumentException">Thrown when the <see cref="Version"/> of the deserialized token is not the expected <see cref="LatestTokenVersion"/>.</exception> /// <exception cref="FormatException">Thrown when <paramref name="base64OperationId"/> is not a valid base-64 string.</exception> /// <exception cref="JsonException">Thrown when <paramref name="base64OperationId"/> cannot be deserialized from JSON.</exception> public static OperationContinuationToken Deserialize(string base64OperationId) { byte[] plainTextBytes = Convert.FromBase64String(base64OperationId); OperationContinuationToken token = JsonSerializer.Deserialize <OperationContinuationToken>(plainTextBytes, s_jsonOptions); if (token.Version != s_latestTokenVersion) { throw new ArgumentException($"Unsupported continuation token version. Expected: '{s_latestTokenVersion}'. Actual: '{token.Version}'."); } Argument.AssertNotNull(token.JobId, nameof(JobId)); Argument.AssertNotNull(token.InputDocumentOrder, nameof(InputDocumentOrder)); return(token); }
/// <summary> /// Initializes a new instance of the <see cref="AnalyzeHealthcareEntitiesOperation"/> class. /// </summary> /// <param name="operationId">The ID of this operation.</param> /// <param name="client">The client used to check for completion.</param> public AnalyzeHealthcareEntitiesOperation(string operationId, TextAnalyticsClient client) { Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); Argument.AssertNotNull(client, nameof(client)); try { OperationContinuationToken token = OperationContinuationToken.Deserialize(operationId); _jobId = token.JobId; _showStats = token.ShowStats; _idToIndexMap = token.InputDocumentOrder; } catch (Exception e) { throw new ArgumentException($"Invalid value. Please use the {nameof(AnalyzeHealthcareEntitiesOperation)}.{nameof(Id)} property value.", nameof(operationId), e); } Id = operationId; _serviceClient = client.ServiceClient; _diagnostics = _serviceClient.Diagnostics; _operationInternal = new(_diagnostics, this, rawResponse : null); }