2016-08-06 19:56:32 -07:00
|
|
|
|
define(['serversync'], function (ServerSync) {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
function syncNext(connectionManager, servers, index, options, resolve, reject) {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
var length = servers.length;
|
2015-09-09 20:22:52 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
if (index >= length) {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-27 08:00:57 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
var server = servers[index];
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
console.log("Creating ServerSync to server: " + server.Id);
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
new ServerSync(connectionManager).sync(server, options).then(function () {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
syncNext(connectionManager, servers, index + 1, options, resolve, reject);
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
}, function () {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
syncNext(connectionManager, servers, index + 1, options, resolve, reject);
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
return function (connectionManager) {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
var self = this;
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
self.sync = function (options) {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
return new Promise(function (resolve, reject) {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
var servers = connectionManager.getSavedServers();
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2016-08-06 19:56:32 -07:00
|
|
|
|
syncNext(connectionManager, servers, 0, options, resolve, reject);
|
2015-09-09 10:49:44 -07:00
|
|
|
|
});
|
2016-08-06 19:56:32 -07:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|