예제 #1
0
 public HttpResponseMessage Spaces(int customerId, Space space)
 {
     if (!string.IsNullOrWhiteSpace(space.Id))
     {
         var message = "You can only POST a new Space";
         var errorResponse = Request.CreateErrorResponse(HttpStatusCode.Conflict, message);
         throw new HttpResponseException(errorResponse);
     }
     if (string.IsNullOrWhiteSpace(space.Name))
     {
         var message = "The space must be given a name";
         var errorResponse = Request.CreateErrorResponse(HttpStatusCode.BadRequest, message);
         throw new HttpResponseException(errorResponse);
     }
     // obviously not thread safe..
     var modelId = GetModel().Spaces.Select(s => s.ModelId).Max() + 1;
     var newSpace = new Space(modelId, customerId, space.Name, DateTime.Now, space.DefaultTags, space.DefaultMaxUnauthorised);
     GetModel().Spaces.Add(newSpace);
     var response = Request.CreateResponse(HttpStatusCode.Created);
     response.Headers.Location = new Uri(newSpace.Id);
     return response;
 }
예제 #2
0
파일: MockModel.cs 프로젝트: dlcs/dlcs-net
 private static List<Image> MakeImagesForSpace(int howMany, Space space, 
     Dictionary<string, List<string>> spaceDefaultRoles, Dictionary<string, List<string>> imageRoles,
     List<ImageOptimisationPolicy> imageOptimisationPolicies, List<ThumbnailPolicy> thumbnailPolicies)
 {
     Random r = new Random();
     var images = new List<Image>();
     var ongoing = space.ModelId%2 == 0;
     var queued = ongoing ? DateTime.Now.AddHours(-4) : new DateTime(2015, 11, 30); 
     for (int i = 0; i < howMany; i++)
     {
         DateTime? dequeued = ongoing ? (DateTime?) null : queued.AddHours(1).AddSeconds(i * 5);
         if (ongoing && i < 6) dequeued = DateTime.Now.AddSeconds(-80 + 9*i);
         DateTime? finished = ongoing ? (DateTime?)null : queued.AddSeconds(3608).AddSeconds(i * 7);
         if (ongoing && i < 4) finished = DateTime.Now.AddSeconds(-60 + 9 * i);
         var id = Guid.NewGuid().ToString().Substring(0, 8) + i.ToString().PadLeft(5, '0');
         var image = new Image(space.CustomerId, space.ModelId, id,
             DateTime.Now, "https://customer.com/images/" + id + ".tiff", null,
             r.Next(2000,11000), r.Next(3000,11000), space.DefaultMaxUnauthorised,
             queued, dequeued, finished, !finished.HasValue, null,
             space.DefaultTags, "b12345678", null, null, i, 0, 0,
             imageOptimisationPolicies.First().Id, thumbnailPolicies.First().Id);
         images.Add(image);
         if (spaceDefaultRoles.ContainsKey(space.Id))
         {
             var roles = spaceDefaultRoles[space.Id];
             if (roles.Any())
             {
                 imageRoles.Add(image.Id, roles);
             }
         }
     }
     return images;
 }