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); }
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)); }
private XmlNodeList GetEnumeration(ITypeDescriptorContext context, XmlNode simpleType) { if (enumeration == null) { XmlAttributeAdapter adapter = context.Instance as XmlAttributeAdapter; enumeration = simpleType.SelectNodes("xs:restriction/xs:enumeration", adapter.WixFiles.XsdNsmgr); } return(enumeration); }
public void SetDefaultValues(XmlNode node, XmlNode parentNode) { if (node.Name.ToLower() == "control") { int left = 0; int top = 0; int width = 50; int height = 17; XmlAttribute typeAtt = node.Attributes["Type"]; if (typeAtt != null && typeAtt.Value.Length > 0) { switch (typeAtt.Value.ToLower()) { case "pushbutton": width = 56; height = 17; break; default: break; } } XmlAttribute att = WixFiles.WxsDocument.CreateAttribute("Width"); att.Value = width.ToString(); node.Attributes.Append(att); att = WixFiles.WxsDocument.CreateAttribute("Height"); att.Value = height.ToString(); node.Attributes.Append(att); att = WixFiles.WxsDocument.CreateAttribute("X"); att.Value = left.ToString(); node.Attributes.Append(att); att = WixFiles.WxsDocument.CreateAttribute("Y"); att.Value = top.ToString(); node.Attributes.Append(att); } else { // A sub-node int width = 50; int height = 17; int left = 0; int top = parentNode.ChildNodes.Count * height * 3 / 2; XmlAttributeAdapter attAdapter = new XmlAttributeAdapter(node, WixFiles); XmlNodeList xmlAttributes = attAdapter.XmlNodeDefinition.SelectNodes("xs:attribute", WixFiles.XsdNsmgr); foreach (XmlNode at in xmlAttributes) { string attName = at.Attributes["name"].Value; // Add only required attributes if ((at.Attributes["use"] != null && at.Attributes["use"].Value == "required") || (attName == "Value")) { XmlAttribute att = WixFiles.WxsDocument.CreateAttribute(attName); switch (attName) { case "Width": att.Value = width.ToString(); break; case "Height": att.Value = height.ToString(); // Give the parent more room to display this item if (parentNode.ParentNode != null && parentNode.ParentNode.Attributes["Height"] != null) { try { int currentParentHeight = Int32.Parse(parentNode.ParentNode.Attributes["Height"].Value); if (currentParentHeight < top + height) { parentNode.ParentNode.Attributes["Height"].Value = (top + height).ToString(); } } catch { } } break; case "X": att.Value = left.ToString(); break; case "Y": att.Value = top.ToString(); break; } node.Attributes.Append(att); } } } }
private void ShowWixProperties(XmlNode xmlNode) { XmlAttributeAdapter attAdapter = null; if (xmlNode != null) { attAdapter = new XmlAttributeAdapter(xmlNode, WixFiles); } CurrentGrid.SelectedObject = null; CurrentGrid.SelectedObject = attAdapter; CurrentGrid.Update(); return; }
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 */ }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { XmlAttributeAdapter adapter = context.Instance as XmlAttributeAdapter; XmlNode xmlNode = adapter.XmlNode; string nodeNameRef = xmlNode.Name; if (nodeNameRef.EndsWith("Ref")) { string nodeName = nodeNameRef.Remove(nodeNameRef.Length - 3, 3); XmlNodeList referencedNodes = null; if (nodeName.IndexOf(":") < 0) { referencedNodes = xmlNode.OwnerDocument.SelectNodes(String.Format("//wix:{0}", nodeName), adapter.WixFiles.WxsNsmgr); } else { referencedNodes = xmlNode.OwnerDocument.SelectNodes(String.Format("//{0}", nodeName), adapter.WixFiles.WxsNsmgr); } ArrayList strings = new ArrayList(); foreach (XmlNode node in referencedNodes) { if (node.Attributes["Id"] != null) { strings.Add(node.Attributes["Id"].Value); } } return(new StandardValuesCollection(strings.ToArray(typeof(string)))); } else if (xmlNode.Attributes["BinaryKey"] != null) { XmlNodeList referencedNodes = xmlNode.OwnerDocument.SelectNodes("//wix:Binary", adapter.WixFiles.WxsNsmgr); ArrayList strings = new ArrayList(); foreach (XmlNode node in referencedNodes) { strings.Add(node.Attributes["Id"].Value); } return(new StandardValuesCollection(strings.ToArray(typeof(string)))); } else if (xmlNode.Attributes["FileKey"] != null) { XmlNodeList referencedNodes = xmlNode.OwnerDocument.SelectNodes("//wix:File", adapter.WixFiles.WxsNsmgr); ArrayList strings = new ArrayList(); foreach (XmlNode node in referencedNodes) { strings.Add(node.Attributes["Id"].Value); } return(new StandardValuesCollection(strings.ToArray(typeof(string)))); } else { throw new Exception(nodeNameRef + " should be a reference to another nodes. (Should end on \"Ref\")"); } }
public override void SetValue(object component, object value) { wixFiles.UndoManager.BeginNewCommandRange(); // Object can be a Int or DateTime or String. Etc. if (value == null) { wixFiles.UndoManager.StartPropertyGridEdit(); Attribute.Value = String.Empty; wixFiles.UndoManager.EndPropertyGridEdit(); } else { string stringValue = value.ToString(); XmlAttributeAdapter adapter = component as XmlAttributeAdapter; XmlNode simpleType = null; if (AttributeDescription != null) { XmlAttribute typeAttrib = AttributeDescription.Attributes["type"]; if (typeAttrib == null) { simpleType = AttributeDescription.SelectSingleNode("xs:simpleType", adapter.WixFiles.XsdNsmgr); } else { string simpleTypeString = AttributeDescription.Attributes["type"].Value; string selectString = String.Format("/xs:schema/xs:simpleType[@name='{0}']", simpleTypeString); simpleType = AttributeDescription.OwnerDocument.SelectSingleNode(selectString, adapter.WixFiles.XsdNsmgr); } } if (simpleType != null) { XmlNode pattern = simpleType.SelectSingleNode("xs:restriction/xs:pattern", adapter.WixFiles.XsdNsmgr); if (pattern != null && pattern.Attributes["value"] != null) { string patternValue = pattern.Attributes["value"].Value; if (patternValue != null && patternValue.Length > 0) { Match match = Regex.Match(stringValue, patternValue); if (match.Success == false) { XmlNode documentation = simpleType.SelectSingleNode("xs:annotation/xs:documentation", adapter.WixFiles.XsdNsmgr); if (documentation != null) { throw new Exception(documentation.InnerText); } else { throw new Exception("Invalide by xsd definition"); } } } } } wixFiles.UndoManager.StartPropertyGridEdit(); Attribute.Value = value.ToString(); wixFiles.UndoManager.EndPropertyGridEdit(); } }