Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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());
        });
Пример #4
0
        private static string GetSizeOnAllDisks()
        {
            var totalBytes = GetAllDrives()
                             .Select(x => x.AvailableFreeSpace)
                             .Sum();

            return(ByteConverter.BytesToString(totalBytes));
        }
Пример #5
0
 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);
         }
     }
 }
Пример #6
0
        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);
            }));
        }
Пример #7
0
        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);
            }));
        }
Пример #8
0
        public void ByteConverterShouldCalculate(long byteCount, int precision, string expectedValue)
        {
            var stringValue = ByteConverter.BytesToString(byteCount, precision);

            stringValue.Should().Be(expectedValue);
        }
Пример #9
0
        public void ByteConverterShouldCalculateWithNoPrecisionSupplied(long byteCount, string expectedValue)
        {
            var stringValue = ByteConverter.BytesToString(byteCount);

            stringValue.Should().Be(expectedValue);
        }
Пример #10
0
 //Bytes
 public static string BytesToString(byte[] bytes)
 {
     return(ByteConverter.BytesToString(bytes));
 }
Пример #11
0
 public void BytesToStringReturnsEmptyIfEmptyPassed()
 {
     Assert.IsEmpty(ByteConverter.BytesToString(new byte[0]));
 }
Пример #12
0
 public void BytesToStringTwoBytesTest()
 {
     Assert.AreEqual("abcd", ByteConverter.BytesToString(new byte[] { 0xab, 0xcd }));
 }
Пример #13
0
 public void BytesToStringReturnsNullIfNullIsPassed()
 {
     Assert.IsNull(ByteConverter.BytesToString(null));
 }