internal static TaskState DeserializeTaskState(JsonElement element)
        {
            DateTimeOffset               lastUpdateDateTime = default;
            Optional <string>            name   = default;
            TextAnalyticsOperationStatus status = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("lastUpdateDateTime"))
                {
                    lastUpdateDateTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("status"))
                {
                    status = new TextAnalyticsOperationStatus(property.Value.GetString());
                    continue;
                }
            }
            return(new TaskState(lastUpdateDateTime, name.Value, status));
        }
        internal static KeyPhraseExtractionTasksItem DeserializeKeyPhraseExtractionTasksItem(JsonElement element)
        {
            KeyPhraseResult              results            = default;
            DateTimeOffset               lastUpdateDateTime = default;
            Optional <string>            name   = default;
            TextAnalyticsOperationStatus status = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("results"))
                {
                    results = KeyPhraseResult.DeserializeKeyPhraseResult(property.Value);
                    continue;
                }
                if (property.NameEquals("lastUpdateDateTime"))
                {
                    lastUpdateDateTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("status"))
                {
                    status = new TextAnalyticsOperationStatus(property.Value.GetString());
                    continue;
                }
            }
            return(new KeyPhraseExtractionTasksItem(lastUpdateDateTime, name.Value, status, results));
        }
Esempio n. 3
0
        internal KeyPhraseExtractionTasksItem(DateTimeOffset lastUpdateDateTime, TextAnalyticsOperationStatus status, KeyPhraseResult resultsInternal) : base(lastUpdateDateTime, status)
        {
            if (resultsInternal == null)
            {
                throw new ArgumentNullException(nameof(resultsInternal));
            }

            ResultsInternal = resultsInternal;
        }
