|
@@ -20,8 +20,32 @@ import 'PackageService.dart';
|
|
|
|
|
|
class PublishService {
|
|
|
String _deployInfo = "start...";
|
|
|
+
|
|
|
String _installDirectory = "";
|
|
|
+
|
|
|
String _ipAddress = "";
|
|
|
+ String _domain = "";
|
|
|
+
|
|
|
+ String _emailAccount = '';
|
|
|
+ String _emailPassword = '';
|
|
|
+ String _emailServer = '';
|
|
|
+ int _smtpPort = 0;
|
|
|
+ bool _enableSSL = false;
|
|
|
+
|
|
|
+ bool _isDistributed = false;
|
|
|
+ bool _isMasterServer = false;
|
|
|
+ String _masterServerAddress = "";
|
|
|
+ String _serverID = "";
|
|
|
+
|
|
|
+ bool _hasWingAIDiagnosisService = false;
|
|
|
+ bool _hasWingRtcService = false;
|
|
|
+ bool _hasWingLiveConsultationService = false;
|
|
|
+ bool _hasWingASRService = false;
|
|
|
+ bool _hasWingPaymentService = false;
|
|
|
+ bool _hasWingLabService = false;
|
|
|
+ bool _hasWingEducationService = false;
|
|
|
+
|
|
|
+ bool _isRemoteDeployable = false;
|
|
|
|
|
|
Future<String?> getLocalIPv4Address() async {
|
|
|
try {
|
|
@@ -45,9 +69,48 @@ class PublishService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- Future<bool> deployProcess(String installDirectory, String ipAddress) async {
|
|
|
+ Future<bool> deployProcess(
|
|
|
+ String installDirectory,
|
|
|
+ String ipAddress,
|
|
|
+ String domain,
|
|
|
+ String emailAccount,
|
|
|
+ String emailPassword,
|
|
|
+ String emailServer,
|
|
|
+ int smtpPort,
|
|
|
+ bool enableSSL,
|
|
|
+ bool isDistributed,
|
|
|
+ bool isMasterServer,
|
|
|
+ String masterServerAddress,
|
|
|
+ String serverID,
|
|
|
+ bool isRemoteDeployable,
|
|
|
+ bool hasWingAIDiagnosisService,
|
|
|
+ bool hasWingRtcService,
|
|
|
+ bool hasWingLiveConsultationService,
|
|
|
+ bool hasWingASRService,
|
|
|
+ bool hasWingPaymentService,
|
|
|
+ bool hasWingLabService,
|
|
|
+ bool hasWingEducationService) async {
|
|
|
_installDirectory = installDirectory;
|
|
|
_ipAddress = ipAddress;
|
|
|
+ _domain = domain;
|
|
|
+ _emailAccount = emailAccount;
|
|
|
+ _emailPassword = emailPassword;
|
|
|
+ _emailServer = emailServer;
|
|
|
+ _smtpPort = smtpPort;
|
|
|
+ _enableSSL = enableSSL;
|
|
|
+ _isDistributed = isDistributed;
|
|
|
+ _isMasterServer = isMasterServer;
|
|
|
+ _masterServerAddress = masterServerAddress;
|
|
|
+ _serverID = serverID;
|
|
|
+ _isRemoteDeployable = isRemoteDeployable;
|
|
|
+
|
|
|
+ _hasWingAIDiagnosisService = hasWingAIDiagnosisService;
|
|
|
+ _hasWingRtcService = hasWingRtcService;
|
|
|
+ _hasWingLiveConsultationService = hasWingLiveConsultationService;
|
|
|
+ _hasWingASRService = hasWingASRService;
|
|
|
+ _hasWingPaymentService = hasWingPaymentService;
|
|
|
+ _hasWingLabService = hasWingLabService;
|
|
|
+ _hasWingEducationService = hasWingEducationService;
|
|
|
var isNeedUpdateServer = false;
|
|
|
String basePath = getBasePath();
|
|
|
String deployPackageDir = '$basePath/DeployPackage';
|
|
@@ -76,7 +139,7 @@ class PublishService {
|
|
|
await copyWingServerContent();
|
|
|
|
|
|
_deployInfo = "try start server...";
|
|
|
- await runStartBat();
|
|
|
+ runStartBat();
|
|
|
await checkStartStatus();
|
|
|
_deployInfo = "upload files...";
|
|
|
|
|
@@ -85,13 +148,13 @@ class PublishService {
|
|
|
_deployInfo = "update config...";
|
|
|
await updateAppSettings(uploadResult);
|
|
|
await terminateWingCloudServer();
|
|
|
- await runStartBat();
|
|
|
+ runStartBat();
|
|
|
} else {
|
|
|
|
|
|
_deployInfo = "update config...";
|
|
|
await updateAppSettings(null);
|
|
|
await terminateWingCloudServer();
|
|
|
- await runStartBat();
|
|
|
+ runStartBat();
|
|
|
}
|
|
|
break;
|
|
|
} catch (e) {
|
|
@@ -241,18 +304,161 @@ class PublishService {
|
|
|
String oldJsonString = await oldAppSettingsFile.readAsString();
|
|
|
Map<String, dynamic> oldJsonMap = jsonDecode(oldJsonString);
|
|
|
|
|
|
-
|
|
|
- if (oldJsonMap.containsKey('Gateway')) {
|
|
|
- Map<String, dynamic> gatewayMap = oldJsonMap['Gateway'];
|
|
|
- if (gatewayMap.containsKey('Host')) {
|
|
|
- if (copyType == 1) {
|
|
|
+
|
|
|
+ if (copyType == 2) {
|
|
|
+ if (oldJsonMap.containsKey('Gateway')) {
|
|
|
+ Map<String, dynamic> gatewayMap = oldJsonMap['Gateway'];
|
|
|
+ if (gatewayMap.containsKey('Host')) {
|
|
|
+ gatewayMap['Host'] = "http://" + _ipAddress + ":8305/";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (copyType == 1) {
|
|
|
+ if (oldJsonMap.containsKey('Gateway')) {
|
|
|
+ Map<String, dynamic> gatewayMap = oldJsonMap['Gateway'];
|
|
|
+ if (gatewayMap.containsKey('Host')) {
|
|
|
gatewayMap['Host'] =
|
|
|
"http://" + _ipAddress + ":8303/";
|
|
|
- } else {
|
|
|
- gatewayMap['Host'] = "http://" + _ipAddress + ":8305/";
|
|
|
}
|
|
|
+ if (gatewayMap.containsKey('Domains')) {
|
|
|
+ gatewayMap['Domains'] =
|
|
|
+ _domain == "" ? gatewayMap['Host'] : _domain;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (oldJsonMap.containsKey("General")) {
|
|
|
+ Map<String, dynamic> generalMap = oldJsonMap['General'];
|
|
|
+ if (generalMap.containsKey('IsDistributed')) {
|
|
|
+ generalMap['IsDistributed'] = _isDistributed;
|
|
|
+ }
|
|
|
+ if (generalMap.containsKey('IsMaster')) {
|
|
|
+ generalMap['IsMaster'] = _isMasterServer;
|
|
|
+ }
|
|
|
+ if (generalMap.containsKey('MasterUrl') &&
|
|
|
+ _masterServerAddress != "") {
|
|
|
+ generalMap['MasterUrl'] = _masterServerAddress;
|
|
|
+ }
|
|
|
+ if (generalMap.containsKey('ServerID') && _serverID != "") {
|
|
|
+ generalMap['ServerID'] = _serverID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (oldJsonMap.containsKey("Email")) {
|
|
|
+ Map<String, dynamic> emailMap = oldJsonMap['Email'];
|
|
|
+ if (emailMap.containsKey('EmailUserName') &&
|
|
|
+ _emailAccount != "") {
|
|
|
+ emailMap['EmailUserName'] = _emailAccount;
|
|
|
+ }
|
|
|
+ if (emailMap.containsKey('EmailUserPassword') &&
|
|
|
+ _emailPassword != "") {
|
|
|
+ emailMap['EmailUserPassword'] = _emailPassword;
|
|
|
+ }
|
|
|
+ if (emailMap.containsKey('MailHost') && _emailServer != "") {
|
|
|
+ emailMap['MailHost'] = _emailServer;
|
|
|
+ }
|
|
|
+ if (emailMap.containsKey('SmtpPort') && _smtpPort != "") {
|
|
|
+ emailMap['SmtpPort'] = _smtpPort;
|
|
|
+ }
|
|
|
+ if (emailMap.containsKey('UseSSL')) {
|
|
|
+ emailMap['UseSSL'] = _enableSSL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (oldJsonMap.containsKey("Services")) {
|
|
|
+ Map<String, dynamic> servicesMap = oldJsonMap['Services'];
|
|
|
+ var inProcess = servicesMap["InProcess"].toString();
|
|
|
+ var jsonRpcHttp = servicesMap["JsonRpcHttp"].toString();
|
|
|
+ var remote = servicesMap["Remote"].toString();
|
|
|
+ if (_hasWingAIDiagnosisService == false) {
|
|
|
+ inProcess = inProcess
|
|
|
+ .replaceAll("WingAIDiagnosisService,", "")
|
|
|
+ .replaceAll("WingAIDiagnosisService", "");
|
|
|
+ jsonRpcHttp = jsonRpcHttp
|
|
|
+ .replaceAll("WingAIDiagnosisService,", "")
|
|
|
+ .replaceAll("WingAIDiagnosisService", "");
|
|
|
+ remote = remote
|
|
|
+ .replaceAll("WingAIDiagnosisService,", "")
|
|
|
+ .replaceAll("WingAIDiagnosisService", "");
|
|
|
+ }
|
|
|
+ if (_hasWingRtcService == false) {
|
|
|
+ inProcess = inProcess
|
|
|
+ .replaceAll("WingRtcService,", "")
|
|
|
+ .replaceAll("WingRtcService", "");
|
|
|
+ jsonRpcHttp = jsonRpcHttp
|
|
|
+ .replaceAll("WingRtcService,", "")
|
|
|
+ .replaceAll("WingRtcService", "");
|
|
|
+ remote = remote
|
|
|
+ .replaceAll("WingRtcService,", "")
|
|
|
+ .replaceAll("WingRtcService", "");
|
|
|
+ }
|
|
|
+ if (_hasWingLiveConsultationService == false) {
|
|
|
+ inProcess = inProcess
|
|
|
+ .replaceAll("WingLiveConsultationService,", "")
|
|
|
+ .replaceAll("WingLiveConsultationService", "");
|
|
|
+ jsonRpcHttp = jsonRpcHttp
|
|
|
+ .replaceAll("WingLiveConsultationService,", "")
|
|
|
+ .replaceAll("WingLiveConsultationService", "");
|
|
|
+ remote = remote
|
|
|
+ .replaceAll("WingLiveConsultationService,", "")
|
|
|
+ .replaceAll("WingLiveConsultationService", "");
|
|
|
+ }
|
|
|
+ if (_hasWingASRService == false) {
|
|
|
+ inProcess = inProcess
|
|
|
+ .replaceAll("WingASRService,", "")
|
|
|
+ .replaceAll("WingASRService", "");
|
|
|
+ jsonRpcHttp = jsonRpcHttp
|
|
|
+ .replaceAll("WingASRService,", "")
|
|
|
+ .replaceAll("WingASRService", "");
|
|
|
+ remote = remote
|
|
|
+ .replaceAll("WingASRService,", "")
|
|
|
+ .replaceAll("WingASRService", "");
|
|
|
+ }
|
|
|
+ if (_hasWingPaymentService == false) {
|
|
|
+ inProcess = inProcess
|
|
|
+ .replaceAll("WingPaymentService,", "")
|
|
|
+ .replaceAll("WingPaymentService", "");
|
|
|
+ jsonRpcHttp = jsonRpcHttp
|
|
|
+ .replaceAll("WingPaymentService,", "")
|
|
|
+ .replaceAll("WingPaymentService", "");
|
|
|
+ remote = remote
|
|
|
+ .replaceAll("WingPaymentService,", "")
|
|
|
+ .replaceAll("WingPaymentService", "");
|
|
|
+ }
|
|
|
+ if (_hasWingLabService == false) {
|
|
|
+ inProcess = inProcess
|
|
|
+ .replaceAll("WingLabService,", "")
|
|
|
+ .replaceAll("WingLabService", "");
|
|
|
+ jsonRpcHttp = jsonRpcHttp
|
|
|
+ .replaceAll("WingLabService,", "")
|
|
|
+ .replaceAll("WingLabService", "");
|
|
|
+ remote = remote
|
|
|
+ .replaceAll("WingLabService,", "")
|
|
|
+ .replaceAll("WingLabService", "");
|
|
|
+ }
|
|
|
+ if (_hasWingEducationService == false) {
|
|
|
+ inProcess = inProcess
|
|
|
+ .replaceAll("WingEducationService,", "")
|
|
|
+ .replaceAll("WingEducationService", "");
|
|
|
+ jsonRpcHttp = jsonRpcHttp
|
|
|
+ .replaceAll("WingEducationService,", "")
|
|
|
+ .replaceAll("WingEducationService", "");
|
|
|
+ remote = remote
|
|
|
+ .replaceAll("WingEducationService,", "")
|
|
|
+ .replaceAll("WingEducationService", "");
|
|
|
+ }
|
|
|
+ if (inProcess.endsWith(',')) {
|
|
|
+ inProcess = inProcess.substring(0, inProcess.length - 1);
|
|
|
+ }
|
|
|
+ if (jsonRpcHttp.endsWith(',')) {
|
|
|
+ jsonRpcHttp = jsonRpcHttp.substring(0, jsonRpcHttp.length - 1);
|
|
|
+ }
|
|
|
+ if (remote.endsWith(',')) {
|
|
|
+ remote = remote.substring(0, remote.length - 1);
|
|
|
+ }
|
|
|
+ servicesMap["InProcess"] = inProcess;
|
|
|
+ servicesMap["JsonRpcHttp"] = jsonRpcHttp;
|
|
|
+ servicesMap["Remote"] = remote;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
|
|
|
String updatedJsonString = jsonEncode(oldJsonMap);
|
|
|
await oldAppSettingsFile.writeAsString(updatedJsonString);
|
|
@@ -264,11 +470,14 @@ class PublishService {
|
|
|
|
|
|
Future<void> runStartBat() async {
|
|
|
Logger.info("runStartBat start");
|
|
|
- String parentDir = path.dirname(_installDirectory);
|
|
|
- File deployServerStartBat = File('$parentDir/DeployServer/start.bat');
|
|
|
- if (await deployServerStartBat.exists()) {
|
|
|
- await Process.start(deployServerStartBat.path, [],
|
|
|
- workingDirectory: _installDirectory, runInShell: true);
|
|
|
+
|
|
|
+ if (_isRemoteDeployable) {
|
|
|
+ String parentDir = path.dirname(_installDirectory);
|
|
|
+ File deployServerStartBat = File('$parentDir/DeployServer/start.bat');
|
|
|
+ if (await deployServerStartBat.exists()) {
|
|
|
+ await Process.start(deployServerStartBat.path, [],
|
|
|
+ workingDirectory: _installDirectory, runInShell: true);
|
|
|
+ }
|
|
|
}
|
|
|
File startBat = File('${_installDirectory}/start.bat');
|
|
|
|
|
@@ -290,9 +499,10 @@ class PublishService {
|
|
|
|
|
|
|
|
|
Future<void> checkStartStatus() async {
|
|
|
+ Logger.info("checkStartStatus start");
|
|
|
var num = 0;
|
|
|
var result = false;
|
|
|
- while (!result && num < 10) {
|
|
|
+ while (!result && num < 6) {
|
|
|
try {
|
|
|
await Future.delayed(Duration(seconds: 5));
|
|
|
result = await getServerStateAsync(_ipAddress);
|
|
@@ -300,6 +510,10 @@ class PublishService {
|
|
|
Logger.info("server start success");
|
|
|
print("server start success");
|
|
|
break;
|
|
|
+ } else {
|
|
|
+ Logger.warning("erver not start yet ");
|
|
|
+ print("erver not start yet ");
|
|
|
+ num++;
|
|
|
}
|
|
|
} catch (e) {
|
|
|
Logger.info("server not start yet");
|
|
@@ -307,6 +521,9 @@ class PublishService {
|
|
|
num++;
|
|
|
}
|
|
|
}
|
|
|
+ if (num >= 6) {
|
|
|
+ throw Exception("start server error");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -737,24 +954,27 @@ class PublishService {
|
|
|
|
|
|
Future<List<String>> getLogsAsync(String id, String ip) async {
|
|
|
List<String> logs = [];
|
|
|
- logs = await getPublishPackageLogsAsync(ip);
|
|
|
- final rpc = GetIt.instance.get<JsonRpcProxy>();
|
|
|
- var result =
|
|
|
- await rpc.deployPlatform.getServerAsync(new GetServerRequest(id: id));
|
|
|
- var detailLogs = result.logs ?? "";
|
|
|
- if (logs.length > 0) {
|
|
|
- if (!detailLogs.contains(logs.last) &&
|
|
|
- logs.last.contains('publish completed')) {
|
|
|
- saveLogsAsync(id, logs);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (detailLogs != '') {
|
|
|
- List<dynamic> jsonList = json.decode(detailLogs);
|
|
|
- List<String> stringList = jsonList.cast<String>();
|
|
|
- logs = stringList;
|
|
|
+ try {
|
|
|
+ logs = await getPublishPackageLogsAsync(ip);
|
|
|
+ final rpc = GetIt.instance.get<JsonRpcProxy>();
|
|
|
+ var result =
|
|
|
+ await rpc.deployPlatform.getServerAsync(new GetServerRequest(id: id));
|
|
|
+ var detailLogs = result.logs ?? "";
|
|
|
+ if (logs.length > 0) {
|
|
|
+ if (!detailLogs.contains(logs.last) &&
|
|
|
+ logs.last.contains('publish completed')) {
|
|
|
+ saveLogsAsync(id, logs);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (detailLogs != '') {
|
|
|
+ List<dynamic> jsonList = json.decode(detailLogs);
|
|
|
+ List<String> stringList = jsonList.cast<String>();
|
|
|
+ logs = stringList;
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (e) {
|
|
|
+ Logger.error(e);
|
|
|
}
|
|
|
-
|
|
|
return logs;
|
|
|
}
|
|
|
}
|