Esempio n. 1
0
        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,
            });
        }
Esempio n. 2
0
            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));
            }
Esempio n. 3
0
        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",
            });
        }
Esempio n. 4
0
        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",
            });
        }
Esempio n. 5
0
        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,
            });
        }
Esempio n. 6
0
        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,
            });
        }
Esempio n. 7
0
        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,
            });
        }