コード例 #1
0
        private void LoadFile(FilterChain filterChain) {
            string content = null;

            try {
                content = FileUtils.ReadFile(File.FullName, filterChain,
                    Encoding);
            } catch (IOException ex) {
                throw new BuildException("The properties file could not be read.",
                    Location, ex);
            }

            PropertyDictionary properties = Project.Properties;

            PropertyTask propertyTask = new PropertyTask();
            propertyTask.Parent = this;
            propertyTask.Project = Project;

            using (StringReader sr = new StringReader(content)) {
                string line = sr.ReadLine();
                int current_line = 0;

                while (line != null) {
                    current_line++;

                    // skip empty lines and comments
                    if (String.IsNullOrEmpty(line) || line.StartsWith ("#")) {
                        line = sr.ReadLine ();
                        continue;
                    }

                    int equals_pos = line.IndexOf ('=');
                    if (equals_pos == -1)
                        throw new BuildException (string.Format(CultureInfo.InvariantCulture,
                            "Invalid property defined on line {0}.",  current_line),
                            Location);

                    string name = line.Substring(0, equals_pos).Trim();
                    string value = line.Substring (equals_pos + 1, 
                        line.Length - equals_pos - 1).Trim();

                    string expandedValue = properties.ExpandProperties(value,
                        Location);

                    propertyTask.PropertyName = name;
                    propertyTask.Value = expandedValue;
                    propertyTask.Execute();

                    line = sr.ReadLine ();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Reads the list of global properties specified in the NAnt configuration
        /// file.
        /// </summary>
        /// <param name="propertyNodes">An <see cref="XmlNodeList" /> representing global properties.</param>
        private void ProcessGlobalProperties(XmlNodeList propertyNodes)
        {
            //deals with xml info from the config file, not build document.
            foreach (XmlNode propertyNode in propertyNodes) {
                //skip special elements like comments, pis, text, etc.
                if (!(propertyNode.NodeType == XmlNodeType.Element)) {
                    continue;
                }

                // initialize task
                PropertyTask propertyTask = new PropertyTask();
                propertyTask.Parent = propertyTask.Project = Project;
                propertyTask.NamespaceManager = NamespaceManager;
                propertyTask.InitializeTaskConfiguration();
                // configure using xml node
                propertyTask.Initialize(propertyNode);
                // execute task
                propertyTask.Execute();
            }
        }