Example #1
0
        public override int Execute()
        {
            if (ApplicationContext.Options.Count < 2)
            {
                WriteLine("Please specify a directory to import.");
                return 1;
            }

            var directory = ApplicationContext.Arguments[1];

            // Create the generator directory
            // TODO: this should also work with a proper path, e.g. C:\temp
            var source = new DirectoryInfo(Path.Combine(Context.CurrentDirectory, directory));
            var destination = new DirectoryInfo(Path.Combine(Context.GeneratorsDirectory, source.Name));

            foreach (var option in ApplicationContext.Options)
            {
                if (option.ShortName == "n" || option.LongName == "name")
                {
                    Name = option.Value;
                    break;
                }
            }

            if (Name != null)
            {
                destination = new DirectoryInfo(Path.Combine(Context.GeneratorsDirectory, Name));
            }

            // TODO: check if a generator with that name already exists
            Context.WorkingDirectory = Context.GeneratorsDirectory;

            // Use CopyStrategy so the output is consistent
            var strategy = new CopyStrategy {Context = Context};
            strategy.Process(source, destination);

            // Copy all directories and files from the source directory
            var strategies = new FileSystemStrategy[] {strategy};
            // Use destination.FullName so the output contains the name of the new generator
            new FileSystemIterator(destination.FullName, strategies).Iterate(source);

            return 0;
        }
Example #2
0
        public void Execute()
        {
            var directory = new DirectoryInfo(Context.GeneratorDirectory);

            if (directory.Exists)
            {
                var strategies = new FileSystemStrategy[]
                    {
                        new RenamingStrategy(),
                        new CopyStrategy(),
                        new TextSubstitutionStrategy()
                    };
                foreach (var strategy in strategies)
                {
                    strategy.Context = Context;
                }

                new FileSystemIterator(Context.CurrentDirectory, strategies).Iterate(directory);
            }
            else
            {
                Context.Out.WriteLine("Generator '{0}' not found.", Context.Generator.Name);
            }
        }
Example #3
0
 public FileSystemIterator(string workingDirectory, FileSystemStrategy[] strategies)
 {
     ignores = new List<string> {"manifest.xml"};
     WorkingDirectory = workingDirectory;
     this.strategies = strategies;
 }