public static DeploymentMappings Read(string configFileName)
        {
            //Verify that the deployment mappings file is a valid file
            TraceHelper.TraceInformation(TraceSwitches.TfsDeployer, "Reading Configuration File:{0}", configFileName);


            TraceHelper.TraceInformation(TraceSwitches.TfsDeployer, "Verifying Configuration File:{0}", configFileName);
            if (Properties.Settings.Default.SignDeploymentMappingFile)
            {
                if (!Encrypter.VerifyXml(configFileName, Properties.Settings.Default.KeyFile))
                {
                    TraceHelper.TraceWarning(TraceSwitches.TfsDeployer, "Verification Failed for the deployment mapping file:{0} and key file {1}", configFileName, Properties.Settings.Default.KeyFile);
                    return(null);
                }
                TraceHelper.TraceInformation(TraceSwitches.TfsDeployer, "Verification Succeeded for the deployment mapping file:{0}", configFileName);
            }

            if (File.Exists(configFileName))
            {
                using (TextReader reader = new StreamReader(configFileName))
                {
                    DeploymentMappings config = Read(reader);
                    return(config);
                }
            }
            else
            {
                TraceHelper.TraceWarning(TraceSwitches.TfsDeployer, "Reading Configuration File:{0} failed.", configFileName);

                return(null);
            }
        }
Example #2
0
        public IEnumerable <Mapping> ReadMappings(BuildDetail buildDetail)
        {
            TraceHelper.TraceInformation(TraceSwitches.TfsDeployer, "Reading Configuration for Team Project: {0} Team Build: {1}", buildDetail.TeamProject, buildDetail.BuildDefinition.Name);

            DeploymentMappings configuration = null;

            using (var stream = _deploymentFileSource.DownloadDeploymentFile(buildDetail))
            {
                if (stream != null)
                {
                    configuration = Read(stream);
                }
            }

            if (configuration == null)
            {
                TraceHelper.TraceWarning(TraceSwitches.TfsDeployer, "No configuration found for this team project.");
                return(Enumerable.Empty <Mapping>());
            }

            if (configuration.Mappings == null || configuration.Mappings.Length == 0)
            {
                TraceHelper.TraceWarning(TraceSwitches.TfsDeployer, "Configuration did not contain any Mappings.");
                return(Enumerable.Empty <Mapping>());
            }

            return(configuration.Mappings
                   .Where(m => string.IsNullOrEmpty(m.BuildDefinitionPattern) ||
                          Regex.IsMatch(buildDetail.BuildDefinition.Name, m.BuildDefinitionPattern))
                   .ToArray());
        }
        /// <summary>
        /// Read the config file from a stream
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private static DeploymentMappings Read(TextReader reader)
        {
            XmlSerializer      serializer = new XmlSerializer(typeof(DeploymentMappings));
            DeploymentMappings config     = (DeploymentMappings)serializer.Deserialize(reader);

            reader.Close();
            return(config);
        }