Inheritance: DataNode
Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        public override void Parse(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            string path        = Helper.AttributeValue(node, "path", ".");
            string pattern     = Helper.AttributeValue(node, "pattern", "*");
            bool   recurse     = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false"));
            bool   useRegex    = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false"));
            string buildAction = Helper.AttributeValue(node, "buildAction", String.Empty);

            if (buildAction != string.Empty)
            {
                m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction);
            }

            //TODO: Figure out where the subtype node is being assigned
            //string subType = Helper.AttributeValue(node, "subType", string.Empty);
            //if (subType != String.Empty)
            //    m_SubType = (SubType)Enum.Parse(typeof(SubType), subType);
            m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName);
            m_CopyToOutput = (CopyToOutput)Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", m_CopyToOutput.ToString()));
            m_Link         = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
            if (m_Link)
            {
                m_LinkPath = Helper.AttributeValue(node, "linkPath", string.Empty);
            }
            m_PreservePath = bool.Parse(Helper.AttributeValue(node, "preservePath", bool.FalseString));


            if (path != null && path.Length == 0)
            {
                path = ".";                //use current directory
            }
            //throw new WarningException("Match must have a 'path' attribute");

            if (pattern == null)
            {
                throw new WarningException("Match must have a 'pattern' attribute");
            }

            path = Helper.NormalizePath(path);
            if (!Directory.Exists(path))
            {
                throw new WarningException("Match path does not exist: {0}", path);
            }

            try
            {
                if (useRegex)
                {
                    m_Regex = new Regex(pattern);
                }
            }
            catch (ArgumentException ex)
            {
                throw new WarningException("Could not compile regex pattern: {0}", ex.Message);
            }


            foreach (XmlNode child in node.ChildNodes)
            {
                IDataNode dataNode = Kernel.Instance.ParseNode(child, this);
                if (dataNode is ExcludeNode)
                {
                    ExcludeNode excludeNode = (ExcludeNode)dataNode;
                    m_Exclusions.Add(excludeNode);
                }
            }

            RecurseDirectories(path, pattern, recurse, useRegex, m_Exclusions);

            if (m_Files.Count < 1)
            {
                // Include the project name when the match node returns no matches to provide extra
                // debug info.
                ProjectNode project     = Parent.Parent as ProjectNode;
                string      projectName = "";

                if (project != null)
                {
                    projectName = " in project " + project.AssemblyName;
                }

                throw new WarningException("Match" + projectName + " returned no files: {0}{1}", Helper.EndPath(path), pattern);
            }
            m_Regex = null;
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        public override void Parse(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            string path     = Helper.AttributeValue(node, "path", ".");
            string pattern  = Helper.AttributeValue(node, "pattern", "*");
            bool   recurse  = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false"));
            bool   useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false"));

            m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction),
                                                    Helper.AttributeValue(node, "buildAction", m_BuildAction.ToString()));
            m_SubType = (SubType)Enum.Parse(typeof(SubType),
                                            Helper.AttributeValue(node, "subType", m_SubType.ToString()));
            m_ResourceName      = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString());
            this.m_CopyToOutput = (CopyToOutput)Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString()));
            this.m_Link         = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));


            if (path != null && path.Length == 0)
            {
                path = ".";                //use current directory
            }
            //throw new WarningException("Match must have a 'path' attribute");

            if (pattern == null)
            {
                throw new WarningException("Match must have a 'pattern' attribute");
            }

            path = Helper.NormalizePath(path);
            if (!Directory.Exists(path))
            {
                throw new WarningException("Match path does not exist: {0}", path);
            }

            try
            {
                if (useRegex)
                {
                    m_Regex = new Regex(pattern);
                }
            }
            catch (ArgumentException ex)
            {
                throw new WarningException("Could not compile regex pattern: {0}", ex.Message);
            }

            RecurseDirectories(path, pattern, recurse, useRegex);

            foreach (XmlNode child in node.ChildNodes)
            {
                IDataNode dataNode = Kernel.Instance.ParseNode(child, this);
                if (dataNode is ExcludeNode)
                {
                    ExcludeNode excludeNode = (ExcludeNode)dataNode;
                    if (m_Files.Contains(Helper.NormalizePath(excludeNode.Name)))
                    {
                        m_Files.Remove(Helper.NormalizePath(excludeNode.Name));
                    }
                }
            }

            if (m_Files.Count < 1)
            {
                throw new WarningException("Match returned no files: {0}{1}", Helper.EndPath(path), pattern);
            }
            m_Regex = null;
        }