Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 90 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ EasyMorph Server Command Line Client (in further text – **ems-cmd**) allows yo
#### Download
ems-cmd comes together with EasyMorph Server. Also it can be [downloaded](https://github.com/easymorph/server-cmd/releases) separately

Current version is 1.2.0.


#### General command format:

Expand All @@ -33,6 +31,13 @@ ems-cmd may return one of the following exit codes:
* `0` ems-cmd was successfully run to completion.
* `1` A fatal error occurred during command parsing or execution.

#### Authorization
For password protected spaces you should pass password via command parameter `-password`.
```
ems-cmd upload http://192.168.100.200:6330 -space Default -password your_password -source D:\your\local\folder\file.xml -target \
```
In the example above, a session will be opened for the specified space Default, of course if password was correct. In case of incorrect password or public spaces, error will be thrown.
Some hash computations are applied to the password before it is sent to the server.


### Commands
Expand All @@ -53,24 +58,87 @@ Retrieving server status...
STATUS:
StatusCode: OK
StatusMessage: Server is OK
ServerVersion:1.2.0.0
ServerVersion:1.3.0.0
```


#### Retrieve spaces list
A list of all spaces will be displayed. This command doesn't require authorization.

```bash
ems-cmd listspaces http://192.168.100.200:6330
```
###### Parameters
This command has no additional parameters

###### Output
```
Available spaces:
* closed one
Default
Listing done
```
Asterisk `*` means that the space requires an authorization.


#### Space status
Returns specified space status. This command may require authorization if space is password protected.

```bash
ems-cmd spacestatus http://192.168.100.200:6330 -space "closed one" -password some_password
```
###### Parameters

* `-space` - space name.
* `-password` - if password is required.

###### Output
```
Checking space default status...
Space: Default
IsPublic: True
Permissions: FilesList, FileDownload
done
```



### Tasks Related
#### Start the task
This command will start specified task and wait until it is done.

To start the task you need to know space name and the task ID.
Make sure to check the task execution server log to determine task execution info.


```
ems-cmd run http://192.168.100.200:6330 -space Default -taskID 59b824f0-4b81-453f-b9e0-1c58b97c9fb9
```
###### Parameters
* `-space` - space name, e.g. `Default`
* `-taskID` - task guid.
* `-param:XXX ZZ` - set task parameter `XXX` with value `ZZ`.

Task guid can be found in the browser location toolbar. E.g, if you have clicked on the edit task link, your browser location seems to be `http://localhost:6330/default/tasks/edit/59b824f0-4b81-453f-b9e0-1c58b97c9fb9`, where `59b824f0-4b81-453f-b9e0-1c58b97c9fb9` - is a desired value

If you want to pass (or override) parameters that were defined in morph project, add `-param:XXX ZZ` to ems-cmd execution line.
Where `XXX` is a parameter name and `ZZ` is a parameter value.
At least one space between parameter name and parameter value is required.


E.g. If you've defined parameter `Timeout` in your morph project, and want to set it to 73 use `-param:Timeout 73`. Pay attention, that parameters are case sensitive.


Examples:


Set parameter `Rounds` to `10` : `-param:Timeout 73`

Set parameter `Full name` to `John Smith` : `-param:"Full name" "John Smith"`

Set parameter `From Date` to the `10th of December 2000` : `-param:"From Date" "2000-12-10"` (ISO 8601 date format)


###### Output
```
Attempting to start task 59b824f0-4b81-453f-b9e0-1c58b97c9fb9
Expand All @@ -91,9 +159,28 @@ ems-cmd runasync http://192.168.100.200:6330 -space Default -taskID 59b824f0-4b8
###### Parameters
* `-space` - space name, e.g. `Default`
* `-taskID` - task guid.
* `-param:XXX ZZ` - set task parameter `XXX` with value `ZZ`.

Task guid can be found in the browser location toolbar. E.g, if you have clicked on the edit task link, your browser location seems to be `http://localhost:6330/default/tasks/edit/59b824f0-4b81-453f-b9e0-1c58b97c9fb9`, where `59b824f0-4b81-453f-b9e0-1c58b97c9fb9` - is a desired value

If you want to pass (or override) parameters that were defined in morph project, add `-param:XXX ZZ` to ems-cmd execution line.
Where `XXX` is a parameter name and `ZZ` is a parameter value.
At least one space between parameter name and parameter value is required.


E.g. If you've defined parameter `Timeout` in your morph project, and want to set it to 73 use `-param:Timeout 73`. Pay attention, that parameters are case sensitive.


Examples:


Set parameter `Rounds` to `10` : `-param:Timeout 73`

Set parameter `Full name` to `John Smith` : `-param:"Full name" "John Smith"`

Set parameter `From Date` to the `10th of December 2000` : `-param:"From Date" "2000-12-10"` (ISO 8601 date format)


###### Output
```
Attempting to start task 59b824f0-4b81-453f-b9e0-1c58b97c9fb9
Expand Down
20 changes: 20 additions & 0 deletions src/BusinessLogic/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Morph.Server.Sdk.Client;
using Morph.Server.Sdk.Model;
using MorphCmd.Interfaces;
using MorphCmd.Models;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -31,5 +33,23 @@ protected void RequireParam(Guid? value)

}

protected async Task<ApiSession> OpenSession(Parameters parameters)
{
// for simplification we just check that the user has pass any password
// in more complex logic, you should call GetSpacesListAsync to retrieve a spaces list and check the isPublic property or the space
// isPublic means that you need to open an anon session, otherwise - open a real session
if (string.IsNullOrWhiteSpace(parameters.Password))
{
var apiSession = ApiSession.Anonymous(parameters.SpaceName);
return apiSession;
}
else
{
var apiSession = await _apiClient.OpenSessionAsync(parameters.SpaceName, parameters.Password, _cancellationTokenSource.Token);
return apiSession;
}

}

}
}
47 changes: 0 additions & 47 deletions src/BusinessLogic/Commands/BrowseCommand.cs

This file was deleted.

55 changes: 55 additions & 0 deletions src/BusinessLogic/Commands/BrowseFilesCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Morph.Server.Sdk.Client;
using Morph.Server.Sdk.Model;
using MorphCmd.Interfaces;
using MorphCmd.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MorphCmd.BusinessLogic.Commands
{

internal class BrowseFilesCommand : BaseCommand, ICommand
{
public BrowseFilesCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient) : base(output, input, apiClient)
{

}

public bool IsApiSessionRequired => true;

public async Task Execute(Parameters parameters)
{
if (string.IsNullOrWhiteSpace(parameters.Location))
{
_output.WriteInfo("Browsing the root folder of the space " + parameters.SpaceName);
}
else
{
_output.WriteInfo("Browsing the folder '" + parameters.Location + "' of the space " + parameters.SpaceName);
}

using (var apiSession = await OpenSession(parameters))
{

var data = await _apiClient.BrowseSpaceAsync(apiSession, parameters.Location, _cancellationTokenSource.Token);
_output.WriteInfo("Space: " + data.SpaceName);
_output.WriteInfo("Free space: " + data.FreeSpaceBytes + " bytes");
foreach (var folder in data.Folders)
{
_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));
}
foreach (var file in data.Files)
{
_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));
}


_output.WriteInfo("Listing done");
}

}
}
}
6 changes: 5 additions & 1 deletion src/BusinessLogic/Commands/CommandsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ public static ICommand Construct(Command command, IOutputEndpoint output, IInput
case Command.Upload:
return new UploadFileCommand(output, input, apiClient);
case Command.Browse:
return new BrowseCommand(output, input, apiClient);
return new BrowseFilesCommand(output, input, apiClient);
case Command.Del:
return new DeleteFileCommand(output, input, apiClient);
case Command.Download:
return new DownloadFileCommand(output, input, apiClient);
case Command.ValidateTasks:
return new ValidateTasksCommand(output, input, apiClient);
case Command.ListSpaces:
return new ListSpacesCommand(output, input, apiClient);
case Command.SpaceStatus:
return new SpaceStatusCommand(output, input, apiClient);
default:
throw new Exception("Command not supported");
}
Expand Down
12 changes: 9 additions & 3 deletions src/BusinessLogic/Commands/DeleteFileCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Morph.Server.Sdk.Client;
using Morph.Server.Sdk.Model;
using MorphCmd.Exceptions;
using MorphCmd.Interfaces;
using MorphCmd.Models;
Expand All @@ -17,16 +18,21 @@ public DeleteFileCommand(IOutputEndpoint output, IInputEndpoint input, IMorphSer

}

public bool IsApiSessionRequired => true;

public async Task Execute(Parameters parameters)
{
if (string.IsNullOrWhiteSpace(parameters.Target))
{
throw new WrongCommandFormatException("Target is required");
}

_output.WriteInfo(string.Format("Deleting file {0} in space {1}...", parameters.Target, parameters.Space ?? "Default"));
await _apiClient.DeleteFileAsync(parameters.Space, parameters.Target, null, _cancellationTokenSource.Token);
_output.WriteInfo("Operation completed");
using (var apiSession = await OpenSession(parameters))
{
_output.WriteInfo(string.Format("Deleting file {0} in space {1}...", parameters.Target, apiSession.SpaceName));
await _apiClient.DeleteFileAsync(apiSession, parameters.Target, null, _cancellationTokenSource.Token);
_output.WriteInfo("Operation completed");
}

}
}
Expand Down
Loading