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> 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);
        }
Exemple #4
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> DirectoryExistsAsync(string dir)
 {
     return(await BucketManager.FolderExistsAsync(_Client, _Bucket, dir));
 }