Пример #1
0
            /// <summary>
            /// Process source text.
            /// </summary>
            /// <param name="source">Source text.</param>
            private BatchComprenoTaskResult process(BatchFileContainer source)
            {
                try
                {
                    IEnumerable<BatchOperationResult> operationResults = _sourceProcessor.Process(source);

                    return new BatchComprenoTaskResult(source.FilePath, operationResults);
                }
                catch (ComprenoException ex)
                {
                    return new BatchComprenoTaskResult(source.FilePath, ex);
                }
            }
Пример #2
0
            /// <summary>
            /// Starts a document processing task and gets results when it is completed.
            /// </summary>
            /// <param name="source">Source text.</param>
            /// <returns>Task result.</returns>
            public IEnumerable<BatchOperationResult> Process(BatchFileContainer source)
            {
                byte[] content = _tasksApiProvider.RunTaskAndWaitResult(source, _taskSettings);

                BatchOperationResult operationResult = new BatchOperationResult(content, ResultFormat.Json);

                return new[] { operationResult };
            }
Пример #3
0
            /// <summary>
            /// Starts a document processing task and gets results when it is completed.
            /// </summary>
            /// <param name="source">Source text.</param>
            /// <returns>Task result.</returns>
            public IEnumerable<BatchOperationResult> Process(BatchFileContainer source)
            {
                Guid taskId = _tasksApiProvider.RunTask(source, _taskSettings);

                ComprenoTaskState taskState;

                do
                {
                    Thread.Sleep(_pollingInterval);

                    taskState = _tasksApiProvider.GetTaskState(taskId);
                } while (!taskState.IsCompleted);

                try
                {
                    if (taskState.Status != ComprenoTaskStatus.ProcessingSuccessful)
                        throw new ComprenoTaskProcessingException(string.Empty, ErrorCode.TaskIsNotProcessed, taskState.Errors.ToArray());

                    List<BatchOperationResult> results = new List<BatchOperationResult>();

                    foreach (ResultFormat format in taskState.ResultFormats)
                    {
                        byte[] content = _tasksApiProvider.GetTaskResult(taskId, format);

                        results.Add(new BatchOperationResult(content, format));
                    }

                    return results;
                }
                finally
                {
                    deleteTask(taskId);
                }
            }