Esempio n. 4
0
        internal EntityRecognitionPiiTasksItem(DateTimeOffset lastUpdateDateTime, TextAnalyticsOperationStatus status, PiiEntitiesResult resultsInternal) : base(lastUpdateDateTime, status)
        {
            if (resultsInternal == null)
            {
                throw new ArgumentNullException(nameof(resultsInternal));
            }

            ResultsInternal = resultsInternal;
        }
        /// <summary>
        /// Calls the server to get updated status of the long-running operation.
        /// </summary>
        /// <param name="async">When <c>true</c>, the method will be executed asynchronously; otherwise, it will execute synchronously.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> used for the service call.</param>
        /// <returns>The HTTP response received from the server.</returns>
        private async ValueTask <Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken)
        {
            if (!_hasCompleted)
            {
                using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(AnalyzeHealthcareEntitiesOperation)}.{nameof(UpdateStatus)}");
                scope.Start();

                try
                {
                    Response <HealthcareJobState> update = async
                        ? await _serviceClient.HealthStatusAsync(new Guid(Id), null, null, _showStats, cancellationToken).ConfigureAwait(false)
                        : _serviceClient.HealthStatus(new Guid(Id), null, null, _showStats, cancellationToken);

                    _response     = update.GetRawResponse();
                    _status       = update.Value.Status;
                    _createdOn    = update.Value.CreatedDateTime;
                    _expiresOn    = update.Value.ExpirationDateTime;
                    _lastModified = update.Value.LastUpdateDateTime;

                    if (_status == TextAnalyticsOperationStatus.Succeeded)
                    {
                        var nextLink = update.Value.NextLink;
                        var value    = Transforms.ConvertToAnalyzeHealthcareEntitiesResultCollection(update.Value.Results, _idToIndexMap);
                        _firstPage = Page.FromValues(new List <AnalyzeHealthcareEntitiesResultCollection>()
                        {
                            value
                        }, nextLink, _response);
                        _hasCompleted = true;
                    }
                    else if (_status == TextAnalyticsOperationStatus.Failed)
                    {
                        _requestFailedException = await ClientCommon.CreateExceptionForFailedOperationAsync(async, _diagnostics, _response, update.Value.Errors)
                                                  .ConfigureAwait(false);

                        _hasCompleted = true;
                        throw _requestFailedException;
                    }
                    else if (_status == TextAnalyticsOperationStatus.Cancelled)
                    {
                        _requestFailedException = new RequestFailedException("The operation was canceled so no value is available.");
                        _hasCompleted           = true;
                        throw _requestFailedException;
                    }
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            return(GetRawResponse());
        }
        /// <summary>
        /// Calls the server to get updated status of the long-running operation.
        /// </summary>
        /// <param name="async">When <c>true</c>, the method will be executed asynchronously; otherwise, it will execute synchronously.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> used for the service call.</param>
        /// <returns>The HTTP response received from the server.</returns>
        private async ValueTask <Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken)
        {
            if (!_hasCompleted)
            {
                using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(AnalyzeBatchActionsOperation)}.{nameof(UpdateStatus)}");
                scope.Start();

                try
                {
                    Response <AnalyzeJobState> update = async
                        ? await _serviceClient.AnalyzeStatusAsync(Id, _showStats, null, null, cancellationToken).ConfigureAwait(false)
                        : _serviceClient.AnalyzeStatus(Id, _showStats, null, null, cancellationToken);

                    _response = update.GetRawResponse();

                    _displayName       = update.Value.DisplayName;
                    _createdOn         = update.Value.CreatedDateTime;
                    _expiresOn         = update.Value.ExpirationDateTime;
                    _lastModified      = update.Value.LastUpdateDateTime;
                    _status            = update.Value.Status;
                    _actionsFailed     = update.Value.Tasks.Failed;
                    _actionsInProgress = update.Value.Tasks.InProgress;
                    _actionSucceeded   = update.Value.Tasks.Completed;
                    _totalActions      = update.Value.Tasks.Total;

                    if (update.Value.Status == TextAnalyticsOperationStatus.Succeeded || update.Value.Status == TextAnalyticsOperationStatus.PartiallySucceeded)
                    {
                        // we need to first assign a value and then mark the operation as completed to avoid race conditions
                        var nextLink = update.Value.NextLink;
                        var value    = Transforms.ConvertToAnalyzeOperationResult(update.Value, _idToIndexMap);
                        _firstPage = Page.FromValues(new List <AnalyzeBatchActionsResult>()
                        {
                            value
                        }, nextLink, _response);
                        _hasCompleted = true;
                    }
                    else if (update.Value.Status == TextAnalyticsOperationStatus.Failed)
                    {
                        _requestFailedException = await ClientCommon.CreateExceptionForFailedOperationAsync(async, _diagnostics, _response, update.Value.Errors).ConfigureAwait(false);

                        _hasCompleted = true;
                        throw _requestFailedException;
                    }
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            return(GetRawResponse());
        }
Esempio n. 7
0
        async ValueTask <OperationState <AsyncPageable <AnalyzeActionsResult> > > IOperation <AsyncPageable <AnalyzeActionsResult> > .UpdateStateAsync(bool async, CancellationToken cancellationToken)
        {
            Response <AnalyzeTextJobStatusResult> response = async
                ? await _serviceClient.AnalyzeStatusAsync(_jobId, _showStats, null, null, _idToIndexMap, cancellationToken).ConfigureAwait(false)
                : _serviceClient.AnalyzeStatus(_jobId, _showStats, null, null, _idToIndexMap, cancellationToken);

            _displayName       = response.Value.DisplayName;
            _createdOn         = response.Value.CreatedOn;
            _expiresOn         = response.Value.ExpiresOn;
            _lastModified      = response.Value.LastModifiedOn;
            _status            = response.Value.Status;
            _actionsFailed     = response.Value.ActionsFailed;
            _actionsInProgress = response.Value.AcionsInProgress;
            _actionSucceeded   = response.Value.AcionsSucceeded;
            _actionsTotal      = response.Value.ActionsTotal;

            Response rawResponse = response.GetRawResponse();

            if (response.Value.Status == TextAnalyticsOperationStatus.Failed)
            {
                if (CheckIfGenericError(response.Value))
                {
                    RequestFailedException requestFailedException;

                    if (async)
                    {
                        requestFailedException = await ClientCommon.CreateExceptionForFailedOperationAsync(true, _diagnostics, rawResponse, response.Value.Errors).ConfigureAwait(false);
                    }
                    else
                    {
                        requestFailedException = ClientCommon.CreateExceptionForFailedOperationAsync(false, _diagnostics, rawResponse, response.Value.Errors).EnsureCompleted();
                    }

                    return(OperationState <AsyncPageable <AnalyzeActionsResult> > .Failure(rawResponse, requestFailedException));
                }
            }

            if (response.Value.Status == TextAnalyticsOperationStatus.Succeeded ||
                response.Value.Status == TextAnalyticsOperationStatus.Failed)
            {
                string nextLink = response.Value.NextLink;
                _firstPage = Page.FromValues(new List <AnalyzeActionsResult>()
                {
                    response.Value.Result
                }, nextLink, rawResponse);

                return(OperationState <AsyncPageable <AnalyzeActionsResult> > .Success(rawResponse, CreateOperationValueAsync(CancellationToken.None)));
            }

            return(OperationState <AsyncPageable <AnalyzeActionsResult> > .Pending(rawResponse));
        }
Esempio n. 8
0
        /// <summary>
        /// Calls the server to get updated status of the long-running operation.
        /// </summary>
        /// <param name="async">When <c>true</c>, the method will be executed asynchronously; otherwise, it will execute synchronously.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> used for the service call.</param>
        /// <returns>The HTTP response received from the server.</returns>
        private async ValueTask <Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken)
        {
            if (!_hasCompleted)
            {
                using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(AnalyzeHealthcareEntitiesOperation)}.{nameof(UpdateStatus)}");
                scope.Start();

                try
                {
                    Response <HealthcareJobState> update = async
                        ? await _serviceClient.HealthStatusAsync(new Guid(Id), _top, _skip, _showStats, cancellationToken).ConfigureAwait(false)
                        : _serviceClient.HealthStatus(new Guid(Id), _top, _skip, _showStats, cancellationToken);

                    _response = update.GetRawResponse();
                    _status   = update.Value.Status;

                    if (update.Value.Status == TextAnalyticsOperationStatus.Succeeded)
                    {
                        // we need to first assign a vaue and then mark the operation as completed to avoid race conditions
                        _value        = Transforms.ConvertToRecognizeHealthcareEntitiesResultCollection(update.Value.Results, _idToIndexMap);
                        NextLink      = update.Value.NextLink;
                        _hasCompleted = true;
                    }
                    else if (update.Value.Status == TextAnalyticsOperationStatus.Failed)
                    {
                        _requestFailedException = await ClientCommon.CreateExceptionForFailedOperationAsync(async, _diagnostics, _response, update.Value.Errors)
                                                  .ConfigureAwait(false);

                        _hasCompleted = true;
                        throw _requestFailedException;
                    }
                    else if (update.Value.Status == TextAnalyticsOperationStatus.Cancelled)
                    {
                        _requestFailedException = new RequestFailedException("The operation was canceled so no value is available.");
                        _hasCompleted           = true;
                        throw _requestFailedException;
                    }
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            return(GetRawResponse());
        }
        async ValueTask <OperationState <AsyncPageable <AnalyzeActionsResult> > > IOperation <AsyncPageable <AnalyzeActionsResult> > .UpdateStateAsync(bool async, CancellationToken cancellationToken)
        {
            Response <AnalyzeJobState> response = async
                ? await _serviceClient.AnalyzeStatusAsync(Id, _showStats, null, null, cancellationToken).ConfigureAwait(false)
                : _serviceClient.AnalyzeStatus(Id, _showStats, null, null, cancellationToken);

            // Add lock to avoid race condition?
            _displayName       = response.Value.DisplayName;
            _createdOn         = response.Value.CreatedDateTime;
            _expiresOn         = response.Value.ExpirationDateTime;
            _lastModified      = response.Value.LastUpdateDateTime;
            _status            = response.Value.Status;
            _actionsFailed     = response.Value.Tasks.Failed;
            _actionsInProgress = response.Value.Tasks.InProgress;
            _actionSucceeded   = response.Value.Tasks.Completed;
            _actionsTotal      = response.Value.Tasks.Total;

            Response rawResponse = response.GetRawResponse();

            if (response.Value.Status == TextAnalyticsOperationStatus.Failed)
            {
                if (CheckIfGenericError(response.Value))
                {
                    RequestFailedException requestFailedException = await ClientCommon.CreateExceptionForFailedOperationAsync(async, _diagnostics, rawResponse, response.Value.Errors).ConfigureAwait(false);

                    return(OperationState <AsyncPageable <AnalyzeActionsResult> > .Failure(rawResponse, requestFailedException));
                }
            }

            if (response.Value.Status == TextAnalyticsOperationStatus.Succeeded ||
                response.Value.Status == TextAnalyticsOperationStatus.Failed)
            {
                string nextLink            = response.Value.NextLink;
                AnalyzeActionsResult value = Transforms.ConvertToAnalyzeActionsResult(response.Value, _idToIndexMap);
                _firstPage = Page.FromValues(new List <AnalyzeActionsResult>()
                {
                    value
                }, nextLink, rawResponse);

                return(OperationState <AsyncPageable <AnalyzeActionsResult> > .Success(rawResponse, CreateOperationValueAsync(CancellationToken.None)));
            }

            return(OperationState <AsyncPageable <AnalyzeActionsResult> > .Pending(rawResponse));
        }
        async ValueTask <OperationState <AsyncPageable <AnalyzeHealthcareEntitiesResultCollection> > > IOperation <AsyncPageable <AnalyzeHealthcareEntitiesResultCollection> > .UpdateStateAsync(bool async, CancellationToken cancellationToken)
        {
            Response <HealthcareJobState> response = async
                ? await _serviceClient.HealthStatusAsync(new Guid(_jobId), null, null, _showStats, cancellationToken).ConfigureAwait(false)
                : _serviceClient.HealthStatus(new Guid(_jobId), null, null, _showStats, cancellationToken);

            // Add lock to avoid race condition?
            _status       = response.Value.Status;
            _createdOn    = response.Value.CreatedDateTime;
            _expiresOn    = response.Value.ExpirationDateTime;
            _lastModified = response.Value.LastUpdateDateTime;

            Response rawResponse = response.GetRawResponse();

            if (response.Value.Status == TextAnalyticsOperationStatus.Succeeded)
            {
                string nextLink = response.Value.NextLink;
                AnalyzeHealthcareEntitiesResultCollection value = Transforms.ConvertToAnalyzeHealthcareEntitiesResultCollection(response.Value.Results, _idToIndexMap);
                _firstPage = Page.FromValues(new List <AnalyzeHealthcareEntitiesResultCollection>()
                {
                    value
                }, nextLink, rawResponse);

                return(OperationState <AsyncPageable <AnalyzeHealthcareEntitiesResultCollection> > .Success(rawResponse, CreateOperationValueAsync(CancellationToken.None)));
            }
            else if (response.Value.Status == TextAnalyticsOperationStatus.Failed)
            {
                RequestFailedException requestFailedException = await ClientCommon
                                                                .CreateExceptionForFailedOperationAsync(async, _diagnostics, rawResponse, response.Value.Errors)
                                                                .ConfigureAwait(false);

                return(OperationState <AsyncPageable <AnalyzeHealthcareEntitiesResultCollection> > .Failure(rawResponse, requestFailedException));
            }
            else if (response.Value.Status == TextAnalyticsOperationStatus.Cancelled)
            {
                return(OperationState <AsyncPageable <AnalyzeHealthcareEntitiesResultCollection> > .Failure(rawResponse,
                                                                                                            new RequestFailedException("The operation was canceled so no value is available.")));
            }

            return(OperationState <AsyncPageable <AnalyzeHealthcareEntitiesResultCollection> > .Pending(rawResponse));
        }
Esempio n. 11
0
        internal static EntityLinkingTasksItem DeserializeEntityLinkingTasksItem(JsonElement element)
        {
            Optional <EntityLinkingResult> results          = default;
            DateTimeOffset               lastUpdateDateTime = default;
            Optional <string>            name   = default;
            TextAnalyticsOperationStatus status = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("results"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    results = EntityLinkingResult.DeserializeEntityLinkingResult(property.Value);
                    continue;
                }
                if (property.NameEquals("lastUpdateDateTime"))
                {
                    lastUpdateDateTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("status"))
                {
                    status = new TextAnalyticsOperationStatus(property.Value.GetString());
                    continue;
                }
            }
            return(new EntityLinkingTasksItem(lastUpdateDateTime, name.Value, status, results.Value));
        }
        async ValueTask <OperationState <AsyncPageable <AnalyzeActionsResult> > > IOperation <AsyncPageable <AnalyzeActionsResult> > .UpdateStateAsync(bool async, CancellationToken cancellationToken)
        {
            Response <AnalyzeJobState> response = async
                ? await _serviceClient.AnalyzeStatusAsync(Id, _showStats, null, null, cancellationToken).ConfigureAwait(false)
                : _serviceClient.AnalyzeStatus(Id, _showStats, null, null, cancellationToken);

            // Add lock to avoid race condition?
            _displayName       = response.Value.DisplayName;
            _createdOn         = response.Value.CreatedDateTime;
            _expiresOn         = response.Value.ExpirationDateTime;
            _lastModified      = response.Value.LastUpdateDateTime;
            _status            = response.Value.Status;
            _actionsFailed     = response.Value.Tasks.Failed;
            _actionsInProgress = response.Value.Tasks.InProgress;
            _actionSucceeded   = response.Value.Tasks.Completed;
            _actionsTotal      = response.Value.Tasks.Total;

            Response rawResponse = response.GetRawResponse();

            // TODO - Remove PartiallySucceeded once service deploys this to WestUS2
            if (response.Value.Status == TextAnalyticsOperationStatus.Succeeded ||
                response.Value.Status == TextAnalyticsOperationStatus.PartiallySucceeded ||
                response.Value.Status == TextAnalyticsOperationStatus.PartiallyCompleted ||
                response.Value.Status == TextAnalyticsOperationStatus.Failed)
            {
                string nextLink            = response.Value.NextLink;
                AnalyzeActionsResult value = Transforms.ConvertToAnalyzeActionsResult(response.Value, _idToIndexMap);
                _firstPage = Page.FromValues(new List <AnalyzeActionsResult>()
                {
                    value
                }, nextLink, rawResponse);

                return(OperationState <AsyncPageable <AnalyzeActionsResult> > .Success(rawResponse, CreateOperationValueAsync()));
            }

            return(OperationState <AsyncPageable <AnalyzeActionsResult> > .Pending(rawResponse));
        }
