public LocalPath Download(string src) { src = EncodePath(LexicalPath.Combine(_rootPath, src)); var res = new LocalPath(LocalUtils.GetTempFileName()); var downloaded = false; for (var i = 0; i < RETRIES; ++i) { try { using (var stream = _graphServiceClient.Drive.Root.ItemWithPath(src).Content.Request().GetAsync().Result) using (var outputStream = System.IO.File.OpenWrite(res.Path)) stream.CopyTo(outputStream); downloaded = true; break; } catch (Exception) { LocalUtils.TryDeleteFile(res.Path); } } if (!downloaded) { throw new StorageException($"Failed to download '{src}' ({RETRIES} attempts)."); } return(res); }
public LocalPath Download(string src) { src = LexicalPath.Combine(_rootPath, src); string id = GetId(src); var req = service.Files.Get(id); LocalPath res = new LocalPath(LocalUtils.GetTempFileName()); var downloaded = false; for (var i = 0; i < RETRIES && !downloaded; ++i) { try { using (var stream = File.OpenWrite(res.Path)) req.Download(stream); downloaded = true; break; } catch (Exception) { LocalUtils.TryDeleteFile(res.Path); } } if (!downloaded) { throw new StorageException($"Failed to download '{src}' ({RETRIES} attempts)."); } return(res); }
public void Download(string src, string dest) { var downloaded = false; for (var i = 0; i < RETRIES && !downloaded; ++i) { try { DownloadAction(src, dest); downloaded = true; break; } catch (Exception) { } LocalUtils.TryDeleteFile(dest); } if (!downloaded) { throw new StorageException($"Failed to download '{src}' ({RETRIES} attempts)."); } }