public async Task ThumbnailContentRequest_PutAsync()
        {
            using (var requestStream = new MemoryStream())
            using (var httpResponseMessage = new HttpResponseMessage())
            using (var responseStream = new MemoryStream())
            using (var streamContent = new StreamContent(responseStream))
            {
                httpResponseMessage.Content = streamContent;

                var requestUrl = "https://api.onedrive.com/v1.0/drive/items/id/thumbnails/0/id/content";
                this.httpProvider.Setup(
                    provider => provider.SendAsync(
                        It.Is<HttpRequestMessage>(
                            request => request.RequestUri.ToString().StartsWith(requestUrl)),
                        HttpCompletionOption.ResponseContentRead,
                        CancellationToken.None))
                    .Returns(Task.FromResult(httpResponseMessage));

                var expectedThumbnail = new Thumbnail { Url = "https://localhost" };

                this.serializer.Setup(
                    serializer => serializer.DeserializeObject<Thumbnail>(It.IsAny<string>()))
                    .Returns(expectedThumbnail);

                var responseThumbnail = await this.oneDriveClient.Drive.Items["id"].Thumbnails["0"]["id"].Content.Request().PutAsync<Thumbnail>(requestStream);

                Assert.IsNotNull(responseThumbnail, "Thumbnail not returned.");
                Assert.AreEqual(expectedThumbnail, responseThumbnail, "Unexpected thumbnail returned.");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates the specified Thumbnail using PUT.
 /// </summary>
 /// <param name="thumbnail">The Thumbnail to create.</param>
 /// <returns>The created Thumbnail.</returns>
 public async Task<Thumbnail> CreateAsync(Thumbnail thumbnail)
 {
     this.ContentType = "application/json";
     this.Method = "PUT";
     var entity = await this.SendAsync<Thumbnail>(thumbnail);
     this.InitializeCollectionProperties(entity);
     return entity;
 }
Exemplo n.º 3
0
        //원드라이브로 부터 썸네일로 이미지를 다운로드 받아,
        //NetworItemInfo에 이미지를 로딩 시킨후 DB에 캐쉬로 저장한다.
        private async Task StoreImageFromWeb(NetworkItemInfo networkItem, Microsoft.OneDrive.Sdk.Thumbnail itemThumb)
        {
            if (itemThumb != null)
            {
                try
                {
                    var webReq = System.Net.WebRequest.Create(itemThumb.Url);
                    await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(async() =>
                    {
                        using (var webRes = await webReq.GetResponseAsync())
                        {
                            using (var imageStream = webRes.GetResponseStream())
                            {
                                WriteableBitmap wb           = await BitmapFactory.FromStream(imageStream);
                                networkItem.ImageItemsSource = wb;

                                using (InMemoryRandomAccessStream newStream = new InMemoryRandomAccessStream())
                                {
                                    await wb.ToStream(newStream, BitmapEncoder.PngEncoderId);
                                    byte[] pngData = new byte[newStream.Size];
                                    await newStream.ReadAsync(pngData.AsBuffer(), (uint)pngData.Length, InputStreamOptions.None);

                                    //DB 등록
                                    ThumbnailDAO.InsertThumbnail(new Models.Thumbnail
                                    {
                                        Name            = networkItem.Name,
                                        ParentPath      = networkItem.ParentFolderPath,
                                        Size            = (ulong)networkItem.Size,
                                        RunningTime     = networkItem.Duration,
                                        CreatedDateTime = networkItem.Modified,
                                        ThumbnailData   = pngData
                                    });
                                }
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes any collection properties after deserialization, like next requests for paging.
 /// </summary>
 /// <param name="thumbnail">The <see cref="Thumbnail"/> with the collection properties to initialize.</param>
 private void InitializeCollectionProperties(Thumbnail thumbnail)
 {
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes any collection properties after deserialization, like next requests for paging.
 /// </summary>
 /// <param name="thumbnail">The <see cref="Thumbnail"/> with the collection properties to initialize.</param>
 private void InitializeCollectionProperties(Thumbnail thumbnail)
 {
 
 }
 /// <summary>
 /// Creates the specified Thumbnail using PUT.
 /// </summary>
 /// <param name="thumbnailToCreate">The Thumbnail to create.</param>
 /// <returns>The created Thumbnail.</returns>
 public Task <Thumbnail> CreateAsync(Thumbnail thumbnailToCreate)
 {
     return(this.CreateAsync(thumbnailToCreate, CancellationToken.None));
 }
        public void ThumbnailSetExtensions_CustomThumbnailNotFound()
        {
            var expectedThumbnail = new Thumbnail { Url = "https://localhost" };
            var thumbnailSet = new ThumbnailSet
            {
                AdditionalData = new Dictionary<string, object>
                {
                    { "custom", expectedThumbnail }
                }
            };

            var thumbnail = thumbnailSet["custom2"];

            Assert.IsNull(thumbnail, "Unexpected thumbnail returned.");
        }