Example #1
0
        public override string CreateText(AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IDatabaseSource     db      = appobj.FindDatabaseConnection(connpack);
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            if (conn != null && objpath != null && conn.SystemConnection != null)
            {
                string text = conn.InvokeR <string>((Func <string>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    string sql = GetSelect(objpath);
                    using (var cmd = conn.SystemConnection.CreateCommand())
                    {
                        cmd.CommandText = sql;
                        using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                        {
                            if (reader.Read())
                            {
                                return(reader[m_colnumber].SafeToString());
                            }
                        }
                    }
                    return("");
                });
                return(text);
            }
            return("");
        }
Example #2
0
        public override ITabularDataView GetTabularData(ConnectionPack connpack)
        {
            var tabdata = GetTableConnection(connpack).GetTabularData() as GenericTabularDataView;

            tabdata.FixedPerspective = FileName;
            return(tabdata);
        }
Example #3
0
        public override void GetObjectList(List <AppObject> objs, AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath objpath = appobj.GetObjectPath();
            var        tsrc    = appobj.TableSource;

            //IDatabaseSource conn = appobj.FindDatabaseConnection(connpack);
            if (tsrc == null)
            {
                return;
            }
            if (!tsrc.Connection.IsOpened)
            {
                return;
            }
            var ts = tsrc.InvokeLoadStructure(TableStructureMembers.Columns | TableStructureMembers.PrimaryKey | TableStructureMembers.ForeignKeys);

            foreach (var col in ts.Columns)
            {
                var cobj = new ColumnAppObject();
                cobj.Column = new ColumnStructure(col);
                cobj.FillFromTable(tsrc);
                cobj.FillRelatedConstraints(ts.Constraints);
                objs.Add(cobj);
            }
        }
Example #4
0
 protected TreeNodeBase(string protocol)
 {
     m_connpack = new ConnectionPack(this);
     m_name     = "root";
     m_fullpath = protocol + ":";
     //CopyDerivedProperties();
     InitializeExtenders();
 }
Example #5
0
 public GenerateDataSqlJobCommand(IDataSqlGenerator generator, IFilePlace place, ISqlDialect dialect, TableDataFrame dataFrame, DataFrameRowsExtractor rows, ConnectionPack connpack, SqlFormatProperties formatProps)
 {
     Generator   = generator;
     Place       = place;
     Dialect     = dialect;
     ConnPack    = connpack;
     m_rows      = rows;
     m_dataFrame = dataFrame;
     FormatProps = formatProps;
 }
Example #6
0
 public GenerateSqlJobCommand(IAppObjectSqlGenerator generator, IFilePlace place, ISqlDialect dialect, AppObject[] objs, ConnectionPack connpack, SqlFormatProperties formatProps)
     : this()
 {
     Generator = generator;
     Place     = place;
     Dialect   = dialect;
     Args.AddRange(objs);
     ConnPack    = connpack;
     FormatProps = formatProps;
 }
Example #7
0
        public static ITableSource FindTableConnection(this AppObject appobj, ConnectionPack connpack)
        {
            var tbl = appobj as TableFieldsAppObject;

            if (tbl == null)
            {
                return(null);
            }
            return(tbl.GetDatabaseConnection(connpack).GetTable(tbl.DbObjectName));
        }
Example #8
0
 public ContentFrame()
 {
     Usage              = new UsageBuilder(UsageEventName);
     PersistString      = Guid.NewGuid().ToString();
     m_invoker          = new ControlInvoker(this);
     m_readDetailFrames = new ReadOnlyCollection <ContentFrame>(m_detailFrames);
     ConnPack           = new ConnectionPack(this);
     Disposed          += ContentFrame_Disposed;
     InitializeComponent();
     HConnection.RemoveByKey += HConnection_RemoveByKey;
     HUsage.ClosingApp       += HUsage_ClosingApp;
 }
        public static T ChangeConnection <T>(this T usage, ConnectionPack connpack)
            where T : IConnectionUsage
        {
            if (usage.Connection == null)
            {
                throw new InternalError("DAE-00009 Connection property not set");
            }
            var conn = connpack.GetConnection(usage.Connection.PhysicalFactory, true);

            usage.Connection = conn;
            return(usage);
        }
Example #10
0
 protected TreeNodeBase(ITreeNode parent, string name)
 {
     m_connpack = parent.ConnPack;
     if (parent == null)
     {
         throw new InternalError("DAE-00007 Parent cannot be null");
     }
     m_name     = name;
     m_parent   = parent;
     m_fullpath = parent.Path + "/" + name;
     //CopyDerivedProperties();
     InitializeExtenders();
 }
