Skip to content

Commit 81571e3

Browse files
Merge branch 'ver.1.2'
2 parents d6dc602 + 2e101e1 commit 81571e3

22 files changed

+897
-492
lines changed

README.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
### Introduction
1+
## Introduction
22

33
EasyMorph Server Command Line Client (in further text – **ems-cmd**) allows you to run server commands via REST API.
44

55

6-
### Requirements
7-
1. OS Windows with .Net 4.5 or later
8-
2. Morph.Server.Sdk.dll (deployed together with ems-cmd).
6+
#### Requirements
7+
1. OS Windows x86/x64 with .Net 4.5 or later
8+
2. Morph.Server.Sdk.dll (deployed together with ems-cmd). Also [hosted on github](https://github.com/easymorph/server-sdk)
9+
3. [EasyMorph Server 1.2](http://easymorph.com/server.html) or higher (installed on a separate PC)
910

1011

11-
General command format:
12+
#### General command format:
1213

1314
```
1415
ems-cmd <commad> <host> -param1 value1 -param2 "value two"
@@ -21,6 +22,12 @@ where
2122
+ **```<host>```** - Server host like `http://192.168.100.200:6330`.
2223

2324

25+
#### exit codes
26+
ems-cmd may return one of the following exit codes:
27+
* `0` ems-cmd was successfully run to completion.
28+
* `1` A fatal error occurred during command parsing or execution.
29+
30+
2431

2532
### Commands
2633

@@ -114,20 +121,27 @@ Listing done
114121
```
115122

116123

117-
#### Download the file
124+
#### Download file
118125
This command will download one single file from server
119126

120127
If local file already exists, you will be prompted to overwrite it.
121128
Notice, that when you are using a redirected output (e.g. to the file) and local file already exists, download will fail.
122129
In any case, you may use parameter `/y` to overwrite existing file without any prompts.
123130

131+
132+
Be careful with folders that contain spaces in their names. You should add quotation marks around such parameter values.
133+
Keep in mind, that sequence `\"` will escape double quotes. So `"D:\"`, `"D:\another folder\"` are incorrect, use `D:\` and `"D:\another folder"` instead.
134+
124135
```
125-
ems-cmd download http://192.168.100.200:6330 -space Default -to "D:\your\local\folder" -from "server\folder\file.xml"
136+
ems-cmd download http://192.168.100.200:6330 -space Default -target D:\your\local\folder -source file.xml
137+
ems-cmd download http://192.168.100.200:6330 -space Default -target D:\your\local\folder -source \file.xml
138+
ems-cmd download http://192.168.100.200:6330 -space Default -target D:\your\local\folder -source \server\folder\file.xml
139+
ems-cmd download http://192.168.100.200:6330 -space Default -target "D:\local\folder with spaces" -source "server\folder with spaces\file3.xml"
126140
```
127141
###### Parameters
128142
* `-space` - space name, e.g. `Default`
129-
* `-to` - destination folder (you local folder).
130-
* `-from` - relative path to file in the space `-space`
143+
* `-target` - destination folder (you local folder).
144+
* `-source` - relative path to file in the space `-space`
131145
* `/y` - overwrite existing file (silent agree)
132146

133147
###### Output
@@ -137,20 +151,28 @@ Operation completed
137151
```
138152

139153

140-
#### Upload the file
154+
#### Upload file
141155
This command will upload one single to server
142156

143157
If remote file already exists, you will be prompted to overwrite it.
144158
Notice, that when you are using a redirected output (e.g. to the file) and remote file already exists, upload will fail.
145159
In any case, you may use parameter `/y` to overwrite existing file without any prompts.
146160

161+
162+
Be careful with folders that contain spaces in their names. You should add quotation marks around such parameter values.
163+
Keep in mind, that sequence `\"` will escape double quotes. So `"D:\"`, `"D:\another folder\"` are incorrect, use `D:\` and `"D:\another folder"` instead.
164+
165+
147166
```
148-
ems-cmd upload http://192.168.100.200:6330 -space Default -from "D:\your\local\folder\file.xml" -to "\"
167+
ems-cmd upload http://192.168.100.200:6330 -space Default -source D:\your\local\folder\file.xml -target \
168+
ems-cmd upload http://192.168.100.200:6330 -space Default -source D:\your\local\folder\file2.xml -target "folder 2"
169+
ems-cmd upload http://192.168.100.200:6330 -space Default -source D:\your\local\folder\file2.xml -target "folder 2\sub folder"
170+
ems-cmd upload http://192.168.100.200:6330 -space Default -source "D:\local\folder with spaces" -target "folder 2\sub folder"
149171
```
150172
###### Parameters
151173
* `-space` - space name, e.g. `Default`
152-
* `-to` - destination folder (remote folder, relative path in the space `-space`).
153-
* `-from` - path to your local file
174+
* `-target` - destination folder (remote folder, relative path in the space `-space`).
175+
* `-source` - path to your local file
154176
* `/y` - overwrite existing file (silent agree)
155177

156178
###### Output
@@ -164,13 +186,15 @@ Operation completed
164186
This command will delete remote file
165187

166188
```
167-
ems-cmd del http://192.168.100.200:6330 -space Default -file "folder 2\file.xml"
189+
ems-cmd del http://192.168.100.200:6330 -space Default -target "folder 2\file.xml"
168190
```
169191
###### Parameters
170192
* `-space` - space name, e.g. `Default`
171-
* `-file` - relative path in the space `-space` to the file
193+
* `-target` - relative path in the space `-space` to file
172194

195+
## License
173196

197+
**ems-cmd** is licensed under the [MIT license](https://github.com/easymorph/server-cmd/blob/master/LICENSE).
174198

175199

176200

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Morph.Server.Sdk.Client;
2+
using MorphCmd.Interfaces;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace MorphCmd.BusinessLogic.Commands
11+
{
12+
internal abstract class BaseCommand
13+
{
14+
15+
16+
protected readonly IOutputEndpoint _output;
17+
protected readonly IInputEndpoint _input;
18+
protected readonly IMorphServerApiClient _apiClient;
19+
protected readonly CancellationTokenSource _cancellationTokenSource;
20+
21+
public BaseCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient)
22+
{
23+
_output = output;
24+
_input = input;
25+
_apiClient = apiClient;
26+
_cancellationTokenSource = new CancellationTokenSource();
27+
}
28+
29+
protected void RequireParam(Guid? value)
30+
{
31+
32+
}
33+
34+
}
35+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Morph.Server.Sdk.Client;
2+
using MorphCmd.Interfaces;
3+
using MorphCmd.Models;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace MorphCmd.BusinessLogic.Commands
11+
{
12+
13+
internal class BrowseCommand : BaseCommand, ICommand
14+
{
15+
public BrowseCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient) : base(output, input, apiClient)
16+
{
17+
18+
}
19+
20+
public async Task Execute(Parameters parameters)
21+
{
22+
if (string.IsNullOrWhiteSpace(parameters.Location))
23+
{
24+
_output.WriteInfo("Browsing the root folder of the space " + parameters.Space);
25+
}
26+
else
27+
{
28+
_output.WriteInfo("Browsing the folder '" + parameters.Location + "' of the space " + parameters.Space);
29+
}
30+
var data = await _apiClient.BrowseSpaceAsync(parameters.Space, parameters.Location, _cancellationTokenSource.Token);
31+
_output.WriteInfo("Space: " + data.SpaceName);
32+
_output.WriteInfo("Free space: " + data.FreeSpaceBytes + " bytes");
33+
foreach (var folder in data.Folders)
34+
{
35+
_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));
36+
}
37+
foreach (var file in data.Files)
38+
{
39+
_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));
40+
}
41+
42+
43+
_output.WriteInfo("Listing done");
44+
45+
}
46+
}
47+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Morph.Server.Sdk.Client;
2+
using MorphCmd.Interfaces;
3+
using MorphCmd.Models;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace MorphCmd.BusinessLogic.Commands
11+
{
12+
internal static class CommandsFactory
13+
{
14+
public static ICommand Construct(Command command, IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient)
15+
{
16+
switch (command)
17+
{
18+
case Command.Run:
19+
return new RunTaskAndWaitCommand(output, input, apiClient);
20+
case Command.RunAsync:
21+
return new RunTaskAndForgetCommand(output, input, apiClient);
22+
case Command.Status:
23+
return new ServerStatusCommand(output, input, apiClient);
24+
case Command.Upload:
25+
return new UploadFileCommand(output, input, apiClient);
26+
case Command.Browse:
27+
return new BrowseCommand(output, input, apiClient);
28+
case Command.Del:
29+
return new DeleteFileCommand(output, input, apiClient);
30+
case Command.Download:
31+
return new DownloadFileCommand(output, input, apiClient);
32+
case Command.ValidateTasks:
33+
return new ValidateTasksCommand(output, input, apiClient);
34+
default:
35+
throw new Exception("Command not supported");
36+
}
37+
}
38+
}
39+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Morph.Server.Sdk.Client;
2+
using MorphCmd.Exceptions;
3+
using MorphCmd.Interfaces;
4+
using MorphCmd.Models;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace MorphCmd.BusinessLogic.Commands
12+
{
13+
internal class DeleteFileCommand : BaseCommand, ICommand
14+
{
15+
public DeleteFileCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient) : base(output, input, apiClient)
16+
{
17+
18+
}
19+
20+
public async Task Execute(Parameters parameters)
21+
{
22+
if (string.IsNullOrWhiteSpace(parameters.Target))
23+
{
24+
throw new WrongCommandFormatException("Target is required");
25+
}
26+
27+
_output.WriteInfo(string.Format("Deleting file {0} in space {1}...", parameters.Target, parameters.Space ?? "Default"));
28+
await _apiClient.DeleteFileAsync(parameters.Space, parameters.Target, null, _cancellationTokenSource.Token);
29+
_output.WriteInfo("Operation completed");
30+
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)