Beispiel #1
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 #2
0
        private void DoWork()
        {
            while (_started)
            {
                ITask task = _taskProvider.GetNext();
                if (task == null)
                {
                    Thread.Sleep(10);
                    continue;
                }

                try
                {
                    task.Execute();
                    OnTaskDone(this);
                }
                catch (Exception ex)
                {
                    OnTaskError(this, task, ex);
                }
            }
        }