Exemple #1
0
        public async Task AvailableSpace(GoogleDriveService gd, Action action)
        {
            var spaceBefore = await gd.AvailableSpaceGoogleDrive();

            _logger.Info($"Avalible: {(float)spaceBefore / (1024 * 1024)} mb.");
            action();
            var spaceAfter = await gd.AvailableSpaceGoogleDrive();

            var cleaned = spaceAfter - spaceBefore;

            _logger.Info($"Cleaned: {cleaned} b.");
            _logger.Info($"Avalible: {(float)spaceAfter / (1024 * 1024)} mb.");
        }
Exemple #2
0
        public async Task DeleteFiles(Func <string, Task <bool> > IsDeleteFile)
        {
            foreach (var key in _keys)
            {
                var gd    = new GoogleDriveService(_logger, key);
                var ids   = (await gd.ListAllFiles()).Select(x => x.Id);
                var count = ids.Count();
                _logger.Info($"There are `{count}` ids.");
                int i = 0;
                int j = 0;
                foreach (var id in ids)
                {
                    if (await IsDeleteFile(id))
                    {
                        await gd.Files.Delete(id).ExecuteAsync();

                        j++;
                    }
                    i++;
                }
            }
        }
Exemple #3
0
        private async Task <GoogleDriveService> GoogleDriveService(long memory)
        {
begin:
            var key = _keys.FirstOrDefault();

            if (key == null)
            {
                var msg = "No avalible keys.";
                _logger.Error(msg);
                throw new Exception(msg);
            }
            var gd = new GoogleDriveService(_logger, key);

            var space = await gd.AvailableSpaceGoogleDrive();

            _logger.Info($"There are {(float)space/(1024*1024)} avalible mb at google drive.");
            if (space < memory + 10 * 1024 * 1024) // memory + additional 10mb
            {
                _keys.RemoveAt(0);
                goto begin;
            }

            return(gd);
        }