Ejemplo n.º 1
0
        public async Task Process(BlobLoaded blob)
        {
            var  fileId   = NewId.NextGuid();
            var  blobInfo = blob.BlobInfo;
            Guid userId   = blobInfo.UserId.HasValue ? blobInfo.UserId.Value : new Guid(blobInfo.Metadata[nameof(userId)].ToString());
            //TODO: is it possible that parentId is nul???
            Guid?parentId = blobInfo.Metadata != null?blobInfo.Metadata.ContainsKey(nameof(parentId)) ? (Guid?)new Guid(blobInfo.Metadata[nameof(parentId)].ToString()) : null : null;

            var file = new MicroscopyFile(fileId, userId, parentId, blobInfo.FileName, FileStatus.Loaded, blobInfo.Bucket, blobInfo.Id, blobInfo.Length, blobInfo.MD5);
            await _session.Add(file);

            await _session.Commit();

            await _bus.Publish <ProcessMicroscopyFile>(new
            {
                Id       = fileId,
                Bucket   = blobInfo.Bucket,
                ParentId = parentId,
                BlobId   = blobInfo.Id,
                UserId   = userId
            });
        }
 public static void EntityShouldBeEquivalentTo(this GenericDictionaryAssertions <string, object> assertions, MicroscopyFile file)
 {
     assertions.Subject.Should().BeEquivalentTo(new Dictionary <string, object>
     {
         { "_id", file.Id },
         { "Blob", new Dictionary <string, object>()
           {
               { "_id", file.BlobId },
               { "Bucket", file.Bucket },
               { "Length", file.Length },
               { "Md5", file.Md5 }
           } },
         { "SubType", FileType.Microscopy.ToString() },
         { "OwnedBy", file.OwnedBy },
         { "CreatedBy", file.CreatedBy },
         { "CreatedDateTime", file.CreatedDateTime.UtcDateTime },
         { "UpdatedBy", file.UpdatedBy },
         { "UpdatedDateTime", file.UpdatedDateTime.UtcDateTime },
         { "ParentId", file.ParentId },
         { "Name", file.FileName },
         { "Status", file.Status.ToString() },
         { "Version", file.Version },
         { "Images", file.Images.Select(i => new Dictionary <string, object> {
                 { "_id", i.Id },
                 { "Bucket", file.Bucket },
                 { "Height", i.Height },
                 { "Width", i.Height },
                 { "MimeType", i.MimeType },
                 { "Scale", i.GetScale() }
             }) },
         { "Properties", new Dictionary <string, object>()
           {
               { "BioMetadata", file.BioMetadata.Select(i => new Dictionary <string, object> {
                         { "Name", i.Name },
                         { "Value", i.Value }
                     }) }
           } }
     });
 }