}
}
}
ProfileManager profileManager = new ProfileManager(profilesFile);
final Synchronizer sync = new Synchronizer();
// Apply executing options
if (line.hasOption("r")) {
Profile p = profileManager.getProfile(line.getOptionValue("r"));
TaskTree tree = sync.executeProfile(p, false);
sync.performActions(tree);
p.setLastUpdate(new Date());
profileManager.save();
return;
}
boolean activateRemote = false;
int port = 10000;
String password = "admin";
RemoteException listenerStarupException = null;
if (line.hasOption("p")) {
activateRemote = true;
try {
String portStr = line.getOptionValue("p");
port = Integer.parseInt(portStr);
}
catch (NumberFormatException e) {
}
if (line.hasOption("a")) {
password = line.getOptionValue("a");
}
}
else {
activateRemote = preferences.listeningForRemoteConnections();
port = preferences.getRemoteConnectionsPort();
password = preferences.getRemoteConnectionsPassword();
}
if (activateRemote) {
try {
Logger logger = LoggerFactory.getLogger("FullSync");
RemoteController.getInstance().startServer(port, password, profileManager, sync);
logger.info("Remote Interface available on port: " + port);
}
catch (RemoteException e) {
ExceptionHandler.reportException(e);
listenerStarupException = e;
}
}
if (line.hasOption("d")) {
profileManager.addSchedulerListener(new ProfileSchedulerListener() {
@Override
public void profileExecutionScheduled(Profile profile) {
TaskTree tree = sync.executeProfile(profile, false);
if (tree == null) {
profile.setLastError(1, "An error occured while comparing filesystems.");
}
else {
int errorLevel = sync.performActions(tree);
if (errorLevel > 0) {
profile.setLastError(errorLevel, "An error occured while copying files.");
}
else {
profile.setLastUpdate(new Date());