public override HttpResponseMessage Execute()
        {
            IProcessedEntity task = _taskKeeper.Get(_id);

            if (task == null || task.EntityType != ProcessedEntityType)
            {
                return(Controller.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid entity identifier."));
            }

            task.Started = DateTime.UtcNow;

            try
            {
                task.SetState(new ProcessingState());
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to change task state: {0}", e);
            }

            HttpResponseMessage response = Controller.Request.CreateResponse(HttpStatusCode.OK, GetResponseEntity(task));

            response.Content.Headers.ContentType.MediaType = HttpHelper.GetContentType(task.EntityType);

            return(response);
        }
Beispiel #2
0
        public TaskState GetState(IProcessedEntity entity)
        {
            if (!_previousStates.Contains(entity.State))
            {
                string message = string.Format("Unable to change state from {0} to {1}", entity.State, State);
                throw new InvalidOperationException(message);
            }

            return State;
        }
Beispiel #3
0
        public TaskState GetState(IProcessedEntity entity)
        {
            if (!_previousStates.Contains(entity.State))
            {
                string message = string.Format("Unable to change state from {0} to {1}", entity.State, State);
                throw new InvalidOperationException(message);
            }

            return(State);
        }
Beispiel #4
0
        /// <summary>
        ///     Checks processed task.
        /// </summary>
        /// <param name="task">Task entity.</param>
        public void CheckTask(IProcessedEntity task)
        {
            if (!_failedStates.Contains(task.State))
            {
                return;
            }

            task.AttemptsCount++;

            CheckTasks();
        }
        public override HttpResponseMessage Execute()
        {
            IProcessedEntity task = _taskKeeper.Get(_id);

            if (task == null)
            {
                return(Controller.Request.CreateErrorResponse(HttpStatusCode.NotFound, "NotFound"));
            }

            if (task.EntityType != ProcessedEntityType || task.State != TaskState.Processing)
            {
                return(Controller.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid entity identifier."));
            }

            task.SetProgress(_model.Progress);

            return(Controller.Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #6
0
        public override HttpResponseMessage Execute()
        {
            // Gets an accepted task types
            ParsedTaskRequest request = HttpHelper.GetTaskRequest(Controller.Request);

            if (request.Accepts.Count == 0)
            {
                return(Controller.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad request."));
            }

            // Gets a task
            IProcessedEntity task = _taskProvider.GetNext(request.Accepts);

            if (task == null)
            {
                return(Controller.Request.CreateResponse(HttpStatusCode.NoContent));
            }

            // Creates a response
            HttpResponseMessage responseMessage = Controller.Request.CreateResponse(
                HttpStatusCode.Created,
                new VideoProcessingTask
            {
                TaskId = task.TaskId
            });

            responseMessage.Content.Headers.ContentType.MediaType = HttpHelper.GetContentType(task.EntityType);

            var routeParameters = new Dictionary <string, object>
            {
                { "id", task.TaskId }
            };

            string controllerName = HttpHelper.GetControllerName(task.EntityType);
            string routeAddress   = Controller.Url.Route(controllerName + "Api", routeParameters);

            if (routeAddress != null)
            {
                responseMessage.Headers.Location = new Uri(routeAddress, UriKind.Relative);
            }

            return(responseMessage);
        }
Beispiel #7
0
        public override HttpResponseMessage Execute()
        {
            IProcessedEntity task = _taskProvider.Get(_id);

            if (task == null)
            {
                return(Controller.Request.CreateErrorResponse(HttpStatusCode.NotFound, "NotFound"));
            }

            if (task.EntityType != ProcessedEntityType || task.State != TaskState.Processing)
            {
                return(Controller.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid entity identifier."));
            }

            task.Completed         = DateTime.UtcNow;
            task.DestinationFileId = _model.FileId;

            try
            {
                task.SetState(TaskStateFactory.GetState(_model.Result));
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to change task state: {0}", e);
            }

            _taskChecker.CheckTask(task);


            if (!string.IsNullOrEmpty(_model.Message))
            {
                Trace.TraceError("File {0} processing failed: {1}", task.SourceFileId, _model.Message);
            }

            return(Controller.Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #8
0
        /// <summary>
        ///     Checks processed task.
        /// </summary>
        /// <param name="task">Task entity.</param>
        public void CheckTask(IProcessedEntity task)
        {
            if (!_failedStates.Contains(task.State))
            {
                return;
            }

            task.AttemptsCount++;

            CheckTasks();
        }