Beispiel #1
0
 /// <summary>
 /// Nothing to do here really.
 /// </summary>
 /// <param name="field"></param>
 /// <returns></returns>
 public TemplateManager CreateTemplate(DatabaseElement field)
 {
     return(new TemplateManager()
     {
         SelectedDatabase = field
     });
 }
Beispiel #2
0
 void PushState(DatabaseElement database)
 {
     Model.LastViewMode       = ViewMode.Database;
     Model.LastSelectedObject = database;
     Model.LastFactory        = CreateTemplate(database);
     SetCombos(database);
 }
Beispiel #3
0
        public void RefreshDataTree(DatabaseElement parent)
        {
            var selectedparent = FindTreeViewSelectedItemContainer(tvModel, parent);

            selectedparent.ItemsSource = parent.Children;
            selectedparent.Items.Refresh();
            selectedparent.UpdateLayout();
        }
Beispiel #4
0
        private void ShowDatabases(Int32 level, String nodeText, String parentNodeText)
        {
            if (level == 0 || level == 1 || level == 2)
            {
                listView1.Items.Clear();
                listView1.Columns.Clear();
                listView1.Columns.Add("Name", -1, HorizontalAlignment.Left);
                listView1.Columns.Add("Key", -1, HorizontalAlignment.Left);
                listView1.Columns.Add("Directory", -1, HorizontalAlignment.Left);
                listView1.Columns.Add("Gen Insert", -1, HorizontalAlignment.Left);
                listView1.Columns.Add("Gen Update", -1, HorizontalAlignment.Left);
                listView1.Columns.Add("Gen Delete", -1, HorizontalAlignment.Left);
                listView1.Columns.Add("Gen Select", -1, HorizontalAlignment.Left);
                listView1.Columns.Add("Timeout", -1, HorizontalAlignment.Right);

                IList list;
                if (level == 0)
                {
                    list = databases;
                }
                else if (level == 1)
                {
                    list = new ArrayList();
                    list.Add(DatabaseElement.FindByName((ArrayList)databases, nodeText));
                }
                else
                {
                    list = new ArrayList();
                    DatabaseElement  database  = DatabaseElement.FindByName((ArrayList)databases, treeView1.SelectedNode.Parent.Text);
                    SqlEntityElement sqlentity = database.FindSqlEntityByName(nodeText);
                    list.Add(sqlentity);
                }

                foreach (SqlEntityData database in list)
                {
                    //SqlEntityData database = (SqlEntityData)o;
                    ListViewItem lvi = new ListViewItem(database.Name);
                    lvi.SubItems.Add(database.Key);
                    lvi.SubItems.Add(database.SqlScriptDirectory);
                    lvi.SubItems.Add(database.GenerateInsertStoredProcScript.ToString());
                    lvi.SubItems.Add(database.GenerateUpdateStoredProcScript.ToString());
                    lvi.SubItems.Add(database.GenerateDeleteStoredProcScript.ToString());
                    lvi.SubItems.Add(database.GenerateSelectStoredProcScript.ToString());
                    lvi.SubItems.Add(database.CommandTimeout.ToString());
                    listView1.Items.Add(lvi);
                }
            }
        }
Beispiel #5
0
 static public string Parse(
     DatabaseCollection databases,
     DatabaseElement database,
     TemplateCollection templates,
     TableElement table,
     TableTemplate template
     )
 {
     return(Parse(
                new DataCfg()
     {
         Databases = databases,
         Database = database,
         Table = table,
         Templates = templates,
         Template = template
     }));
 }
Beispiel #6
0
        internal static bool CheckForError(DatabaseElement db, TableElement table, bool showMessageBox = false, bool ignoreException = true)
        {
            bool hasError = false;

            if (hasError = (db == null || table == null))
            {
                if (showMessageBox)
                {
                    System.Windows.Forms.MessageBox.Show(
                        Gen.Strings.MsgDatabaseOrTableNullError_Title,
                        Gen.Strings.MsgDatabaseOrTableNullError_Message
                        );
                }
                if (!ignoreException)
                {
                    throw new ArgumentException(Gen.Strings.MsgDatabaseOrTableNullError_Exception);
                }
            }
            return(hasError);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var env = Environment.GetEnvironmentVariable("APP_ENV") ?? "development";
              System.Console.WriteLine(env);

              var db = ConfigFile.Load("database.config", null);
              System.Console.WriteLine(db["host"]);
              System.Console.ReadLine();
              return;
              //var x = ConfigurationManager.GetSection("database");
              //System.Console.WriteLine(x == null);

              var appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
              var y = appConfig.GetSectionGroup("database") as AppConfigEnv.EnvironmentSection;
              var t = y.Current as DefaultSection;
              var e = new DatabaseElement(t);
              System.Console.WriteLine(e.Host);
              System.Console.WriteLine(e.Get("new_database"));

              System.Console.ReadLine();
        }
