Ejemplo n.º 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("");
        }
Ejemplo n.º 2
0
        public override ITabularDataView GetTabularData(ConnectionPack connpack)
        {
            var tabdata = GetTableConnection(connpack).GetTabularData() as GenericTabularDataView;

            tabdata.FixedPerspective = FileName;
            return(tabdata);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
 protected TreeNodeBase(string protocol)
 {
     m_connpack = new ConnectionPack(this);
     m_name     = "root";
     m_fullpath = protocol + ":";
     //CopyDerivedProperties();
     InitializeExtenders();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 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();
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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));
                });
            }
        }
Ejemplo n.º 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));
                });
            }
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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("");
        }
Ejemplo n.º 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());
                        }
                    }
                });
            }
        }