Example #11
0
        public void GetWidgetsEx(List <IWidget> res, ConnectionPack connpack)
        {
            GetWidgets(res);
            var conn = connpack.GetConnection(GetConnection(), false);

            if (conn != null)
            {
                var dialect = conn.Dialect;
                if (dialect != null)
                {
                    dialect.GetAdditionalWidgets(res, this);
                }
            }
        }
Example #12
0
        public IDatabaseSource GetDatabaseConnection(ConnectionPack connpack)
        {
            if (connpack == null)
            {
                return(null);
            }
            var phys = connpack.GetConnection(Connection, true);

            if (phys == null)
            {
                return(null);
            }
            return(phys.PhysicalFactory.CreateDatabaseSource(phys, DatabaseName));
        }
Example #13
0
        public IServerSource GetServerConnection(ConnectionPack connpack)
        {
            if (connpack == null)
            {
                return(null);
            }
            var phys = connpack.GetConnection(Connection, true);

            if (phys == null)
            {
                return(null);
            }
            return(phys.PhysicalFactory.CreateServerSource(phys));
        }
Example #14
0
        public static IServerSource FindServerConnection(this AppObject appobj, ConnectionPack connpack)
        {
            var srv = appobj as ServerFieldsAppObject;

            if (srv == null)
            {
                return(null);
            }
            if (connpack == null)
            {
                return(null);
            }
            return(srv.GetServerConnection(connpack));
        }
Example #15
0
        public static IDatabaseSource FindDatabaseConnection(this AppObject appobj, ConnectionPack connpack)
        {
            if (appobj == null)
            {
                return(null);
            }
            var db = appobj as DatabaseFieldsAppObject;

            if (db == null)
            {
                return(null);
            }
            return(db.GetDatabaseConnection(connpack));
        }
Example #16
0
        public override string CreateHtml(AppObject appobj, ConnectionPack connpack, IDictionary <string, object> outnames)
        {
            HtmlGenerator       gen   = new HtmlGenerator();
            IPhysicalConnection pconn = appobj.FindPhysicalConnection(connpack);
            string dbversion          = null;

            if (pconn != null && pconn.SystemConnection != null)
            {
                try
                {
                    dbversion = pconn.SystemConnection.ServerVersion;
                }
                catch
                {
                    dbversion = null;
                }
            }
            IStoredConnection scon = pconn.StoredConnection;

            gen.BeginHtml(VersionInfo.ProgramTitle, HtmlGenerator.HtmlObjectViewStyle);
            gen.Heading(Texts.Get("s_properties"), 2);
            gen.PropsTableBegin();
            if (scon != null)
            {
                gen.PropTableRow("s_path", scon.FileName);
            }
            var attr = XmlTool.GetRegisterAttr(scon);

            if (attr != null)
            {
                gen.PropTableRow("s_database_engine", attr.Title ?? attr.Name);
            }
            if (scon != null)
            {
                gen.PropTableRow("s_host", scon.GetDataSource());
                gen.PropTableRow("s_database", scon.ExplicitDatabaseName);
                gen.PropTableRow("s_login", scon.GetLogin());
            }
            else
            {
                gen.PropTableRow("s_path", pconn.PhysicalFactory.GetDataSource());
            }
            if (dbversion != null)
            {
                gen.PropTableRow("s_version", dbversion);
            }
            gen.PropsTableEnd();
            gen.EndHtml();
            return(gen.HtmlText);
        }
Example #17
0
        public override void GetObjectList(List <AppObject> objs, AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath      objpath = appobj.GetObjectPath();
            IDatabaseSource conn    = appobj.FindDatabaseConnection(connpack);

            if (conn != null && conn.Connection.IsOpened)
            {
                var dbmem = new DatabaseStructureMembers();
                dbmem.IgnoreSystemObjects = true;
                if (_Type.ObjectType == "table")
                {
                    dbmem.TableList = true;
                }
                else
                {
                    var smem = new SpecificObjectMembers {
                        ObjectList = true
                    };
                    dbmem.SpecificObjectOverride[_Type.ObjectType] = smem;
                }
                var dbs = conn.InvokeLoadStructure(dbmem, null);
                if (_Type.ObjectType == "table")
                {
                    foreach (var tbl in dbs.Tables)
                    {
                        var o = new TableAppObject();
                        o.FillFromDatabase(conn);
                        o.DbObjectName = tbl.FullName;
                        objs.Add(o);
                    }
                }
                else
                {
                    if (dbs.SpecificObjects.ContainsKey(_Type.ObjectType))
                    {
                        foreach (var spec in dbs.SpecificObjects[_Type.ObjectType])
                        {
                            var o = new SpecificObjectAppObject();
                            o.FillFromDatabase(conn);
                            o.DbObjectName = spec.ObjectName;
                            o.DbObjectType = _Type.ObjectType;
                            objs.Add(o);
                        }
                    }
                }
            }
            objs.SortByKey(o => o.ToString());
        }
