public ICommandLineHandler Create(Command options)
        {
            if (options.Name.Equals("Export", StringComparison.InvariantCultureIgnoreCase))
            {
                return new ExportCommandHandler();
            }

            return new ImportCommandHandler();
        }
Example #2
0
        static void Main(string[] args)
        {
            var command = new Command();
            bool isHelp = args.Any(x => x == "-?");
            var success = Parser.Default.ParseArguments(args, command);

            if (!success || isHelp)
            {
                if (!isHelp && args.Length > 0)
                    Console.Error.WriteLine("error parsing command line");

            }

            var factory = new CommandHandlerFactory();
            var commandHandler = factory.Create(command);
            commandHandler.Execute(command);
        }
        public void Execute(Command command)
        {
            using (var stream = File.Open(command.FilePath, FileMode.Open))
            {

                using (var reader = new StreamReader(stream))
                {

                    var line = reader.ReadLine();

                    while (!string.IsNullOrEmpty(line))
                    {
                        line = reader.ReadLine();

                    }

                }
            }
        }
        public void Execute(Command command)
        {
            var client = new HttpClient { BaseAddress = new Uri(command.Server) };

            client.DefaultRequestHeaders.Add("X-Octopus-ApiKey", command.ApiKey);
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            var api = client.GetResource<Api>("/api");
            var projects = client.GetResource<IEnumerable<Project>>(api.Links.Projects);
            var project = projects.FirstOrDefault(x => x.Name.Equals(command.ProjectName, StringComparison.InvariantCultureIgnoreCase));
            var variables = client.GetResource<IEnumerable<Variable>>(project.Links.Variables);
            var environmentLookup = client.GetResource<IEnumerable<Environment>>(api.Links.Environments).ToDictionary(x=> x.Id);

            var csv = new StringBuilder();

            const string format = "\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\"";

            csv.AppendLine("Name,Value,Environment,Role,Step");

            foreach (var variable in variables)
            {
                var data = new VariableData();
                data.Name = variable.Name;
                data.Value = variable.Value;
                data.Environment = !string.IsNullOrEmpty(variable.EnvironmentId)  ? environmentLookup[variable.EnvironmentId].Name : string.Empty;
                data.Role = variable.Role;
                data.Step = string.Empty;

                csv.AppendFormat(format, data.Name, data.Value, data.Environment, data.Role, data.Step);
                csv.AppendLine();

            }

            var content = csv.ToString();

            File.WriteAllText(command.FilePath, content, Encoding.UTF8);
        }