/// <summary>
        /// Allows to write the process status
        /// </summary>
        /// <param name="status">The status to write</param>
        /// <param name="token">The cancellation token, if any</param>
        /// <returns></returns>
        public Task WriteProcessStatusAsync(TransformationProcessStatus status, CancellationToken token = default)
        {
            if (status == null) throw new ArgumentNullException(nameof(status));

            processStatuses.AddOrUpdate(status.ProcessId, status, (k, o) => status);
            return Task.CompletedTask;
        }
        /// <summary>
        /// Raises the process progress, if a Progress function is defined
        /// </summary>
        /// <param name="status">The status to notify</param>
        protected virtual Task RaiseProgressAsync(TransformationProcessStatus status)
        {
            if (Progress != null)
            {
                return(Progress(status));
            }

            return(Task.CompletedTask);
        }
        /// <summary>
        /// Sets the state of the process
        /// </summary>
        /// <param name="status">The process status</param>
        /// <param name="token">Cancellation token to use, if any</param>
        /// <returns>The updated process status</returns>
        protected virtual async Task <TransformationProcessStatus> ChangeProcessStatusAsync(TransformationExecutionState status, CancellationToken token)
        {
            // NOTE: This one returns the TransformationProcessStatus, while the next one doesn't (for the task)
            // Evaluate a different and more consistent approach

            var newStatus = new TransformationProcessStatus(Id, status);
            await TransformationStateManager
            .WriteProcessStatusAsync(newStatus, token)
            .ConfigureAwait(false);

            await RaiseProgressAsync(newStatus).ConfigureAwait(false);

            return(newStatus);
        }
Пример #4
0
        /// <summary>
        /// Public constructor
        /// </summary>
        /// <param name="id">The id of the process</param>
        /// <param name="logger">A custom logger</param>
        /// <param name="transformationDistiller">The Page Transformation Distiller to collect items to process</param>
        /// <param name="pageTransformator">The Page Transformator instance to use</param>
        public InProcessTransformationProcess(
            Guid id,
            ILogger <InProcessTransformationProcess> logger,
            ITransformationDistiller transformationDistiller,
            IPageTransformator pageTransformator)
        {
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
            this.transformationDistiller = transformationDistiller ?? throw new ArgumentNullException(nameof(transformationDistiller));
            this.pageTransformator       = pageTransformator ?? throw new ArgumentNullException(nameof(pageTransformator));

            Id = id;

            status        = new TransformationProcessStatus(Id, TransformationExecutionState.Pending);
            tasksStatuses = new ConcurrentDictionary <Guid, TransformationProcessTaskStatus>();
        }
Пример #5
0
 private Task ChangeProcessStateAsync(TransformationExecutionState state)
 {
     status = new TransformationProcessStatus(Id, state);
     return(RaiseProgressAsync(status));
 }