Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        public override void Parse(XmlNode node)
        {
            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_Link         = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
            this.m_CopyToOutput = (CopyToOutput)Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString()));

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText);
            if (m_Path == null)
            {
                m_Path = "";
            }

            m_Path  = m_Path.Trim();
            m_Valid = true;
            if (!File.Exists(m_Path))
            {
                m_Valid = false;
                Kernel.Instance.Log.Write(LogType.Warning, "File does not exist: {0}", m_Path);
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        public override void Parse(XmlNode node)
        {
            string buildAction = Helper.AttributeValue(node, "buildAction", String.Empty);

            if (buildAction != string.Empty)
            {
                m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction);
            }
            string subType = Helper.AttributeValue(node, "subType", string.Empty);

            if (subType != String.Empty)
            {
                m_SubType = (SubType)Enum.Parse(typeof(SubType), subType);
            }

            Console.WriteLine("[FileNode]:BuildAction is {0}", buildAction);


            m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString());
            this.m_Link    = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
            if (this.m_Link == true)
            {
                this.m_LinkPath = Helper.AttributeValue(node, "linkPath", string.Empty);
            }
            this.m_CopyToOutput = (CopyToOutput)Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString()));
            this.m_PreservePath = bool.Parse(Helper.AttributeValue(node, "preservePath", bool.FalseString));

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText);
            if (m_Path == null)
            {
                m_Path = "";
            }

            m_Path  = m_Path.Trim();
            m_Valid = true;
            if (!File.Exists(m_Path))
            {
                m_Valid = false;
                Kernel.Instance.Log.Write(LogType.Warning, "File does not exist: {0}", m_Path);
            }

            if (System.IO.Path.GetExtension(m_Path) == ".settings")
            {
                m_SubType     = SubType.Settings;
                m_BuildAction = BuildAction.None;
            }
        }
Example #3
0
            public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            {
                if (destinationType == typeof(string))
                {
                    string result = null;

                    // In some cases if multiple nodes are selected the windows form engine
                    // calls us with a null value if the selected node's property values are not equal
                    // Example of windows form engine passing us null: File set to Compile, Another file set to None, bot nodes are selected, and the build action combo is clicked.
                    if (value != null)
                    {
                        CopyToOutput iValue = (CopyToOutput)value;
                        switch (iValue)
                        {
                        case CopyToOutput.CopyNever:
                            result = CopyNever;
                            break;

                        case CopyToOutput.CopyAlways:
                            result = CopyAlways;
                            break;

                        case CopyToOutput.CopyPreserveNewest:
                            result = PreserveNewest;
                            break;

                        default:
                            result = CopyNever;
                            break;
                        }
                    }
                    else
                    {
                        result = CopyNever;
                    }

                    if (result != null)
                    {
                        return(result);
                    }
                }

                return(base.ConvertTo(context, culture, value, destinationType));
            }
Example #4
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;
        }
Example #5
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.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 ( this.m_Link == true )
			{
				this.m_LinkPath = Helper.AttributeValue( node, "linkPath", string.Empty );
			}
            this.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)
			{
				throw new WarningException("Match returned no files: {0}{1}", Helper.EndPath(path), pattern);
			}
			m_Regex = null;
		}
Example #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        public override void Parse(XmlNode node)
        {
            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_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
            if ( this.m_Link == true )
            {
                this.m_LinkPath = Helper.AttributeValue( node, "linkPath", string.Empty );
            }
            this.m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString()));
            this.m_PreservePath = bool.Parse( Helper.AttributeValue( node, "preservePath", bool.FalseString ) );

            if( node == null )
            {
                throw new ArgumentNullException("node");
            }

            m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText);
            if(m_Path == null)
            {
                m_Path = "";
            }

            m_Path = m_Path.Trim();
            m_Valid = true;
            if(!File.Exists(m_Path))
            {
                m_Valid = false;
                Kernel.Instance.Log.Write(LogType.Warning, "File does not exist: {0}", m_Path);
            }
        }
