Dalibor Votruba 4 سال پیش
والد
کامیت
da13c2ca20
1فایلهای تغییر یافته به همراه21 افزوده شده و 9 حذف شده
  1. 21 9
      ProcessServer/Business/Workers/SingleDocumentCalculationWorker.cs

+ 21 - 9
ProcessServer/Business/Workers/SingleDocumentCalculationWorker.cs

@@ -49,6 +49,10 @@ namespace BO.ProcessServer.Business.Workers
             Status = ServerProcessStateEnum.Running;
             Started = DateTime.Now;
 
+            var processName = string.Empty;
+            var processId = 0;
+
+
             // get document metadata
             var document = await ctx.Connection.GetDocumentInfoAsync(ctx.DocumentId);
             
@@ -66,9 +70,9 @@ namespace BO.ProcessServer.Business.Workers
             {
                 // scenario exists
                 var processInfo = new ProcessStartInfo();
-                processInfo.FileName = scenario.ShellCommand;
                 processInfo.WindowStyle = scenario.RunWindowsStyle;
-                processInfo.WorkingDirectory = ctx.Configuration.System.ScenarioPathBase;
+                processInfo.WorkingDirectory = TranslatePath(ctx.Configuration.System.ScenarioPathBase);
+                processInfo.FileName = _fileSystem.Path.Combine(processInfo.WorkingDirectory, scenario.ShellCommand);
                 processInfo.Arguments = TranslateArguments(scenario.ShellCommandArguments, ctx.InputFiles,
                     document.PresetProcessProfile, document.PresetQuality, document.PresetWatermark,
                     document.PresetTest);
@@ -78,10 +82,12 @@ namespace BO.ProcessServer.Business.Workers
 
                 using (ctx.Process = Process.Start(processInfo))
                 {
-                    var errors = await ctx.Process.StandardError.ReadToEndAsync();
-                    var outputs = await ctx.Process.StandardOutput.ReadToEndAsync();
+                    processName = "process";
+                    processId = ctx.Process?.Id ?? 0;
+                    var errors = await ctx.Process?.StandardError?.ReadToEndAsync();
+                    var outputs = await ctx.Process?.StandardOutput?.ReadToEndAsync();
                     Log(LogSeverityEnum.Info,
-                        $"Starting process '{Name}.{ctx.Process?.ProcessName}' [Id:{ctx.Process?.Id}]: {ShellCommand}");
+                        $"Starting process '{Name}.{processName}' [Id:{processId}]: {ShellCommand}");
                     if (ctx.Process != null)
                     {
                         ctx.Process.WaitForExit();
@@ -91,7 +97,7 @@ namespace BO.ProcessServer.Business.Workers
                             Log(LogSeverityEnum.Info, outputs);
 
                         Log(LogSeverityEnum.Info,
-                            $"End process '{Name}.{ctx.Process?.ProcessName}' [Id:{ctx.Process?.Id}]: Exit code {ctx.Process.ExitCode}");
+                            $"End process '{Name}.{processName}' [Id:{processId}]: Exit code {ctx.Process.ExitCode}");
 
                         if (ctx.Process.ExitCode == scenario.ExitCodeSucc)
                         {
@@ -105,7 +111,7 @@ namespace BO.ProcessServer.Business.Workers
                         else
                         {
                             Log(LogSeverityEnum.Warn,
-                                $"Process '{Name}.{ctx.Process?.ProcessName}' has unhandled exitcode {ctx.Process.ExitCode}! Goes to fail.");
+                                $"Process '{Name}.{processName}' has unhandled exitcode {ctx.Process.ExitCode}! Goes to fail.");
                             Status = ServerProcessStateEnum.FailInternal;
                         }
                     }
@@ -127,7 +133,7 @@ namespace BO.ProcessServer.Business.Workers
                         await ctx.Connection.SetDocumentContentAsync(document.Id,
                             _fileSystem.Path.GetFileNameWithoutExtension(file),
                             MimeTypeUtil.GetMimeType(_fileSystem.Path.GetExtension(file)), false, fs);
-                        Log(LogSeverityEnum.Debug, $"Process '{Name}.{ctx.Process?.ProcessName}' file '{file}' uploaded.");
+                        Log(LogSeverityEnum.Debug, $"Process '{Name}.{processName}' file '{file}' uploaded.");
                     }
                 }
                 await ctx.Connection.SetDocumentStateAsync(document.Id, DocumentStatusEnum.DoneOk);
@@ -138,7 +144,7 @@ namespace BO.ProcessServer.Business.Workers
             {
                 ctx.Pool.MoveDocumentFiles(Pool.PoolTypeEnum.Working, Pool.PoolTypeEnum.Fail, document.Id);
             }
-            Log(LogSeverityEnum.Info, $"Process '{Name}.{ctx.Process?.ProcessName}' resolution state is '{Status}'.");
+            Log(LogSeverityEnum.Info, $"Process '{Name}.{processName}' resolution state is '{Status}'.");
         }
 
         #endregion
@@ -173,6 +179,12 @@ namespace BO.ProcessServer.Business.Workers
             result = result.Replace(Constants.CS_TAG_P_OUT_EXT, Constants.CS_POOL_OUTFILE_EXT, StringComparison.OrdinalIgnoreCase);
             return result;
         }
+        private string TranslatePath(string path)
+        {
+            if (string.IsNullOrEmpty(path))
+                return path;
+            return path.Replace(Constants.CS_TAG_CURRENT_DIR, _fileSystem.Directory.GetCurrentDirectory());
+        }
         #endregion
     }
 }