Beispiel #8
0
        /// <summary>
        /// Generate default elements for a empty configuration file.
        /// </summary>
        /// <returns></returns>
        virtual public DatabaseCollection CreateConfig()
        {
            var dc    = new DatabaseCollection();
            var dbelm = new DatabaseElement(string.Format(Messages.Node_New_Database_Element, __dbIncr));

            dc.Queries   = new List <QueryElement>();
            dc.Databases = new List <DatabaseElement>()
            {
                dbelm
            };
            __dbIncr++;

            dbelm.Items = new List <TableElement>();
            dbelm.Views = new List <DataViewElement>();
            var te = new TableElement();

            te.Fields = new List <FieldElement>();
            te.Name   = string.Format(Messages.Node_New_Table_Element, __tbIncr);

            dbelm.Items.Add(te);
            SelectedCollection = dc;
            return(dc);
        }
Beispiel #9
0
 private void CreateSqlElementAssociations(ParserValidationDelegate vd)
 {
     // find and assign the foreign entity and EnumElement now that they are parsed
     foreach (DatabaseElement database in databases)
     {
         foreach (SqlEntityElement sqlEntity in database.SqlEntities)
         {
             foreach (ConstraintElement constraint in sqlEntity.Constraints)
             {
                 if (constraint.ForeignEntity.Name.Length > 0)
                 {
                     SqlEntityElement entity = SqlEntityElement.FindByName(DatabaseElement.GetAllSqlEntities(databases), constraint.ForeignEntity.Name);
                     if (entity != null)
                     {
                         constraint.ForeignEntity = (SqlEntityElement)entity.Clone();
                     }
                     else
                     {
                         vd(ParserValidationArgs.NewError("ForeignEntity (" + constraint.ForeignEntity.Name + ") specified in constraint " + constraint.Name + " could not be found as an defined entity"));
                     }
                 }
                 if (constraint.CheckEnum.Name.Length > 0)
                 {
                     EnumElement entity = EnumElement.FindByName(enumtypes as ArrayList, constraint.CheckEnum.Name);
                     if (entity != null)
                     {
                         constraint.CheckEnum = (EnumElement)entity.Clone();
                     }
                     else
                     {
                         vd(ParserValidationArgs.NewError("CheckEnum (" + constraint.CheckEnum.Name + ") specified in constraint " + constraint.Name + " could not be found as an defined entity"));
                     }
                 }
             }
         }
     }
 }
Beispiel #10
0
 /// <summary>
 /// 设置元素集合
 /// </summary>
 /// <param name="oItem"></param>
 public void SetElement(DatabaseElement oItem)
 {
     m_Items.Add(oItem);
 }
Beispiel #11
0
        /// <summary>
        /// 创建一个新的数据集
        /// </summary>
        public DatabaseElement CreateNew()
        {
            DatabaseElement oItem = new DatabaseElement(FieldCount);

            return(oItem);
        }
Beispiel #12
0
        public void Parse(String filename)
        {
            FileInfo file = new FileInfo(filename);

            if (!file.Exists)
            {
                throw new FileNotFoundException("Could not load config file", filename);
            }
            isValid = true;
            ValidateSchema(filename);

            doc = new XmlDocument();
            Stream filestream = XIncludeReader.GetStream(filename);

            doc.Load(filestream);
            filestream.Close();

            if (doc == null)
            {
                throw new InvalidOperationException("Could not parse xml document: " + filename);
            }

            // event handler for all of the ParseFromXml methods
            ParserValidationDelegate vd = new ParserValidationDelegate(ParserValidationEventHandler);

            XmlNode root = doc.DocumentElement["config"];

            if (root != null)
            {
                this.options = new Configuration(root, vd);
            }
            else
            {
                this.options = new Configuration();
            }

            sqltypes = SqlTypeElement.ParseFromXml(doc, vd);
            types    = TypeElement.ParseFromXml(options, doc, vd);

            // parse generate/task information so that type registration will happen before other types are loaded
            generator = GeneratorElement.ParseFromXml(options, doc, vd);
            TaskElement.RegisterTypes(doc, options, generator.Tasks, types);

            // see if we want to generate collections for all entities
            XmlNodeList collectionElement = doc.DocumentElement.GetElementsByTagName("collections");
            XmlNode     collectionNode    = collectionElement[0];

            if (collectionNode.Attributes["generateall"] == null)
            {
                options.GenerateAllCollections = false;
            }
            else
            {
                options.GenerateAllCollections = Boolean.Parse(collectionNode.Attributes["generateall"].Value.ToString());
            }

            // if the root directory is not specified, make it the directory the config file is loaded from
            if (options.RootDirectory.Equals(String.Empty))
            {
                options.RootDirectory = file.DirectoryName + "\\";
            }
            if (!options.RootDirectory.EndsWith("\\"))
            {
                options.RootDirectory += "\\";
            }

            enumtypes         = EnumElement.ParseFromXml(options, doc, sqltypes, types, vd);
            databases         = DatabaseElement.ParseFromXml(options, doc, sqltypes, types, vd);
            entities          = EntityElement.ParseFromXml(options, doc, sqltypes, types, DatabaseElement.GetAllSqlEntities(databases), vd);
            messages          = MessageElement.ParseFromXml(options, doc, sqltypes, types, DatabaseElement.GetAllSqlEntities(databases), vd);
            reportExtractions = ReportExtractionElement.ParseFromXml(options, doc, sqltypes, types, entities, vd);
            ArrayList collectableClasses  = new ArrayList();
            ArrayList autoGenerateClasses = new ArrayList();

            collectableClasses.AddRange(entities);
            collectableClasses.AddRange(reportExtractions);
            autoGenerateClasses.AddRange(entities);
            autoGenerateClasses.AddRange(reportExtractions);
            collections = CollectionElement.ParseFromXml(options, doc, sqltypes, types, vd, collectableClasses, autoGenerateClasses, (ArrayList)entities);

            CreateSqlElementAssociations(vd);
            CreateEntityElementAssociations(vd);
            Validate(vd);
        }
