public void Compile(MainWindowViewModel vm, CompilationFileViewModel compilationFileViewModel) { string file = compilationFileViewModel.File; compilationFileViewModel.Messages.Clear(); Version ver; GetAndIncrementVersionFile(Path.GetDirectoryName(compilationFileViewModel.File), vm.IncrementVersion, out ver); string rewrittenFilePath = RewriteSourceFile(compilationFileViewModel.File, ver); try { using (var compiler = new Process()) { compiler.StartInfo.FileName = SettingsManager.CompilerLocation; compiler.StartInfo.Arguments = string.Format( "{0} -o=\"{1}\"", rewrittenFilePath, Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file))); compiler.StartInfo.UseShellExecute = false; compiler.StartInfo.RedirectStandardOutput = true; compiler.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; compiler.StartInfo.CreateNoWindow = true; compiler.EnableRaisingEvents = true; compiler.Start(); string output = compiler.StandardOutput.ReadToEnd(); if (File.Exists(rewrittenFilePath)) { File.Delete(rewrittenFilePath); } if (!string.IsNullOrWhiteSpace(output)) { foreach (CompilationMessage message in GetCompilationMessagesFromOutput(output.Split('\n'))) { compilationFileViewModel.Messages.Add(message); } } UpdateCompilationDataStatus(compilationFileViewModel); if (!compilationFileViewModel.Messages.Any(m => CompilationMessageHelper.IsLineError(m.Prefix)) && SettingsManager.ExecutePostBuildScripts) { RunPostBuildScript(Path.GetDirectoryName(file)); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private static void UpdateCompilationDataStatus(CompilationFileViewModel fileViewModel, bool isCompiling = false) { if (isCompiling) { fileViewModel.Result = CompilationResult.Compiling; fileViewModel.StatusIcon = "/Tsukuru;component/Resources/script_code.png"; return; } if (!fileViewModel.Messages.Any()) { fileViewModel.Result = CompilationResult.Unknown; fileViewModel.StatusIcon = "/Tsukuru;component/Resources/script_code.png"; return; } if (fileViewModel.Messages.Any(m => CompilationMessageHelper.IsLineError(m.Prefix))) { fileViewModel.Result = CompilationResult.FailedWithErrors; fileViewModel.StatusIcon = "/Tsukuru;component/Resources/cross.png"; } else if (fileViewModel.Messages.Any(m => CompilationMessageHelper.IsLineWarning(m.Prefix))) { fileViewModel.Result = CompilationResult.CompletedWithWarnings; fileViewModel.StatusIcon = "/Tsukuru;component/Resources/error.png"; } else { fileViewModel.Result = CompilationResult.Completed; fileViewModel.StatusIcon = "/Tsukuru;component/Resources/tick.png"; } }