Exemple #1
0
        private static void Code1()
        {
            string basePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            dbRoot          = new dbRoot();
            dbRoot.DbTarget = "SqlClient";
            dbRoot.DbTargetMappingFileName = Path.Combine(basePath, @"cfg\DbTargets.xml");

            dbRoot.Language = "C#";
            dbRoot.LanguageMappingFileName = Path.Combine(basePath, @"cfg\Languages.xml");

            //dbRoot.UserMetaDataFileName = @"C:\Program Files\MyGeneration\Settings\UserMetaData.xml";
            dbRoot.Connect(dbDriver.SQL,
                           "Provider=sqloledb;Data Source=(local);Initial Catalog=Northwind;Integrated Security = SSPI; ");

            var database = dbRoot.DefaultDatabase;

            var sps = database.Procedures.ToList();

            var sps1 = sps.FindAll(p => p.Alias.StartsWith("sp"));

            var sps2 = sps.FindAll(p => p.Alias.StartsWith("dm_"));

            var sps3 = sps.FindAll(p =>
                                   !p.Alias.StartsWith("dm_") && !p.Alias.StartsWith("sp_") && !p.Alias.StartsWith("xp_") &&
                                   !p.Alias.StartsWith("fn_"));

            Console.WriteLine(sps.Count);
        }
Exemple #2
0
        public static void Test(IMyMetaTestContext criteria)
        {
            dbRoot root = null;

            if (!criteria.HasErrors)
            {
                root = new dbRoot();
                try
                {
                    root.Connect(criteria.ProviderType, criteria.ConnectionString);
                    root.ShowDefaultDatabaseOnly = true;
                    criteria.AppendLog("MyMeta dbRoot Connection Successful.");
                }
                catch (Exception ex)
                {
                    criteria.AppendLog("Error connecting to dbRoot", ex);
                }
            }

            TestDatabases(criteria, root);
            TestTables(criteria, root);
            TestViews(criteria, root);
            TestProcedures(criteria, root);
            TestSQL(criteria, root);
        }
Exemple #3
0
        virtual public object Reconstitute(string source)
        {
            string[] items = source.Split(';');

            dbRoot myMeta = new dbRoot();

            if (items.Length >= 7)
            {
                // DriverString, ConnectionString
                myMeta.Connect(
                    ReadableDeserialize(items[3]),
                    ReadableDeserialize(items[0])
                    );

                // DbTargetMappingFileName
                myMeta.DbTargetMappingFileName = ReadableDeserialize(items[1]);

                // DomainOverride
                myMeta.DomainOverride = Convert.ToBoolean(items[2]);

                // Language
                myMeta.Language = ReadableDeserialize(items[4]);

                // LanguageMappingFileName
                myMeta.LanguageMappingFileName = ReadableDeserialize(items[5]);

                // UserMetaDataFileName
                myMeta.UserMetaDataFileName = ReadableDeserialize(items[6]);
            }

            return(myMeta);
        }
Exemple #4
0
        private void OpenDataLinkDialog(string connection, dbDriver driver, string caption)
        {
            DataLinksClass dl = new MSDASC.DataLinksClass();

            ADODB.Connection conn = new ADODB.ConnectionClass();
            conn.ConnectionString = connection;

            object objCn = (object)conn;

            //	dl.PromptNew();
            if (dl.PromptEdit(ref objCn))
            {
                this.Text = "MyMeta Browser " + caption;

                string error = "";
                try
                {
                    myMeta = new dbRoot();
                    myMeta.Connect(driver, conn.ConnectionString);
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }

                this.InitializeTree(myMeta, error);
            }
        }
Exemple #5
0
        static void Main()
        {
            OMeta = new dbRoot();
            //连接到SqlServer数据库,注意必须使用oledb连接字符串
            OMeta.Connect(dbDriver.SQL, "Provider=sqloledb;Data Source=(local);Initial Catalog=Northwind;Integrated Security = SSPI; ");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }
        public List <ITable> GetAllExportTablesOrders()
        {
            dbRoot db = new dbRoot();

            db.Connect(dbDriver.SQL, this.Connstring);

            List <ITable> tables = TableGenerationHelper.GetAllExportDataOrderTables(db.DefaultDatabase);

            return(tables);
        }
