public void ProcessScriptBase(IScriptBase scriptBase, XmlNode scriptBaseNode) { /* * <Name>Table1</Name> * <Description /> * <Enabled>False</Enabled> * <IsUserDefined>False</IsUserDefined> * <UID>00000000-0000-0000-0000-000000000000</UID> */ NodeProcessor proc = new NodeProcessor(scriptBaseNode); scriptBase.Name = proc.GetString("Name"); scriptBase.Schema = proc.GetString("Schema"); scriptBase.Description = proc.GetString("Description"); scriptBase.Enabled = proc.GetBool("Enabled"); scriptBase.IsUserDefined = proc.GetBool("IsUserDefined"); if (proc.Exists(VirtualPropertyDeserialiser.VirtualPropertiesNodeName)) { var deserialiser = new VirtualPropertyDeserialiser(); scriptBase.Ex = deserialiser.DeserialiseVirtualProperties( scriptBaseNode.SelectSingleNode(VirtualPropertyDeserialiser.VirtualPropertiesNodeName)); } }
public Property DeserialiseProperty(XmlNode propertyNode, EntityImpl parentEntity) { Property property = new PropertyImpl(); property.Entity = parentEntity; NodeProcessor processor = new NodeProcessor(propertyNode); if (processor.Exists("IsKey")) { property.IsKeyProperty = processor.GetBool("IsKey"); } property.Name = processor.GetString("Name"); property.ReadOnly = processor.GetBool("ReadOnly"); property.Type = processor.GetString("Type"); if (processor.Exists("NHibernateType")) { property.NHibernateType = processor.GetString("NHibernateType"); } if (processor.Exists("Validation")) { property.ValidationOptions = DeserialiseValidationOptions(propertyNode.SelectSingleNode("Validation")); } else { property.ValidationOptions = new ValidationOptions(); } if (processor.Exists("IsHiddenByAbstractParent")) { property.IsHiddenByAbstractParent = processor.GetBool("IsHiddenByAbstractParent"); } if (processor.Exists("IsPartOfHiddenKey")) { property.IsPartOfHiddenKey = processor.GetBool("IsPartOfHiddenKey"); } ProcessScriptBase(property, propertyNode); return(property); }
public EntityKey DeserialiseKey(XmlNode keyNode, Entity parentEntity) { var key = new EntityKeyImpl(); key.Parent = parentEntity; if (keyNode.InnerXml == "") { return(key); } NodeProcessor keyProc = new NodeProcessor(keyNode); bool propertiesExist = false; bool componentExists = false; var nodes = keyNode.SelectNodes("Properties/Property"); if (nodes != null) { propertiesExist = true; foreach (XmlNode node in nodes) { key.AddProperty(node.InnerText); } } if (keyProc.Exists("Component")) { componentExists = true; string componentName = keyProc.SubNode("Component").Attributes.GetString("name"); Component component = parentEntity.Components.FirstOrDefault(c => c.Name == componentName); if (component == null) { throw new DeserialisationException(string.Format("Could not find component named {0} on Entity {1}", componentName, parentEntity.Name)); } key.Component = component; } if (keyProc.Attributes.Exists("keytype")) { key.KeyType = keyProc.Attributes.GetEnum <EntityKeyType>("keytype"); } else if (propertiesExist && componentExists) { throw new DeserialisationException(string.Format("Both a Component and a set of Properties were listed as the Key for entity {0}, but no keytype attribute was found on the Key node in the Entity Model XML.", parentEntity.Name)); } ProcessScriptBase(key, keyNode); return(key); }
public ValidationOptions DeserialiseValidationOptions(XmlNode validationNode) { var options = new ValidationOptions(); var proc = new NodeProcessor(validationNode); options.NotEmpty = proc.GetNullable <bool>("NotEmpty"); options.Nullable = proc.GetNullable <bool>("Nullable"); options.MaximumValue = proc.GetNullable <int>("MaximumValue"); options.MinimumValue = proc.GetNullable <int>("MinimumValue"); options.FutureDate = proc.GetNullable <bool>("FutureDate"); options.PastDate = proc.GetNullable <bool>("PastDate"); options.FractionalDigits = proc.GetNullable <int>("FractionalDigits"); options.IntegerDigits = proc.GetNullable <int>("IntegerDigits"); options.MaximumLength = proc.GetNullable <long>("MaximumLength"); options.MinimumLength = proc.GetNullable <int>("MinimumLength"); options.RegexPattern = proc.GetString("RegexPattern", null); options.Validate = proc.Exists("Validate"); return(options); }
public ComponentProperty DeserialiseComponentProperty(XmlNode propertyNode, ComponentSpecification spec) { NodeProcessor proc = new NodeProcessor(propertyNode); ComponentProperty property = new ComponentPropertyImpl(); property.Specification = spec; property.Name = proc.GetString("Name"); property.Type = proc.GetString("Type"); if (proc.Exists("Validation")) { property.ValidationOptions = DeserialiseValidationOptions(propertyNode.SelectSingleNode("Validation")); } else { property.ValidationOptions = new ValidationOptions(); } ProcessScriptBase(property, propertyNode); return(property); }
public void ApplyConstraints(MappingSet set, IEnumerable<string> nhvFiles, ParseResults parseResults) { foreach (var nhv in nhvFiles) { string text = _fileController.ReadAllText(nhv); if (nhibernateFileVerifier.IsValidValidationMappingFile(new StringReader(text)) == false) continue; // Load the NHV file XmlDocument doc = new XmlDocument(); doc.LoadXml(text); var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("nhv", NHIBERNATE_VALIDATOR_NAMESPACE); var className = doc.SelectSingleNode("/nhv:nhv-mapping/nhv:class", ns).GetAttributeValueIfExists("name"); var shortClassName = GetShortClassName(className); var possibleEntity = set.EntitySet.Entities.FirstOrDefault(e => e.Name == shortClassName); if (possibleEntity == null) { log.WarnFormat("Could not find Entity named {1}", className); return; } var propertyNodes = doc.SelectNodes("/nhv:nhv-mapping/nhv:class/nhv:property", ns); if (propertyNodes == null) { log.WarnFormat("Could not find any property nodes in {0}", nhv); return; } foreach (XmlNode node in propertyNodes) { var proc = new NodeProcessor(node, ns); var propertyName = proc.Attributes.GetString("name"); var property = possibleEntity.Properties.FirstOrDefault(p => p.Name == propertyName); if (property == null) { log.WarnFormat("Could not find property {0} in Entity {1}", propertyName, possibleEntity.Name); continue; } if (proc.Exists("nhv:length")) { if (proc.SubNode("nhv:length").Attributes.Exists("max")) property.ValidationOptions.MaximumLength = proc.SubNode("nhv:length").Attributes.GetInt("max"); if (proc.SubNode("nhv:length").Attributes.Exists("min")) property.ValidationOptions.MinimumLength = proc.SubNode("nhv:length").Attributes.GetInt("min"); } if (proc.Exists("nhv:digits")) { var subNode = proc.SubNode("nhv:digits"); var integerDigits = subNode.Attributes.GetInt("integerDigits"); var fractionalDigits = subNode.Attributes.GetNullableInt("fractionalDigits"); property.ValidationOptions.IntegerDigits = integerDigits; property.ValidationOptions.FractionalDigits = fractionalDigits; } if (proc.Exists("nhv:not-null")) property.ValidationOptions.Nullable = false; if (proc.Exists("nhv:not-empty")) property.ValidationOptions.NotEmpty = true; if (proc.Exists("nhv:future")) property.ValidationOptions.FutureDate = true; if (proc.Exists("nhv:past")) property.ValidationOptions.PastDate = true; if (proc.Exists("nhv:email")) property.ValidationOptions.Email = true; //if (proc.Exists("nhv:size")) // property.ValidationOptions.si = false; if (proc.Exists("nhv:min")) { var subNode = proc.SubNode("nhv:min"); property.ValidationOptions.MinimumValue = subNode.Attributes.GetInt("value"); } //if (proc.Exists("nhv:range")) // property.ValidationOptions.patt = false; //if (proc.Exists("nhv:pattern")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:asserttrue")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:rule")) // property.ValidationOptions.xxx = false; if (proc.Exists("nhv:max")) { var subNode = proc.SubNode("nhv:max"); property.ValidationOptions.MaximumValue = subNode.Attributes.GetInt("value"); } //if (proc.Exists("nhv:decimalmax")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:decimalmin")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:notnull-notempty")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:ipaddress")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:ean")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:creditcardnumber")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:assertfalse")) // property.ValidationOptions.xxx = false; //if (proc.Exists("nhv:fileexists")) // property.ValidationOptions.xxx = false; if (proc.Exists("nhv:valid")) property.ValidationOptions.Validate = true; //if (proc.Exists("nhv:iban")) // property.ValidationOptions..xxx = false; } } }
private ConnectionStringHelper LoadGenericDatabaseData(XmlNode node, DatabaseTypes databaseType) { NodeProcessor proc = new NodeProcessor(node); var connectionHelper = new ConnectionStringHelper(); if (string.IsNullOrEmpty(connectionHelper.ServerName)) { switch (databaseType) { case DatabaseTypes.SQLCE: //case DatabaseTypes.SQLServer2000: case DatabaseTypes.SQLServer2005: connectionHelper.ServerName = Environment.MachineName; break; case DatabaseTypes.SQLServerExpress: connectionHelper.ServerName = Environment.MachineName + "\\SQLEXPRESS"; break; case DatabaseTypes.MySQL: connectionHelper.ServerName = "localhost"; break; case DatabaseTypes.Oracle: connectionHelper.ServerName = "localhost"; break; case DatabaseTypes.PostgreSQL: connectionHelper.ServerName = "localhost"; break; case DatabaseTypes.Firebird: connectionHelper.ServerName = "localhost"; break; case DatabaseTypes.SQLite: connectionHelper.ServerName = Environment.MachineName; break; default: throw new NotImplementedException("Database type not handled yet: " + databaseType.ToString()); } } connectionHelper.CurrentDbType = databaseType; if (proc.Exists("ServerName")) { connectionHelper.ServerName = proc.GetString("ServerName"); } if (proc.Exists("DatabaseName")) { connectionHelper.DatabaseName = proc.GetString("DatabaseName"); connectionHelper.UseFileName = false; } if (proc.Exists("FileName")) { connectionHelper.FileName = proc.GetString("FileName"); connectionHelper.UseFileName = true; } if (proc.Exists("UseIntegratedSecurity")) { connectionHelper.UseIntegratedSecurity = proc.GetBool("UseIntegratedSecurity"); } if (proc.Exists("UserName")) { connectionHelper.UserName = proc.GetString("UserName"); } if (proc.Exists("Password")) { string password = ""; try { password = proc.GetString("Password").Decrypt(); } catch { // Do nothing password = ""; } connectionHelper.Password = password; } if (proc.Exists("Port")) { connectionHelper.Port = proc.GetInt("Port"); } if (proc.Exists("ServiceName")) { connectionHelper.ServiceName = proc.GetString("ServiceName"); } if (proc.Exists("SchemaName")) { connectionHelper.ServiceName = proc.GetString("SchemaName"); } if (proc.Exists("UseDirectConnection")) { connectionHelper.UseDirectConnection = proc.GetBool("UseDirectConnection"); } else { connectionHelper.UseDirectConnection = false; } return(connectionHelper); }
private ConnectionStringHelper LoadGenericDatabaseData(XmlNode node, DatabaseTypes databaseType) { NodeProcessor proc = new NodeProcessor(node); var connectionHelper = new ConnectionStringHelper(); if (string.IsNullOrEmpty(connectionHelper.ServerName)) { switch (databaseType) { case DatabaseTypes.SQLCE: //case DatabaseTypes.SQLServer2000: case DatabaseTypes.SQLServer2005: connectionHelper.ServerName = Environment.MachineName; break; case DatabaseTypes.SQLServerExpress: connectionHelper.ServerName = Environment.MachineName + "\\SQLEXPRESS"; break; case DatabaseTypes.MySQL: connectionHelper.ServerName = "localhost"; break; case DatabaseTypes.Oracle: connectionHelper.ServerName = "localhost"; break; case DatabaseTypes.PostgreSQL: connectionHelper.ServerName = "localhost"; break; case DatabaseTypes.Firebird: connectionHelper.ServerName = "localhost"; break; case DatabaseTypes.SQLite: connectionHelper.ServerName = Environment.MachineName; break; default: throw new NotImplementedException("Database type not handled yet: " + databaseType.ToString()); } } connectionHelper.CurrentDbType = databaseType; if (proc.Exists("ServerName")) connectionHelper.ServerName = proc.GetString("ServerName"); if (proc.Exists("DatabaseName")) { connectionHelper.DatabaseName = proc.GetString("DatabaseName"); connectionHelper.UseFileName = false; } if (proc.Exists("FileName")) { connectionHelper.FileName = proc.GetString("FileName"); connectionHelper.UseFileName = true; } if (proc.Exists("UseIntegratedSecurity")) connectionHelper.UseIntegratedSecurity = proc.GetBool("UseIntegratedSecurity"); if (proc.Exists("UserName")) connectionHelper.UserName = proc.GetString("UserName"); if (proc.Exists("Password")) { string password = ""; try { password = proc.GetString("Password").Decrypt(); } catch { // Do nothing password = ""; } connectionHelper.Password = password; } if (proc.Exists("Port")) connectionHelper.Port = proc.GetInt("Port"); if (proc.Exists("ServiceName")) connectionHelper.ServiceName = proc.GetString("ServiceName"); if (proc.Exists("SchemaName")) connectionHelper.ServiceName = proc.GetString("SchemaName"); if (proc.Exists("UseDirectConnection")) connectionHelper.UseDirectConnection = proc.GetBool("UseDirectConnection"); else connectionHelper.UseDirectConnection = false; return connectionHelper; }
public void ProcessScriptBase(IScriptBase scriptBase, XmlNode scriptBaseNode) { /* <Name>Table1</Name> <Description /> <Enabled>False</Enabled> <IsUserDefined>False</IsUserDefined> <UID>00000000-0000-0000-0000-000000000000</UID> */ NodeProcessor proc = new NodeProcessor(scriptBaseNode); scriptBase.Name = proc.GetString("Name"); scriptBase.Schema = proc.GetString("Schema"); scriptBase.Description = proc.GetString("Description"); scriptBase.Enabled = proc.GetBool("Enabled"); scriptBase.IsUserDefined = proc.GetBool("IsUserDefined"); if (proc.Exists(VirtualPropertyDeserialiser.VirtualPropertiesNodeName)) { var deserialiser = new VirtualPropertyDeserialiser(); scriptBase.Ex = deserialiser.DeserialiseVirtualProperties( scriptBaseNode.SelectSingleNode(VirtualPropertyDeserialiser.VirtualPropertiesNodeName)); } }