Skip to content

Commit 1420c35

Browse files
Added FilesSearch command (QuickFilesSearchCommand)
1 parent d18a591 commit 1420c35

File tree

6 files changed

+95
-5
lines changed

6 files changed

+95
-5
lines changed

src/BusinessLogic/Commands/BrowseFilesCommand.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
using Morph.Server.Sdk.Model;
33
using MorphCmd.Interfaces;
44
using MorphCmd.Models;
5-
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
8-
using System.Text;
95
using System.Threading.Tasks;
106

117
namespace MorphCmd.BusinessLogic.Commands

src/BusinessLogic/Commands/CommandsFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public static ICommand Construct(Command command, IOutputEndpoint output, IInput
2727
return new UploadFileCommand(output, input, apiClient);
2828
case Command.Browse:
2929
return new BrowseFilesCommand(output, input, apiClient);
30+
case Command.FilesSearch:
31+
return new QuickFilesSearchCommand(output, input, apiClient);
3032
case Command.Del:
3133
return new DeleteFileCommand(output, input, apiClient);
3234
case Command.Download:
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}

src/BusinessLogic/ParametersHelper.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ public static Parameters ExtractParameters(string command, string host, Dictiona
2727

2828
if (paramsDict.ContainsKey("location"))
2929
parameters.Location = paramsDict["location"];
30+
if (paramsDict.ContainsKey("lookup-string"))
31+
parameters.LookupString = paramsDict["lookup-string"];
32+
if (paramsDict.ContainsKey("file-extensions"))
33+
parameters.FileExtensions = paramsDict["file-extensions"];
34+
if (paramsDict.ContainsKey("offset"))
35+
{
36+
if(int.TryParse(paramsDict["offset"], out var offset)){
37+
parameters.Offset = offset;
38+
}
39+
}
40+
41+
if (paramsDict.ContainsKey("limit"))
42+
{
43+
if (int.TryParse(paramsDict["limit"], out var limit)){
44+
parameters.Limit = limit;
45+
}
46+
}
47+
3048

3149
if (paramsDict.ContainsKey("y"))
3250
parameters.YesToAll = true;

src/Models/Command.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum Command
1414
Status,
1515
Upload,
1616
Browse,
17+
FilesSearch,
1718
Download,
1819
Del,
1920
ValidateTasks,

src/Models/Parameters.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ public class Parameters
1414
public string SpaceName { get; set; }
1515
public string Source { get; set; }
1616
public string Target { get; set; }
17+
18+
public string LookupString { get; set; }
19+
public string FileExtensions { get; set; }
1720
public string Location { get; set; }
18-
21+
22+
public int? Offset { get; set; }
23+
public int? Limit { get; set; }
24+
1925
public Guid? TaskId { get; set; }
2026
public bool YesToAll { get; set; }
2127
public string Host { get; set; }

0 commit comments

Comments
 (0)