Exemple #7
0
        private void Setup(DefaultSettings settings)
        {
            string error = string.Empty;

            try
            {
                myMeta    = new dbRoot();
                this.Text = "MyMeta Browser (" + settings.DbDriver + ")";

                if (settings.DbDriver.ToUpper() != "NONE")
                {
#if !DEBUG
                    TestConnectionForm tcf = new TestConnectionForm(settings.DbDriver, settings.ConnectionString, true);
                    if (isFirstRun)
                    {
                        tcf.StartPosition = FormStartPosition.CenterScreen;
                        isFirstRun        = false;
                    }
                    tcf.ShowDialog(this.MdiParent);
                    if (TestConnectionForm.State == ConnectionTestState.Error)
                    {
                        if (TestConnectionForm.LastErrorMsg != null)
                        {
                            error = TestConnectionForm.LastErrorMsg;
                        }
                        else
                        {
                            error = "Connection Error...";
                        }
                    }
                    tcf = null;
#endif
                }

                if (error == string.Empty)
                {
                    myMeta.Connect(settings.DbDriver, settings.ConnectionString);
                    myMeta.LanguageMappingFileName = settings.LanguageMappingFile;
                    myMeta.Language = settings.Language;
                    myMeta.DbTargetMappingFileName = settings.DbTargetMappingFile;
                    myMeta.DbTarget             = settings.DbTarget;
                    myMeta.UserMetaDataFileName = settings.UserMetaDataFileName;

                    myMeta.DomainOverride = settings.DomainOverride;

                    myMeta.ShowSystemData = chkSystem.Checked;
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            this.InitializeTree(myMeta, error);
        }
Exemple #8
0
        public void TestConnection(IHost host)
        {
            var myMeta = new dbRoot();

            if (myMeta.Connect(dbDriver.SQL, ConnectionString))
            {
                MessageBox.Show("Connection was successful");
            }
            else
            {
                MessageBox.Show("Connection failed");
            }
        }
Exemple #9
0
        public OMetaMSSQLTests()
        {
            string basePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            dbRoot          = new dbRoot();
            dbRoot.DbTarget = "SqlClient";
            dbRoot.DbTargetMappingFileName = Path.Combine(basePath, @"cfg\DbTargets.xml");

            dbRoot.Language = "C#";
            dbRoot.LanguageMappingFileName = Path.Combine(basePath, @"cfg\Languages.xml");

            //dbRoot.UserMetaDataFileName = @"C:\Program Files\MyGeneration\Settings\UserMetaData.xml";
            dbRoot.Connect(dbDriver.SQL, "Provider=sqloledb;Data Source=(local);Initial Catalog=Northwind;Integrated Security = SSPI; ");
        }
        public List <ITable> GetAllTables()
        {
            dbRoot db = new dbRoot();

            db.Connect(dbDriver.SQL, this.Connstring);

            List <ITable> tables = new List <ITable>();

            foreach (ITable table in db.DefaultDatabase.Tables)
            {
                tables.Add(table);
            }

            return(tables);
        }
        private void tsbAddDataBase_Click(object sender, EventArgs e)
        {
            DataBaseItem dataBase = new DataBaseItem();

            dataBase.Name       = "1";
            dataBase.Connstring = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=BackhaulDB;Data Source=192.168.1.8";

            dbRoot db = new dbRoot();

            db.Connect(dbDriver.SQL, dataBase.Connstring);

            dataBase.DefaultDatabaseName = db.DefaultDatabase.Name;

            DatabaseAccess.Repository.Add(dataBase);

            RefreshDbTreeView();
        }
Exemple #12
0
        public static IDatabase CreateDbConnection(IConnectionSettings connectionInfo)
        {
            dbRoot server = new dbRoot();

            if (!server.Connect(connectionInfo.DriverType, connectionInfo.ConnectionString))
            {
                throw new SqlMigrationException("Could not connect to database server.");
            }

            IDatabase db = server.Databases[connectionInfo.Database];

            if (db == null)
            {
                throw new SqlMigrationException(
                          string.Format("Unable to find the database {0} on server.",
                                        connectionInfo.Database));
            }
            return(db);
        }
Exemple #13
0
        public dbRoot CurrentDbRoot()
        {
            dbRoot mymeta = null;

            try
            {
                mymeta = _mdi.PerformMdiFunction(this.Parent as IMyGenContent, "getstaticdbroot") as dbRoot;
                _isUsingCurrentConnection = true;
                if (!(mymeta is dbRoot))
                {
                    mymeta = new dbRoot();
                    mymeta.Connect(DbDriver, ConnectionString);
                    _isUsingCurrentConnection = false;
                }
            }
            catch (Exception ex)
            {
                this._mdi.ErrorList.AddErrors(ex);
            }

            return(mymeta);
        }
Exemple #14
0
        static void Main(string[] args)
        {
            //初始化元数据类
            dbRoot = new dbRoot();
            //连接到SqlServer数据库,注意必须使用oledb连接字符串
            dbRoot.Connect(dbDriver.SQL, "Provider=sqloledb;Data Source=(local);Initial Catalog=Northwind;Integrated Security = SSPI; ");
            //获取当前连接默认数据库
            var database = dbRoot.DefaultDatabase;

            //输出当前默认数据库名
            Console.WriteLine("当前默认数据库名:" + database.Name);
            Console.WriteLine("----------------------------------------");
            //遍历循环当前数据库所有的表
            int i = 1;

            foreach (var table in database.Tables)
            {
                //输出表名和备注
                Console.WriteLine("表" + i.ToString("D2") + ":" + table.Name + ",备注:" + table.Description);
                Console.WriteLine("---------------");
                int j = 1;
                //遍历循环表所有的字段
                foreach (var column in table.Columns)
                {
                    //输出字段名和字段类型
                    Console.Write("字段" + j.ToString("D2") + ":" + column.Name + "," + column.DataTypeNameComplete);
                    Console.WriteLine("");
                    j++;
                }
                i++;
            }

            Console.ReadKey();


            //Code1();
        }
Exemple #15
0
        void FillTablesListbox()
        {
            lbTables.Items.Clear();

            _dbroot = new dbRoot();
            _dbroot.Connect("SQL", "Provider=SQLOLEDB;" + _connectionstring);

            if (_dbroot.Databases == null)
            {
                //	MessageBox.Show(this, "Cannot connect to database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                toolStripStatusLabel1.BackColor = Color.Red;
                toolStripStatusLabel1.Text      = "Cannot connect to database: " + cbConnectionStrings.SelectedItem;
                MessageBeep(BeepType.Exclamation);
            }
            else
            {
                Cursor.Current                  = Cursors.WaitCursor;
                toolStripStatusLabel1.Text      = "";
                toolStripStatusLabel1.BackColor = Color.FromKnownColor(KnownColor.Control);

                lbTables.Items.AddRange(_dbroot.DefaultDatabase.Tables.ToArray());
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #16
0
        private void _ProcessMyMeta(IZeusContext context)
        {
            IZeusInput input  = context.Input;
            dbRoot     myMeta = null;

            if (context.Objects.Contains("MyMeta"))
            {
                myMeta = context.Objects["MyMeta"] as dbRoot;
            }

            if (myMeta != null)
            {
                if (!myMeta.IsConnected)
                {
                    string driver = null, connectionString = null;

                    if (input.Contains("__dbDriver"))
                    {
                        driver = input["__dbDriver"].ToString();
                    }

                    if (input.Contains("__dbConnectionString"))
                    {
                        connectionString = input["__dbConnectionString"].ToString();
                    }

                    if ((driver != null) && (connectionString != null))
                    {
                        myMeta.Connect(driver, connectionString);

                        if (input.Contains("__showDefaultDatabaseOnly"))
                        {
                            myMeta.ShowDefaultDatabaseOnly = ((string)input["__showDefaultDatabaseOnly"] == bool.TrueString);
                        }

                        if (input.Contains("__dbTargetMappingFileName"))
                        {
                            myMeta.DbTargetMappingFileName = (string)input["__dbTargetMappingFileName"];
                        }

                        if (input.Contains("__dbLanguageMappingFileName"))
                        {
                            myMeta.LanguageMappingFileName = (string)input["__dbLanguageMappingFileName"];
                        }

                        if (input.Contains("__userMetaDataFileName"))
                        {
                            myMeta.UserMetaDataFileName = (string)input["__userMetaDataFileName"];
                        }

                        if (input.Contains("__dbTarget"))
                        {
                            myMeta.DbTarget = (string)input["__dbTarget"];
                        }

                        if (input.Contains("__language"))
                        {
                            myMeta.Language = (string)input["__language"];
                        }

                        if (input.Contains("__domainOverride"))
                        {
                            myMeta.DomainOverride = (bool)input["__domainOverride"];
                        }
                    }
                }
            }
        }
Exemple #17
0
        public void SyncFromDataSourceToTableModel(IHost host)
        {
            var myMeta = new dbRoot();

            myMeta.Connect(dbDriver.SQL, ConnectionString);

            try
            {
                Engine.MuteNotify();
                var tablesTrans = Tables.BeginTransaction();
                foreach (ITable metaTable in myMeta.DefaultDatabase.Tables)
                {
                    var table = tablesTrans.GetNamedChild <TableElement>(metaTable.Name);
                    Tables.AddChild(table);

                    var columnsTrans = table.Columns.BeginTransaction();
                    foreach (IColumn metaColumn in metaTable.Columns)
                    {
                        var column = columnsTrans.GetNamedChild <ColumnElement>(metaColumn.Name);

                        column.Name             = metaColumn.Name;
                        column.IsNullable       = metaColumn.IsNullable;
                        column.IsAutoKey        = metaColumn.IsAutoKey;
                        column.IsInPrimaryKey   = metaColumn.IsInPrimaryKey;
                        column.Default          = metaColumn.Default;
                        column.Ordinal          = metaColumn.Ordinal;
                        column.DbType           = metaColumn.DataTypeName;
                        column.MaxLength        = metaColumn.NumericPrecision;
                        column.AutoKeySeed      = metaColumn.AutoKeySeed;
                        column.AutoKeyIncrement = metaColumn.AutoKeyIncrement;

                        table.Columns.AddChild(column);
                    }
                }

                //update foreign keys
                //must be done in a 2nd step since all columns are not available in the first loop
                foreach (ITable metaTable in myMeta.DefaultDatabase.Tables)
                {
                    var table            = tablesTrans.GetNamedChild <TableElement>(metaTable.Name);
                    var foreignKeysTrans = table.ForeignKeys.BeginTransaction();
                    foreach (IForeignKey metaForeignKey in metaTable.ForeignKeys)
                    {
                        if (metaForeignKey.PrimaryTable.Name == metaTable.Name)
                        {
                            continue;
                        }

                        var foreignKey = foreignKeysTrans.GetNamedChild <ForeignKeyElement>(metaForeignKey.Name);
                        foreignKey.PrimaryTable = tablesTrans.GetNamedChild <TableElement>(metaForeignKey.PrimaryTable.Name);
                        table.ForeignKeys.AddChild(foreignKey);
                        var foreignKeyTrans = foreignKey.BeginTransaction();

                        for (int i = 0; i < metaForeignKey.ForeignColumns.Count; i++)
                        {
                            var columnPair = new ColumnPairElement();
                            columnPair.PrimaryColumn = foreignKey.PrimaryTable.Columns.GetNamedChild <ColumnElement>(((IColumn)metaForeignKey.PrimaryColumns[i]).Name);
                            columnPair.ForeignColumn = foreignKey.ForeignTable.Columns.GetNamedChild <ColumnElement>(((IColumn)metaForeignKey.ForeignColumns[i]).Name);

                            foreignKey.AddChild(columnPair);
                        }
                    }
                }

                var viewTrans = Views.BeginTransaction();
                foreach (IView metaView in myMeta.DefaultDatabase.Views)
                {
                    var view = viewTrans.GetNamedChild <ViewElement>(metaView.Name);

                    view.Name = metaView.Name;
                    Views.AddChild(view);
                }

                var procTrans = Procedures.BeginTransaction();
                foreach (IProcedure metaProcedure in myMeta.DefaultDatabase.Procedures)
                {
                    if (metaProcedure.Type == 3)
                    {
                        continue;
                    }

                    var procedure = procTrans.GetNamedChild <ProcedureElement>(metaProcedure.Name);

                    procedure.Name = metaProcedure.Name;
                    Procedures.AddChild(procedure);
                }

                Engine.EnableNotify();
                Engine.OnNotifyChange();
            }
            catch
            {
                MessageBox.Show("Connection failed");
            }

            host.RefreshProjectTree();
        }
Exemple #18
0
        static void Main(string[] args)
        {
            //初始化元数据类
            dbRoot = new dbRoot();
            //连接到SqlServer数据库,注意必须使用oledb连接字符串
            dbRoot.Connect(dbDriver.SQL, "Provider=sqloledb;Data Source=(local);Initial Catalog=Northwind;Integrated Security = SSPI; ");
            //获取当前连接默认数据库
            var database = dbRoot.DefaultDatabase;

            //输出当前默认数据库名
            Console.WriteLine("当前默认数据库名:" + database.Name);
            Console.WriteLine("----------------------------------------");
            //遍历循环当前数据库所有的表
            int i = 1;

            foreach (var table in database.Tables)
            {
                //输出表名和备注
                Console.WriteLine("表" + i.ToString("D2") + ":" + table.Name + ",备注:" + table.Description);
                Console.WriteLine("---------------");
                int j = 1;
                //遍历循环表所有的字段
                foreach (var column in table.Columns)
                {
                    //输出字段名和字段类型
                    Console.Write("字段" + j.ToString("D2") + ":" + column.Name + "," + column.DataTypeNameComplete);
                    Console.WriteLine("");
                    j++;
                }
                i++;
            }

            //获取指定名称数据库(当前用户有权访问的数据库)
            var database2 = dbRoot.Databases["Northwind"];

            //输出当前默认数据库名
            Console.WriteLine("数据库名:" + database2.Name);
            Console.WriteLine("----------------------------------------");


            int k = 1;

            foreach (var view in database.Views)
            {
                //输出视图名和备注
                Console.WriteLine("视图" + i.ToString("D2") + ":" + view.Name + ",备注:" + view.Description);
                Console.WriteLine("---------------");
                //输出存储过程脚本
                Console.WriteLine("视图过程脚本:" + view.ViewText);
                Console.WriteLine("---------------");
                int j = 1;
                //遍历循环视图所有的字段
                foreach (var column in view.Columns)
                {
                    //输出字段名和字段类型
                    Console.Write("字段" + j.ToString("D2") + ":" + column.Name + "," + column.DataTypeNameComplete);
                    Console.WriteLine("");
                    j++;
                }
                k++;
            }


            int l = 1;

            foreach (var procedure in database.Procedures)
            {
                //输出存储过程名和备注
                Console.WriteLine("存储过程" + i.ToString("D2") + ":" + procedure.Name + ",备注:" + procedure.Description);
                Console.WriteLine("---------------");
                //输出存储过程脚本
                Console.WriteLine("存储过程脚本:" + procedure.ProcedureText);
                Console.WriteLine("---------------");
                int j = 1;
                //遍历循环存储过程所有的参数
                foreach (var parameter in procedure.Parameters)
                {
                    //输出参数名和参数类型
                    Console.Write("参数" + j.ToString("D2") + ":" + parameter.Name + "," + parameter.DataTypeNameComplete);
                    Console.WriteLine("");
                    j++;
                }

                j = 1;
                //遍历循环存储过程所有的结果
                foreach (IResultColumn column in procedure.ResultColumns)
                {
                    //输出字段名和字段类型
                    Console.Write("字段" + j.ToString("D2") + ":" + column.Name + "," + column.DataTypeNameComplete);
                    Console.WriteLine("");
                    j++;
                }
                l++;
            }


            Console.ReadKey();


            //Code1();
        }
Exemple #19
0
        public void ExecuteTemplate(ZeusTemplate template)
        {
            this.Cursor = Cursors.WaitCursor;

            DefaultSettings settings = new DefaultSettings();

            ZeusInput           zin     = new ZeusInput();
            ZeusOutput          zout    = new ZeusOutput();
            Hashtable           objects = new Hashtable();
            ZeusGuiContext      guicontext;
            ZeusTemplateContext bodycontext = null;

            dbRoot myMeta = new dbRoot();

            // Set the global variables for the default template/output paths
            zin["defaultTemplatePath"] = settings.DefaultTemplateDirectory;
            zin["defaultOutputPath"]   = settings.DefaultOutputDirectory;

            string driver, connectionString;

            //if there is a connection string set, it in the input section here.
            if (settings.DbDriver != string.Empty)
            {
                driver           = settings.DbDriver;
                connectionString = settings.ConnectionString;

                zin["dbDriver"]           = driver;
                zin["dbConnectionString"] = connectionString;

                try
                {
                    // Try to connect to the DB with MyMeta (using default connection info)
                    myMeta.Connect(settings.DbDriver, settings.ConnectionString);

                    // Set DB global variables and also input variables

                    if (settings.DbTarget != string.Empty)
                    {
                        myMeta.DbTarget = settings.DbTarget;
                    }

                    if (settings.DbTargetMappingFile != string.Empty)
                    {
                        myMeta.DbTargetMappingFileName = settings.DbTargetMappingFile;
                    }

                    if (settings.LanguageMappingFile != string.Empty)
                    {
                        myMeta.LanguageMappingFileName = settings.LanguageMappingFile;
                    }

                    if (settings.DbTarget != string.Empty)
                    {
                        myMeta.DbTarget = settings.DbTarget;
                    }

                    if (settings.Language != string.Empty)
                    {
                        myMeta.Language = settings.Language;
                    }

                    if (settings.UserMetaDataFileName != string.Empty)
                    {
                        myMeta.UserMetaDataFileName = settings.UserMetaDataFileName;
                    }
                }
                catch
                {
                    // Give them an empty MyMeta
                    myMeta = new dbRoot();
                }
            }

            bool exceptionOccurred = false;

            bool result = false;

            try
            {
                // Add any objects here that need to be embedded in the script.
                objects.Add("MyMeta", myMeta);

                guicontext = new ZeusGuiContext(zin, new GuiController(), objects);

                template.GuiSegment.ZeusScriptingEngine.Executioner.ScriptTimeout = settings.ScriptTimeout;
                template.GuiSegment.ZeusScriptingEngine.Executioner.SetShowGuiHandler(new ShowGUIEventHandler(DynamicGUI_Display));
                result = template.GuiSegment.Execute(guicontext);

                if (result)
                {
                    bodycontext = new ZeusTemplateContext(guicontext);
                    result      = template.BodySegment.Execute(bodycontext);
                }
            }
            catch (Exception ex)
            {
                ZeusDisplayError formError = new ZeusDisplayError(ex);
                formError.SetControlsFromException();
                formError.ShowDialog(this);

                exceptionOccurred = true;
            }

            if (!exceptionOccurred && result)
            {
                MessageBox.Show("Successfully rendered template: " + template.Title);
            }

            this.Cursor = Cursors.Default;
        }