Esempio n. 13
0
 internal EntityLinkingTasksItem(DateTimeOffset lastUpdateDateTime, string name, TextAnalyticsOperationStatus status, EntityLinkingResult resultsInternal) : base(lastUpdateDateTime, name, status)
 {
     ResultsInternal = resultsInternal;
 }
Esempio n. 14
0
 internal EntityLinkingTasksItem(DateTimeOffset lastUpdateDateTime, TextAnalyticsOperationStatus status) : base(lastUpdateDateTime, status)
 {
 }
Esempio n. 15
0
 internal TaskState(DateTimeOffset lastUpdateDateTime, TextAnalyticsOperationStatus status)
 {
     LastUpdateDateTime = lastUpdateDateTime;
     Status             = status;
 }
Esempio n. 16
0
 internal EntityRecognitionPiiTasksItem(DateTimeOffset lastUpdateDateTime, TextAnalyticsOperationStatus status) : base(lastUpdateDateTime, status)
 {
 }
 internal TasksStateTasksDetails(DateTimeOffset lastUpdateDateTime, string name, TextAnalyticsOperationStatus status) : base(lastUpdateDateTime, name, status)
 {
 }
Esempio n. 18
0
 internal KeyPhraseExtractionTasksItem(DateTimeOffset lastUpdateDateTime, string name, TextAnalyticsOperationStatus status, KeyPhraseResult resultsInternal) : base(lastUpdateDateTime, name, status)
 {
     ResultsInternal = resultsInternal;
 }
Esempio n. 19
0
 internal EntityRecognitionPiiTasksItem(DateTimeOffset lastUpdateDateTime, string name, TextAnalyticsOperationStatus status, PiiEntitiesResult resultsInternal) : base(lastUpdateDateTime, name, status)
 {
     ResultsInternal = resultsInternal;
 }
 internal KeyPhraseExtractionTasksItem(DateTimeOffset lastUpdateDateTime, TextAnalyticsOperationStatus status) : base(lastUpdateDateTime, status)
 {
 }