fly пре 1 година
родитељ
комит
05a0609c28

+ 9 - 6
Tools/Flyinsono.Deployment/lib/PublishView.dart

@@ -82,10 +82,8 @@ class _PublishViewState extends State<PublishView> {
       final packages = await service.getListAsync(0);
       setState(() {
         _packages = packages
-            .where((p) =>
-                p.packageLogs
-                    ?.contains("Packaging Successful") ??
-                false)
+            .where(
+                (p) => p.packageLogs?.contains("Packaging Successful") ?? false)
             .toList();
         _packageVersions = _packages.map((e) => e.version).toList();
       });
@@ -629,7 +627,10 @@ class _DeploymentLogDialogState extends State<_DeploymentLogDialog> {
       final logs = await service.getPublishPackageLogsAsync(widget._ip);
       setState(() {
         _logs = logs;
-        if (_logs.isNotEmpty && _logs.last.contains('publish completed')) {
+        if (_logs.isNotEmpty && _logs.last.contains('not on line')) {
+          _stopTimer();
+        } else if (_logs.isNotEmpty &&
+            _logs.last.contains('publish completed')) {
           _stopTimer();
           //记录日志
           service.saveLogsAsync(widget._id, logs);
@@ -711,7 +712,9 @@ class _HistoryDeploymentLogDialogState
       await Future.delayed(Duration(seconds: 5));
       var service = GetIt.instance.get<PublishService>();
       final newLogs = await service.getLogsAsync(widget.id, widget.ip);
-      if (newLogs.isNotEmpty && !_logs.contains(newLogs.last)) {
+      if (newLogs.isNotEmpty && newLogs.last.contains('not on line')) {
+        setState(() => _isCompleted = true);
+      } else if (newLogs.isNotEmpty && !_logs.contains(newLogs.last)) {
         setState(
             () => _logs.addAll(newLogs.where((log) => !_logs.contains(log))));
         _scrollToBottom();

+ 81 - 39
Tools/Flyinsono.Deployment/lib/Services/PublishService.dart

@@ -865,6 +865,7 @@ class PublishService {
       return deployIsOnline;
     } catch (e) {
       print('get remote statues error: $e');
+      Logger.warning('get remote statues error: $e');
       return false;
     }
   }
@@ -877,78 +878,119 @@ class PublishService {
       var serverIsOnline = result.code == 0;
       return serverIsOnline;
     } catch (e) {
-      print('get remote statues error: $e');
+      print('get server statues error: $e');
+      Logger.warning('get server statues error: $e');
       return false;
     }
   }
 
   //关闭
   Future remoteStopServer(String ip) async {
-    final rpc = JsonRpcProxy(host: ip + ":8305");
-    await rpc.deployPlatform.stopServer();
+    try {
+      final rpc = JsonRpcProxy(host: ip + ":8305");
+      await rpc.deployPlatform.stopServer();
+    } catch (e) {
+      Logger.error(e);
+      print('remoteStopServer error: $e');
+      Logger.warning('remoteStopServer error: $e');
+    }
   }
 
   //启动
   Future remoteStartServer(String ip) async {
-    final rpc = JsonRpcProxy(host: ip + ":8305");
-    await rpc.deployPlatform.start();
+    try {
+      final rpc = JsonRpcProxy(host: ip + ":8305");
+      await rpc.deployPlatform.start();
+    } catch (e) {
+      print('remoteStartServer error: $e');
+      Logger.warning('remoteStartServer error: $e');
+    }
   }
 
   //一键部署
   Future remoteDeploy(String ip, String recordId) async {
-    var recordDetal = await new PackageService().getDetailAsync(recordId);
-    var rpc = JsonRpcProxy(host: ip + ":8305");
-    var request = DeployRequest();
-    request.isUpgradeServer = recordDetal.isServerSelected!;
-
-    var packageLogs = recordDetal.PackageLogs ?? [];
-    if (request.isUpgradeServer) {
-      String? serverZipUrl;
-      for (String str in packageLogs.where((s) =>
-          s.contains('Upload Successful') && s.contains('Flyinsono_Server'))) {
-        final match = RegExp(
-                r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
-            .firstMatch(str);
-        if (match != null) {
-          serverZipUrl = match.group(0);
-          break;
+    try {
+      var recordDetal = await new PackageService().getDetailAsync(recordId);
+      var rpc = JsonRpcProxy(host: ip + ":8305");
+      var request = DeployRequest();
+      request.isUpgradeServer = recordDetal.isServerSelected!;
+
+      var packageLogs = recordDetal.PackageLogs ?? [];
+      if (request.isUpgradeServer) {
+        String? serverZipUrl;
+        for (String str in packageLogs.where((s) =>
+            s.contains('Upload Successful') &&
+            s.contains('Flyinsono_Server'))) {
+          final match = RegExp(
+                  r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
+              .firstMatch(str);
+          if (match != null) {
+            serverZipUrl = match.group(0);
+            break;
+          }
         }
+        request.serverZipUrl = serverZipUrl;
       }
-      request.serverZipUrl = serverZipUrl;
+      request.upgradeSettings =
+          packageLogs.firstWhere((s) => s.contains('"Description":')).trim();
+      await rpc.deployPlatform.deployAsync(request);
+    } catch (e) {
+      print('remoteDeploy error: $e');
+      Logger.warning('remoteDeploy error: $e');
     }
-    request.upgradeSettings =
-        packageLogs.firstWhere((s) => s.contains('"Description":')).trim();
-    await rpc.deployPlatform.deployAsync(request);
   }
 
   //获取远程配置
   Future<String> readAppSettingsJsonAsync(String ip) async {
-    final rpc = JsonRpcProxy(host: ip + ":8305");
-    var rpcResult = await rpc.deployPlatform.readAppSettingsJsonAsync();
-    return rpcResult;
+    try {
+      final rpc = JsonRpcProxy(host: ip + ":8305");
+      var rpcResult = await rpc.deployPlatform.readAppSettingsJsonAsync();
+      return rpcResult;
+    } catch (e) {
+      print('readAppSettingsJsonAsync error: $e');
+      Logger.warning('readAppSettingsJsonAsync error: $e');
+      return "";
+    }
   }
 
   //修改远程配置
   Future modifyAppSettingsJsonAsync(String ip, String json) async {
-    final rpc = JsonRpcProxy(host: ip + ":8305");
-    await rpc.deployPlatform.modifyAppSettingsJsonAsync(
-        new ModifyAppSettingsJsonRequest(json: json));
+    try {
+      final rpc = JsonRpcProxy(host: ip + ":8305");
+      await rpc.deployPlatform.modifyAppSettingsJsonAsync(
+          new ModifyAppSettingsJsonRequest(json: json));
+    } catch (e) {
+      print('modifyAppSettingsJsonAsync error: $e');
+      Logger.warning('modifyAppSettingsJsonAsync error: $e');
+    }
   }
 
   //获取部署日志
   Future<List<String>> getPublishPackageLogsAsync(String ip) async {
-    final rpc = JsonRpcProxy(host: ip + ":8305");
-    var result = await rpc.deployPlatform.getPublishPackageLogsAsync();
-    return result;
+    try {
+      final rpc = JsonRpcProxy(host: ip + ":8305");
+      var result = await rpc.deployPlatform.getPublishPackageLogsAsync();
+      return result;
+    } catch (e) {
+      print('getPublishPackageLogsAsync error: $e');
+      Logger.warning('getPublishPackageLogsAsync error: $e');
+      return ["not on line"];
+    }
   }
 
   //保存部署日志
   Future<bool> saveLogsAsync(String id, List<String> logList) async {
-    var logs = json.encode(logList);
-    final rpc = GetIt.instance.get<JsonRpcProxy>();
-    var result = await rpc.deployPlatform
-        .saveLogsAsync(new SaveLogsRequest(id: id, logs: logs));
-    return result;
+    try {
+      var logs = json.encode(logList);
+      final rpc = GetIt.instance.get<JsonRpcProxy>();
+      var result = await rpc.deployPlatform
+          .saveLogsAsync(new SaveLogsRequest(id: id, logs: logs));
+      return result;
+    } catch (e) {
+      print('saveLogsAsync error: $e');
+      Logger.warning('saveLogsAsync error: $e');
+      return false;
+    }
   }
 
   //查询日志