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 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));
        }