Пример #1
0
        protected override string BuildBindingFunctions(CstTemplate template)
        {
            StringBuilder code        = new StringBuilder();
            StringBuilder entity      = new StringBuilder();
            StringBuilder entitySetup = new StringBuilder();
            CstProperty   dbProp      = null;

            string setupDatabase =
                @"	Public Sub cbo§NAME§_Setup(cbo§NAME§ As GuiComboBox)
		If MyMeta.IsConnected Then
			cbo§NAME§.BindData(MyMeta.Databases)
			If Not MyMeta.DefaultDatabase Is Nothing Then
				cbo§NAME§.SelectedValue = MyMeta.DefaultDatabase.Name

				§EXTRA§
			End If
		End If
	End Sub"    ;

            string setupEntity =
                @"	Public Sub cbo§NAME§_Bind(databaseName As string)
		Dim cbo§NAME§ As GuiComboBox = CType(ui(""§NAME§""), GuiComboBox)
		
		Dim database As IDatabase = MyMeta.Databases(databaseName)
		cbo§NAME§.BindData(database.§MYMETATYPE§)
	End Sub"    ;


            string databaseEventHandler =
                @"	Public Sub cbo§NAME§_OnChange(control As GuiComboBox)
		Dim cbo§NAME§ As GuiComboBox = CType(ui(""§NAME§""), GuiComboBox)
		
		§EXTRA§
	End Sub"    ;
            string bindFunction = @"cbo{0}_Bind(cbo{1}.SelectedValue);";


            foreach (CstProperty prop in template.Properties)
            {
                if (prop.Type == "SchemaExplorer.DatabaseSchema")
                {
                    dbProp = prop;
                    break;
                }
            }

            if (dbProp != null)
            {
                foreach (CstProperty prop in template.Properties)
                {
                    string myMetaName = string.Empty;

                    if (prop.Type == "SchemaExplorer.ViewSchema")
                    {
                        myMetaName = "Views";
                    }
                    else if (prop.Type == "SchemaExplorer.TableSchema")
                    {
                        myMetaName = "Tables";
                    }
                    else if (prop.Type == "SchemaExplorer.CommandSchema")
                    {
                        myMetaName = "Procedures";
                    }

                    if (myMetaName != string.Empty)
                    {
                        entitySetup.Append(setupEntity.Replace("§NAME§", prop.Name).Replace("§MYMETATYPE§", myMetaName));
                        entitySetup.Append(Environment.NewLine);
                        entitySetup.Append(Environment.NewLine);

                        entity.AppendFormat(bindFunction, prop.Name, dbProp.Name);
                        entity.Append(Environment.NewLine);
                    }
                }

                code.Append(setupDatabase.Replace("§NAME§", dbProp.Name).Replace("§EXTRA§", entity.ToString()));
                code.Append(Environment.NewLine);
                code.Append(Environment.NewLine);
                code.Append(databaseEventHandler.Replace("§NAME§", dbProp.Name).Replace("§EXTRA§", entity.ToString()));
                code.Append(Environment.NewLine);
                code.Append(Environment.NewLine);
                code.Append(entitySetup.ToString());
            }

            return(code.ToString());
        }
Пример #2
0
 protected string BuildInputProperty(CstProperty prop)
 {
     return(PropertyText.Replace("§NAME§", prop.Name).Replace("§TYPE§", prop.Type));
 }
