/// <summary> /// Initializes a new instance of the <see cref="OneDriveStorageItem"/> class. /// </summary> /// <param name="oneDriveProvider">Instance of OneDriveClient class</param> /// <param name="requestBuilder">Http request builder.</param> /// <param name="oneDriveItem">OneDrive's item</param> public OneDriveStorageItem(IOneDriveClient oneDriveProvider, IItemRequestBuilder requestBuilder, Item oneDriveItem) { _requestBuilder = requestBuilder; _oneDriveProvider = oneDriveProvider; _oneDriveItem = oneDriveItem; _name = oneDriveItem.Name; _dateCreated = oneDriveItem.CreatedDateTime; _dateModified = oneDriveItem.LastModifiedDateTime; _displayName = _name; _folderId = oneDriveItem.Id; if (IsFile()) { _displayType = "File"; } else if (IsFolder()) { _displayType = "Folder"; } else { _displayType = "OneNote"; } // ParentReference null means is root if (oneDriveItem.ParentReference != null) { _path = oneDriveItem.ParentReference.Path.Replace("/drive/root:", string.Empty); } }
/// <summary> /// Create children http request with specific options /// </summary> /// <param name="requestBuilder">request builder</param> /// <param name="top">The number of items to return in a result set.</param> /// <param name="orderBy">Sort the order of items in the response collection</param> /// <param name="filter">Filters the response based on a set of criteria.</param> /// <returns>Returns the http request</returns> public static IItemChildrenCollectionRequest CreateChildrenRequest(this IItemRequestBuilder requestBuilder, int top, OrderBy orderBy = OrderBy.None, string filter = null) { IItemChildrenCollectionRequest oneDriveitemsRequest = null; if (orderBy == OrderBy.None && string.IsNullOrEmpty(filter)) { return(requestBuilder.Children.Request().Top(top)); } if (orderBy == OrderBy.None) { return(requestBuilder.Children.Request().Top(top).Filter(filter)); } string order = OneDriveHelper.TransformOrderByToODataString(orderBy); if (string.IsNullOrEmpty(filter)) { oneDriveitemsRequest = requestBuilder.Children.Request().Top(top).OrderBy(order); } else { oneDriveitemsRequest = requestBuilder.Children.Request().Top(top).OrderBy(order).Filter(filter); } return(oneDriveitemsRequest); }
/// <summary> /// Initializes a new instance of the <see cref="OneDriveRequestSource{T}"/> class. /// </summary> /// <param name="provider">OneDrive Data Client Provider</param> /// <param name="requestBuilder">Http request to execute</param> /// <param name="orderBy">Sort the order of items in the response collection</param> /// <param name="filter">Filters the response based on a set of criteria.</param> public OneDriveRequestSource(IOneDriveClient provider, IItemRequestBuilder requestBuilder, OrderBy orderBy, string filter) { _provider = provider; _requestBuilder = requestBuilder; _orderBy = orderBy; _filter = filter; }
private async Task GetFileFromOneDrive() { try { await AuthenticateAsync(); IItemRequestBuilder builder = client.Drive.Special.AppRoot.ItemWithPath(FILENAME); Item file = await builder.Request().GetAsync(); Stream contentStream = await builder.Content.Request().GetAsync(); content = ""; using (var reader = new StreamReader(contentStream)) { content = await reader.ReadToEndAsync(); } if (!string.IsNullOrWhiteSpace(content) && encrypter != null && encrypter.IsInitialized) { decrypted = encrypter.Decrypt(content); _isInitialSetup = false; } } catch (OneDriveException ex) { if (ex.IsMatch(OneDriveErrorCode.ItemNotFound.ToString())) { _isInitialSetup = true; } } }
public async Task <bool> Remove() { bool result = false; try { await AuthenticateAsync(); IItemRequestBuilder builder = client.Drive.Special.AppRoot.ItemWithPath(FILENAME); Item file = await builder.Request().GetAsync(); await client.Drive.Items[file.Id].Request().DeleteAsync(); result = true; } catch (OneDriveException e) { if (e.IsMatch(OneDriveErrorCode.ItemNotFound.ToString())) { result = true; } else { throw new NetworkException(); } } return(result); }
async Task get_children(DItem dItem) { IItemRequestBuilder irb = string.IsNullOrEmpty(dItem.Id) ? oneDriveClient.Drive.Root : oneDriveClient.Drive.Items[dItem.Id]; try { List <Task> tasks = new List <Task>(); var request = irb.Children.Request() .Select("id,name,createdDateTime,size,file,folder,parentReference,webUrl"); while (request != null) { var children = await request .GetAsync(); foreach (var item in children) { DItem child = new DItem { Id = item.Id, Name = item.Name, Size = item.Size, WebUrl = item.WebUrl, Checksum = item.File != null && item.File.Hashes != null ? item.File.Hashes.Crc32Hash : null, CreatedDate = item.CreatedDateTime.Value.DateTime, Path = item.ParentReference.Path, IsFolder = item.Folder != null, Parent = dItem }; dItem.Children.Add(child); if (!child.IsFolder) { child.CountFile = 1; } else if (item.Folder.ChildCount > 0) { tasks.Add(get_children(child)); } } // next request if exceed 200 item request = children.NextPageRequest; } await Task.WhenAll(tasks); dItem.Size = dItem.Children.Sum(i => ((KFile)i).Size); dItem.CountFile = dItem.Children.Sum(i => ((KFile)i).CountFile); } catch (ServiceException ex) { MessageBox.Show(ex.Error.Message); } }
/// <summary> /// Gets a file's thumbnail set /// </summary> /// <param name="builder">Http request builder</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>When this method completes, return a thumbnail set, or null if no thumbnail are available</returns> public static async Task <OneDriveThumbnailSet> GetThumbnailSetAsync(this IItemRequestBuilder builder, CancellationToken cancellationToken) { // Requests the differente size of the thumbnail var requestThumbnail = await builder.Thumbnails.Request().GetAsync(cancellationToken).ConfigureAwait(false); var thumbnailSet = requestThumbnail.FirstOrDefault(); if (thumbnailSet == null) { return(null); } return(new OneDriveThumbnailSet(thumbnailSet)); }
private async Task LoadMediaInformationByFFmepg(NetworkItemInfo networkItem, IItemRequestBuilder requestBuilder) { try { using (Stream stream = await requestBuilder.Content.Request().GetAsync()) { var ffInfo = CCPlayer.UWP.Factory.MediaInformationFactory.CreateMediaInformationFromStream(stream.AsRandomAccessStream()); networkItem.ImageItemsSource = await this.GetThumbnailAsync(networkItem, ffInfo); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private async Task GetFolder(IItemRequestBuilder builder, bool childrenToo) { ShowBusy(true); Exception error = null; IChildrenCollectionPage children = null; try { var root = await builder.Request().GetAsync(); if (childrenToo) { children = await builder.Children.Request().GetAsync(); } DisplayHelper.ShowContent( "SHOW FOLDER ++++++++++++++++++++++", root, children, async message => { var dialog = new MessageDialog(message); await dialog.ShowAsync(); }); ShowBusy(false); } catch (Exception ex) { error = ex; } if (error != null) { var dialog = new MessageDialog(error.Message, "Error!"); await dialog.ShowAsync(); ShowBusy(false); return; } }
/// <summary> /// Gets a file's thumbnail /// </summary> /// <param name="builder">Http request builder</param> /// <param name="provider">Http provider to execute the request</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <param name="optionSize"> A value from the enumeration that specifies the size of the image to retrieve. Small ,Medium, Large</param> /// <returns>When this method completes, return a stream containing the thumbnail, or null if no thumbnail are available</returns> public static async Task <Stream> GetThumbnailAsync(this IItemRequestBuilder builder, IOneDriveClient provider, CancellationToken cancellationToken, ThumbnailSize optionSize) { // Requests the different sizes of the thumbnail var thumbnailSet = await builder.GetThumbnailSetAsync(cancellationToken).ConfigureAwait(false); if (thumbnailSet == null) { return(null); } string requestUrl = null; if (optionSize == ThumbnailSize.Small) { requestUrl = thumbnailSet.Small; } else if (optionSize == ThumbnailSize.Medium) { requestUrl = thumbnailSet.Medium; } else if (optionSize == ThumbnailSize.Large) { requestUrl = thumbnailSet.Large; } HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); await provider.AuthenticationProvider.AuthenticateRequestAsync(request).ConfigureAwait(false); var response = await provider.HttpProvider.SendAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsStreamAsync()); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="OneDriveStorageFile"/> class. /// <para>Permissions : Have full access to user files and files shared with user</para> /// </summary> /// <param name="oneDriveProvider">Instance of OneDriveClient class</param> /// <param name="requestBuilder">Http request builder.</param> /// <param name="oneDriveItem">OneDrive's item</param> public OneDriveStorageFile(IOneDriveClient oneDriveProvider, IItemRequestBuilder requestBuilder, Item oneDriveItem) : base(oneDriveProvider, requestBuilder, oneDriveItem) { ParseFileType(oneDriveItem.Name); }
/// <summary> /// Initializes a new instance of the <see cref="OneDriveStorageFolder"/> class. /// <para>Permissions : Have full access to user files and files shared with user</para> /// </summary> /// <param name="oneDriveProvider">Instance of OneDriveClient class</param> /// <param name="requestBuilder">Http request builder.</param> /// <param name="oneDriveItem">OneDrive's item</param> public OneDriveStorageFolder(IOneDriveClient oneDriveProvider, IItemRequestBuilder requestBuilder, Item oneDriveItem) : base(oneDriveProvider, requestBuilder, oneDriveItem) { }