コード例 #1
0
        private static async Task TestItemRoundtrip(IStorageItem item)
        {
            var expectedContent = GetRandomItemContent();

            Assert.False(await item.Exists());
            Assert.Null(await item.Get());
            Assert.False(await item.Delete());
            await item.PutText(expectedContent);

            var actualContent = await item.GetText();

            Assert.Equal(expectedContent, actualContent);

            Assert.True(await item.Exists());
            Assert.True(await item.Delete());
            Assert.False(await item.Exists());
            Assert.Null(await item.Get());
            Assert.False(await item.Delete());
        }
コード例 #2
0
        public static async Task <string> GetText(this IStorageItem item)
        {
            using (var stream = await item.Get())
            {
                if (stream == null)
                {
                    return(null);
                }

                using (var reader = new StreamReader(stream))
                    return(await reader.ReadToEndAsync());
            }
        }
コード例 #3
0
        private async Task <IHttpActionResult> Storage(IStorageItem item)
        {
            if (item.CanGetUri)
            {
                var uri = await item.GetUri();

                if (uri != null)
                {
                    return(Redirect(uri));
                }
            }
            else
            {
                var stream = await item.Get();

                if (stream != null)
                {
                    return(Ok(new StreamContent(stream)));
                }
            }

            return(NotFound());
        }