JobOrder
using System;
using System.Collections.Generic;
namespace Aspera.Transfer
{
public class JobOrder
{
private FileLocation source;
private FileLocation destination;
private XferParams xferParams;
public JobOrder(FileLocation source, FileLocation destination, XferParams xferParams)
{
this.source = source;
this.destination = destination;
this.xferParams = xferParams;
validate();
}
public FileLocation getSource()
{
return source;
}
public FileLocation getDestination()
{
return destination;
}
public XferParams getXferParams()
{
return xferParams;
}
protected internal List<string> buildCommand(Guid xferId, int xferRetry = 0)
{
List<string> list = new List<string>();
list.Add("--mode");
RemoteFileLocation remoteFileLocation;
if (source is RemoteFileLocation) {
remoteFileLocation = (RemoteFileLocation)source;
list.Add("recv");
} else {
remoteFileLocation = (RemoteFileLocation)destination;
list.Add("send");
}
if (remoteFileLocation.IsHostIPv6())
list.Add("-6");
list.Add("-q");
list.AddRange(xferParams.buildCommand(isUpload(), xferId, xferRetry));
if (remoteFileLocation.IsPartialFileTransfer())
list.Add(remoteFileLocation.getRangeCmdString());
if (remoteFileLocation.getIdentity() != null) {
list.Add("-i");
list.Add(remoteFileLocation.getIdentity());
}
list.Add("--user");
list.Add(remoteFileLocation.getUser());
list.Add("--host");
list.Add(remoteFileLocation.getHost());
if (xferParams.persist)
list.Add("--keepalive");
string text = source.buildCommand();
if (text.Length > 0)
list.Add(text);
string text2 = xferParams.getDestinationRoot();
if (string.IsNullOrEmpty(text2) || text2.Trim().Length == 0)
text2 = XferParams.DEFAULT_DESTINATION_ROOT;
if (text2.Length == 0 && !string.IsNullOrEmpty(destination.getFirstPath()) && destination.getFirstPath().Trim().Length > 0)
text2 = destination.getFirstPath();
list.Add(text2);
return list;
}
public bool isUpload()
{
if (source is RemoteFileLocation && destination is LocalFileLocation)
return false;
return true;
}
private void validate()
{
string text = "";
if (xferParams == null) {
text = "XferParams must be non null";
throw new FaspManagerException("JobOrder validation failed: " + text);
}
xferParams.validate();
if (source == null || destination == null) {
text = "The source and destination must be non null";
throw new FaspManagerException("JobOrder validation failed: " + text);
}
if ((source is RemoteFileLocation && destination is RemoteFileLocation) || (source is LocalFileLocation && destination is LocalFileLocation)) {
text = "One of the source and destination must be local and the other remote";
throw new FaspManagerException("JobOrder validation failed: " + text);
}
if (xferParams.persist && (source.getFirstPath().Length > 0 || destination.getPaths().Count > 0))
throw new FaspManagerException("When starting a persistent transfer do not specify any paths on the source/destination object");
if (!xferParams.persist && source.getFirstPath().Length <= 0)
throw new FaspManagerException("There must be at least one source path or source/destination pair.");
}
}
}