/// <summary>
        /// if controller is null, use CreatorController.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="controller"></param>
        /// <param name="pageSize">default value was 200, max value was 1000 ( test on 2015-07-27 ).</param>
        /// <returns></returns>
        public async static Task<WebResult<OneDriveItemPage<Item>>> ListChildrenAsync(this IRoot folder, OneDriveWebController controller = null, int? pageSize = null)
        {
            if (pageSize.HasValue)
            {
                if (pageSize.Value <= 0 || pageSize.Value > 1000)
                    throw new ArgumentOutOfRangeException($"{nameof(pageSize)} must be 0 < {nameof(pageSize)} < 1001");

                return await (controller ?? folder.CreatorController)
                    .WrapRequestAsync<OneDriveItemPage<Item>>($"drive/items/{folder.Id}/children?top={pageSize}");
            }
            else
            {
                return await (controller ?? folder.CreatorController)
                    .WrapRequestAsync<OneDriveItemPage<Item>>($"drive/items/{folder.Id}/children");
            }
        }
Exemplo n.º 2
0
 public async Task<WebResult<string>> GetStreamUrlAsync(OneDriveWebController controller = null)
 {
     try
     {
         var request = (controller ?? this.CreatorController).CreateRequest($"drive/items/{this.Id}/content");
         var response = await request.GetResponseAsync();
         return new WebResult<string>(response, ((dynamic)request).Address.ToString());
     }
     catch (WebException e)
     {
         return new WebResult<string>(e);
     }
     catch (Exception e)
     {
         throw new NotSupportedException("can not get Address", e);
     }
 }
        /// <summary>
        /// if controller is null, use CreatorController.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="newFolderName"></param>
        /// <param name="conflict"></param>
        /// <param name="controller"></param>
        /// <param name="pageSize">default value was 200, max value was 1000 ( test on 2015-07-27 ).</param>
        /// <returns></returns>
        public async static Task<WebResult<Item>> CreateFolderAsync(this IRoot folder,
            string newFolderName, ConflictBehavior conflict = ConflictBehavior.Fail, OneDriveWebController controller = null)
        {
            var entity = new CreateFolderEntity()
            {
                Name = newFolderName,
                Folder = new EmptyEntity(),
                NameconflictBehavior = conflict.GetValue()
            };

            var json = entity.ObjectToJson();
            Debug.WriteLine(json);

            return await (controller ?? folder.CreatorController)
                .WrapRequestAsync<Item>($"drive/items/{folder.Id}/children",
                    HttpWebRequestResourceString.Method.Post,
                    json.GetBytes());
        }
 internal virtual void SetCreatorController(OneDriveWebController controller)
 {
     this.CreatorController = controller;
 }
 public async static Task<WebResult> DeleteAsync(this IItem item, OneDriveWebController controller = null)
 {
     return await (controller ?? item.CreatorController)
         .WrapRequestAsync($"drive/items/{item.Id}",
             HttpWebRequestResourceString.Method.Delete);
 }
Exemplo n.º 6
0
 public async Task<WebResult<Root>> GetRootAsync(OneDriveWebController controller = null)
 {
     return await (controller ?? this.CreatorController)
         .WrapRequestAsync<Root>("drive/root");
 }
Exemplo n.º 7
0
        public async Task<WebResult<Item>> MoveByIdAsync(string targetFolderId, string newName = null, OneDriveWebController controller = null)
        {
            if (targetFolderId.IsNullOrWhiteSpace())
                throw new ArgumentException($"{nameof(targetFolderId)} can not be empty.");

            var entity = new MoveMethodBodyEntity()
            {
                Name = newName.IsNullOrWhiteSpace() ? this.Name : newName,
                ParentInfo = new ItemReferenceFacetOnlyId()
                {
                    Id = targetFolderId
                }
            };

            return await (controller ?? this.CreatorController).WrapRequestAsync<Item>(
                $"drive/items/{this.Id}",
                HttpWebRequestResourceString.Method.Patch,
                entity.ObjectToJson().GetBytes());
        }
Exemplo n.º 8
0
 public async Task<WebResult<OneDriveItemPage<ThumbnailSet>>> GetThumbnailsAsync(OneDriveWebController controller = null)
 {
     return await (controller ?? this.CreatorController)
         .WrapRequestAsync<OneDriveItemPage<ThumbnailSet>>($"drive/items/{this.Id}/thumbnails");
 }