コード例 #1
0
        private void LoadExcludes(XmlNode node)
        {
            if (_excludes != null)
            {
                return;
            }
            lock (excludeLoadLock)
            {
                if (_excludes != null)
                {
                    return;
                }

                //first we'll try to load exclude files
                var excludefolder = Path.Combine(ConfigurationRootDirectory, "exclude");
                _excludes = new List <string>();
                if (Directory.Exists(excludefolder))
                {
                    var excludefiles = Directory.GetFiles(excludefolder, "*.config", SearchOption.AllDirectories);
                    foreach (string str in excludefiles)
                    {
                        //now hide conditionalconfigs
                        using (var stream = File.OpenRead(str))
                            using (var xmlTextReader = new XmlTextReader(stream))
                            {
                                var xmlDocument = new XmlDocument();
                                xmlDocument.Load(xmlTextReader);
                                if (ConfigPatcher.IsElementMatch(xmlDocument.DocumentElement, str))
                                {
                                    foreach (XmlNode child in xmlDocument.DocumentElement.ChildNodes)
                                    {
                                        var attr = child.Attributes.GetNamedItem("value");
                                        if (attr != null)
                                        {
                                            _excludes.Add(attr.Value.ToLowerInvariant().TrimStart('\\', '/'));
                                        }
                                    }
                                }
                            }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// update packages create config files like "myconfig.config.d50f2217-de81-4265-b365-95a4c72c928b" when it doesn't want to overwrite an existing file, let's overwrite it now
        /// and patch connectionstrings and smtp settings
        /// </summary>
        public static void PreStart()
        {
            var folder = Path.Combine(ConfigurationRootDirectory, "include");

            if (Directory.Exists(folder))
            {
                //update packages create config files like "myconfig.config.d50f2217-de81-4265-b365-95a4c72c928b" when it doesn't want to overwrite an existing file, let's overwrite it now
                var files = Directory.GetFiles(folder, "*.config", SearchOption.AllDirectories);
                Array.Sort(files);
                foreach (var file in files)
                {
                    var newConfigFiles = Directory.GetFiles(Path.GetDirectoryName(file),
                                                            Path.GetFileName(file + ".*"))
                                         .Where(f => f != file && IsNonReplacedConfig(f));
                    if (newConfigFiles.Any())
                    {
                        var newestConfigFile = newConfigFiles.OrderByDescending(File.GetLastWriteTimeUtc).First();
                        File.Replace(newestConfigFile, file, null);
                        foreach (string deleteme in newConfigFiles)
                        {
                            File.Delete(deleteme);
                        }
                    }
                }
            }
            //connectionstrings
            folder = Path.Combine(ConfigurationRootDirectory, ConnectionStringsFolderName);
            if (Directory.Exists(folder))
            {
                var files = Directory.GetFiles(folder, "*.config", SearchOption.AllDirectories);
                Array.Sort(files);
                foreach (var file in files)
                {
                    if ((File.GetAttributes(file) & FileAttributes.Hidden) == (FileAttributes)0)
                    {
                        var includeFile = new XmlDocument();
                        includeFile.XmlResolver = null; //ComSEC audit: prevent DTD injection
                        includeFile.Load(file);
                        if (ConfigPatcher.IsElementMatch(includeFile.DocumentElement, file))
                        {
                            Trace.TraceInformation("Found connection string file '{0}', going to patch", file);
                            PatchConnectionStrings(includeFile.DocumentElement);
                        }
                    }
                }
            }
            //mailsettings
            folder = Path.Combine(ConfigurationRootDirectory, MailsettingsFolderName);
            if (Directory.Exists(folder))
            {
                var files = Directory.GetFiles(folder, "*.config", SearchOption.AllDirectories);
                Array.Sort(files);
                foreach (var file in files)
                {
                    if ((File.GetAttributes(file) & FileAttributes.Hidden) == (FileAttributes)0)
                    {
                        var includeFile = new XmlDocument();
                        includeFile.XmlResolver = null; //ComSEC audit: prevent DTD injection
                        includeFile.Load(file);
                        if (ConfigPatcher.IsElementMatch(includeFile.DocumentElement, file))
                        {
                            Trace.TraceInformation("Found mail settings file '{0}', going to patch", file);
                            PatchMailSettings(includeFile.DocumentElement);
                        }
                    }
                }
            }
        }