/// <summary> /// This method will be used when deserializing the property from an XML property set. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="propertyValue">The XML node to read the property value from.</param> /// <returns>The value to be assigned to the template property.</returns> public object ReadPropertyXml(PropertySerializerContext context, System.Xml.XmlNode propertyValue) { if (context.PropertyInfo.PropertyType != typeof(ModalEditorProperty)) return null; // use XPath to select out values XPathNavigator navigator = propertyValue.CreateNavigator(); // we need to import the CodeSmith Namespace XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable); manager.AddNamespace("cs", CodeSmithProject.DefaultNamespace); // expresion to select SampleBoolean value XPathExpression sampleBooleanExpression = XPathExpression.Compile("string(cs:SampleBoolean/text())", manager); string boolString = navigator.Evaluate(sampleBooleanExpression) as string; bool sampleBoolean; bool.TryParse(boolString, out sampleBoolean); // expresion to select SampleString value XPathExpression sampleTextExpression = XPathExpression.Compile("string(cs:SampleString/text())", manager); string sampleString = navigator.Evaluate(sampleTextExpression) as string; ModalEditorProperty modalEditorPropertyValue = new ModalEditorProperty(); modalEditorPropertyValue.SampleBoolean = sampleBoolean; modalEditorPropertyValue.SampleString = sampleString; return modalEditorPropertyValue; }
public object ReadPropertyXml(PropertySerializerContext context, XmlNode propertyValue) { if (context.PropertyInfo.PropertyType != typeof(TableConfigurationCollection)) { return(null); } XPathNavigator navigator = propertyValue.CreateNavigator(); XmlNamespaceManager oManager = new XmlNamespaceManager(navigator.NameTable); TableConfigurationCollection collection = new TableConfigurationCollection(); TableConfigurationSerializer itemSerializer = new TableConfigurationSerializer(); // Add the CodeSmith namespace oManager.AddNamespace("cs", CodeSmithProject.DefaultNamespace); // Loop through items XPathNodeIterator oIterator = navigator.Select("cs:TableConfiguration", oManager); while (oIterator.MoveNext()) { collection.Add(itemSerializer.ReadPropertyXmlInner(context, ((IHasXmlNode)oIterator.Current).GetNode())); } return(collection); }
/// <summary> /// This method will be used when deserializing the property from an XML property set. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="propertyValue">The XML node to read the property value from.</param> /// <returns>The value to be assigned to the template property.</returns> public object ReadPropertyXml(PropertySerializerContext context, System.Xml.XmlNode propertyValue) { if (context.PropertyInfo.PropertyType != typeof(DropDownEditorProperty)) { return(null); } // use XPath to select out values XPathNavigator navigator = propertyValue.CreateNavigator(); // we need to import the CodeSmith Namespace XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable); manager.AddNamespace("cs", CodeSmithProject.DefaultNamespace); // expression to select SampleBoolean value XPathExpression sampleBooleanExpression = XPathExpression.Compile("string(cs:SampleBoolean/text())", manager); string boolString = navigator.Evaluate(sampleBooleanExpression) as string; bool sampleBoolean; bool.TryParse(boolString, out sampleBoolean); // expression to select SampleString value XPathExpression sampleTextExpression = XPathExpression.Compile("string(cs:SampleString/text())", manager); string sampleString = navigator.Evaluate(sampleTextExpression) as string; // create and return DropDownEditorProperty dropDownEditorPropertyValue = new DropDownEditorProperty(); dropDownEditorPropertyValue.SampleBoolean = sampleBoolean; dropDownEditorPropertyValue.SampleString = sampleString; return(dropDownEditorPropertyValue); }
public object ReadPropertyXml(PropertySerializerContext context, XmlNode propertyValue) { if (context.PropertyInfo.PropertyType != typeof(TableConfiguration)) { return null; } return ReadPropertyXmlInner(context, propertyValue); }
public object ReadPropertyXml(PropertySerializerContext context, XmlNode propertyValue) { if (context.PropertyInfo.PropertyType != typeof(TableConfiguration)) { return(null); } return(ReadPropertyXmlInner(context, propertyValue)); }
internal TableConfiguration ReadPropertyXmlInner(PropertySerializerContext context, XmlNode propertyValue) { XPathNavigator navigator = propertyValue.CreateNavigator(); XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable); XPathNodeIterator iterator; // Add the CodeSmith namespace manager.AddNamespace("cs", CodeSmithProject.DefaultNamespace); // Get the DatabaseSchema DatabaseSchema databaseSchema = null; iterator = (XPathNodeIterator)navigator.Evaluate("cs:DatabaseSchema", manager); if (iterator.MoveNext()) { XmlNode oNode = ((IHasXmlNode)iterator.Current).GetNode(); databaseSchema = (DatabaseSchema) new DatabaseSchemaSerializer().ReadPropertyXml(context, oNode); } // Get the SourceTable TableSchema sourceTable = null; if (databaseSchema != null) { string strOwner = navigator.Evaluate("string(cs:SourceTable/cs:Owner/text())", manager) as string; string strName = navigator.Evaluate("string(cs:SourceTable/cs:Name/text())", manager) as string; if (!string.IsNullOrEmpty(strName)) { sourceTable = !string.IsNullOrEmpty(strOwner) ? databaseSchema.Tables[strOwner, strName] : databaseSchema.Tables[strName]; } } // Get the SourceView ViewSchema sourceView = null; if (databaseSchema != null) { string strOwner = navigator.Evaluate("string(cs:SourceView/cs:Owner/text())", manager) as string; string strName = navigator.Evaluate("string(cs:SourceView/cs:Name/text())", manager) as string; if (!string.IsNullOrEmpty(strName)) { sourceView = !string.IsNullOrEmpty(strOwner) ? databaseSchema.Views[strOwner, strName] : databaseSchema.Views[strName]; } } // Create and return return(new TableConfiguration { SourceTable = sourceTable, SourceView = sourceView }); }
/// <summary> /// This method will be used when serializing the property value to an XML property set. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="writer">The XML writer that the property value will be written to.</param> /// <param name="propertyValue">The property to be serialized.</param> public void WritePropertyXml(PropertySerializerContext context, System.Xml.XmlWriter writer, object propertyValue) { if (propertyValue == null) { return; } DropDownEditorProperty dropDownEditorPropertyValue = propertyValue as DropDownEditorProperty; if (dropDownEditorPropertyValue != null) { writer.WriteElementString("SampleBoolean", dropDownEditorPropertyValue.SampleBoolean.ToString()); writer.WriteElementString("SampleString", dropDownEditorPropertyValue.SampleString); } }
public void WritePropertyXml(PropertySerializerContext context, XmlWriter writer, object propertyValue) { TableConfigurationCollection collection = propertyValue as TableConfigurationCollection; if (collection != null) { TableConfigurationSerializer itemSerializer = new TableConfigurationSerializer(); foreach (TableConfiguration item in collection) { writer.WriteStartElement("TableConfiguration"); itemSerializer.WritePropertyXml(context, writer, item); writer.WriteEndElement(); } } }
/// <summary> /// This method will be used to parse a default value for a property when a template is being instantiated. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="defaultValue">The default value.</param> /// <returns>An object that will be assigned to the template property.</returns> public object ParseDefaultValue(PropertySerializerContext context, string defaultValue) { if (context.PropertyInfo.PropertyType == typeof(ModalEditorProperty)) { ModalEditorProperty modalEditorPropertyValue = new ModalEditorProperty(); string[] values = defaultValue.Split(','); if (values.Length == 2) { modalEditorPropertyValue.SampleString = values[0]; modalEditorPropertyValue.SampleBoolean = Boolean.Parse(values[1]); return(modalEditorPropertyValue); } return(null); } return(null); }
/// <summary> /// This method will be used to parse a default value for a property when a template is being instantiated. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="defaultValue">The default value.</param> /// <returns>An object that will be assigned to the template property.</returns> public object ParseDefaultValue(PropertySerializerContext context, string defaultValue) { if (context.PropertyInfo.PropertyType == typeof(ModalEditorProperty)) { ModalEditorProperty modalEditorPropertyValue = new ModalEditorProperty(); string[] values = defaultValue.Split(','); if (values.Length == 2) { modalEditorPropertyValue.SampleString = values[0]; modalEditorPropertyValue.SampleBoolean = Boolean.Parse(values[1]); return modalEditorPropertyValue; } return null; } return null; }
public void WritePropertyXml(PropertySerializerContext context, XmlWriter writer, object propertyValue) { TableConfiguration configuration = propertyValue as TableConfiguration; if (configuration != null) { DatabaseSchema database = null; if (configuration.SourceTable != null) { database = configuration.SourceTable.Database; } else if (configuration.SourceView != null) { database = configuration.SourceView.Database; } if (database != null) { writer.WriteStartElement("DatabaseSchema"); new DatabaseSchemaSerializer().WritePropertyXml(context, writer, database); writer.WriteEndElement(); } if (configuration.SourceTable != null) { writer.WriteStartElement("SourceTable"); writer.WriteElementString("Owner", configuration.SourceTable.Owner); writer.WriteElementString("Name", configuration.SourceTable.Name); writer.WriteEndElement(); } if (configuration.SourceView != null) { writer.WriteStartElement("SourceView"); writer.WriteElementString("Owner", configuration.SourceView.Owner); writer.WriteElementString("Name", configuration.SourceView.Name); writer.WriteEndElement(); } } }
/// <summary> /// This method will be used when serializing the property value to an XML property set. /// </summary> /// <param name="propertyInfo">Information about the target property.</param> /// <param name="writer">The XML writer that the property value will be written to.</param> /// <param name="propertyValue">The property to be serialized.</param> public void WritePropertyXml(PropertySerializerContext propertySerializerContext, System.Xml.XmlWriter writer, object propertyValue) { if (propertyValue == null) { return; } MappingProperty mappingPropertyValue = propertyValue as MappingProperty; if (mappingPropertyValue != null) { writer.WriteStartElement("MappingInfoCollection"); foreach (MappingInfo mappingInfo in mappingPropertyValue.MappingInfoCollection) { writer.WriteStartElement("MappingInfo"); writer.WriteElementString("IsPK", mappingInfo.IsPK.ToString()); writer.WriteElementString("IsUnique", mappingInfo.IsUnique.ToString()); writer.WriteElementString("PKGenerator", mappingInfo.PKGenerator); writer.WriteElementString("ClassPropertyName", mappingInfo.ClassPropertyName); writer.WriteElementString("TableColumnName", mappingInfo.TableColumnName); writer.WriteElementString("DataType", mappingInfo.DataType); writer.WriteElementString("DataLength", mappingInfo.DataLength.ToString()); writer.WriteElementString("IsNullable", mappingInfo.IsNullable.ToString()); writer.WriteElementString("PKMany2OnePropertyName", mappingInfo.PKMany2OnePropertyName); writer.WriteElementString("PKMany2OnePropertyDataType", mappingInfo.PKMany2OnePropertyDataType); writer.WriteElementString("IsOne2Many", mappingInfo.IsOne2Many.ToString()); writer.WriteElementString("One2ManyTable", mappingInfo.One2ManyTable); writer.WriteElementString("One2ManyColumn", mappingInfo.One2ManyColumn); writer.WriteElementString("One2ManyInverse", mappingInfo.One2ManyInverse.ToString()); writer.WriteElementString("One2ManyLazy", mappingInfo.One2ManyLazy.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); } }
/// <summary> /// This method will be used when deserializing the property from an XML property set. /// </summary> /// <param name="propertyInfo">Information about the target property.</param> /// <param name="propertyValue">The XML node to read the property value from.</param> /// <param name="basePath">The path to use for resolving file references.</param> /// <returns>The value to be assigned to the template property.</returns> public object ReadPropertyXml(PropertySerializerContext propertySerializerContext, System.Xml.XmlNode propertyValue) { if (propertySerializerContext.PropertyInfo.PropertyType == typeof(MappingProperty)) { MappingProperty mappingPropertyValue = new MappingProperty(); XmlNodeList nodes = propertyValue.SelectNodes("MappingInfoCollection/MappingInfo"); foreach (XmlNode node in nodes) { MappingInfo mappingInfo = new MappingInfo(); mappingInfo.IsPK = bool.Parse(node.SelectSingleNode("IsPK").InnerText); mappingInfo.IsUnique = bool.Parse(node.SelectSingleNode("IsUnique").InnerText); mappingInfo.PKGenerator = node.SelectSingleNode("PKGenerator").InnerText; mappingInfo.ClassPropertyName = node.SelectSingleNode("ClassPropertyName").InnerText; mappingInfo.TableColumnName = node.SelectSingleNode("TableColumnName").InnerText; mappingInfo.DataType = node.SelectSingleNode("DataType").InnerText; mappingInfo.DataLength = int.Parse(node.SelectSingleNode("DataLength").InnerText); mappingInfo.PKMany2OnePropertyName = node.SelectSingleNode("PKMany2OnePropertyName").InnerText; mappingInfo.PKMany2OnePropertyDataType = node.SelectSingleNode("PKMany2OnePropertyDataType").InnerText; mappingInfo.IsOne2Many = bool.Parse(node.SelectSingleNode("IsOne2Many").InnerText); mappingInfo.One2ManyTable = node.SelectSingleNode("One2ManyTable").InnerText; mappingInfo.One2ManyColumn = node.SelectSingleNode("One2ManyColumn").InnerText; mappingInfo.One2ManyInverse = bool.Parse(node.SelectSingleNode("One2ManyInverse").InnerText); mappingInfo.One2ManyLazy = bool.Parse(node.SelectSingleNode("One2ManyLazy").InnerText); mappingPropertyValue.MappingInfoCollection.Add(mappingInfo); } return(mappingPropertyValue); } else { return(null); } }
public object ReadPropertyXml(PropertySerializerContext context, XmlNode propertyValue) { if (context.PropertyInfo.PropertyType != typeof(TableConfigurationCollection)) { return null; } XPathNavigator navigator = propertyValue.CreateNavigator(); XmlNamespaceManager oManager = new XmlNamespaceManager(navigator.NameTable); TableConfigurationCollection collection = new TableConfigurationCollection(); TableConfigurationSerializer itemSerializer = new TableConfigurationSerializer(); // Add the CodeSmith namespace oManager.AddNamespace("cs", CodeSmithProject.DefaultNamespace); // Loop through items XPathNodeIterator oIterator = navigator.Select("cs:TableConfiguration", oManager); while (oIterator.MoveNext()) { collection.Add(itemSerializer.ReadPropertyXmlInner(context, ((IHasXmlNode)oIterator.Current).GetNode())); } return collection; }
public object ParseDefaultValue(PropertySerializerContext context, string defaultValue) { return null; }
internal TableConfiguration ReadPropertyXmlInner(PropertySerializerContext context, XmlNode propertyValue) { XPathNavigator navigator = propertyValue.CreateNavigator(); XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable); XPathNodeIterator iterator; // Add the CodeSmith namespace manager.AddNamespace("cs", CodeSmithProject.DefaultNamespace); // Get the DatabaseSchema DatabaseSchema databaseSchema = null; iterator = (XPathNodeIterator)navigator.Evaluate("cs:DatabaseSchema", manager); if (iterator.MoveNext()) { XmlNode oNode = ((IHasXmlNode)iterator.Current).GetNode(); databaseSchema = (DatabaseSchema)new DatabaseSchemaSerializer().ReadPropertyXml(context, oNode); } // Get the SourceTable TableSchema sourceTable = null; if (databaseSchema != null) { string strOwner = navigator.Evaluate("string(cs:SourceTable/cs:Owner/text())", manager) as string; string strName = navigator.Evaluate("string(cs:SourceTable/cs:Name/text())", manager) as string; if (!string.IsNullOrEmpty(strName)) { sourceTable = !string.IsNullOrEmpty(strOwner) ? databaseSchema.Tables[strOwner, strName] : databaseSchema.Tables[strName]; } } // Get the SourceView ViewSchema sourceView = null; if (databaseSchema != null) { string strOwner = navigator.Evaluate("string(cs:SourceView/cs:Owner/text())", manager) as string; string strName = navigator.Evaluate("string(cs:SourceView/cs:Name/text())", manager) as string; if (!string.IsNullOrEmpty(strName)) { sourceView = !string.IsNullOrEmpty(strOwner) ? databaseSchema.Views[strOwner, strName] : databaseSchema.Views[strName]; } } // Create and return return new TableConfiguration { SourceTable = sourceTable, SourceView = sourceView }; }
/// <summary> /// This method will be used to restore the property value after a template has been compiled. /// </summary> /// <param name="propertyInfo">Information about the target property.</param> /// <param name="propertyValue">The property to be loaded.</param> /// <returns>The value to be assigned to the template property after it has been compiled.</returns> public object LoadProperty(PropertySerializerContext propertySerializerContext, object propertyValue) { // Nothing special needs to be done to load this property so we just return the unmodified property value. return(propertyValue); }
/// <summary> /// This method will be used to parse a default value for a property when a template is being instantiated. /// </summary> /// <param name="propertyInfo">Information about the target property.</param> /// <param name="defaultValue">The default value.</param> /// <param name="basePath">The path to use for resolving file references.</param> /// <returns>An object that will be assigned to the template property.</returns> public object ParseDefaultValue(PropertySerializerContext propertySerializerContext, string defaultValue) { return(null); }
public object ParseDefaultValue(PropertySerializerContext context, string defaultValue) { return new TableConfigurationCollection(); }
/// <summary> /// This method will be used to restore the property value after a template has been compiled. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="propertyValue">The property to be loaded.</param> /// <returns>The value to be assigned to the template property after it has been compiled.</returns> public object LoadProperty(PropertySerializerContext context, object propertyValue) { // Nothing special needs to be done to load this property so we just return the unmodified property value. return propertyValue; }
/// <summary> /// This method will be used when serializing the property value to an XML property set. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="writer">The XML writer that the property value will be written to.</param> /// <param name="propertyValue">The property to be serialized.</param> public void WritePropertyXml(PropertySerializerContext context, System.Xml.XmlWriter writer, object propertyValue) { if (propertyValue == null) return; ModalEditorProperty modalEditorPropertyValue = propertyValue as ModalEditorProperty; if (modalEditorPropertyValue != null) { writer.WriteElementString("SampleBoolean", modalEditorPropertyValue.SampleBoolean.ToString()); writer.WriteElementString("SampleString", modalEditorPropertyValue.SampleString); } }
public object SaveProperty(PropertySerializerContext context, object propertyValue) { return propertyValue; }
public object ParseDefaultValue(PropertySerializerContext context, string defaultValue) { return(new TableConfigurationCollection()); }
public object LoadProperty(PropertySerializerContext context, object propertyValue) { return(propertyValue); }