Example #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        public override void Parse(XmlNode node)
        {
            string buildAction = Helper.AttributeValue(node, "buildAction", String.Empty);
            if (buildAction != string.Empty)
                m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction);

            string subType = Helper.AttributeValue(node, "subType", string.Empty);
            if (subType != String.Empty)
                m_SubType = (SubType)Enum.Parse(typeof(SubType), subType);

            string generator = Helper.AttributeValue(node, "generator", string.Empty);
            if (generator != String.Empty)
                m_Generator = generator;

            string genOutput = Helper.AttributeValue(node, "genOutput", string.Empty);
            if (genOutput != String.Empty)
                m_GenOutput = genOutput;
            else if (m_Generator != String.Empty)
                throw new InvalidDataException("Generator requires specification of genOutput.");

            //Console.WriteLine("[FileNode]: BuildAction is {0}", buildAction);

            m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString());
            this.m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
            if ( this.m_Link == true )
            {
                this.m_LinkPath = Helper.AttributeValue( node, "linkPath", string.Empty );
            }
            this.m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString()));
            this.m_PreservePath = bool.Parse( Helper.AttributeValue( node, "preservePath", bool.FalseString ) );

            if( node == null )
            {
                throw new ArgumentNullException("node");
            }

            m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText);
            if(m_Path == null)
            {
                m_Path = "";
            }

            m_Path = m_Path.Trim();
            m_Valid = true;
            if(!File.Exists(m_Path))
            {
                m_Valid = false;
                Kernel.Instance.Log.Write(LogType.Warning, "File does not exist: {0}", m_Path);
            }

            if (System.IO.Path.GetExtension(m_Path) == ".settings")
            {
                m_SubType = SubType.Settings;
                m_BuildAction = BuildAction.None;
            }
        }
        /// <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;
        }
        public CsProjectFileDefinition Deserialize(Func <string, string> csprojToLabel,
                                                   IReadOnlyDictionary <string, string> importLabels, string projectFilePath)
        {
            _document = XDocument.Load(projectFilePath);
            var projectFileDir = Path.GetDirectoryName(projectFilePath);

            Type = GetProjectType(_document);

            foreach (var reference in _document.Descendants("PackageReference"))
            {
                var name = reference.Attribute("Include").Value;

                if (importLabels.ContainsKey(name))
                {
                    ProjectReference.Add(importLabels[name]);
                }
                else
                {
                    if (name.Equals("microsoft.net.test.sdk", StringComparison.OrdinalIgnoreCase))
                    {
                        PackageReferences.Add("microsoft.testplatform.testhost");
                        PackageReferences.Add("microsoft.codecoverage");
                    }
                    else
                    {
                        PackageReferences.Add(name);
                    }
                }
            }

            foreach (var frameworkReference in _document.Descendants("FrameworkReference"))
            {
                // TODO naming .Ref?
                var name = frameworkReference.Attribute("Include").Value;
                PackageReferences.Add($"{name}.Ref");
            }

            foreach (var descendant in _document.Descendants("ProjectReference"))
            {
                var include = descendant.Attribute("Include").Value;
                var name    = Path.GetFileNameWithoutExtension(include);

                if (importLabels.ContainsKey(name))
                {
                    ProjectReference.Add(importLabels[name]);
                }
                else
                {
                    ProjectReference.Add(csprojToLabel(Path.Combine(projectFileDir, include)));
                }
            }

            foreach (var bazelDataArray in _document.Descendants("BazelData"))
            {
                BazelData.AddRange(bazelDataArray.Value.Split(';'));
            }

            foreach (var resource in _document.Descendants("EmbeddedResource"))
            {
                var include = resource.Attribute("Include")?.Value;
                var remove  = resource.Attribute("Remove")?.Value;
                var update  = resource.Attribute("Update")?.Value;

                if (include != null)
                {
                    EmbeddedResources.Add(new EmbeddedResourceDefinition(EmbeddedResourceType.Include, include));
                }
                if (remove != null)
                {
                    EmbeddedResources.Add(new EmbeddedResourceDefinition(EmbeddedResourceType.Remove, remove));
                }
                if (update != null)
                {
                    EmbeddedResources.Add(new EmbeddedResourceDefinition(EmbeddedResourceType.Update, update));
                }
            }

            foreach (var copyNode in _document.Descendants("CopyToOutputDirectory"))
            {
                // PreserveNewest ?

                var include = copyNode.Parent?.Attribute("Include")?.Value
                              ?? copyNode.Parent?.Attribute("Update")?.Value;
                if (include != null)
                {
                    CopyToOutput.Add(include.Replace("\\", "/"));
                }
            }

            TestOnly = string.Equals(_document.Descendants("BazelTestOnly").LastOrDefault()?.Value, "true", StringComparison.OrdinalIgnoreCase);

            return(this);
        }