Beispiel #1
0
        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;
        }
Beispiel #2
0
        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);
            }

            Solution solution = null;
            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.Projects.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);
            }

            try
            {
                var key = actionDialog.SelectedKeys.First();
                switch (key)
                {
                case "All":
                    solution = GenerateAllProjects(binariesDirectory, generateEntryProject, directories);
                    break;

                case "Custom":
                    solution = HandleCustomSolution(binariesDirectory, generateEntryProject, directories);
                    break;

                case "Clean":
                    Cleaner.Clean(outputDirectory);
                    new MessageDialog(Title, "Solution cleaned.").Show();
                    return(CleanedResultCode);

                default:
                    var mainProject = Scanner.Instance.Projects.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);
                    }
                    solution = SolutionGenerator.GenerateWithAllReferences(mainProject, generateEntryProject, binariesDirectory);
                    break;
                }
            }
            catch (DirectoryNotFoundException e)
            {
                new MessageDialog("Error", e.Message).Show();
                return(ErrorResultCode);
            }

            if (solution == null)
            {
                new MessageDialog("Bootstrap failure", "Couldn't generate the solution file: no project file found in the directories provided. Exiting").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);
            }

            solution.Save(outputDirectory);
            solution.SaveTestsFile(Path.Combine(outputDirectory, testsFileName));

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