当前位置: 首页>>代码示例>>C#>>正文


C# IShellContext.GetDefaultConnection方法代码示例

本文整理汇总了C#中IShellContext.GetDefaultConnection方法的典型用法代码示例。如果您正苦于以下问题:C# IShellContext.GetDefaultConnection方法的具体用法?C# IShellContext.GetDefaultConnection怎么用?C# IShellContext.GetDefaultConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IShellContext的用法示例。


在下文中一共展示了IShellContext.GetDefaultConnection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TargetEntitySqlModel

        public TargetEntitySqlModel(DataSyncSqlModel dataSyncSqlModel, Target dbsh, IShellContext context)
        {
            this._dataSyncSqlModel = dataSyncSqlModel;
            this._dbsh = dbsh;
            TargetTable = new NameWithSchema(context.Replace(dbsh.TableSchema), context.Replace(dbsh.TableName));
            string findSchema = dbsh.TableSchema;
            if (findSchema != null && findSchema.StartsWith(NameWithSchema.NoQuotePrefix)) findSchema = null;
            Structure = dataSyncSqlModel.TargetStructure.FindTableLike(findSchema, TargetTable.Name);
            SqlAlias = _dbsh.Alias ?? "dst_" + _dataSyncSqlModel.Entities.Count;

            foreach (var col in dbsh.Columns)
            {
                var targetCol = new TargetNoRefColumnSqlModel(col, FindColumnInfo(col.Name));
                TargetColumns.Add(targetCol);

                foreach (string alias in ExtractColumnSources(col))
                {
                    SourceColumnSqlModel source = null;
                    if (dataSyncSqlModel.SourceGraphModel == null)
                    {
                        // flat sync
                        if (!String.IsNullOrEmpty(dbsh.PrimarySource))
                        {
                            var tableSource = DataSync.FlatSources.FirstOrDefault(x => x.Match(Dbsh.PrimarySource));
                            if (tableSource != null)
                            {
                                source = tableSource.Columns.FirstOrDefault(x => x.Alias == alias);
                            }
                        }
                    }
                    else
                    {
                        source = dataSyncSqlModel.SourceGraphModel[alias];
                        //targetCol.Sources.Add(source);
                    }
                    RequiredSourceColumns.Add(source);
                    if (col.IsKey) KeySourceColumns.Add(source);
                }
            }

            if (!String.IsNullOrEmpty(_dbsh.Connection))
            {
                var ctxConn = new NormalizedDatabaseConnectionInfo(new DatabaseConnectionInfoHolder { ProviderString = context.GetDefaultConnection() });
                var tableConn = new NormalizedDatabaseConnectionInfo(new DatabaseConnectionInfoHolder { ProviderString = context.Replace(_dbsh.Connection), LinkedInfo = _dbsh.LinkedInfo });

                if (ctxConn != tableConn)
                {
                    if (ctxConn.ServerConnectionString == tableConn.ServerConnectionString)
                    {
                        TargetLinkedInfo = tableConn.GetLinkedInfo();
                    }
                    else
                    {
                        throw new IncorrectRdsDefinitionException($"DBSH-00000 RDS target must be reachable by database or linked server: ({TargetTable})");
                    }
                }
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:58,代码来源:TargetEntitySqlModel.cs

示例2: GetProviderString

 public string GetProviderString(IShellContext context)
 {
     string providerString = Connection ?? context.GetDefaultConnection();
     if (providerString == null)
     {
         throw new Exception("DBSH-00151 Connection is not set, element=" + GetType().FullName);
     }
     return providerString;
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:9,代码来源:ElementBase.cs

示例3: InitializeQuerySource

        public void InitializeQuerySource(ITabularDataSource dataSource, IShellContext context, string sourceTableVariable, string sourceQueryVariable)
        {
            if (!_dbsh.ForceExternalSource)
            {
                // try to create non-external source

                var tableOrView = dataSource as DbShell.Core.Utility.TableOrView;

                if (!String.IsNullOrEmpty(sourceTableVariable))
                {
                    QuerySource = new DmlfSource
                    {
                        Alias = SqlAlias,
                        TableOrView = new NameWithSchema($"###({sourceTableVariable})###"),
                    };
                    TableName = new NameWithSchema(sourceTableVariable);
                    return;
                }

                if (!String.IsNullOrEmpty(sourceQueryVariable))
                {
                    QuerySource = new DmlfSource
                    {
                        Alias = SqlAlias,
                        SubQueryString = $"###({sourceQueryVariable})###",
                    };
                    return;

                }

                if (tableOrView != null)
                {
                    bool canUseTable = true;
                    LinkedDatabaseInfo linked = null;

                    var ctxConn = new NormalizedDatabaseConnectionInfo(new DatabaseConnectionInfoHolder { ProviderString = context.GetDefaultConnection() });
                    var tableConn = tableOrView.GetNormalizedConnectionInfo(context);

                    if (ctxConn != tableConn)
                    {
                        if (ctxConn.ServerConnectionString == tableConn.ServerConnectionString)
                        {
                            linked = tableConn.GetLinkedInfo();
                        }
                        else
                        {
                            canUseTable = false;
                        }
                    }

                    if (canUseTable)
                    {
                        TableName = tableOrView.GetFullName(context);
                        QuerySource = new DmlfSource
                        {
                            Alias = SqlAlias,
                            TableOrView = TableName,
                            LinkedInfo = linked,
                        };
                        return;
                    }
                }

                var query = dataSource as DbShell.Core.Query;
                if (query != null && query.GetProviderString(context) == context.GetDefaultConnection())
                {
                    string sql = context.Replace(query.Text);
                    QuerySource = new DmlfSource
                    {
                        Alias = SqlAlias,
                        SubQueryString = sql,
                    };
                    return;
                }
            }

            IsExternal = true;
            _externalDataName = new NameWithSchema(null, $"##{SqlAlias}_{new Random().Next(10000, 100000)}");
            QuerySource = new DmlfSource
            {
                Alias = SqlAlias,
                TableOrView = _externalDataName,
            };
            _dataSync.AddExternalSource(this);
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:85,代码来源:SourceEntitySqlModel.cs


注:本文中的IShellContext.GetDefaultConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。