Exemple #1
0
        private static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            var configuration = builder.Build();

            Console.WriteLine(configuration.GetConnectionString("Storage"));

            var apiUrl = configuration["Octopus:APIUrl"];
            var apiKey = configuration["Octopus:APIKey"];
            var help   = false;

            var p = new OptionSet {
                { "api-url", v => apiUrl = v },
                { "api-key", v => apiKey = v },
                { "h|?|help", v => help = v != null },
            };

            var extra = p.Parse(args);

            if (!apiUrl.IsEmpty() &&
                !apiKey.IsEmpty())
            {
                _octopusApi = new OctopusApi(apiUrl, apiKey);
            }
            else
            {
                Console.WriteLine("Please specify Octopus API url and key in eaither app.config or as a command line argument.");
                return;
            }

            if (help)
            {
                Console.WriteLine("Octopus Search" +
                                  "example: octopus-search -api-url 'http://myoctopuswebsite.com' -api-key 'API-XXX'");
            }

            var menu = new EasyConsoleCore.Menu()
                       .Add("Search variables (by name and value)", () =>
            {
                var searchFor = Input.ReadString("Search for: ");

                _octopusApi.SearchVariablesFor(searchFor)
                .Result
                .ForEach(o => Console.WriteLine($"Project: {o.Project}, VariableSet: {o.VariableSet}, Variable: {o.VariableName}, Value: {o.VariableValue}"));
            })
                       .Add("Get projects by role(s) (which are specified in the project's process)", () =>
            {
                var roles = new List <string>();
                string enteredRole;
                Console.WriteLine("Enter role name(s), you can use wildcards:");
                do
                {
                    enteredRole = Input.ReadString("");
                    if (!enteredRole.IsEmpty())
                    {
                        roles.Add(enteredRole);
                    }
                } while (enteredRole.IsEmpty());

                _octopusApi.GetProjectsByRole(roles.ToArray())
                .Result
                .ForEach(o => Console.WriteLine($"Project: {o.Project}, Found Roles: {string.Join(",", o.FoundRoles)}, All Roles: {string.Join(",", o.AllRoles)}"));
            })
                       .Add("Get projects which are using a variable set", () =>
            {
                var variableSetId = Input.ReadString("Enter the variable set id: ");

                _octopusApi.GetProjectsUsingAVariableSet(variableSetId)
                .Result
                .ForEach(o => Console.WriteLine($"Project: {o.Project}"));
            })
                       .Add("Get deployment targets which are using a variable set in an enviroment (indirectly via a project)", () =>
            {
                var variableSetId = Input.ReadString("Enter the variable set id: ");
                var environmentId = Input.ReadString("Enter the environment id: ");

                _octopusApi.GetDeploymentTargetsWhichThisVariableSetIsUsed(variableSetId, environmentId)
                .Result
                .ForEach(o => Console.WriteLine($"Project: {o.Project}, Machines: {string.Join(", ", o.Machines)}"));
            })
                       .Add("Exit", () =>
            {
                _exiting = true;
                Environment.Exit(0);
            })
            ;

            while (!_exiting)
            {
                menu.Display();

                PressAnyKey();
            }
        }
Exemple #2
0
        /// <summary>
        /// Initialize inputs from console, then do calculations.
        /// </summary>
        public void InitilazeInputsAndCalculate()
        {
            var plateau = new Plateau();

            #region Plateau Size
            var    isUpperRightCoordinatesValid = false;
            string upperRightCoordinatesInput   = "";
            while (!isUpperRightCoordinatesValid)
            {
                Output.WriteLine(ConsoleColor.Yellow, UserFirendlyMessages.ENTER_UPPER_RIGHT_COORDINATES);
                upperRightCoordinatesInput = Console.ReadLine();

                isUpperRightCoordinatesValid = _inputValidator.IsUpperRightCoordinatesValid(upperRightCoordinatesInput);

                if (!isUpperRightCoordinatesValid)
                {
                    Output.WriteLine(ConsoleColor.Red, UserFirendlyMessages.UPPER_RIGHT_COORDINATES_NOT_VALID);
                }
            }

            var upperRightCoordinates = Regex.Replace(upperRightCoordinatesInput.Trim(), @"\s+", " ").Split(" ");
            var upperRightX           = int.Parse(upperRightCoordinates[0]);
            var upperRightY           = int.Parse(upperRightCoordinates[1]);

            plateau.UpperRightCoordinateX = upperRightX;
            plateau.UpperRightCoordinateY = upperRightY;
            #endregion

            var addRover  = true;
            var roverList = new List <Rover>();
            var order     = 1;
            while (addRover)
            {
                #region Validate Position
                string positionInput   = "";
                var    isPositionValid = false;
                while (!isPositionValid)
                {
                    Output.WriteLine(ConsoleColor.Yellow, UserFirendlyMessages.ENTER_POSITION);
                    positionInput   = Console.ReadLine();
                    isPositionValid = _inputValidator.IsRoverPositionValid(positionInput, upperRightX, upperRightY);

                    if (!isPositionValid)
                    {
                        Output.WriteLine(ConsoleColor.Red, UserFirendlyMessages.POSITION_NOT_VALID);
                    }
                }
                #endregion

                #region Validate Command
                var isCommandValid = false;
                var commandInput   = "";
                while (!isCommandValid)
                {
                    Output.WriteLine(ConsoleColor.Yellow, UserFirendlyMessages.ENTER_COMMAND_ROVER);
                    commandInput   = Console.ReadLine();
                    isCommandValid = _inputValidator.IsCommandValid(commandInput);
                    if (!isCommandValid)
                    {
                        Output.WriteLine(ConsoleColor.Red, UserFirendlyMessages.COMMAND_NOT_VALID);
                    }
                }
                #endregion

                #region Create Rover

                var roverPosition = GetPositionByInputString(positionInput);

                roverList.Add(new Rover()
                {
                    Order    = order,
                    Position = roverPosition,
                    Command  = commandInput.Trim().ToUpper()
                });

                #endregion

                var addRoverMenu = new EasyConsoleCore.Menu()
                                   .Add("Add one more rover", () => addRover = true)
                                   .Add("Continue", () => addRover           = false);
                addRoverMenu.Display();
                order++;
            }
            plateau.Rovers = roverList;

            CalculateMovements(plateau);
            DisplayOutputs(plateau);

            Console.ReadLine();
        }