コード例 #1
0
        public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromBody] jobCollectionType items, [MatrixParameter] string[] zone = null, [MatrixParameter] string[] context = null)
        {
            string sessionToken = CheckAuthorisation(serviceName, zone, context, new Right(RightType.CREATE, RightValue.APPROVED));

            HttpResponseMessage result;

            try
            {
                IFunctionalService service = getService(serviceName);

                List <createType> creates = new List <createType>();
                foreach (jobType job in items.job)
                {
                    try
                    {
                        if (!service.AcceptJob(serviceName, job.name))
                        {
                            throw new ArgumentException("Service " + serviceName + " does not handle jobs named " + job.name);
                        }
                        Guid id = service.Create(job, zone: (zone == null ? null : zone[0]), context: (context == null ? null : context[0]));

                        if (SettingsManager.ProviderSettings.JobBinding)
                        {
                            service.Bind(id, getOwnerId(sessionToken));
                        }

                        creates.Add(ProviderUtils.CreateCreate(HttpStatusCode.Created, id.ToString(), job.id));
                    }
                    catch (CreateException e)
                    {
                        ProviderUtils.CreateCreate(HttpStatusCode.Conflict, job.id, error: ProviderUtils.CreateError(HttpStatusCode.Conflict, HttpStatusCode.Conflict.ToString(), e.Message));
                    }
                }

                createResponseType createResponse = ProviderUtils.CreateCreateResponse(creates.ToArray());

                result = Request.CreateResponse <createResponseType>(HttpStatusCode.Created, createResponse);
                string uri = Url.Link("ServicesRoute", new { controller = serviceName });
                result.Headers.Location = new Uri(uri);
            }
            catch (AlreadyExistsException e)
            {
                result = Request.CreateErrorResponse(HttpStatusCode.Conflict, e);
            }
            catch (ArgumentException e)
            {
                result = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Object to create Jobs is invalid.\n ", e);
            }
            catch (CreateException e)
            {
                result = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Request failed for creating Jobs.\n ", e);
            }
            catch (RejectedException e)
            {
                result = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Create request rejected for creating Jobs.\n", e);
            }
            catch (QueryException e)
            {
                result = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Request failed for Job.\n", e);
            }
            catch (Exception e)
            {
                result = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
            }
            return(result);
        }