public async Task <IEnumerable <FileModel> > Get(string 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)) { var json = await response.Content.ReadAsStringAsync(); response.EnsureSuccessStatusCode(); var content = JsonConvert.DeserializeObject <YandexContentResponse>(json); var models = content.Embedded.Items .Select(file => new FileModel( file.Name, file.Path.Replace("disk:", ""), file.Type == "dir", false, ByteConverter.BytesToString(file.Size))); return(models); } }
public void Set <T>(string key, T value, Func <T, byte[]> convertFunc) where T : new() { var bytes = convertFunc.Invoke(value); string str = ByteConverter.BytesToString(bytes); SetString(key, str); }
public Task <IEnumerable <FileModel> > Get(string path) => Task.Run(() => { if (string.IsNullOrWhiteSpace(path)) { var driveQuery = from entity in GetAllDrives() where entity.IsReady let size = ByteConverter.BytesToString(entity.AvailableFreeSpace) select new FileModel(entity.Name, entity.Name, true, size); return(driveQuery .ToList() .AsEnumerable()); } if (!Directory.Exists(path)) { throw new ArgumentException("Directory doesn't exist."); } var query = from entity in Directory.GetFileSystemEntries(path) let isDirectory = IsDirectory(entity) let size = isDirectory ? "*" : ByteConverter.BytesToString(new FileInfo(entity).Length) select new FileModel(Path.GetFileName(entity), entity, isDirectory, size); return(query .ToList() .AsEnumerable()); });
private static string GetSizeOnAllDisks() { var totalBytes = GetAllDrives() .Select(x => x.AvailableFreeSpace) .Sum(); return(ByteConverter.BytesToString(totalBytes)); }
public void BytesToStringSingleByteTest() { for (var i = 0; i <= 0xf; i++) { for (var j = 0; j <= 0xf; j++) { var b = (byte)(i * 0x10 + j); string str = i.ToString("x") + j.ToString("x"); Assert.AreEqual(str, ByteConverter.BytesToString(new[] { b }), str); } } }
public async Task <IEnumerable <FileModel> > Get(string path) { var documents = await _api.Docs.GetAsync(); return(documents.Select(document => { var size = string.Empty; if (document.Size.HasValue) { size = ByteConverter.BytesToString(document.Size.Value); } return new FileModel(document.Title, document.Id.ToString(), false, size); })); }
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 => { var size = string.Empty; if (document.Size.HasValue) { size = ByteConverter.BytesToString(document.Size.Value); } return new FileModel(document.Title, document.Uri, false, false, size); })); }
public void ByteConverterShouldCalculate(long byteCount, int precision, string expectedValue) { var stringValue = ByteConverter.BytesToString(byteCount, precision); stringValue.Should().Be(expectedValue); }
public void ByteConverterShouldCalculateWithNoPrecisionSupplied(long byteCount, string expectedValue) { var stringValue = ByteConverter.BytesToString(byteCount); stringValue.Should().Be(expectedValue); }
//Bytes public static string BytesToString(byte[] bytes) { return(ByteConverter.BytesToString(bytes)); }
public void BytesToStringReturnsEmptyIfEmptyPassed() { Assert.IsEmpty(ByteConverter.BytesToString(new byte[0])); }
public void BytesToStringTwoBytesTest() { Assert.AreEqual("abcd", ByteConverter.BytesToString(new byte[] { 0xab, 0xcd })); }
public void BytesToStringReturnsNullIfNullIsPassed() { Assert.IsNull(ByteConverter.BytesToString(null)); }