Exemplo n.º 1
0
        private static RunResult RunProccess(RunParam param, List <string> messageBackToCaller, string errorCrumb)
        {
            errorCrumb += "|PubCode.ProcessMgr_v1.cs~RunProccess";
            var prmOutput = new RunResult();

            string OutputString;
            string ErrorString;
            int    ExitCode;

            try
            {
                var appArgs = param.AppArgs;
                if (appArgs == "\"\"")
                {
                    appArgs = "";
                }

                messageBackToCaller.Add($"### RunProcess ### {param.AppPath} {appArgs}");
                using (var myProcess = new System.Diagnostics.Process())
                {
                    ProcessStartInfo startInfo;
                    startInfo = new ProcessStartInfo()
                    {
                        FileName               = param.AppPath,
                        WindowStyle            = ProcessWindowStyle.Hidden,
                        Arguments              = appArgs,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true,
                        UseShellExecute        = false,
                        CreateNoWindow         = true
                    };
                    if (!string.IsNullOrWhiteSpace(param.WorkingDirectory))
                    {
                        startInfo.WorkingDirectory = param.WorkingDirectory;
                    }

                    myProcess.StartInfo = startInfo;
                    myProcess.Start();
                    OutputString = myProcess.StandardOutput.ReadToEnd();
                    ErrorString  = myProcess.StandardError.ReadToEnd();
                    myProcess.WaitForExit();
                    ExitCode = myProcess.ExitCode;
                    myProcess.Close();
                }

                prmOutput.OutputString = OutputString;
                prmOutput.ErrorString  = ErrorString;
                prmOutput.ExitCode     = ExitCode;
            }
            catch (Exception ex)
            {
                throw new Exception($"FAILURE/ERROR; ###errorCrumb:[[{errorCrumb}]]###; RunProccess(({param})", ex);
            }

            return(prmOutput);
        }
Exemplo n.º 2
0
 public static RunResult Run(RunParam param, List <string> messageBackToCaller, string errorCrumb = "")
 {
     if (Debugger.IsAttached && param == null)
     {
         Debugger.Break(); //MessageBox.Show("DEBUG!");
         return(null);
     }
     errorCrumb += "|PubCode.ProcessMgr_v1.cs~Run";
     ValidateParameters(param, errorCrumb);
     return(RunProccess(param, messageBackToCaller, errorCrumb));
 }
Exemplo n.º 3
0
 //Произвести расчет
 public void Calculate()
 {
     if (RunParam == null)
     {
         RunParam = new CalcParamRun(this, null, Owner == null ? Project.RootParam : Owner.RunParam, null);
     }
     if (ReceiverSignal != null)
     {
         ReceiverSignal.Value = RunParam.CalcValue.SingleValue;
     }
     RunParam.JoinArchiveParam(FullCode);
 }
Exemplo n.º 4
0
 private static void ValidateParameters(RunParam param, string errorCrumb)
 {
     errorCrumb += "|PubCode.ProcessMgr_v1.cs~ValidateParameters";
     if (param == null || string.IsNullOrWhiteSpace(param.AppPath))
     {
         var errTxt = $"FAILURE/ERROR; ###errorCrumb:[[{errorCrumb}]]###; AppPath is empty string. ValidateParameters({param})";
         if (Debugger.IsAttached)
         {
             Debugger.Break(); //MessageBox.Show("GO FIND IT; " + errTxt);
             return;
         }
         throw new Exception(errTxt);
     }
 }
Exemplo n.º 5
0
        public static RunResult Run(string paramJSON, List <string> messageBackToCaller, string errorCrumb = "")
        {
            if (Debugger.IsAttached && paramJSON == null)
            {
                Debugger.Break(); //MessageBox.Show("DEBUG!");
                return(null);
            }
            errorCrumb += "|PubCode.ProcessMgr_v1.cs~Run";
            RunParam param = null;

            if (paramJSON != null)
#if NETFRAMEWORK
            { param = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <ProcessMgr.RunParam>(paramJSON); }
#elif NET
            { param = System.Text.Json.JsonSerializer.Deserialize <ProcessMgr.RunParam>(paramJSON); }
#else
            { throw new NotImplementedException(); }
#endif
            return(Run(param, messageBackToCaller, errorCrumb));
        }