public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken)) { CLILogs.Debug("Command Bucket : Upload"); BucketConfiguration config = iconfig as BucketConfiguration; List <Task> listOfTask = new List <Task>(); if (!config.ApiConnection.DisableBucketPathsSanitization && (PathSanitization.IsThePathInvalid(config.RemoteRelativePath))) { return(new CommandValues.GenericInfoCommandValue() { Uuid = bucket.Shortname, Message = "Upload failed. Invalid remote path", }); } if (!string.IsNullOrEmpty(config.String)) { CLILogs.Debug("Command Bucket : Upload String "); CLILogs.Debug(config.StringPath); await bucket.UploadStringAsync(config.String, config.StringPath, cancellationToken : ct); } listOfTask.AddRange(config.LocalPathFiles.Select(localFile => bucket.UploadFileAsync(localFile, config.RemoteRelativePath, cancellationToken: ct))); listOfTask.AddRange(config.LocalPathFolders.Select(localFolder => bucket.UploadFolderAsync(localFolder, config.RemoteRelativePath, cancellationToken: ct))); await Task.WhenAll(listOfTask); return(new CommandValues.GenericInfoCommandValue() { Uuid = bucket.Shortname, Message = "Bucket Upload", }); }
public async override Task <CommandValues.GenericInfoCommandValue> Create(IConfiguration iconfig, QarnotSDK.Connection connect, CancellationToken ct) { BucketConfiguration config = iconfig as BucketConfiguration; if (!config.ApiConnection.DisableBucketPathsSanitization && (PathSanitization.IsThePathInvalid(config.RemoteRelativePath))) { return(new CommandValues.GenericInfoCommandValue() { Uuid = config.Name, Message = "Creation failed. Invalid remote path", }); } QBucket bucket = await this.CreateBucket(config, connect, ct); await this.LaunchBucket(bucket, ct); List <Task> listOfTask = new List <Task>(); listOfTask.AddRange(config.LocalPathFiles.Select(localFile => bucket.UploadFileAsync(localFile, config.RemoteRelativePath, cancellationToken: ct))); listOfTask.AddRange(config.LocalPathFolders.Select(localFolder => bucket.UploadFolderAsync(localFolder, config.RemoteRelativePath, cancellationToken: ct))); await Task.WhenAll(listOfTask); return(this.PrintBucketInformation(bucket)); }
public virtual async Task <CommandValues.BucketInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken)) { CLILogs.Debug("Command Bucket : Info"); await bucket.UpdateAsync(ct); BucketConfiguration config = iconfig as BucketConfiguration; List <string> folderList = new List <string>(); string folder = config.RemoteRelativePath ?? ""; if (!config.ApiConnection.DisableBucketPathsSanitization && (PathSanitization.IsThePathInvalid(folder))) { return(null); } folderList = await ExtractBucketFilesInfoFromBucket(bucket, folder, ct, iconfig.HumanReadable); return(new CommandValues.BucketInfoCommandValue() { Shortname = bucket.Shortname, TotalFileCount = bucket.FileCount.ToString(), TotalUsedSpaceBytes = iconfig.HumanReadable ? this.ConvertBytes.ConvertToHumanReadable(bucket.UsedSpaceBytes, 2) : bucket.UsedSpaceBytes.ToString(), BucketFilesDetail = folderList, }); }
public async Task <QarnotSDK.QBucket> RetrieveAsync(IConfiguration configuration, QarnotSDK.Connection connection, CancellationToken ct) { BucketConfiguration config = configuration as BucketConfiguration; CLILogs.Debug("Retrieve QBucket by Name : " + config.Name); return(await connection.RetrieveBucketAsync(config.Name, ct)); }
public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken)) { CLILogs.Debug("Command Bucket : SyncTo"); BucketConfiguration config = iconfig as BucketConfiguration; string localFolderPath = config.LocalPathGet; bool donTDelete = config.DeleteFiles; string remoteFolderRelativePath = config.RemoteRelativePath; if (!config.ApiConnection.DisableBucketPathsSanitization && (PathSanitization.IsThePathInvalid(remoteFolderRelativePath))) { return(new CommandValues.GenericInfoCommandValue() { Uuid = bucket.Shortname, Message = "Synchronization failed. Invalid remote path", }); } CLILogs.Debug("Local path : " + localFolderPath); await bucket.SyncLocalToRemoteAsync(localFolderPath, ct, donTDelete, remoteFolderRelativePath); return(new CommandValues.GenericInfoCommandValue() { Uuid = bucket.Shortname, Message = localFolderPath + "send to Bucket", }); }
public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken)) { BucketConfiguration config = iconfig as BucketConfiguration; if (bucket == default) { var message = "Removal failed. Bucket not found"; throw new System.Exception(message); } if (!config.ApiConnection.DisableBucketPathsSanitization && (config.RemoteRelativePaths.Any(remoteFile => PathSanitization.IsThePathInvalid(remoteFile)))) { var message = "Removal failed. Invalid remote path(s)"; throw new System.Exception(message); } CLILogs.Debug("Command Bucket : Remove entities " + string.Join(", ", config.RemoteRelativePaths)); string returnString = "Bucket delete paths : " + string.Join(", ", config.RemoteRelativePaths); await config.RemoteRelativePaths.ParallelForEachAsync(bucket.DeleteEntryAsync, 10, ct : ct); return(new CommandValues.GenericInfoCommandValue() { Uuid = bucket.Shortname, Message = returnString, }); }
public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken)) { CLILogs.Debug("Command Bucket : SyncFrom"); BucketConfiguration config = iconfig as BucketConfiguration; if (bucket == default) { var message = "Synchronization failed. Bucket not found"; throw new System.Exception(message); } string localFolderPath = config.LocalPathGet; bool donTDelete = config.DeleteFiles; string remoteFolderRelativePath = config.RemoteRelativePath; if (!config.ApiConnection.DisableBucketPathsSanitization && (PathSanitization.IsThePathInvalid(remoteFolderRelativePath))) { var message = "Synchronization failed. Invalid remote path"; throw new System.Exception(message); } CLILogs.Debug("Local path : " + localFolderPath); await bucket.SyncRemoteToLocalAsync(localFolderPath, ct, donTDelete, remoteFolderRelativePath); return(new CommandValues.GenericInfoCommandValue() { Uuid = bucket.Shortname, Message = "Bucket sync to " + localFolderPath, }); }
public BucketConfiguration ConvertBucketOption(ConfigType type, CommandApi command, Options.IBucketGetOptions option) { if (command == CommandApi.List && !string.IsNullOrEmpty(option.Name)) { command = CommandApi.InfoBucket; } BucketConfiguration config = new BucketConfiguration(type, command); GetDefaultOptions(config, option); ConfigGetGlobalOptions(option); ConfigPrintInformation(option, type, Enum.GetName(typeof(CommandApi), command)); config.Name = option.Name; if (option is Options.TerminateBucketOptions bucketDelete) { if (bucketDelete.BucketPath.Count() > 0) { config.Command = CommandApi.Remove; config.RemoteRelativePaths = bucketDelete.BucketPath.ToList(); } } else if (option is Options.CreateBucketOptions bucketCreate) { config.LocalPathFolders = bucketCreate.FolderList.ToList(); config.LocalPathFiles = bucketCreate.FileList.ToList(); } else if (option is Options.SetBucketOptions bucketSet) { config.LocalPathFolders = bucketSet.LocalFoldersPath.ToList(); config.LocalPathFiles = bucketSet.LocalFilesPath.ToList(); config.RemoteRelativePath = bucketSet.RemoteFolderPath; config.StringPath = bucketSet.RemoteFolderPath; config.String = bucketSet.String; } else if (option is Options.GetBucketOptions bucketGet) { config.LocalPathGet = bucketGet.LocalPath; config.RemoteRelativePathFolders = bucketGet.RemoteFoldersPath.ToList(); config.RemoteRelativePathFiles = bucketGet.RemoteFilesPath.ToList(); config.StringPath = bucketGet.String; } else if (option is Options.ListBucketOptions bucketInfo) { config.RemoteRelativePath = bucketInfo.RemoteFolderPath; } else if (option is Options.SyncFromBucketOptions bucketFrom) { config.LocalPathGet = bucketFrom.LocalPath; config.RemoteRelativePath = bucketFrom?.RemoteFolderPath ?? string.Empty; } else if (option is Options.SyncToBucketOptions bucketTo) { config.LocalPathGet = bucketTo.LocalPath; config.RemoteRelativePath = bucketTo?.RemoteFolderPath ?? string.Empty; } return(config); }
private async Task <QBucket> CreateBucket(BucketConfiguration config, QarnotSDK.Connection connect, CancellationToken ct) { var bucket = await connect.CreateBucketAsync(config.Name, ct); if (config.CacheTTL.HasValue) { bucket.WithCacheTTL(config.CacheTTL.Value); } return(bucket); }
public async Task <List <QarnotSDK.QBucket> > RetrieveAsync(IConfiguration configuration, QarnotSDK.Connection connection, CancellationToken ct) { BucketConfiguration config = configuration as BucketConfiguration; if (config != null && !string.IsNullOrEmpty(config.Name)) { CLILogs.Debug("Retrieve QBucket by Name : " + config.Name); return(new List <QBucket>() { await connection.RetrieveBucketAsync(config.Name, cancellationToken : ct), }); } else { CLILogs.Debug("Retrieve all the QBuckets"); return(await connection.RetrieveBucketsAsync(cancellationToken : ct)); } }
public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken)) { CLILogs.Debug("Command Bucket : Delete"); BucketConfiguration config = iconfig as BucketConfiguration; if (bucket == default) { var message = "Ignore deletion. Bucket not found"; throw new System.Exception(message); } await bucket.DeleteAsync(ct); return(new CommandValues.GenericInfoCommandValue() { Uuid = bucket.Shortname, Message = "Bucket deleted", }); }
public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken)) { CLILogs.Debug("Command Bucket : Download"); BucketConfiguration config = iconfig as BucketConfiguration; List <Task> listOfTask = new List <Task>(); if (bucket == default) { var message = "Download failed. Bucket not found"; throw new System.Exception(message); } string returnString = "Bucket download"; string localPath = config.LocalPathGet ?? "."; if (!config.ApiConnection.DisableBucketPathsSanitization && (config.RemoteRelativePathFiles.Any(remoteFile => PathSanitization.IsThePathInvalid(remoteFile)) || config.RemoteRelativePathFolders.Any(remoteFile => PathSanitization.IsThePathInvalid(remoteFile)) || PathSanitization.IsThePathInvalid(config.StringPath))) { var message = "Download failed. Invalid remote path(s)"; throw new System.Exception(message); } if (!string.IsNullOrEmpty(config.StringPath)) { CLILogs.Debug("Command Bucket : DownLoad String"); returnString = await bucket.DownloadStringAsync(config.StringPath, cancellationToken : ct); } listOfTask.AddRange(config.RemoteRelativePathFiles.Select(remoteFile => bucket.DownloadFileAsync(remoteFile, Path.Join(localPath, Path.GetFileName(remoteFile)), cancellationToken: ct))); listOfTask.AddRange(config.RemoteRelativePathFolders.Select(remoteFolder => bucket.DownloadFolderAsync(remoteFolder, localPath, cancellationToken: ct))); await Task.WhenAll(listOfTask); return(new CommandValues.GenericInfoCommandValue() { Uuid = bucket.Shortname, Message = returnString, }); }
private async Task <QBucket> CreateBucket(BucketConfiguration config, QarnotSDK.Connection connect, CancellationToken ct) { return(await connect.CreateBucketAsync(config.Name, ct)); }