private void Initialize(CodeTemplate template) { _namespace = (string)template.GetProperty("ClassNamespace"); _dalNamespace = (string)template.GetProperty("DalNamespace"); if (_dalNamespace == string.Empty) _dalNamespace = "Dal"; _objectName = (string)template.GetProperty("ObjectName"); _baseClass = (string)template.GetProperty("BaseClass"); //template settings _transactionType = (TransactionalTypes)template.GetProperty("TransactionalType"); _propertyAuthorization = (PropertyAccessSecurity)template.GetProperty("PropertyAuthorization"); _useSecurity = (bool)template.GetProperty("AuthorizationRules"); _codeGenMethod = (CodeGenerationMethod)template.GetProperty("GenerationMethod"); _classType = (GenerationClassType)template.GetProperty("ClassType"); //db commands _fetchCommand = string.Format(FetchCommandFormat, _objectName); _insertCommand = string.Format(InsertCommandFormat, _objectName); _updateCommand = string.Format(UpdateCommandFormat, _objectName); _deleteCommand = string.Format(DeleteCommandFormat, _objectName); }
private void LoadFromXml(CodeTemplate template) { //read from xml file string path = (string)template.GetProperty("XmlFilePath"); XmlTextReader xtr = new XmlTextReader(path); if(!MoveToObject(xtr, _objectName)) throw new ApplicationException(string.Format("Object {0} does not exist!", _objectName)); //read object attributes while (xtr.MoveToNextAttribute()) { switch (xtr.LocalName.ToLower()) { case "namespace": _namespace = xtr.Value; break; case "dalnamespace": _dalNamespace = xtr.Value; break; case "access": _access = xtr.Value; break; case "type": _objectType = (ObjectType)Enum.Parse(typeof(ObjectType), xtr.Value, true); break; case "base": _baseClass = xtr.Value; break; } } if (_entityName == string.Empty) _entityName = _objectName; //read object elements while (xtr.Read()) { if (xtr.NodeType == XmlNodeType.EndElement && xtr.LocalName.ToLower() == "object") break; //reach end of object node if (xtr.NodeType == XmlNodeType.Element) { switch (xtr.LocalName.ToLower()) { case "properties": LoadProperties(xtr); //read properties break; case "transactionaltype": _transactionType = (TransactionalTypes)Enum.Parse(typeof(TransactionalTypes), xtr.ReadElementString()); break; case "propertyauthorization": _propertyAuthorization = (PropertyAccessSecurity)Enum.Parse(typeof(PropertyAccessSecurity), xtr.ReadElementString()); break; case "authorizationrules": _useSecurity = bool.Parse(xtr.ReadElementString()); break; case "relationship": while (xtr.MoveToNextAttribute()) { switch (xtr.LocalName.ToLower()) { case "parent": _parent = xtr.Value; break; case "child": _child = xtr.Value; break; } } break; case "dbcommands": _dbName = xtr.GetAttribute("DbName"); while (xtr.Read()) { if (xtr.NodeType == XmlNodeType.EndElement && xtr.LocalName.ToLower() == "dbcommands") break; //reach end of properties node if (xtr.NodeType == XmlNodeType.Element) { switch (xtr.LocalName.ToLower()) { case "fetchcommand": _fetchCommand = xtr.ReadElementString(); break; case "insertcommand": _insertCommand = xtr.ReadElementString(); break; case "updatecommand": _updateCommand = xtr.ReadElementString(); break; case "deletecommand": _deleteCommand = xtr.ReadElementString(); break; } } } break; } } } //whild(xtr.Read()) xtr.Close(); }