Example #18
0
        public override void GetData(AppObject appobj, ConnectionPack connpack, out System.Data.DataTable data, out DatAdmin.Scripting.ObjectGrid grid)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            data = null;
            grid = null;
            if (conn != null && conn.IsOpened && conn.SystemConnection != null)
            {
                data = conn.InvokeR <DataTable>((Func <DataTable>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    return(LoadSchema(conn.SystemConnection, objpath));
                });
            }
        }
Example #19
0
        public override void GetData(AppObject appobj, ConnectionPack connpack, out System.Data.DataTable data, out DatAdmin.Scripting.ObjectGrid grid)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            data = null;
            grid = null;
            if (conn != null && objpath != null)
            {
                data = InvokerExtension.InvokeR <DataTable>(conn, (Func <DataTable>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    return(m_dbtype.LoadOverview(conn.SystemConnection, objpath));
                });
            }
        }
Example #20
0
        public override void GetObjectList(List <AppObject> objs, AppObject appobj, ConnectionPack connpack)
        {
            var server = appobj.FindServerConnection(connpack);

            if (server == null || server.Connection == null)
            {
                return;
            }

            foreach (string name in server.Databases)
            {
                var dbappobj = new DatabaseAppObject();
                dbappobj.FillFromDatabase(server.GetDatabase(name));
                objs.Add(dbappobj);
            }
            objs.SortByKey(o => o.ToString());
        }
Example #21
0
 public override void GetObjectList(List <AppObject> objs, AppObject appobj, ConnectionPack connpack)
 {
     if (IsDesigning)
     {
         objs.Add(new AddShortcutAppObject(this));
     }
     foreach (var item in Items)
     {
         var newobj = item.CloneUsingXml() as DatabaseFieldsAppObject;
         if (newobj == null)
         {
             continue;
         }
         newobj.AssignDbFields(appobj as DatabaseFieldsAppObject);
         objs.Add(newobj);
     }
 }
Example #22
0
        public override ISqlDialect GetDialect(AppObject appobj, ConnectionPack connpack)
        {
            var fav = appobj as FavoriteAppObject;

            if (fav == null)
            {
                return(null);
            }
            var holder = fav.LoadHolder();
            var favsql = holder.Favorite as IFavoriteWithSql;

            if (favsql == null)
            {
                return(GenericDialect.Instance);
            }
            return(favsql.GetDialect());
        }
Example #23
0
        public override string CreateText(AppObject appobj, ConnectionPack connpack)
        {
            var fav = appobj as FavoriteAppObject;

            if (fav == null)
            {
                return("");
            }
            var holder = fav.LoadHolder();
            var favsql = holder.Favorite as IFavoriteWithSql;

            if (favsql == null)
            {
                return("");
            }
            return(favsql.LoadSql());
        }
Example #24
0
        public override void GetObjectList(List <AppObject> objs, AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath      objpath = appobj.GetObjectPath();
            IDatabaseSource conn    = appobj.FindDatabaseConnection(connpack);

            if (conn != null && conn.Connection.IsOpened)
            {
                var ts = conn.InvokeLoadTableStructure(objpath.ObjectName, TableStructureMembers.ConstraintsNoRefs);
                foreach (var cnt in ts.Constraints)
                {
                    var cobj = new ConstraintAppObject();
                    cobj.Constraint = Constraint.CreateCopy(cnt);
                    cobj.FillFromTable(conn.GetTable(objpath.ObjectName));
                    objs.Add(cobj);
                }
            }
            objs.SortByKey(o => o.ToString());
        }
Example #25
0
        public override void CreateNew(AppObject appobj, ConnectionPack connpack)
        {
            var tp = _Type;

            if (tp.ObjectType == "table")
            {
                var pars = new AlterTableEditorPars {
                    SavedCallback = RefreshList
                };
                MainWindow.Instance.OpenContent(new TableEditFrame(appobj.CreateDatabaseConnection(), null, pars));
            }
            else
            {
                var dbconn = appobj.FindDatabaseConnection(connpack);
                var dbtype = dbconn.Dialect.GetSpecificObjectType(tp.ObjectType);
                if (dbconn.DatabaseCaps.ExecuteSql)
                {
                    OpenQueryParameters pars    = new OpenQueryParameters();
                    IPhysicalConnection newconn = dbconn.Connection.Clone();
                    string dbname = appobj.FindDatabaseName();
                    if (dbname != null)
                    {
                        newconn.AfterOpen += ConnTools.ChangeDatabaseCallback(dbname);
                    }
                    pars.GenerateSql = delegate(IPhysicalConnection conn)
                    {
                        return(dbtype.GenerateCreateNew(conn.SystemConnection, appobj.GetObjectPath()));
                    };
                    pars.HideDesign       = true;
                    pars.ExecutedCallback = RefreshList;
                    MainWindow.Instance.OpenContent(new QueryFrame(newconn, pars));
                }
                else
                {
                    string sql  = dbtype.GenerateCreateNew(dbconn.Connection.SystemConnection, appobj.GetObjectPath());
                    var    pars = new ObjectEditorPars {
                        SavedCallback = RefreshList
                    };
                    var frm = new SpecificObjectFrame(dbconn, tp.ObjectType, sql, pars);
                    MainWindow.Instance.OpenContent(frm);
                }
            }
        }
