public async Task <bool> PrepareAync(string primaryDirectory, IEnumerable <string> subdirs)
        {
            await BucketManager.CreateBucketAsync(_Client, _Bucket);

            if (string.IsNullOrWhiteSpace(primaryDirectory))
            {
                throw new ArgumentException("primaryDirectory", string.Format(Messages.ListNullOrEmpty, "primaryDirectory"));
            }
            if (subdirs == null || !subdirs.Any())
            {
                throw new ArgumentException("subdirs", string.Format(Messages.ListNullOrEmpty, "subdirs"));
            }
            if (subdirs.Any(d => string.IsNullOrWhiteSpace(d)))
            {
                throw new ArgumentException("subdirs", string.Format(Messages.StringListNullEmptyOrWhiteSpace, "sbudirs"));
            }
            var created = await CreateDirectoryIfNotExists(primaryDirectory);

            if (!created)
            {
                return(false);
            }
            foreach (var subdir in subdirs)
            {
                var dir = Path.Combine(primaryDirectory, subdir);
                created = await CreateDirectoryIfNotExists(dir);

                if (!created)
                {
                    return(false);
                }
            }
            return(true);
        }
        internal async Task <bool> CreateDirectoryIfNotExists(string dir)
        {
            dir = dir.Replace("\\", "/");
            var fileExists = await BucketManager.FolderExistsAsync(_Client, _Bucket, dir);

            if (!fileExists)
            {
                await BucketManager.CreateBucketDirectoryAsync(_Client, _Bucket, dir);
            }
            return(await BucketManager.FolderExistsAsync(_Client, _Bucket, dir));
        }
        public async Task <string> ReadAllTextAsync(string pathToFile)
        {
            pathToFile = pathToFile.Replace("\\", "/");
            var fileExists = await BucketManager.FileExistsAsync(_Client, _Bucket, pathToFile);

            if (!fileExists)
            {
                return(null);
            }
            var text = await BucketManager.ReadAllTextAsync(_Client, _Bucket, pathToFile);

            return(text);
        }
        public async Task <string> GetNextFileAsync(string unitOfWorkDirectory)
        {
            unitOfWorkDirectory = unitOfWorkDirectory.Replace("\\", "/");
            var folderExists = await BucketManager.FolderExistsAsync(_Client, _Bucket, unitOfWorkDirectory);

            if (!folderExists)
            {
                return(null);
            }
            var unitOfWorkFiles = await BucketManager.ListFilesAsync(_Client, _Bucket, unitOfWorkDirectory, "*.json");

            return(unitOfWorkFiles?.First());
        }
        public async Task WriteAsync(string masterDirectory, Master master)
        {
            var folderExists = await BucketManager.FolderExistsAsync(_Client, _Bucket, masterDirectory);

            if (!folderExists)
            {
                return;
            }
            var filename = $"{master.ToString()}.json";
            var objKey   = Path.Combine(masterDirectory, filename);

            objKey = objKey.Replace("\\", "/");
            var json = JsonConvert.SerializeObject(master);
            await BucketManager.CreateTextFileAsync(_Client, _Bucket, objKey, json);
        }
Пример #6
0
        public async Task WriteAsync(string directory, UnitOfWork unitOfWork)
        {
            var folderExists = await BucketManager.FolderExistsAsync(_Client, _Bucket, directory);

            if (!folderExists)
            {
                return;
            }
            var filename     = $"{unitOfWork.Id}.json".PadLeft(10, '0');
            var fileFullPath = Path.Combine(directory, filename);

            fileFullPath = fileFullPath.Replace("\\", "/");
            var json = JsonConvert.SerializeObject(unitOfWork);
            await BucketManager.CreateTextFileAsync(_Client, _Bucket, fileFullPath, json);
        }
        public async Task <Master> ReadAsync(string masterDirectory)
        {
            var result = await BucketManager.FolderExistsAsync(_Client, _Bucket, masterDirectory);

            if (!result)
            {
                return(null);
            }
            var masterFiles = await BucketManager.ListFilesAsync(_Client, _Bucket, masterDirectory, ".json");

            if (masterFiles == null || !masterFiles.Any())
            {
                return(null);
            }
            var currentMasterFile = masterFiles.OrderByDescending(f => f).First();
            var text = await BucketManager.ReadAllTextAsync(_Client, _Bucket, currentMasterFile);

            var master = JsonConvert.DeserializeObject <Master>(text);

            return(master);
        }
 public async Task <bool> FileExistsAsync(string file)
 {
     return(await BucketManager.FileExistsAsync(_Client, _Bucket, file));
 }
 public async Task <bool> DirectoryExistsAsync(string dir)
 {
     return(await BucketManager.FolderExistsAsync(_Client, _Bucket, dir));
 }
 public async Task <List <string> > GetFilesAsync(string queueDir, string filter = null)
 {
     return(await BucketManager.ListFilesAsync(_Client, _Bucket, queueDir, filter));
 }
Пример #11
0
 public async Task MoveAsync(string source, string destination)
 {
     source      = source.Replace("\\", "/");
     destination = destination.Replace("\\", "/");
     await BucketManager.MoveObjectAsync(_Client, _Bucket, _Bucket, source, destination);
 }