private Tuple<string, string> GetEnvironmentSpecificPropertyConfiguration(string environment, PreProcessorManifest processorManfiest, string manifestFile)
        {
            string staticFile = null;
            string overrideFile = null;

            if (processorManfiest.Environments == null)
            {
                return null;
            }

            var env = processorManfiest.Environments.FirstOrDefault(x => x.Name == environment);
            if (env == null)
            {
                return null;
            }

            var configSettings = env.Configuration;
            if (configSettings == null)
            {
                return null;
            }

            var root = fileSystem.GetDirectoryFullPath(manifestFile);

            staticFile = ResolvePath(root, env.Configuration.StaticFile);

            if (configSettings.OverrideFile != null)
            {
                overrideFile = ResolvePath(root, configSettings.OverrideFile);
            }

            return new Tuple<string, string>(staticFile, overrideFile);
        }
        private Tuple<string, string> GetConfigFilePaths(string environment, PreProcessorManifest processorManfiest, string manifestFile)
        {
            Tuple<string, string> configSettings = null;

            configSettings = GetEnvironmentSpecificPropertyConfiguration(environment, processorManfiest, manifestFile);

            if (configSettings == null && processorManfiest.Default.PropertyConfigurationManifest != null)
            {
                configSettings =  GetDefaultPropertyConfiguration(environment, processorManfiest, manifestFile);
            }
            
            if (configSettings == null)
            {
                throw new InvalidOperationException(string.Format("Property configuration for environment '{0}' not found.", environment));
            }

            return configSettings;
        }
        private void ProcessManifest(IDictionary<string, string> properties, PreProcessorManifest manifest, CommandLineArguments parser)
        {
            Group[] groups = null;
            if (manifest.Environments != null)
            {
                var env = manifest.Environments.FirstOrDefault(x => x.Name == parser.Environment);
                if (env != null)
                {
                    if (env.Groups != null)
                    {
                        groups = env.Groups;
                    }
                }
            }
            if (groups == null)
            {
                log.DebugFormat(
                    "Group config for Environment {0} not found in PreProcessorManifest file.  Using Default group.",
                    parser.Environment);

                groups = manifest.Default.Groups;
                if (groups == null )
                {
                    throw new XmlDidNotPassValidationException(string.Format("No specific Groups specified for environment {0} but no DefaultGroups specified either.", parser.Environment));
                }
            }
            else
            {
                log.DebugFormat(
                    "Using group config for Environment {0} in PreProcessorManifest file.",
                    parser.Environment);
                
            }

            var root = fileSystem.GetDirectoryFullPath(parser.ManifestFile);

            foreach (var group in groups)
            {
                log.InfoFormat("PreProcess group: {0}", group.Name);

                foreach (var command in group.Commands)
                {
                    var source = ResolvePath(root, command.Source);
                    var destination = ResolvePath(root, command.Destination);

                    log.InfoFormat("PreProcess Source: {0}.  Destination:{1}", source, destination);
                    tokeniser.ProcessSingleTemplate(properties, source, destination);
                }   
            }
        }
        private Tuple<string, string> GetDefaultPropertyConfiguration(string environment, PreProcessorManifest processorManfiest, string manifestFile)
        {
            string staticFile = null;
            string overrideFile = null;

            var propertyConfigurationManifestFileAbsolutePath = ResolvePath(fileSystem.GetDirectoryFullPath(manifestFile), processorManfiest.Default.PropertyConfigurationManifest);

            var propertyConfigurationManifest = new SerialisationManager(this.fileSystem).DeserializeXmlFile<PropertyConfigurationManifest>(propertyConfigurationManifestFileAbsolutePath);

            if (propertyConfigurationManifest.Environments == null)
            {
                throw new XmlDidNotPassValidationException("Environments element missing from property configuration manifest.");
            }

            var env = propertyConfigurationManifest.Environments.FirstOrDefault(x => x.Name == environment);
            if (env == null)
            {
                throw new InvalidOperationException(string.Format("Environment '{0}' not found in property configuration manifest file.", environment));
            }

            var configSettings = env.Configuration;
            if (configSettings == null)
            {
                throw new InvalidOperationException(string.Format("Environment Configuration '{0}' not found in property configuration manifest file.", environment));
            }

            var root = fileSystem.GetDirectoryFullPath(propertyConfigurationManifestFileAbsolutePath);

            staticFile = ResolvePath(root, configSettings.StaticFile);

            if (configSettings.OverrideFile != null)
            {
                overrideFile = ResolvePath(root, configSettings.OverrideFile);
            }

            return new Tuple<string, string>(staticFile, overrideFile);

        }