Example #26
0
        public override string CreateHtml(AppObject appobj, ConnectionPack connpack, IDictionary <string, object> outnames)
        {
            var           fav    = (FavoriteAppObject)appobj;
            var           holder = fav.LoadHolder();
            HtmlGenerator gen    = new HtmlGenerator();

            gen.BeginHtml(holder.Name, HtmlGenerator.HtmlObjectViewStyle);
            gen.Heading(holder.Name, 2);
            gen.PropsTableBegin();
            gen.PropTableRow("s_name", IOTool.RelativePathTo(Core.FavoritesDirectory, fav.FileName));
            holder.Favorite.DisplayProps((n, v) => gen.PropTableRow(n, v));
            gen.PropsTableEnd();
            gen.BeginUl();
            gen.Li(String.Format("<a href='callback://open'>{0}</a>", Texts.Get("s_execute")));
            gen.EndUl();
            gen.EndHtml();
            outnames["open"] = (Action) delegate() { holder.Favorite.Open(); };
            return(gen.HtmlText);
        }
Example #27
0
        public virtual ISqlDialect GetDialect(AppObject appobj, ConnectionPack connpack)
        {
            var dbobj = appobj as DatabaseFieldsAppObject;

            if (dbobj == null)
            {
                return(GenericDialect.Instance);
            }
            IDatabaseSource db = dbobj.GetDatabaseConnection(connpack);

            if (db != null && db.Dialect != null)
            {
                return(db.Dialect);
            }
            IPhysicalConnection conn = connpack.GetConnection(appobj.GetConnection(), false);

            if (conn == null)
            {
                return(GenericDialect.Instance);
            }
            return(conn.Dialect ?? GenericDialect.Instance);
        }
Example #28
0
        public override void CreateNew(AppObject appobj, ConnectionPack connpack)
        {
            var dbprops = new DatabaseProperties();

            dbprops.Name = "newdb";
            var server = appobj.FindServerConnection(connpack);

            if (server == null || server.Connection == null)
            {
                return;
            }
            if (DatabasePropertiesForm.Run(dbprops, new GenericDatabaseSource(server, server.Connection, null), false))
            {
                if (ArrayTool.Contains(server.Databases, dbprops.Name))
                {
                    StdDialog.ShowError(Texts.Get("s_database_allready_exists"));
                    return;
                }
                server.Connection.InvokeScript(fmt => { fmt.CreateDatabase(dbprops.Name, dbprops.SpecificData); }, null);
                appobj.CallCompleteChanged();
            }
        }
Example #29
0
        public override string CreateText(AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IDatabaseSource     db      = appobj.FindDatabaseConnection(connpack);
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);
            var sobj = appobj as SpecificObjectAppObject;

            if (conn != null && objpath != null)
            {
                string text = conn.InvokeR <string>((Func <string>) delegate()
                {
                    ISpecificObjectStructure so = db.LoadSpecificObjectDetail(sobj.DbObjectType, objpath.ObjectName);
                    return(conn.Dialect.GenerateScript(dmp => { dmp.CreateSpecificObject(so); }, AppObjectSqlGeneratorBase.TemplateFormatProps));
                });
                if (conn.Dialect != null)
                {
                    text = conn.Dialect.ReformatSpecificObject(sobj.DbObjectType, text);
                }
                return(text);
            }
            return("");
        }
Example #30
0
        public override void GetData(AppObject appobj, ConnectionPack connpack, out System.Data.DataTable data, out DatAdmin.Scripting.ObjectGrid grid)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            data = null;
            grid = null;
            if (conn != null && conn.IsOpened)
            {
                data = conn.InvokeR <DataTable>((Func <DataTable>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    using (DbCommand cmd = conn.SystemConnection.CreateCommand())
                    {
                        cmd.CommandText = GetSelect(objpath);
                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            return(reader.ToDataTable());
                        }
                    }
                });
            }
        }