Skip to content

Commit 6bc6acc

Browse files
Merge pull request #18 from easymorph/development/5.7.0
5.7.0
2 parents 8fdac54 + aa5136b commit 6bc6acc

File tree

8 files changed

+139
-3
lines changed

8 files changed

+139
-3
lines changed

src/BusinessLogic/Commands/CommandsFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public static ICommand Construct(Command command, IOutputEndpoint output, IInput
4343
return new ListTasksCommand(output, input, apiClient);
4444
case Command.HttpSecureChallengeTest:
4545
return new HttpSecureChallengeTestCommand(output, input, apiClient);
46+
case Command.Remember:
47+
return new SharedMemoryRememberCommand(output, input, apiClient);
48+
case Command.Recall:
49+
return new SharedMemoryRecallCommand(output, input, apiClient);
50+
case Command.Forget:
51+
return new SharedMemoryForgetCommand(output, input, apiClient);
4652
default:
4753
throw new Exception("Command not supported");
4854
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Threading.Tasks;
2+
using Morph.Server.Sdk.Client;
3+
using MorphCmd.Exceptions;
4+
using MorphCmd.Interfaces;
5+
using MorphCmd.Models;
6+
7+
namespace MorphCmd.BusinessLogic.Commands
8+
{
9+
internal class SharedMemoryForgetCommand : BaseCommand, ICommand
10+
{
11+
public SharedMemoryForgetCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient) : base(
12+
output, input, apiClient)
13+
{
14+
}
15+
16+
public bool IsApiSessionRequired => true;
17+
18+
public async Task Execute(Parameters parameters)
19+
{
20+
if (string.IsNullOrWhiteSpace(parameters.Key))
21+
throw new WrongCommandFormatException("Key is required");
22+
23+
using (var session = await OpenSession(parameters))
24+
{
25+
_output.WriteInfo($"Deleting shared memory record {parameters.Key} in space {session.SpaceName}...");
26+
var deletedKeyCount = await _apiClient.SharedMemoryForget(session, parameters.Key,
27+
_cancellationTokenSource.Token);
28+
_output.WriteInfo($"Operation completed, {deletedKeyCount} records deleted");
29+
}
30+
}
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Threading.Tasks;
2+
using Morph.Server.Sdk.Client;
3+
using Morph.Server.Sdk.Model.SharedMemory;
4+
using MorphCmd.Exceptions;
5+
using MorphCmd.Interfaces;
6+
using MorphCmd.Models;
7+
8+
namespace MorphCmd.BusinessLogic.Commands
9+
{
10+
internal class SharedMemoryRecallCommand : BaseCommand, ICommand
11+
{
12+
public SharedMemoryRecallCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient) : base(
13+
output, input, apiClient)
14+
{
15+
}
16+
17+
public bool IsApiSessionRequired => true;
18+
19+
public async Task Execute(Parameters parameters)
20+
{
21+
if (string.IsNullOrWhiteSpace(parameters.Key))
22+
throw new WrongCommandFormatException("Key is required");
23+
24+
using (var session = await OpenSession(parameters))
25+
{
26+
_output.WriteInfo($"Retrieving shared memory record {parameters.Key} in space {session.SpaceName}...");
27+
var result = await _apiClient.SharedMemoryRecall(session, parameters.Key, _cancellationTokenSource.Token);
28+
_output.WriteInfo(result.Contents.ToString());
29+
}
30+
}
31+
}
32+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Threading.Tasks;
2+
using Morph.Server.Sdk.Client;
3+
using Morph.Server.Sdk.Model.SharedMemory;
4+
using MorphCmd.Exceptions;
5+
using MorphCmd.Interfaces;
6+
using MorphCmd.Models;
7+
8+
namespace MorphCmd.BusinessLogic.Commands
9+
{
10+
internal class SharedMemoryRememberCommand : BaseCommand, ICommand
11+
{
12+
public SharedMemoryRememberCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient) : base(
13+
output, input, apiClient)
14+
{
15+
}
16+
17+
public bool IsApiSessionRequired => true;
18+
19+
public async Task Execute(Parameters parameters)
20+
{
21+
if (string.IsNullOrWhiteSpace(parameters.Key))
22+
throw new WrongCommandFormatException("Key is required");
23+
if (string.IsNullOrWhiteSpace(parameters.Value))
24+
throw new WrongCommandFormatException("Value is required");
25+
26+
using (var session = await OpenSession(parameters))
27+
{
28+
_output.WriteInfo($"Saving shared memory record {parameters.Key} in space {session.SpaceName}...");
29+
_ = await _apiClient.SharedMemoryRemember(
30+
session,
31+
parameters.Key,
32+
SharedMemoryValue.NewText(parameters.Value),
33+
OverwriteBehavior.Overwrite,
34+
_cancellationTokenSource.Token);
35+
_output.WriteInfo($"Operation completed");
36+
}
37+
}
38+
}
39+
}

src/BusinessLogic/ParametersHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public static Parameters ExtractParameters(string command, string host, Dictiona
8383
parameters.TaskId = guid;
8484

8585
}
86+
87+
if (paramsDict.TryGetValue("key", out var value))
88+
parameters.Key = value;
89+
if (paramsDict.TryGetValue("value", out value))
90+
parameters.Value = value;
8691

8792
if (Enum.TryParse<Command>(command.Trim(), true, out var cmd))
8893
{

src/BusinessLogic/RunUsageSamples.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ public static void WriteCommadUsage(Command cmd, IOutputEndpoint output)
3131
case Command.Del:
3232
output.WriteInfo("DEL usage sample: ems-cmd del http://10.20.30.40:6330 -space Default -target \"folder 1\\sample.txt\" ");
3333
break;
34+
35+
case Command.Remember:
36+
output.WriteInfo("REMEMBER usage sample: ems-cmd remember http://10.20.30.40:6330 -space Default -key path1\\path2\\abc -value XYZ");
37+
break;
38+
case Command.Recall:
39+
output.WriteInfo("RECALL usage sample: ems-cmd recall http://10.20.30.40:6330 -space Default -key path1\\path2\\abc");
40+
break;
41+
case Command.Forget:
42+
output.WriteInfo("FORGET usage sample: ems-cmd forget http://10.20.30.40:6330 -space Default -key path1\\path2\\abc");
43+
break;
44+
3445
default:
3546
output.WriteInfo("This command hasn't usage example");
3647
break;

src/Models/Command.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ public enum Command
2121
ListSpaces,
2222
SpaceStatus,
2323
ListTasks,
24-
HttpSecureChallengeTest
25-
26-
24+
HttpSecureChallengeTest,
25+
26+
// Shared memory commands
27+
Remember,
28+
Recall,
29+
Forget,
2730
}
2831
}

src/Models/Parameters.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public class Parameters
2828
public string Password { get; set; }
2929
public bool SuppressSslErrors { get; set; }
3030
public List<TaskRunParameter> TaskRunParameters { get; set; }
31+
32+
#region Shared Memory Command Parameters
33+
34+
public string Key { get; set; }
35+
public string Value { get; set; }
36+
37+
#endregion
38+
3139
public Parameters()
3240
{
3341
TaskRunParameters = new List<TaskRunParameter>();

0 commit comments

Comments
 (0)