Пример #1
0
        public async Task <Tuple <ResourceInfoDto, Stream> > GetImageResource(Guid uuid)
        {
            var(jObject, stream) = await GetResource("Resources", "GetResource", new { uuid });

            var imageResource = new ResourceInfoDto();

            if (jObject.ContainsKey("uuid"))
            {
                //parse modification time
                var id = jObject["uuid"].ToObject <string>();
                imageResource.Uuid = Guid.Parse(id);
            }

            if (jObject.ContainsKey("name"))
            {
                //parse modification time
                var name = jObject["name"].ToObject <string>();
                imageResource.Name = name;
            }

            //parse mime type
            var mime = jObject.GetValue("mimeType")?.ToString();

            imageResource.ContentType = ParseContentType(mime, imageResource.Name);

            imageResource.ETag = jObject["etag"].ToString();
            imageResource.Size = jObject["size"].ToObject <long>();

            return(new Tuple <ResourceInfoDto, Stream>(imageResource, stream));
        }
Пример #2
0
        public async Task <Tuple <ResourceInfoDto, Stream> > GetFileResource(Uri uri, string etag = null)
        {
            //ignore first stegment:
            string path;

            if (uri.Segments.Skip(1).First().Equals("files/"))
            {
                path = uri.Segments.ToList()
                       .Skip(2)
                       .Aggregate(new StringBuilder("/"),
                                  (accu, i) => accu.Append(i)).ToString();
            }
            else
            {
                path = uri.LocalPath;
            }

            var decodedPath = HttpUtility.UrlDecode(path);

            var filename = uri.Segments.Last();

            var(jObject, stream) = await GetResource("Resources", "GetFile", new { path = decodedPath });

            var resourceInfo = new ResourceInfoDto()
            {
                Uri         = uri,
                RequestPath = path,
                Name        = filename,
            };

            if (jObject.ContainsKey("modificationTime"))
            {
                //parse modification time
                var millis   = jObject["modificationTime"].ToObject <long>();
                var dateTime = DateTimeOffset.FromUnixTimeMilliseconds(millis);
                resourceInfo.LastModified = dateTime;
            }

            //parse mime type
            var mime = jObject?.GetValue("mimeType")?.ToString();

            resourceInfo.ContentType = ParseContentType(mime, filename);

            resourceInfo.ETag = jObject["etag"].ToString();
            resourceInfo.Size = jObject["size"].ToObject <long>();

            return(new Tuple <ResourceInfoDto, Stream>(resourceInfo, stream));
        }
Пример #3
0
        public async Task <Guid> PostImageResource(ResourceInfoDto res, Stream uploadStream)
        {
            var requestBody = new
            {
                name     = res.Name,
                mimeType = res.ContentType.ToString()
            };
            var response = await PostResource("Resources", "PutResource", requestBody, uploadStream);

            if (response.ResponseObject?.ContainsKey("uuid") ?? false)
            {
                return(Guid.Parse(response.ResponseObject["uuid"].ToString()));
            }
            else
            {
                throw new AmqpApiResponseException("Could not read parameters from Amqp Response");
            }
        }