Example #1
0
        private void UpdateXmlFile(DeploymentResult result, string filePath, IDictionary<string, string> replacementItems,IDictionary<string, string> insertItems, IEnumerable<string> removeItems, IDictionary<string, string> namespacePrefixes)
        {
            LogFileChange("[xmlpoke] Starting changes to '{0}'.", filePath);

            var document = new XmlDocument();
            document.Load(filePath);
            var nsManager = new XmlNamespaceManager(document.NameTable);

            foreach (var prefix in namespacePrefixes)
                nsManager.AddNamespace(prefix.Key, prefix.Value);

            XPathNavigator xpathNavigator = document.CreateNavigator();

            foreach (string item in removeItems.OrEmptyListIfNull())
                RemoveNodeInFile(result, xpathNavigator, item, nsManager);

            foreach (KeyValuePair<string, string> item in replacementItems.OrEmptyListIfNull())
                UpdateValueInFile(result, xpathNavigator, item.Key, item.Value, nsManager);

            foreach(KeyValuePair<string, string> item in insertItems.OrEmptyListIfNull())
               UpdateOrInsertValueInFile(result,document, xpathNavigator, item.Key, item.Value, nsManager);

            LogFileChange("[xmlpoke] Completed changes to '{0}'.",filePath);

            if (!result.ContainsError())
                document.Save(filePath);
        }
Example #2
0
        /// <summary>
        /// Determines whether a string matches the given ignore patterns.  This is used
        /// to ignore files which shouldn't be copied from the source to target directories,
        /// e.g. you may first place an App_Offline.htm file into the directory before copying
        /// data to it.  You wouldn't want to delete the App_Offline.html file while copying files.
        /// </summary>
        /// <param name="ignorePatterns"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        protected bool IsIgnored(IEnumerable<Regex> ignorePatterns, FileInfo file)
        {
            bool returnValue = false;

            foreach (Regex ignorePattern in ignorePatterns.OrEmptyListIfNull())
            {
                if (ignorePattern.IsMatch(file.FullName))
                {
                    returnValue = true;
                    break;
                }
            }

            return returnValue;
        }