示例#1
0
文件: Program.cs 项目: rte-se/emul8
        private static void HandleGenerateSolution(string mainProjectPath, string binariesPath, IEnumerable<string> additionalProjectsPaths, IEnumerable<string> robotTests, string output, bool generateEntryProject)
        {
            Project mainProject;
            if(!Project.TryLoadFromFile(mainProjectPath, out mainProject))
            {
                Console.Error.WriteLine("Could not load main project");
                return;
            }

            var additionalProjects = new List<Project>();
            foreach(var additionalProjectPath in additionalProjectsPaths ?? Enumerable.Empty<string>())
            {
                Project additionalProject;
                if(!Project.TryLoadFromFile(additionalProjectPath, out additionalProject))
                {
                    Console.Error.WriteLine("Could not load additional project: {0}", additionalProject);
                    return;
                }
                additionalProjects.Add(additionalProject);
            }

            var solution = SolutionGenerator.Generate(mainProject, generateEntryProject, binariesPath, additionalProjects);
            if(output == null)
            {
                Console.WriteLine(solution);
            }
            else
            {
                var confiugration = new Configuration(solution, robotTests.Select(x => new RobotTestSuite(x)));
                confiugration.Save(output);
            }
        }
示例#2
0
文件: Program.cs 项目: rte-se/emul8
        private static int HandleInteractive(List<string> directories, string binariesDirectory, string outputDirectory, bool generateEntryProject)
        {
            // check if "dialog" application is available
            if(!TryFind("dialog"))
            {
                Console.Error.WriteLine("The 'dialog' application is necessary to run in interactive mode");
                return ErrorResultCode;
            }

            if(directories == null || directories.All(x => string.IsNullOrEmpty(x)))
            {
                var directoryDialog = new InputboxDialog(Title, "Provide directories to scan (colon-separated):", ".");
                if(directoryDialog.Show() != DialogResult.Ok)
                {
                    return CancelResultCode;
                }
                directories = directoryDialog.Value.Split(new [] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }

            if(!directories.Any())
            {
                new MessageDialog("Error", "No directories to scan provided! Exiting.").Show();
                return ErrorResultCode;
            }

            var infobox = new Infobox("Scanning directories...");
            infobox.Show();

            Scanner.Instance.ScanDirectories(directories);

            var actions = new List<Tuple<string, string>> {
                Tuple.Create("All", "Generate solution file with all projects"),
                Tuple.Create("Custom", "Generate custom solution file"),
                Tuple.Create("Clean", "Remove generated configuration")
            };

            foreach(var uiType in Scanner.Instance.Elements.OfType<UiProject>().Select(x => x.UiType).Distinct().OrderByDescending(x => x))
            {
                actions.Insert(1, Tuple.Create(uiType, string.Format("Generate solution file for {0} with references", uiType)));
            }

            var actionDialog = new MenuDialog(Title, "Welcome to the Emul8 bootstrap configuration.\nUse this script to generate your own Emul8.sln file.\n\nChoose action:", actions);
            if(actionDialog.Show() != DialogResult.Ok)
            {
                return CancelResultCode;
            }

            Configuration configuration;
            try
            {
                var key = actionDialog.SelectedKeys.First();
                switch(key)
                {
                case "All":
                    configuration = GenerateAllProjects(binariesDirectory, generateEntryProject, directories);
                    break;
                case "Custom":
                    configuration = HandleCustomSolution(binariesDirectory, generateEntryProject, directories);
                    break;
                case "Clean":
                    Cleaner.Clean(outputDirectory);
                    new MessageDialog(Title, "Solution cleaned.").Show();
                    return CleanedResultCode;
                default:
                    var mainProject = Scanner.Instance.Elements.OfType<UiProject>().SingleOrDefault(x => x.UiType == key);
                    if(mainProject == null)
                    {
                        new MessageDialog("Bootstrap failure", string.Format("Could not load {0} project. Exiting", key)).Show();
                        return ErrorResultCode;
                    }
                    configuration = new Configuration(SolutionGenerator.GenerateWithAllReferences(mainProject, generateEntryProject, binariesDirectory), null);
                    break;
                }
            }
            catch(DirectoryNotFoundException e)
            {
                new MessageDialog("Error", e.Message).Show();
                return ErrorResultCode;
            }

            var confirmDialog = new YesNoDialog(Title, "Are you sure you want to create the solution file?");
            if(confirmDialog.Show() != DialogResult.Ok)
            {
                return CancelResultCode;
            }

            configuration.Save(outputDirectory);

            new MessageDialog(Title, "Solution file created successfully!").Show();
            return 0;
        }