Пример #1
0
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            XmlAttributeAdapter            adapter = context.Instance as XmlAttributeAdapter;
            XmlAttributePropertyDescriptor desc    = context.PropertyDescriptor as XmlAttributePropertyDescriptor;

            XmlNode simpleType = GetSimpleType(desc.AttributeDescription, adapter.WixFiles.XsdNsmgr);

            if (simpleType != null)
            {
                XmlNodeList e = GetEnumeration(context);

                if (IsValidEnumeration(e) == false)
                {
                    return(false);
                }

                XmlNode      restriction = simpleType.SelectSingleNode("xs:restriction", adapter.WixFiles.XsdNsmgr);
                XmlAttribute baseAtt     = restriction.Attributes["base"];
                if (baseAtt != null && baseAtt.Value != null)
                {
                    if (baseAtt.Value.ToLower() == "xs:nmtoken")
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #2
0
        private XmlNodeList GetEnumeration(ITypeDescriptorContext context)
        {
            XmlAttributeAdapter            adapter = context.Instance as XmlAttributeAdapter;
            XmlAttributePropertyDescriptor desc    = context.PropertyDescriptor as XmlAttributePropertyDescriptor;

            XmlNode simpleType = GetSimpleType(desc.AttributeDescription, adapter.WixFiles.XsdNsmgr);

            return(GetEnumeration(context, simpleType));
        }
Пример #3
0
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            if (xmlNodeDefinition == null)
            {
                // maybe the existing properties can be edited?
                ArrayList properties = new ArrayList();
                foreach (XmlAttribute xmlAttribute in xmlNode.Attributes)
                {
                    // We could add an UITypeEditor if desired
                    ArrayList attrs = new ArrayList();
                    attrs.Add(new EditorAttribute(typeof(UITypeEditor), typeof(UITypeEditor)));
                    attrs.Add(new CategoryAttribute("WXS Attribute"));
                    attrs.Add(new TypeConverterAttribute(typeof(StringConverter)));


                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    XmlAttributePropertyDescriptor pd = new XmlAttributePropertyDescriptor(wixFiles, xmlAttribute, null,
                                                                                           xmlAttribute.Name, attrArray);

                    properties.Add(pd);
                }


                PropertyDescriptor[] propertiesArray = properties.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[];

                return(new PropertyDescriptorCollection(propertiesArray));
            }

            ArrayList props = new ArrayList();

            // Show all existing + required elements
            XmlNodeList xmlAttributeDefinitions = xmlNodeDefinition.SelectNodes("xs:attribute", wixFiles.XsdNsmgr);

            foreach (XmlNode xmlAttributeDefinition in xmlAttributeDefinitions)
            {
                XmlAttribute xmlAttribute = xmlNode.Attributes[xmlAttributeDefinition.Attributes["name"].Value];

                if (xmlAttribute == null)
                {
                    if (xmlAttributeDefinition.Attributes["use"] == null ||
                        xmlAttributeDefinition.Attributes["use"].Value != "required")
                    {
                        continue;
                    }

                    // If there is no attibute present, create one.
                    if (xmlAttribute == null)
                    {
                        // Do not call UndoManager.BeginNewCommandRange here, because this can happen after
                        // an undo/redo action when viewing some node. That would mess up the undo mechanism.
                        // So the adding of mandatory attributes will be added to the last undo command sequence.

                        xmlAttribute = xmlNode.OwnerDocument.CreateAttribute(xmlAttributeDefinition.Attributes["name"].Value);
                        xmlNode.Attributes.Append(xmlAttribute);
                    }
                }

                ArrayList attrs = new ArrayList();

                // Add default attributes Category, TypeConverter and Description
                attrs.Add(new CategoryAttribute("WXS Attribute"));
                attrs.Add(new TypeConverterAttribute(GetAttributeTypeConverter(xmlAttributeDefinition)));

                // Get some documentation
                XmlNode deprecated    = xmlAttributeDefinition.SelectSingleNode("xs:annotation/xs:appinfo/xse:deprecated", wixFiles.XsdNsmgr);
                XmlNode documentation = xmlAttributeDefinition.SelectSingleNode("xs:annotation/xs:documentation", wixFiles.XsdNsmgr);
                if (deprecated != null || documentation != null)
                {
                    string docuString = "";
                    if (deprecated != null)
                    {
                        docuString = "** DEPRECATED **\r\n";
                    }

                    if (documentation != null)
                    {
                        docuString = documentation.InnerText;
                        docuString = docuString.Replace("\t", " ");
                        docuString = docuString.Replace("\r\n", " ");
                    }

                    string tmpDocuString = docuString;
                    do
                    {
                        docuString    = tmpDocuString;
                        tmpDocuString = docuString.Replace("  ", " ");
                    } while (docuString != tmpDocuString);

                    docuString = tmpDocuString;
                    docuString = docuString.Trim(' ');

                    attrs.Add(new DescriptionAttribute(docuString));
                }

                bool needsBrowse = false;
                if (xmlAttributeDefinition.Attributes["name"] != null)
                {
                    string attName = xmlNodeElement.Attributes["name"].Value;

                    if (xmlAttributeDefinition.Attributes["name"].Value == "SourceFile")
                    {
                        needsBrowse = true;
                    }
                    else if (xmlAttributeDefinition.Attributes["name"].Value == "Source")
                    {
                        needsBrowse = true;
                    }
                    else if (xmlAttributeDefinition.Attributes["name"].Value == "FileSource")
                    {
                        needsBrowse = true;
                    }
                    else if (xmlAttributeDefinition.Attributes["name"].Value == "Layout")
                    {
                        needsBrowse = true;
                    }
                    else if (xmlAttributeDefinition.Attributes["name"].Value == "src")
                    {
                        needsBrowse = true;
                    }
                }

                if (needsBrowse)
                {
                    // We could add an UITypeEditor if desired
                    attrs.Add(new EditorAttribute(typeof(FilteredFileNameEditor), typeof(System.Drawing.Design.UITypeEditor)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // BinaryElementPropertyDescriptor also uses the src attribute, and a possibility to use relative paths.
                    FileXmlAttributePropertyDescriptor pd = new FileXmlAttributePropertyDescriptor(xmlNode, wixFiles, xmlAttributeDefinition, xmlAttributeDefinition.Attributes["name"].Value, attrArray);

                    props.Add(pd);
                }
                else
                {
                    // We could add an UITypeEditor if desired
                    // attrs.Add(new EditorAttribute(?property.EditorTypeName?, typeof(UITypeEditor)));
                    attrs.Add(new EditorAttribute(GetAttributeEditor(xmlAttributeDefinition), typeof(UITypeEditor)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    XmlAttributePropertyDescriptor pd = new XmlAttributePropertyDescriptor(wixFiles, xmlAttribute, xmlAttributeDefinition,
                                                                                           xmlAttributeDefinition.Attributes["name"].Value, attrArray);

                    props.Add(pd);
                }
            }

            // Add InnerText if required or present.
            if (
                (XmlNodeDefinition.Name == "xs:extension" &&
                 ((xmlNode.InnerText != null && xmlNode.InnerText.Length > 0) || showInnerTextIfEmpty == true)) ||
                (XmlNodeDefinition.Name == "xs:element" && showInnerTextIfEmpty == true))
            {
                ArrayList attrs = new ArrayList();

                // Add default attributes Category, TypeConverter and Description
                attrs.Add(new CategoryAttribute("WXS Attribute"));
                attrs.Add(new TypeConverterAttribute(typeof(StringConverter)));
                attrs.Add(new EditorAttribute(typeof(MultiLineUITypeEditor), typeof(UITypeEditor)));
                attrs.Add(new DescriptionAttribute("InnerText of the element."));


                // Make Attribute array
                Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                // Create and add PropertyDescriptor
                InnerTextPropertyDescriptor pd = new InnerTextPropertyDescriptor(wixFiles, xmlNode, attrArray);

                props.Add(pd);
            }

            if (editSubNodes)
            {
                XmlNodeList subNodes = xmlNode.SelectNodes("*", WixFiles.WxsNsmgr);
                if (subNodes.Count >= 1)
                {
                    ArrayList attrs = new ArrayList();

                    if (subNodes.Count == 1)
                    {
                        attrs.Add(new EditorAttribute(typeof(SearchElementTypeEditor), typeof(UITypeEditor)));
                        attrs.Add(new DescriptionAttribute("Sub Elements of the element."));
                    }

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    PropertySearchElementPropertyDescriptor pd = new PropertySearchElementPropertyDescriptor(wixFiles, xmlNode,
                                                                                                             "SubElements", attrArray);

                    props.Add(pd);
                }
            }

            PropertyDescriptor[] propArray = props.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[];

            return(new PropertyDescriptorCollection(propArray));
        }
Пример #4
0
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            if (xmlNodeDefinition == null) {
                // maybe the existing properties can be edited?
                ArrayList properties = new ArrayList();
                foreach (XmlAttribute xmlAttribute in xmlNode.Attributes) {
                    // We could add an UITypeEditor if desired
                    ArrayList attrs = new ArrayList();
                    attrs.Add(new EditorAttribute(typeof(UITypeEditor), typeof(UITypeEditor)));
                    attrs.Add(new CategoryAttribute("WXS Attribute"));
                    attrs.Add(new TypeConverterAttribute(typeof(StringConverter)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    XmlAttributePropertyDescriptor pd = new XmlAttributePropertyDescriptor(wixFiles, xmlAttribute, null,
                        xmlAttribute.Name, attrArray);

                    properties.Add(pd);
                }

                PropertyDescriptor[] propertiesArray = properties.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[];

                return new PropertyDescriptorCollection(propertiesArray);
            }

            ArrayList props = new ArrayList();

            // Show all existing + required elements
            XmlNodeList xmlAttributeDefinitions = xmlNodeDefinition.SelectNodes("xs:attribute", wixFiles.XsdNsmgr);
            foreach(XmlNode xmlAttributeDefinition in xmlAttributeDefinitions) {
                XmlAttribute xmlAttribute = xmlNode.Attributes[xmlAttributeDefinition.Attributes["name"].Value];

                if (xmlAttribute == null) {
                    if (xmlAttributeDefinition.Attributes["use"] == null ||
                        xmlAttributeDefinition.Attributes["use"].Value != "required") {
                        continue;
                    }

                    // If there is no attibute present, create one.
                    if (xmlAttribute == null) {
                        // Do not call UndoManager.BeginNewCommandRange here, because this can happen after
                        // an undo/redo action when viewing some node. That would mess up the undo mechanism.
                        // So the adding of mandatory attributes will be added to the last undo command sequence.

                        xmlAttribute = xmlNode.OwnerDocument.CreateAttribute(xmlAttributeDefinition.Attributes["name"].Value);
                        xmlNode.Attributes.Append(xmlAttribute);
                    }
                }

                ArrayList attrs = new ArrayList();

                // Add default attributes Category, TypeConverter and Description
                attrs.Add(new CategoryAttribute("WXS Attribute"));
                attrs.Add(new TypeConverterAttribute(GetAttributeTypeConverter(xmlAttributeDefinition)));

                // Get some documentation
                XmlNode deprecated = xmlAttributeDefinition.SelectSingleNode("xs:annotation/xs:appinfo/xse:deprecated", wixFiles.XsdNsmgr);
                XmlNode documentation = xmlAttributeDefinition.SelectSingleNode("xs:annotation/xs:documentation", wixFiles.XsdNsmgr);
                if(deprecated != null || documentation != null) {
                    string docuString = "";
                    if(deprecated != null) {
                        docuString = "** DEPRECATED **\r\n";
                    }

                    if (documentation != null) {
                        docuString = documentation.InnerText;
                        docuString = docuString.Replace("\t", " ");
                        docuString = docuString.Replace("\r\n", " ");
                    }

                    string tmpDocuString = docuString;
                    do {
                        docuString = tmpDocuString;
                        tmpDocuString = docuString.Replace("  ", " ");
                    } while (docuString != tmpDocuString);

                    docuString = tmpDocuString;
                    docuString = docuString.Trim(' ');

                    attrs.Add(new DescriptionAttribute(docuString));
                }

                bool needsBrowse = false;
                if (xmlAttributeDefinition.Attributes["name"] != null) {
                    string attName = xmlNodeElement.Attributes["name"].Value;

                    if (xmlAttributeDefinition.Attributes["name"].Value == "SourceFile") {
                        needsBrowse = true;
                    } else if (xmlAttributeDefinition.Attributes["name"].Value == "Source") {
                        needsBrowse = true;
                    } else if (xmlAttributeDefinition.Attributes["name"].Value == "FileSource") {
                        needsBrowse = true;
                    } else if (xmlAttributeDefinition.Attributes["name"].Value == "Layout") {
                        needsBrowse = true;
                    } else if (xmlAttributeDefinition.Attributes["name"].Value == "src") {
                        needsBrowse = true;
                    }
                }

                if (needsBrowse) {
                    // We could add an UITypeEditor if desired
                    attrs.Add(new EditorAttribute(typeof(FilteredFileNameEditor),typeof(System.Drawing.Design.UITypeEditor)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // BinaryElementPropertyDescriptor also uses the src attribute, and a possibility to use relative paths.
                    FileXmlAttributePropertyDescriptor pd = new FileXmlAttributePropertyDescriptor(xmlNode, wixFiles, xmlAttributeDefinition, xmlAttributeDefinition.Attributes["name"].Value, attrArray);

                    props.Add(pd);
                } else {
                    // We could add an UITypeEditor if desired
                    // attrs.Add(new EditorAttribute(?property.EditorTypeName?, typeof(UITypeEditor)));
                    attrs.Add(new EditorAttribute(GetAttributeEditor(xmlAttributeDefinition), typeof(UITypeEditor)));

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    XmlAttributePropertyDescriptor pd = new XmlAttributePropertyDescriptor(wixFiles, xmlAttribute, xmlAttributeDefinition,
                        xmlAttributeDefinition.Attributes["name"].Value, attrArray);

                    props.Add(pd);
                }
            }

            // Add InnerText if required or present.
            if (
                (XmlNodeDefinition.Name == "xs:extension" &&
                    ( (xmlNode.InnerText != null && xmlNode.InnerText.Length > 0) || showInnerTextIfEmpty == true) ) ||
                (XmlNodeDefinition.Name == "xs:element" && showInnerTextIfEmpty == true) ) {
                ArrayList attrs = new ArrayList();

                // Add default attributes Category, TypeConverter and Description
                attrs.Add(new CategoryAttribute("WXS Attribute"));
                attrs.Add(new TypeConverterAttribute(typeof(StringConverter)));
                attrs.Add(new EditorAttribute(typeof(MultiLineUITypeEditor), typeof(UITypeEditor)));
                attrs.Add(new DescriptionAttribute("InnerText of the element."));

                // Make Attribute array
                Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                // Create and add PropertyDescriptor
                InnerTextPropertyDescriptor pd = new InnerTextPropertyDescriptor(wixFiles, xmlNode, attrArray);

                props.Add(pd);
            }

            if (editSubNodes)
            {
                XmlNodeList subNodes = xmlNode.SelectNodes("*", WixFiles.WxsNsmgr);
                if (subNodes.Count >= 1)
                {
                    ArrayList attrs = new ArrayList();

                    if (subNodes.Count == 1)
                    {
                        attrs.Add(new EditorAttribute(typeof(SearchElementTypeEditor), typeof(UITypeEditor)));
                        attrs.Add(new DescriptionAttribute("Sub Elements of the element."));
                    }

                    // Make Attribute array
                    Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                    // Create and add PropertyDescriptor
                    PropertySearchElementPropertyDescriptor pd = new PropertySearchElementPropertyDescriptor(wixFiles, xmlNode,
                        "SubElements", attrArray);

                    props.Add(pd);
                }
            }

            PropertyDescriptor[] propArray = props.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[];

            return new PropertyDescriptorCollection(propArray);
        }
Пример #5
0
        public override bool IsValid(ITypeDescriptorContext context, object value)
        {
            if (base.IsValid(context, value) == false)
            {
                return(false);
            }

            XmlAttributeAdapter            adapter = context.Instance as XmlAttributeAdapter;
            XmlAttributePropertyDescriptor desc    = context.PropertyDescriptor as XmlAttributePropertyDescriptor;

            long minVal = Int64.MinValue;
            long maxVal = Int64.MaxValue;

            XmlNode restriction = null;

            string typeString = desc.AttributeDescription.Attributes["type"].Value;

            if (typeString.StartsWith("xs:") == false)
            {
                XmlNode simpleType = GetSimpleType(desc.AttributeDescription, adapter.WixFiles.XsdNsmgr);

                if (simpleType != null)
                {
                    restriction = simpleType.SelectSingleNode("xs:restriction", adapter.WixFiles.XsdNsmgr);
                    if (IsValidAttribute(restriction.Attributes["base"]))
                    {
                        typeString = restriction.Attributes["base"].Value;
                    }
                }
            }

            switch (typeString.ToLower())
            {
            case "xs:integer":
                break;

            case "xs:long":
                minVal = long.MinValue;
                maxVal = long.MaxValue;
                break;

            case "xs:int":
                minVal = int.MinValue;
                maxVal = int.MaxValue;
                break;

            case "xs:short":
                minVal = short.MinValue;
                maxVal = short.MaxValue;
                break;

            case "xs:byte":
                minVal = byte.MinValue;
                maxVal = byte.MaxValue;
                break;

            case "xs:nonnegativeinteger":
            case "xs:positiveInteger":
                minVal = 0;
                break;

            case "xs:unsignedlong":
                minVal = 0;
                maxVal = long.MaxValue;
                break;

            case "xs:unsignedint":
                minVal = 0;
                maxVal = int.MaxValue;
                break;

            case "xs:unsignedshort":
                minVal = 0;
                maxVal = short.MaxValue;
                break;

            case "xs:unsignedbyte":
                minVal = 0;
                maxVal = byte.MaxValue;
                break;

            case "xs:nonpositiveinteger":
            case "xs:negativeinteger":
                maxVal = 0;
                break;

            default:
                throw new WixEditException(typeString + " is a non supported type!");
            }


            if (restriction != null)
            {
                XmlNode restrictionSubNode = restriction.SelectSingleNode("xs:maxExclusive", adapter.WixFiles.XsdNsmgr);
                if (restrictionSubNode != null &&
                    IsValidAttribute(restrictionSubNode.Attributes["value"]))
                {
                    maxVal = Int64.Parse(restrictionSubNode.Attributes["value"].Value) - 1;
                }

                restrictionSubNode = restriction.SelectSingleNode("xs:maxInclusive", adapter.WixFiles.XsdNsmgr);
                if (restrictionSubNode != null &&
                    IsValidAttribute(restrictionSubNode.Attributes["value"]))
                {
                    maxVal = Int64.Parse(restrictionSubNode.Attributes["value"].Value);
                }

                restrictionSubNode = restriction.SelectSingleNode("xs:minExclusive", adapter.WixFiles.XsdNsmgr);
                if (restrictionSubNode != null &&
                    IsValidAttribute(restrictionSubNode.Attributes["value"]))
                {
                    minVal = Int64.Parse(restrictionSubNode.Attributes["value"].Value) + 1;
                }

                restrictionSubNode = restriction.SelectSingleNode("xs:minInclusive", adapter.WixFiles.XsdNsmgr);
                if (restrictionSubNode != null &&
                    IsValidAttribute(restrictionSubNode.Attributes["value"]))
                {
                    minVal = Int64.Parse(restrictionSubNode.Attributes["value"].Value);
                }
            }

            Int64 intValue = (Int64)value;

            if (intValue > maxVal)
            {
                return(false);
            }

            if (intValue < minVal)
            {
                return(false);
            }

            return(true);

            /*
             *
             * enumeration
             * fractionDigits
             * length
             * maxExclusive
             * maxInclusive
             * maxLength
             * minExclusive
             * minInclusive
             * minLength
             * pattern
             * totalDigits
             * whiteSpace
             */
        }