public static string GetHXMLData(OpenFLProject project, OpenFLProjectConfiguration configuration)
        {
            ProcessStartInfo info = new ProcessStartInfo();

            info.FileName               = "haxelib";
            info.Arguments              = "run openfl update \"" + project.TargetProjectXMLFile + "\" " + configuration.Platform.ToLower() + " " + project.AdditionalArguments + " " + configuration.AdditionalArguments;
            info.UseShellExecute        = false;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError  = true;
            info.WorkingDirectory       = project.BaseDirectory;
            //info.WindowStyle = ProcessWindowStyle.Hidden;
            info.CreateNoWindow = true;

            using (Process process = Process.Start(info))
            {
                process.WaitForExit();
            }

            info.Arguments = "run openfl display \"" + project.TargetProjectXMLFile + "\" " + configuration.Platform.ToLower() + " " + project.AdditionalArguments + " " + configuration.AdditionalArguments;

            using (Process process = Process.Start(info))
            {
                string data = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                return(data.Replace(Environment.NewLine, " "));
            }
        }
        public static bool CanRun(OpenFLProject project, OpenFLProjectConfiguration configuration, ExecutionContext context)
        {
            ExecutionCommand cmd = CreateExecutionCommand(project, configuration);

            if (cmd == null)
            {
                return(false);
            }
            return(context.ExecutionHandler.CanExecute(cmd));
        }
        public static BuildResult Compile(OpenFLProject project, OpenFLProjectConfiguration configuration, IProgressMonitor monitor)
        {
            string args = "run openfl build \"" + project.TargetProjectXMLFile + "\" " + configuration.Platform.ToLower();

            if (configuration.DebugMode)
            {
                args += " -debug";
            }

            if (project.AdditionalArguments != "")
            {
                args += " " + project.AdditionalArguments;
            }

            if (configuration.AdditionalArguments != "")
            {
                args += " " + configuration.AdditionalArguments;
            }

            string error    = "";
            int    exitCode = DoCompilation("haxelib", args, project.BaseDirectory, monitor, ref error);

            BuildResult result = ParseOutput(project, error);

            if (result.CompilerOutput.Trim().Length != 0)
            {
                monitor.Log.WriteLine(result.CompilerOutput);
            }

            if (result.ErrorCount == 0 && exitCode != 0)
            {
                string errorMessage = File.ReadAllText(error);
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    result.AddError(errorMessage);
                }
                else
                {
                    result.AddError("Build failed. Go to \"Build Output\" for more information");
                }
            }

            FileService.DeleteFile(error);
            return(result);
        }
        public static void Clean(OpenFLProject project, OpenFLProjectConfiguration configuration, IProgressMonitor monitor)
        {
            ProcessStartInfo info = new ProcessStartInfo();

            info.FileName               = "haxelib";
            info.Arguments              = "run openfl clean \"" + project.TargetProjectXMLFile + "\" " + configuration.Platform.ToLower() + " " + project.AdditionalArguments + " " + configuration.AdditionalArguments;
            info.UseShellExecute        = false;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError  = true;
            info.WorkingDirectory       = project.BaseDirectory;
            //info.WindowStyle = ProcessWindowStyle.Hidden;
            info.CreateNoWindow = true;

            using (Process process = Process.Start(info))
            {
                process.WaitForExit();
            }
        }
        public static void Run(OpenFLProject project, OpenFLProjectConfiguration configuration, IProgressMonitor monitor, ExecutionContext context)
        {
            ExecutionCommand cmd = CreateExecutionCommand(project, configuration);

            IConsole console;

            if (configuration.ExternalConsole)
            {
                console = context.ExternalConsoleFactory.CreateConsole(false);
            }
            else
            {
                console = context.ConsoleFactory.CreateConsole(false);
            }

            AggregatedOperationMonitor operationMonitor = new AggregatedOperationMonitor(monitor);

            try
            {
                if (!context.ExecutionHandler.CanExecute(cmd))
                {
                    monitor.ReportError(String.Format("Cannot execute '{0}'.", cmd.CommandString), null);
                    return;
                }

                IProcessAsyncOperation operation = context.ExecutionHandler.Execute(cmd, console);

                operationMonitor.AddOperation(operation);
                operation.WaitForCompleted();

                monitor.Log.WriteLine("Player exited with code {0}.", operation.ExitCode);
            }
            catch (Exception)
            {
                monitor.ReportError(String.Format("Error while executing '{0}'.", cmd.CommandString), null);
            }
            finally
            {
                operationMonitor.Dispose();
                console.Dispose();
            }
        }
        public static string GetCompletionData(Project project, string classPath, string fileName, int position)
        {
            if (!PropertyService.HasValue("HaxeBinding.EnableCompilationServer"))
            {
                PropertyService.Set("HaxeBinding.EnableCompilationServer", true);
                PropertyService.Set("HaxeBinding.CompilationServerPort", 6000);
                PropertyService.SaveProperties();
            }

            string exe  = "haxe";
            string args = "";

            if (project is OpenFLProject)
            {
                OpenFLProjectConfiguration configuration = project.GetConfiguration(MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as OpenFLProjectConfiguration;

                string platform = configuration.Platform.ToLower();
                string path     = ((OpenFLProject)project).TargetProjectXMLFile;

                if (!File.Exists(path))
                {
                    path = Path.Combine(project.BaseDirectory, path);
                }

                DateTime time = File.GetLastWriteTime(Path.GetFullPath(path));

                if (!time.Equals(cacheNMMLTime) || platform != cachePlatform || configuration.AdditionalArguments != cacheArgumentsPlatform || ((OpenFLProject)project).AdditionalArguments != cacheArgumentsGlobal)
                {
                    cacheHXML              = OpenFLCommandLineToolsManager.GetHXMLData((OpenFLProject)project, configuration).Replace(Environment.NewLine, " ");
                    cacheNMMLTime          = time;
                    cachePlatform          = platform;
                    cacheArgumentsGlobal   = ((OpenFLProject)project).AdditionalArguments;
                    cacheArgumentsPlatform = configuration.AdditionalArguments;
                }

                args = cacheHXML + " -D code_completion";
            }
            else if (project is HaxeProject)
            {
                HaxeProjectConfiguration configuration = project.GetConfiguration(MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as HaxeProjectConfiguration;

                args = "\"" + ((HaxeProject)project).TargetHXMLFile + "\" " + ((HaxeProject)project).AdditionalArguments + " " + configuration.AdditionalArguments;
            }
            else
            {
                return("");
            }

            args += " -cp \"" + classPath + "\" --display \"" + fileName + "\"@" + position + " -D use_rtti_doc";

            if (PropertyService.Get <bool> ("HaxeBinding.EnableCompilationServer"))
            {
                var port = PropertyService.Get <int> ("HaxeBinding.CompilationServerPort");

                if (compilationServer == null || compilationServer.HasExited || port != compilationServerPort)
                {
                    StartServer();
                }

                try
                {
                    if (!compilationServer.HasExited)
                    {
                        var client = new TcpClient("127.0.0.1", port);
                        var writer = new StreamWriter(client.GetStream());
                        writer.WriteLine("--cwd " + project.BaseDirectory);

                        // Instead of replacing spaces with newlines, replace only
                        // if the space is followed by a dash.
                        // TODO: Even more intelligent replacement so you can use folders
                        //       that contain the string sequence " -".
                        writer.Write(args.Replace(" -", "\n-"));

                        //writer.WriteLine("--connect " + port);
                        writer.Write("\0");
                        writer.Flush();
                        var reader = new StreamReader(client.GetStream());
                        var lines  = reader.ReadToEnd().Split('\n');
                        client.Close();
                        return(String.Join("\n", lines));
                    }
                }
                catch (Exception)
                {
                    //MonoDevelop.Ide.MessageService.ShowError (ex.ToString ());
                    //TraceManager.AddAsync(ex.Message);
                    //if (!failure && FallbackNeeded != null)
                    // FallbackNeeded(false);
                    //failure = true;
                    //return "";
                }
            }

            //MonoDevelop.Ide.MessageService.ShowError ("Falling back to standard completion");

            Process process = new Process();

            process.StartInfo.FileName              = exe;
            process.StartInfo.Arguments             = args;
            process.StartInfo.UseShellExecute       = false;
            process.StartInfo.CreateNoWindow        = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.WorkingDirectory      = project.BaseDirectory;
            process.Start();

            string result = process.StandardError.ReadToEnd();

            process.WaitForExit();

            return(result);
        }
        private static ExecutionCommand CreateExecutionCommand(OpenFLProject project, OpenFLProjectConfiguration configuration)
        {
            string exe  = "haxelib";
            string args = "run openfl run \"" + project.TargetProjectXMLFile + "\" " + configuration.Platform.ToLower();

            if (configuration.DebugMode)
            {
                args += " -debug";
            }

            if (project.AdditionalArguments != "")
            {
                args += " " + project.AdditionalArguments;
            }

            if (configuration.AdditionalArguments != "")
            {
                args += " " + configuration.AdditionalArguments;
            }

            NativeExecutionCommand cmd = new NativeExecutionCommand(exe);

            cmd.Arguments        = args;
            cmd.WorkingDirectory = project.BaseDirectory.FullPath;

            return(cmd);
        }