Beispiel #13
0
 public FieldReference(DatabaseElement db, FieldElement field)
 {
     this.database = db.Name;
     this.field    = field.DataName;
 }
Beispiel #14
0
        public ConfigParser(String filename)
        {
            FileInfo file = new FileInfo(filename);

            if (!file.Exists)
            {
                throw new FileNotFoundException("Could not load config file", filename);
            }
            isValid = true;
            ValidateSchema(filename);

            doc = new XmlDocument();
            Stream filestream = XIncludeReader.GetStream(filename);

            doc.Load(filestream);
            filestream.Close();

            if (doc == null)
            {
                throw new InvalidOperationException("Could not parse xml document: " + filename);
            }

            // event handler for all of the ParseFromXml methods
            ParserValidationDelegate vd = new ParserValidationDelegate(ParserValidationEventHandler);

            XmlNode root = doc.DocumentElement["config"];

            if (root != null)
            {
                this.options = new Configuration(root, vd);
            }
            else
            {
                this.options = new Configuration();
            }

            // If the root directory is not specified, make it the directory the config file is loaded from.
            if (options.RootDirectory.Equals(String.Empty))
            {
                options.RootDirectory = file.DirectoryName + "\\";
            }
            if (!options.RootDirectory.EndsWith("\\"))
            {
                options.RootDirectory += "\\";
            }

            parser    = ParserElement.ParseFromXml(options, doc, vd);
            generator = GeneratorElement.ParseFromXml(options, doc, vd);
            sqltypes  = SqlTypeElement.ParseFromXml(doc, vd);
            types     = TypeElement.ParseFromXml(options, doc, vd);

            if (parser.Class.Equals(String.Empty))
            {
                enumtypes   = EnumElement.ParseFromXml(options, doc, sqltypes, types, vd);
                databases   = DatabaseElement.ParseFromXml(options, doc, sqltypes, types, vd);
                entities    = EntityElement.ParseFromXml(options, doc, sqltypes, types, DatabaseElement.GetAllSqlEntities(databases), vd);
                collections = CollectionElement.ParseFromXml(options, doc, sqltypes, types, vd, (ArrayList)entities);
            }
            else
            {
                Object o = null;
                try {
                    System.Type clazz = System.Type.GetType(parser.Class, true);
                    Object[]    args  = { parser, options, doc, sqltypes, types, vd };
                    o = System.Activator.CreateInstance(clazz, args);
                } catch (Exception ex) {
                    Console.Out.WriteLine("ERROR: could not create class " + parser.Class + ".\n" + ex.ToString());
                }

                if (o is IParser)
                {
                    IParser p = (IParser)o;
                    enumtypes   = (ArrayList)p.Enums;
                    collections = (ArrayList)p.Collections;
                    databases   = (ArrayList)p.Databases;
                    entities    = (ArrayList)p.Entities;
                }
                else
                {
                    Console.Out.WriteLine("ERROR: class " + parser.Class + " does not support IParser interface.\n");
                }
            }

            Validate(vd);
        }
Beispiel #15
0
 void SetCombos(DatabaseElement db)
 {
     cbDatabase.SelectedItem = db; cbTable.SelectedItem = null; cbField.SelectedItem = null;
 }
Beispiel #16
0
 /// <summary>Set DB as config-selected-db and T to the supplied 'tableName'.</summary>
 public void SetView(string tableName)
 {
     DB = ConfigMemory.SelectedDatabase;
     T  = DB.Items.FirstOrDefault(t => t.Name == tableName);
 }
Beispiel #17
0
 /// <summary>
 /// Set the datbase and table name for the view.
 /// </summary>
 /// <param name="name"></param>
 /// <remarks>
 /// if anybody is going to walk out of the context of a database and into the context
 /// of a database-collection, well --- this would be our guy.
 /// </remarks>
 public void SetView()
 {
     DB = ConfigMemory.SelectedCollection.Databases.FirstOrDefault(dbx => dbx.Name == T.View.Database);
     T  = DB.Items.FirstOrDefault(t => t.Name == T.View.Table);
 }
Beispiel #18
0
 public void SetView(DataViewLink link)
 {
     DB = ConfigMemory.SelectedCollection.Databases.FirstOrDefault(xdb => xdb.Name == link.Database);
     T  = (TableElement)DB.Items.FirstOrDefault(t => T.Name == link.Table);
 }