|
| 1 | +using Morph.Server.Sdk.Client; |
| 2 | +using Morph.Server.Sdk.Model; |
| 3 | +using MorphCmd.Interfaces; |
| 4 | +using MorphCmd.Models; |
| 5 | +using System.Threading.Tasks; |
| 6 | + |
| 7 | +namespace MorphCmd.BusinessLogic.Commands |
| 8 | +{ |
| 9 | + internal class QuickFilesSearchCommand : BaseCommand, ICommand |
| 10 | + { |
| 11 | + public QuickFilesSearchCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient) : base(output, input, apiClient) |
| 12 | + { |
| 13 | + |
| 14 | + } |
| 15 | + |
| 16 | + public bool IsApiSessionRequired => true; |
| 17 | + |
| 18 | + public async Task Execute(Parameters parameters) |
| 19 | + { |
| 20 | + if (string.IsNullOrWhiteSpace(parameters.Location)) |
| 21 | + { |
| 22 | + _output.WriteInfo("Searching in the root folder of the space " + parameters.SpaceName); |
| 23 | + } |
| 24 | + else |
| 25 | + { |
| 26 | + _output.WriteInfo("Searching in the folder '" + parameters.Location + "' of the space " + parameters.SpaceName); |
| 27 | + } |
| 28 | + |
| 29 | + using (var apiSession = await OpenSession(parameters)) |
| 30 | + { |
| 31 | + |
| 32 | + var request = new SpaceFilesQuickSearchRequest |
| 33 | + { |
| 34 | + FolderPath = parameters.Location, |
| 35 | + LookupString = parameters.LookupString, |
| 36 | + FileExtensions = parameters.FileExtensions == null ? |
| 37 | + null : |
| 38 | + (parameters.FileExtensions).Split(';') |
| 39 | + }; |
| 40 | + var data = await _apiClient.SpaceFilesQuickSearchAsync( |
| 41 | + apiSession, |
| 42 | + request, |
| 43 | + _cancellationTokenSource.Token, |
| 44 | + parameters.Offset, |
| 45 | + parameters.Limit |
| 46 | + ); |
| 47 | + |
| 48 | + |
| 49 | + foreach (var folder in data.Values) |
| 50 | + { |
| 51 | + _output.WriteInfo(folder.Path); |
| 52 | + _output.WriteInfo(string.Format("{0}{1} {2}", folder.LastModified.ToLocalTime().ToString("MM/dd/yyyy hh:mm:ss tt").PadRight(30), "<DIR>".PadRight(16), folder.Name)); |
| 53 | + |
| 54 | + foreach (var file in folder.Files) |
| 55 | + { |
| 56 | + _output.WriteInfo(string.Format("{0}{1} {2}", file.LastModified.ToLocalTime().ToString("MM/dd/yyyy hh:mm:ss tt").PadRight(30), file.FileSizeBytes.ToString("n0").PadLeft(16), file.Name)); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + _output.WriteInfo(data.HasMore ? "Has more data" : "Has no more data"); |
| 61 | + |
| 62 | + _output.WriteInfo("Listing done"); |
| 63 | + } |
| 64 | + |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments