Ejemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The XPath navigator containing the
        /// component's configuration information</param>
        internal BuildComponentInfo(XPathNavigator component)
        {
            StringBuilder sb = new StringBuilder();
            FileVersionInfo fvi;
            XPathNavigator item;
            string asmPath, attrValue;

            isValid = true;

            // Load the configuration information from the node
            try
            {
                attrValue = component.GetAttribute("type", String.Empty);

                if(String.IsNullOrEmpty(attrValue))
                {
                    isValid = false;
                    typeName = "??";
                    invalidReason = "Missing type name attribute";
                }
                else
                    typeName = attrValue;

                // If no ID, use the type name
                attrValue = component.GetAttribute("id", String.Empty);

                if(!String.IsNullOrEmpty(attrValue))
                    id = attrValue;
                else
                    id = typeName;

                attrValue = component.GetAttribute("assembly", String.Empty);

                if(String.IsNullOrEmpty(attrValue))
                {
                    isValid = false;
                    assemblyPath = "??";
                    invalidReason = "Missing assembly attribute";
                }
                else
                {
                    assemblyPath = attrValue;

                    // Try to get copyright and version information
                    asmPath = BuildComponentManager.ResolveComponentPath(
                        assemblyPath);

                    if(File.Exists(asmPath))
                    {
                        fvi = FileVersionInfo.GetVersionInfo(asmPath);
                        version = new Version(fvi.FileVersion);
                        copyright = fvi.LegalCopyright;
                    }
                    else
                    {
                        version = new Version("0.0.0.0");
                        copyright = "?? - Unable to locate assembly";
                        isValid = false;
                        invalidReason = "The build component assembly " +
                            asmPath + " could not be found";
                    }
                }

                // If no description use the type name and assembly path
                item = component.SelectSingleNode("description");
                if(item != null)
                    description = item.Value.Trim();
                else
                    description = typeName + ", " + assemblyPath;

                if(component.SelectSingleNode("hidden") != null)
                    isHidden = true;

                item = component.SelectSingleNode("configureMethod");
                if(item != null)
                {
                    attrValue = item.GetAttribute("name", String.Empty);

                    if(!String.IsNullOrEmpty(attrValue))
                        configureMethod = attrValue;
                }

                // The default configuration is wrapped in a <component> tag
                item = component.SelectSingleNode("defaultConfiguration");

                // We need to retain custom attributes on the component as well
                // as the standard id, type, and assembly attributes.
                sb.Append("<component");

                if(component.MoveToFirstAttribute())
                {
                    do
                    {
                        sb.AppendFormat(" {0}=\"{1}\"", component.Name,
                            component.Value);
                    } while(component.MoveToNextAttribute());

                    component.MoveToParent();
                }

                sb.AppendFormat(CultureInfo.InvariantCulture,
                    ">\r\n{0}\r\n</component>",
                    (item == null) ? String.Empty : item.InnerXml);

                defaultConfig = sb.ToString();

                item = component.SelectSingleNode("insert");
                if(item != null)
                    referencePosition = new ComponentPosition(item);
                else
                    referencePosition = new ComponentPosition();

                item = component.SelectSingleNode("insertConceptual");
                if(item != null)
                    conceptualPosition = new ComponentPosition(item);
                else
                    conceptualPosition = new ComponentPosition();

                List<string> deps = new List<string>();

                foreach(XPathNavigator dep in component.Select(
                  "dependencies/component"))
                {
                    attrValue = dep.GetAttribute("id", String.Empty);
                    if(!String.IsNullOrEmpty(attrValue))
                        deps.Add(attrValue);
                }

                dependencies = new ReadOnlyCollection<string>(deps);
            }
            catch(Exception ex)
            {
                isValid = false;
                invalidReason = ex.Message;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The XPath navigator containing the
        /// component's configuration information</param>
        internal BuildComponentInfo(XPathNavigator component)
        {
            StringBuilder   sb = new StringBuilder();
            FileVersionInfo fvi;
            XPathNavigator  item;
            string          asmPath, attrValue;

            isValid = true;

            // Load the configuration information from the node
            try
            {
                attrValue = component.GetAttribute("type", String.Empty);

                if (String.IsNullOrEmpty(attrValue))
                {
                    isValid       = false;
                    typeName      = "??";
                    invalidReason = "Missing type name attribute";
                }
                else
                {
                    typeName = attrValue;
                }

                // If no ID, use the type name
                attrValue = component.GetAttribute("id", String.Empty);

                if (!String.IsNullOrEmpty(attrValue))
                {
                    id = attrValue;
                }
                else
                {
                    id = typeName;
                }

                attrValue = component.GetAttribute("assembly", String.Empty);

                if (String.IsNullOrEmpty(attrValue))
                {
                    isValid       = false;
                    assemblyPath  = "??";
                    invalidReason = "Missing assembly attribute";
                }
                else
                {
                    assemblyPath = attrValue;

                    // Try to get copyright and version information
                    asmPath = BuildComponentManager.ResolveComponentPath(
                        assemblyPath);

                    if (File.Exists(asmPath))
                    {
                        fvi       = FileVersionInfo.GetVersionInfo(asmPath);
                        version   = new Version(fvi.FileVersion);
                        copyright = fvi.LegalCopyright;
                    }
                    else
                    {
                        version       = new Version("0.0.0.0");
                        copyright     = "?? - Unable to locate assembly";
                        isValid       = false;
                        invalidReason = "The build component assembly " +
                                        asmPath + " could not be found";
                    }
                }

                // If no description use the type name and assembly path
                item = component.SelectSingleNode("description");
                if (item != null)
                {
                    description = item.Value.Trim();
                }
                else
                {
                    description = typeName + ", " + assemblyPath;
                }

                if (component.SelectSingleNode("hidden") != null)
                {
                    isHidden = true;
                }

                item = component.SelectSingleNode("configureMethod");
                if (item != null)
                {
                    attrValue = item.GetAttribute("name", String.Empty);

                    if (!String.IsNullOrEmpty(attrValue))
                    {
                        configureMethod = attrValue;
                    }
                }

                // The default configuration is wrapped in a <component> tag
                item = component.SelectSingleNode("defaultConfiguration");

                // We need to retain custom attributes on the component as well
                // as the standard id, type, and assembly attributes.
                sb.Append("<component");

                if (component.MoveToFirstAttribute())
                {
                    do
                    {
                        sb.AppendFormat(" {0}=\"{1}\"", component.Name,
                                        component.Value);
                    } while(component.MoveToNextAttribute());

                    component.MoveToParent();
                }

                sb.AppendFormat(CultureInfo.InvariantCulture,
                                ">\r\n{0}\r\n</component>",
                                (item == null) ? String.Empty : item.InnerXml);

                defaultConfig = sb.ToString();

                item = component.SelectSingleNode("insert");
                if (item != null)
                {
                    referencePosition = new ComponentPosition(item);
                }
                else
                {
                    referencePosition = new ComponentPosition();
                }

                item = component.SelectSingleNode("insertConceptual");
                if (item != null)
                {
                    conceptualPosition = new ComponentPosition(item);
                }
                else
                {
                    conceptualPosition = new ComponentPosition();
                }

                List <string> deps = new List <string>();

                foreach (XPathNavigator dep in component.Select(
                             "dependencies/component"))
                {
                    attrValue = dep.GetAttribute("id", String.Empty);
                    if (!String.IsNullOrEmpty(attrValue))
                    {
                        deps.Add(attrValue);
                    }
                }

                dependencies = new ReadOnlyCollection <string>(deps);
            }
            catch (Exception ex)
            {
                isValid       = false;
                invalidReason = ex.Message;
            }
        }