Пример #1
0
        public async Task <Stream> GetOneDriveContentsAsStreamAsync(OneDriveAttribute attr)
        {
            Stream response;
            // How to download from OneDrive: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/item_downloadcontent
            // GET https://graph.microsoft.com/v1.0/me/drive/root:/test1/hi.txt:/content HTTP/1.1
            bool isShare = attr.Path.StartsWith("https://");

            if (isShare)
            {
                // TODO: Move this to GraphServiceClient

                // Download via a Share URL
                var shareToken = UrlToSharingToken(attr.Path);
                response = await _client.GetOneDriveContentStreamFromShareAsync(shareToken);
            }
            else
            {
                try
                {
                    // Retrieve stream of OneDrive item
                    response = await _client.GetOneDriveContentStreamAsync(attr.Path);
                } catch
                {
                    //File does not exist, so create new memory stream
                    response = new MemoryStream();
                }
            }

            return(ConvertStream(response, attr));
        }
Пример #2
0
 public Stream ConvertStream(Stream stream, OneDriveAttribute attribute)
 {
     if (attribute.Access != FileAccess.Write)
     {
         return(stream);
     }
     return(new OneDriveWriteStream(_client, attribute.Path));
 }
Пример #3
0
        /// <summary>
        /// Retrieve contents of OneDrive file
        /// </summary>
        /// <param name="client"></param>
        /// <param name="graphClient"></param>
        /// <param name="attr"></param>
        /// <returns></returns>
        public async Task <byte[]> GetOneDriveContentsAsByteArrayAsync(OneDriveAttribute attr)
        {
            var response = await GetOneDriveContentsAsStreamAsync(attr);

            using (MemoryStream ms = new MemoryStream())
            {
                await response.CopyToAsync(ms);

                return(ms.ToArray());
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OneDriveAsyncCollector"/> class.
 /// </summary>
 /// <param name="client">GraphServiceClient used to make calls to MS Graph</param>
 /// <param name="attribute">OneDriveAttribute containing necessary info about file</param>
 public OneDriveAsyncCollector(OneDriveService service, OneDriveAttribute attribute)
 {
     _service     = service;
     _attribute   = attribute;
     _fileStreams = new Collection <byte[]>();
 }
 public async Task <OneDriveService> GetOneDriveService(OneDriveAttribute attribute)
 {
     return(new OneDriveService(await GetMSGraphClientAsync(attribute)));
 }
        private IAsyncCollector <byte[]> CreateCollector(OneDriveAttribute attr)
        {
            var service = Task.Run(() => _serviceManager.GetOneDriveService(attr)).GetAwaiter().GetResult();

            return(new OneDriveAsyncCollector(service, attr));
        }
Пример #7
0
 public async Task <DriveItem> UploadOneDriveContentsAsync(OneDriveAttribute attr, Stream fileStream)
 {
     return(await _client.UploadOneDriveItemAsync(attr.Path, fileStream));
 }
Пример #8
0
 public async Task <DriveItem> GetOneDriveItemAsync(OneDriveAttribute attr)
 {
     return(await _client.GetOneDriveItemAsync(attr.Path));
 }
        public async Task <DriveItem> UploadOneDriveContentsAsync(OneDriveAttribute attr, Stream fileStream, CancellationToken token)
        {
            IGraphServiceClient client = await _clientProvider.GetMSGraphClientFromTokenAttributeAsync(attr, token);

            return(await client.UploadOneDriveItemAsync(attr.Path, fileStream, token));
        }
        public async Task <DriveItem> GetOneDriveItemAsync(OneDriveAttribute attr, CancellationToken token)
        {
            IGraphServiceClient client = await _clientProvider.GetMSGraphClientFromTokenAttributeAsync(attr, token);

            return(await client.GetOneDriveItemAsync(attr.Path, token));
        }