/// <summary> /// Visitor implementation. Initializes CurrentDataSetType and Namespaces member variables. /// </summary> /// <param name="schema"></param> public override void Visit(VisitableSchemaRoot schema) { base.Visit(schema); // Find the dataset type declaration. foreach (CodeTypeMember member in CurrentNamespace.Types) { if (member.UserData.Contains("IsDataSet") && ((XmlAttribute)member.UserData["IsDataSet"]).Value == "true") { CurrentDataSetType = member as CodeTypeDeclaration; } } if (CurrentDataSetType == null) { ThrowDataSetNotFound(); } // Remove collection type naming convention from the dataset name. CurrentDataSetType.Name = CurrentDataSetType.Name.Replace(Configuration.CollectionNaming, ""); // Initialize the NamespaceManger to use for resolving XPath expressions in descendents. Namespaces = new XmlNamespaceManager(new NameTable()); XmlQualifiedName[] nss = CurrentSchema.Namespaces.ToArray(); foreach (XmlQualifiedName ns in nss) { if (ns.Name != String.Empty) { Namespaces.NameTable.Add(ns.Name); Namespaces.NameTable.Add(ns.Namespace); Namespaces.AddNamespace(ns.Name, ns.Namespace); } } }
public void Visit(VisitableSchemaRoot element) { _currentns = new CodeNamespace(element.SchemaObject.TargetNamespace); //Get the current state of the generation process. ICurrentState state = (ICurrentState) Host.GetService(typeof(ICurrentState)); state.Unit.Namespaces.Add(_currentns); }
/// <summary> /// Visitor implementation. Processes the passed element /// repositioning the CurrentNamespace and CurrentSchema member variables. /// </summary> /// <param name="element"></param> public virtual void Visit(VisitableSchemaRoot element) { if (element.SchemaObject.TargetNamespace == null || element.SchemaObject.TargetNamespace.Length == 0 || element.SchemaObject.TargetNamespace == String.Empty) { throw new InvalidOperationException("Schema " + element.SchemaObject.SourceUri + " must have a TargetNamespace attribute."); } CurrentNamespace = null; CurrentSchema = element.SchemaObject; CurrentSchemaDom = element.SchemaDocument; foreach (CodeNamespace ns in Unit.Namespaces) { if (ns.Name == element.SchemaObject.TargetNamespace) { CurrentNamespace = ns; break; } } }
public override void Visit(VisitableSchemaRoot element) { OnProgress("Building classes ..."); base.Visit(element); if (CurrentNamespace == null) { CurrentNamespace = new CodeNamespace(element.SchemaObject.TargetNamespace); CurrentNamespace.Imports.AddRange(CodeDomHelper.BuildNamespaceImports(Configuration.NamespaceImports)); // Append unhandled attributes to the type UserData property, for use by custom visitors. XmlAttribute[] attributes = element.SchemaObject.UnhandledAttributes; if (attributes != null) { foreach (XmlAttribute attr in attributes) { CurrentNamespace.UserData.Add(attr.LocalName, attr); } } Unit.Namespaces.Add(CurrentNamespace); } }
/// <summary> /// Notifies progress. /// </summary> /// <param name="schema"></param> public override void Visit(VisitableSchemaRoot schema) { OnProgress("Building custom Member code blocks ... "); base.Visit(schema); }
public override void Visit(VisitableSchemaRoot schema) { OnProgress("Adding debugging statements ... "); base.Visit(schema); }
/// <summary> /// Visitor implementation. /// </summary> public override void Visit(VisitableSchemaRoot schema) { OnProgress("Organizing classes in the DataSet ..."); base.Visit(schema); }
/// <summary> /// Visitor implementation. Notifies progress. /// </summary> /// <param name="schema"></param> public override void Visit(VisitableSchemaRoot schema) { OnProgress("Building Constructors ..."); base.Visit(schema); }
/// <summary> /// Visitor implementation. /// </summary> public override void Visit(VisitableSchemaRoot element) { base.Visit(element); #region DataSet attributes //[Serializable()] CurrentDataSetType.CustomAttributes.Add( new CodeAttributeDeclaration("Serializable")); //[System.ComponentModel.DesignerCategoryAttribute("code")] CurrentDataSetType.CustomAttributes.Add( new CodeAttributeDeclaration("System.ComponentModel.DesignerCategoryAttribute", new CodeAttributeArgument[] { new CodeAttributeArgument( new CodePrimitiveExpression("code")) })); //[System.Diagnostics.DebuggerStepThrough()] CurrentDataSetType.CustomAttributes.Add( new CodeAttributeDeclaration("System.Diagnostics.DebuggerStepThrough")); //[System.ComponentModel.ToolboxItem(true)] CurrentDataSetType.CustomAttributes.Add( new CodeAttributeDeclaration("System.ComponentModel.ToolboxItem", new CodeAttributeArgument[] { new CodeAttributeArgument( new CodePrimitiveExpression(true)) })); #endregion //Add Base type CurrentDataSetType.BaseTypes.Add( typeof(NMatrix.XDL.BaseDataSet)); //Remove the naming convention CurrentDataSetType.Name = CurrentDataSetType.Name.Replace( Configuration.TypeNaming, "").Replace( Configuration.CollectionNaming, ""); #region Constructors //Remove default constructor CodeTypeMember[] members = new CodeTypeMember[CurrentDataSetType.Members.Count]; CurrentDataSetType.Members.CopyTo(members, 0); foreach (CodeTypeMember member in members) { if (member is CodeConstructor) { CurrentDataSetType.Members.Remove(member); } } ////public dsPublishers(string schemaFile) : base(schemaFile) CodeConstructor ctor = new CodeConstructor(); ctor.Attributes = MemberAttributes.Public; ctor.Parameters.Add( new CodeParameterDeclarationExpression( typeof(string), "schemaFile")); ctor.BaseConstructorArgs.Add( new CodeVariableReferenceExpression("schemaFile")); CurrentDataSetType.Members.Add(ctor); //public dsPublishers(string schemaFile, InternalDataSet state) : base(schemaFile, state) { } ctor = new CodeConstructor(); ctor.Attributes = MemberAttributes.Public; ctor.Parameters.Add( new CodeParameterDeclarationExpression( typeof(string), "schemaFile")); ctor.Parameters.Add( new CodeParameterDeclarationExpression( typeof(NMatrix.XDL.Wrappers.InternalDataSet), "state")); ctor.BaseConstructorArgs.Add( new CodeVariableReferenceExpression("schemaFile")); ctor.BaseConstructorArgs.Add( new CodeVariableReferenceExpression("state")); CurrentDataSetType.Members.Add(ctor); #endregion }
public override void Visit(VisitableSchemaRoot schema) { OnProgress("Building backing private field for properties ... "); base.Visit(schema); }
/// <summary> /// Initializes the InitClass and InitVars methods for the DataSet. We process /// in this method as it is called only once per schema. /// </summary> /// <param name="schema"></param> public override void Visit(VisitableSchemaRoot schema) { OnProgress("Adding initialization and DataRelation objects ..."); base.Visit(schema); CodeMemberMethod initclass = RetrieveMethod(CurrentDataSetType, "InitClass"); CodeMemberMethod initvars = RetrieveMethod(CurrentDataSetType, "InitVars"); // Make the InitVars method internal initvars.Attributes = MemberAttributes.Final | MemberAttributes.Assembly; #region Initialize InitClass method. //this.DataSetName = "dsPublishers"; initclass.Statements.Add( new CodeAssignStatement( new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), "DataSetName"), new CodePrimitiveExpression(CurrentDataSetType.Name))); //this.Prefix = ""; initclass.Statements.Add( new CodeAssignStatement( new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), "Prefix"), new CodePrimitiveExpression(""))); //this.Namespace = "deverest-com-ar"; initclass.Statements.Add( new CodeAssignStatement( new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), "Namespace"), new CodePrimitiveExpression(CurrentSchema.TargetNamespace))); //this.Locale = new System.Globalization.CultureInfo("en-US"); string locale = "en-US"; if (CurrentDataSetType.UserData.Contains("Locale")) { locale = ((XmlAttribute)CurrentDataSetType.UserData["Locale"]).Value; } initclass.Statements.Add( new CodeAssignStatement( new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), "Locale"), new CodeObjectCreateExpression( typeof(System.Globalization.CultureInfo), new CodeExpression[] { new CodePrimitiveExpression(locale) }))); //this.CaseSensitive = false; bool sensitive = false; if (CurrentDataSetType.UserData.Contains("CaseSensitive")) { sensitive = bool.Parse(((XmlAttribute)CurrentDataSetType.UserData["CaseSensitive"]).Value); } initclass.Statements.Add( new CodeAssignStatement( new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), "CaseSensitive"), new CodePrimitiveExpression(sensitive))); //this.EnforceConstraints = true; initclass.Statements.Add( new CodeAssignStatement( new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), "EnforceConstraints"), new CodePrimitiveExpression(true))); // Add the variable to use for foreign keys. initclass.Statements.Add( new CodeVariableDeclarationStatement(typeof(ForeignKeyConstraint), "fkc")); #endregion }
public override void Visit(VisitableSchemaRoot schema) { OnProgress("Creating Xml documentation comments ..."); base.Visit(schema); }
/// <summary> /// Visitor implementation. Notifies progress. /// </summary> /// <param name="schema"></param> public override void Visit(VisitableSchemaRoot schema) { OnProgress("Adding DataRow variables ..."); base.Visit(schema); }
/// <summary> /// Create a database with the name of schema target namespace. /// </summary> public void Visit(VisitableSchemaRoot element) { //Can create a database for the schema }