private static void OutputGenerateLog(bool result, string csFilePath, ProcessExecute processExecute) { using (new DisableStackTraceScope()) { var logBuilder = new StringBuilder(); logBuilder.AppendLine(); logBuilder.AppendLine(); logBuilder.AppendFormat("MessagePack file : {0}", csFilePath).AppendLine(); logBuilder.AppendLine(); logBuilder.AppendFormat("Execute:").AppendLine(); logBuilder.AppendLine($"{processExecute.Command} {processExecute.Arguments}"); if (result) { logBuilder.Insert(0, "MessagePack code generate success!"); Debug.Log(logBuilder.ToString()); } else { logBuilder.Insert(0, "MessagePack code generate failed."); Debug.LogError(logBuilder.ToString()); } } }
private static async Task <Tuple <int, string> > ExecuteProcess(TextDataConfig.GenerateAssetSetting setting, Mode mode, bool displayConsole) { var config = TextDataConfig.Instance; var arguments = new StringBuilder(); arguments.AppendFormat("--workspace {0} ", setting.GetTextDataWorkspacePath()); switch (mode) { case Mode.Import: arguments.Append("--mode import "); break; case Mode.Export: arguments.Append("--mode export "); break; } var processExecute = new ProcessExecute(config.ConverterPath, arguments.ToString()) { Encoding = Encoding.GetEncoding("Shift_JIS"), WorkingDirectory = setting.GetTextDataWorkspacePath(), UseShellExecute = displayConsole, Hide = !displayConsole, }; var result = await processExecute.StartAsync(); return(Tuple.Create(result.ExitCode, result.Error)); }
public Execute() { FunctionsCollection f = new FunctionsCollection(); dayTimeFunc = new DayTimeFunc(); directoryFunc = new DirectoryFunc(); networkFunc = new NetworkFunc(); zipFunc = new ZipFunc(); processFunc = new ProcessExecute(); }
/// <summary> /// Получение стандартного вывода из программы /// </summary> private static List <string> GetOutput(ProcessExecute prog) { var output = new List <string>(); using var fs = prog.Output; while (!fs.EndOfStream) { var line = fs.ReadLine()?.Split(' ').SelectMany(elem => elem.Split()).Where(elem => elem != String.Empty); output.AddRange(line); } return(output); }
private IEnumerator FindDotnet() { if (isDotnetInstalled) { yield break; } dotnetVersion = string.Empty; var processTitle = "MessagePackConfig"; var processMessage = "Find .NET Core SDK"; EditorUtility.DisplayProgressBar(processTitle, processMessage, 0f); Tuple <bool, string> result = null; var commandLineProcess = new ProcessExecute("dotnet", "--version"); var findYield = commandLineProcess.StartAsync().ToObservable() .Do(x => result = Tuple.Create(true, x.Output)) .DoOnError(x => result = Tuple.Create(false, (string)null)) .Select(_ => result) .ToYieldInstruction(); while (!findYield.IsDone) { yield return(null); } if (findYield.HasResult) { dotnetVersion = findYield.Result.Item2; isDotnetInstalled = findYield.Result.Item1 && !string.IsNullOrEmpty(dotnetVersion); } if (string.IsNullOrEmpty(dotnetVersion)) { Debug.LogError("Failed get .NET Core SDK version."); } EditorUtility.DisplayProgressBar(processTitle, processMessage, 1f); Repaint(); EditorApplication.delayCall += EditorUtility.ClearProgressBar; }
private static ProcessExecute CreateMpcProcess(MessagePackCodeGenerateInfo generateInfo) { var messagePackConfig = MessagePackConfig.Instance; var mpc = messagePackConfig.MpcRelativePath; if (string.IsNullOrEmpty(mpc)) { mpc = "mpc"; } var processExecute = new ProcessExecute(mpc, generateInfo.MpcArgument) { Encoding = Encoding.GetEncoding("Shift_JIS"), }; return(processExecute); }
public static async Task <string> GetCommitHash() { var masterConfig = MasterConfig.Instance; if (string.IsNullOrEmpty(masterConfig.SourceDirectory)) { return(null); } var processExecute = new ProcessExecute("git", "log --pretty=%H -n 1") { WorkingDirectory = masterConfig.SourceDirectory, }; var result = await processExecute.StartAsync(); if (string.IsNullOrEmpty(result.Output)) { return(null); } // 改行コードを削除. return(result.Output.Replace("\r", "").Replace("\n", "")); }
void Initialize() { this.ProcExec = new ProcessExecute(); this.ProcExec.OutputData += ProcExec_OutputData; }
public override void DiscoverTests( IEnumerable <string> sources, PythonProjectSettings settings, IMessageLogger logger, ITestCaseDiscoverySink discoverySink ) { if (sources is null) { throw new ArgumentNullException(nameof(sources)); } if (discoverySink is null) { throw new ArgumentNullException(nameof(discoverySink)); } _logger = logger ?? throw new ArgumentNullException(nameof(logger)); var workspaceText = settings.IsWorkspace ? Strings.WorkspaceText : Strings.ProjectText; LogInfo(Strings.PythonTestDiscovererStartedMessage.FormatUI(PythonConstants.PytestText, settings.ProjectName, workspaceText, settings.DiscoveryWaitTimeInSeconds)); var env = InitializeEnvironment(sources, settings); var outputFilePath = Path.GetTempFileName(); var arguments = GetArguments(sources, settings, outputFilePath); LogInfo("cd " + settings.WorkingDirectory); LogInfo("set " + settings.PathEnv + "=" + env[settings.PathEnv]); LogInfo($"{settings.InterpreterPath} {string.Join(" ", arguments)}"); try { var stdout = ProcessExecute.RunWithTimeout( settings.InterpreterPath, env, arguments, settings.WorkingDirectory, settings.PathEnv, settings.DiscoveryWaitTimeInSeconds ); if (!String.IsNullOrEmpty(stdout)) { Error(stdout); } } catch (TimeoutException) { Error(Strings.PythonTestDiscovererTimeoutErrorMessage); return; } if (!File.Exists(outputFilePath)) { Error(Strings.PythonDiscoveryResultsNotFound.FormatUI(outputFilePath)); return; } string json = File.ReadAllText(outputFilePath); if (string.IsNullOrEmpty(json)) { return; } try { var results = JsonConvert.DeserializeObject <List <PytestDiscoveryResults> >(json); var testcases = ParseDiscoveryResults(results, settings.ProjectHome); foreach (var tc in testcases) { // Note: Test Explorer will show a key not found exception if we use a source path that doesn't match a test container's source. if (settings.TestContainerSources.TryGetValue(tc.CodeFilePath, out _)) { discoverySink.SendTestCase(tc); } } } catch (InvalidOperationException ex) { Error("Failed to parse: {0}".FormatInvariant(ex.Message)); Error(json); } catch (JsonException ex) { Error("Failed to parse: {0}".FormatInvariant(ex.Message)); Error(json); } }
public void DiscoverTests( IEnumerable <string> sources, IMessageLogger logger, ITestCaseDiscoverySink discoverySink ) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); var workspaceText = _settings.IsWorkspace ? Strings.WorkspaceText : Strings.ProjectText; LogInfo(Strings.PythonTestDiscovererStartedMessage.FormatUI(PythonConstants.PytestText, _settings.ProjectName, workspaceText, _settings.DiscoveryWaitTimeInSeconds)); var env = InitializeEnvironment(sources, _settings); var outputFilePath = Path.GetTempFileName(); var arguments = GetArguments(sources, _settings, outputFilePath); LogInfo("cd " + _settings.WorkingDirectory); LogInfo("set " + _settings.PathEnv + "=" + env[_settings.PathEnv]); LogInfo($"{_settings.InterpreterPath} {string.Join(" ", arguments)}"); try { var stdout = ProcessExecute.RunWithTimeout( _settings.InterpreterPath, env, arguments, _settings.WorkingDirectory, _settings.PathEnv, _settings.DiscoveryWaitTimeInSeconds ); if (!String.IsNullOrEmpty(stdout)) { Error(stdout); } } catch (TimeoutException) { Error(Strings.PythonTestDiscovererTimeoutErrorMessage); return; } if (!File.Exists(outputFilePath)) { Error(Strings.PythonDiscoveryResultsNotFound.FormatUI(outputFilePath)); return; } string json = File.ReadAllText(outputFilePath); if (string.IsNullOrEmpty(json)) { return; } List <PytestDiscoveryResults> results = null; try { results = JsonConvert.DeserializeObject <List <PytestDiscoveryResults> >(json); CreateVsTests(results, discoverySink); } catch (InvalidOperationException ex) { Error("Failed to parse: {0}".FormatInvariant(ex.Message)); Error(json); } catch (JsonException ex) { Error("Failed to parse: {0}".FormatInvariant(ex.Message)); Error(json); } }