Add guards, make impl details private, chnage . to ,
This commit is contained in:
Родитель
60fef52181
Коммит
69f1371a8b
|
@ -8,10 +8,10 @@ namespace Camelotia.Presentation.Tests
|
|||
{
|
||||
[Theory]
|
||||
[InlineData(0, "0B")]
|
||||
[InlineData(520400, "520.4KB")]
|
||||
[InlineData(520400, "520,4KB")]
|
||||
[InlineData(520040000, "520MB")]
|
||||
[InlineData(520068000, "520.1MB")]
|
||||
[InlineData(520185000000, "520.2GB")]
|
||||
[InlineData(520068000, "520,1MB")]
|
||||
[InlineData(520185000000, "520,2GB")]
|
||||
public void ByteConverterShouldCalculateWithNoPrecisionSupplied(long byteCount, string expectedValue)
|
||||
{
|
||||
var stringValue = ByteConverter.BytesToString(byteCount);
|
||||
|
@ -21,10 +21,10 @@ namespace Camelotia.Presentation.Tests
|
|||
[Theory]
|
||||
[InlineData(115, 1, "115B")]
|
||||
[InlineData(115, 3, "115B")]
|
||||
[InlineData(520348, 3, "520.348KB")]
|
||||
[InlineData(520462400, 3, "520.462MB")]
|
||||
[InlineData(520573990000, 3, "520.574GB")]
|
||||
[InlineData(520124960000, 3, "520.125GB")]
|
||||
[InlineData(520348, 3, "520,348KB")]
|
||||
[InlineData(520462400, 3, "520,462MB")]
|
||||
[InlineData(520573990000, 3, "520,574GB")]
|
||||
[InlineData(520124960000, 3, "520,125GB")]
|
||||
public void ByteConverterShouldCalculate(long byteCount, int precision, string expectedValue)
|
||||
{
|
||||
var stringValue = ByteConverter.BytesToString(byteCount, precision);
|
||||
|
|
|
@ -44,6 +44,9 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public async Task DirectAuth(string login, string password)
|
||||
{
|
||||
if (login == null) throw new ArgumentNullException(nameof(login));
|
||||
if (password == null) throw new ArgumentNullException(nameof(password));
|
||||
|
||||
await _api.AuthorizeAsync(new ApiAuthParams
|
||||
{
|
||||
ApplicationId = 5560698,
|
||||
|
@ -63,6 +66,8 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public async Task<IEnumerable<FileModel>> Get(string path)
|
||||
{
|
||||
if (path == null) throw new ArgumentNullException(nameof(path));
|
||||
|
||||
var documents = await _api.Docs.GetAsync();
|
||||
return documents.Select(document =>
|
||||
{
|
||||
|
@ -75,17 +80,24 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public async Task DownloadFile(string from, Stream to)
|
||||
{
|
||||
if (from == null) throw new ArgumentNullException(nameof(from));
|
||||
if (to == null) throw new ArgumentNullException(nameof(to));
|
||||
|
||||
var isValidUriString = Uri.IsWellFormedUriString(from, UriKind.Absolute);
|
||||
if (!isValidUriString) throw new InvalidOperationException("Uri is invalid.");
|
||||
|
||||
using (var downloader = new HttpClient())
|
||||
using (var response = await downloader.GetAsync(from).ConfigureAwait(false))
|
||||
using (var http = new HttpClient())
|
||||
using (var response = await http.GetAsync(from).ConfigureAwait(false))
|
||||
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
|
||||
await stream.CopyToAsync(to).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task UploadFile(string to, Stream from, string name)
|
||||
{
|
||||
if (to == null) throw new ArgumentNullException(nameof(to));
|
||||
if (from == null) throw new ArgumentNullException(nameof(from));
|
||||
if (name == null) throw new ArgumentNullException(nameof(name));
|
||||
|
||||
var server = await _api.Docs.GetUploadServerAsync().ConfigureAwait(false);
|
||||
var uri = new Uri(server.UploadUrl);
|
||||
|
||||
|
@ -132,7 +144,7 @@ namespace Camelotia.Services.Providers
|
|||
}
|
||||
}
|
||||
|
||||
internal class DocUploadResponse
|
||||
private class DocUploadResponse
|
||||
{
|
||||
[JsonProperty("file")]
|
||||
public string File { get; set; }
|
||||
|
|
|
@ -43,7 +43,10 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public async Task<IEnumerable<FileModel>> Get(string path)
|
||||
{
|
||||
var encodedPath = WebUtility.UrlEncode(path);
|
||||
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException(nameof(path));
|
||||
|
||||
var yaPath = path.Replace("\\", "/");
|
||||
var encodedPath = WebUtility.UrlEncode(yaPath);
|
||||
var pathUrl = CloudApiGetPathBase + encodedPath;
|
||||
using (var response = await _http.GetAsync(pathUrl).ConfigureAwait(false))
|
||||
{
|
||||
|
@ -64,6 +67,9 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public async Task DownloadFile(string from, Stream to)
|
||||
{
|
||||
if (from == null) throw new ArgumentNullException(nameof(from));
|
||||
if (to == null) throw new ArgumentNullException(nameof(to));
|
||||
|
||||
var encodedPath = WebUtility.UrlEncode(from);
|
||||
var pathUrl = CloudApiDownloadFileUrl + encodedPath;
|
||||
using (var response = await _http.GetAsync(pathUrl).ConfigureAwait(false))
|
||||
|
@ -151,25 +157,25 @@ namespace Camelotia.Services.Providers
|
|||
$"&client_id={ClientId}&redirect_url={redirect}";
|
||||
}
|
||||
|
||||
internal class YandexTokenAuthResponse
|
||||
private class YandexTokenAuthResponse
|
||||
{
|
||||
[JsonProperty("access_token")]
|
||||
public string AccessToken { get; set; }
|
||||
}
|
||||
|
||||
internal class YandexContentResponse
|
||||
private class YandexContentResponse
|
||||
{
|
||||
[JsonProperty("_embedded")]
|
||||
public YandexContentItemsResponse Embedded { get; set; }
|
||||
}
|
||||
|
||||
internal class YandexContentItemsResponse
|
||||
private class YandexContentItemsResponse
|
||||
{
|
||||
[JsonProperty("items")]
|
||||
public IList<YandexContentItemResponse> Items { get; set; }
|
||||
}
|
||||
|
||||
internal class YandexContentItemResponse
|
||||
private class YandexContentItemResponse
|
||||
{
|
||||
[JsonProperty("path")]
|
||||
public string Path { get; set; }
|
||||
|
@ -187,7 +193,7 @@ namespace Camelotia.Services.Providers
|
|||
public DateTime Created { get; set; }
|
||||
}
|
||||
|
||||
internal class YandexFileDownloadResponse
|
||||
private class YandexFileDownloadResponse
|
||||
{
|
||||
[JsonProperty("href")]
|
||||
public string Href { get; set; }
|
||||
|
|
Загрузка…
Ссылка в новой задаче