Пример #3
0
        private void GrabDirectives()
        {
            log.AddEntry("Searching for directives...");

            Regex ex = new Regex(REGEXP_DIRECTIVE, (RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture));

            bool        usesSchemaExplorer = false;
            bool        hasDatabaseProperty = false;
            int         currentStartIndex = 0;
            string      tagname, tmp;
            CstProperty p;

            while (currentStartIndex >= 0)
            {
                Match match = ex.Match(cstText, currentStartIndex);

                if (match.Success)
                {
                    log.AddEntry("--> Found match: {0}", match.Value.ToString());

                    tagname = this.PullCapturedGroup(match, CstParser.TAG_NAME).ToLower();
                    switch (tagname)
                    {
                    case "codetemplate":
                        //Language, TargetLanguage, Description, Inherits, Src, Debug
                        template.Language       = this.PullCapturedAttribute(match, "Language");
                        template.TargetLanguage = this.PullCapturedAttribute(match, "TargetLanguage");
                        template.Description    = this.PullCapturedAttribute(match, "Description");
                        template.Inherits       = this.PullCapturedAttribute(match, "Inherits");
                        template.Src            = this.PullCapturedAttribute(match, "Src");
                        tmp = this.PullCapturedAttribute(match, "Debug");
                        if (tmp != string.Empty)
                        {
                            template.Debug = Convert.ToBoolean(tmp);
                        }
                        break;

                    case "property":
                        //Name, Type, Default, Category, Description, Optional
                        p              = new CstProperty();
                        p.Name         = this.PullCapturedAttribute(match, "Name");
                        p.Type         = this.PullCapturedAttribute(match, "Type");
                        p.DefaultValue = this.PullCapturedAttribute(match, "Default");
                        p.Category     = this.PullCapturedAttribute(match, "Category");
                        p.Description  = this.PullCapturedAttribute(match, "Description");
                        tmp            = this.PullCapturedAttribute(match, "Optional");
                        if (tmp != string.Empty)
                        {
                            p.Optional = Convert.ToBoolean(tmp);
                        }

                        if (p.Type.StartsWith("SchemaExplorer"))
                        {
                            usesSchemaExplorer = true;
                        }

                        if (p.Type == "SchemaExplorer.DatabaseSchema")
                        {
                            hasDatabaseProperty = true;
                        }

                        template.Properties.Add(p);
                        break;

                    case "assembly":
                        //Name
                        tmp = this.PullCapturedAttribute(match, "Name");
                        template.Assemblies.Add(tmp);
                        break;

                    case "import":
                        //NameSpace
                        tmp = this.PullCapturedAttribute(match, "NameSpace");
                        template.NameSpaces.Add(tmp);
                        break;
                    }

                    cstText = cstText.Remove(match.Index, match.Length);
                }
                else
                {
                    currentStartIndex = -1;
                }
            }

            if (usesSchemaExplorer && !hasDatabaseProperty)
            {
                p             = new CstProperty();
                p.Name        = "Database";
                p.Type        = "SchemaExplorer.DatabaseSchema";
                p.Category    = "Context";
                p.Description = "Select the Database to use for this template.";
                p.Optional    = false;

                template.Properties.Insert(0, p);
            }
        }
Пример #4
0
        protected override string BuildBindingFunctions(CstTemplate template)
        {
            StringBuilder code        = new StringBuilder();
            StringBuilder entity      = new StringBuilder();
            StringBuilder entitySetup = new StringBuilder();
            CstProperty   dbProp      = null;

            string setupDatabase =
                @"	public void cbo§NAME§_Setup(GuiComboBox cbo§NAME§)
	{
		if (MyMeta.IsConnected) 
		{
			cbo§NAME§.BindData(MyMeta.Databases);
			if (MyMeta.DefaultDatabase != null) 
			{
				cbo§NAME§.SelectedValue = MyMeta.DefaultDatabase.Name;
				
				§EXTRA§
			}
		}
	}"    ;

            string setupEntity =
                @"	public void cbo§NAME§_Bind(string databaseName)
	{
		GuiComboBox cbo§NAME§ = ui[""§NAME§""] as GuiComboBox;
		
		IDatabase database = MyMeta.Databases[databaseName];
		cbo§NAME§.BindData(database.§MYMETATYPE§);
	}"    ;


            string databaseEventHandler =
                @"	public void cbo§NAME§_OnChange(GuiComboBox control)
	{
		GuiComboBox cbo§NAME§ = ui[""§NAME§""] as GuiComboBox;
		
		§EXTRA§
	}"    ;
            string bindFunction = @"cbo{0}_Bind(cbo{1}.SelectedValue);";


            foreach (CstProperty prop in template.Properties)
            {
                if (prop.Type == "SchemaExplorer.DatabaseSchema")
                {
                    dbProp = prop;
                    break;
                }
            }

            if (dbProp != null)
            {
                foreach (CstProperty prop in template.Properties)
                {
                    string myMetaName = string.Empty;

                    if (prop.Type == "SchemaExplorer.ViewSchema")
                    {
                        myMetaName = "Views";
                    }
                    else if (prop.Type == "SchemaExplorer.TableSchema")
                    {
                        myMetaName = "Tables";
                    }
                    else if (prop.Type == "SchemaExplorer.CommandSchema")
                    {
                        myMetaName = "Procedures";
                    }

                    if (myMetaName != string.Empty)
                    {
                        entitySetup.Append(setupEntity.Replace("§NAME§", prop.Name).Replace("§MYMETATYPE§", myMetaName));
                        entitySetup.Append(Environment.NewLine);
                        entitySetup.Append(Environment.NewLine);

                        entity.AppendFormat(bindFunction, prop.Name, dbProp.Name);
                        entity.Append(Environment.NewLine);
                    }
                }

                code.Append(setupDatabase.Replace("§NAME§", dbProp.Name).Replace("§EXTRA§", entity.ToString()));
                code.Append(Environment.NewLine);
                code.Append(Environment.NewLine);
                code.Append(databaseEventHandler.Replace("§NAME§", dbProp.Name).Replace("§EXTRA§", entity.ToString()));
                code.Append(Environment.NewLine);
                code.Append(Environment.NewLine);
                code.Append(entitySetup.ToString());
            }

            return(code.ToString());
        }