Esempio n. 1
0
        async public override Task <IDatasetElement> Element(string title)
        {
            DataTable tables = new DataTable(), views = new DataTable();

            try
            {
                using (DbConnection conn = this.ProviderFactory.CreateConnection())
                {
                    conn.ConnectionString = _connectionString;
                    await conn.OpenAsync();

                    DbDataAdapter adapter = this.ProviderFactory.CreateDataAdapter();
                    adapter.SelectCommand             = this.ProviderFactory.CreateCommand();
                    adapter.SelectCommand.CommandText = @"select t.name as tabName, c.name as colName, types.name from sys.tables t join sys.columns c on (t.object_id = c.object_id) join sys.types types on (c.user_type_id = types.user_type_id) where types.name = 'geometry'";
                    adapter.SelectCommand.Connection  = conn;
                    adapter.Fill(tables);

                    adapter.SelectCommand.CommandText = @"select t.name as tabName, c.name as colName, types.name from sys.views t join sys.columns c on (t.object_id = c.object_id) join sys.types types on (c.user_type_id = types.user_type_id) where types.name = 'geometry'";
                    adapter.Fill(views);

                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                _errMsg = ex.Message;
                return(null);
            }

            foreach (DataRow row in tables.Rows)
            {
                string tableName = row["tabName"].ToString();
                if (await EqualsTableName(tableName, title, false))
                {
                    return(new DatasetElement(await Featureclass.Create(this,
                                                                        tableName,
                                                                        IDFieldName(title),
                                                                        row["colName"].ToString(), false)));
                }
            }

            foreach (DataRow row in views.Rows)
            {
                string tableName = row["tabName"].ToString();
                if (await EqualsTableName(tableName, title, true))
                {
                    return(new DatasetElement(await Featureclass.Create(this,
                                                                        tableName,
                                                                        IDFieldName(title),
                                                                        row["colName"].ToString(), true)));
                }
            }

            return(null);
        }
Esempio n. 2
0
        async public override Task <List <IDatasetElement> > Elements()
        {
            if (_layers == null || _layers.Count == 0)
            {
                List <IDatasetElement> layers = new List <IDatasetElement>();
                DataTable tables = new DataTable(), views = new DataTable();
                try
                {
                    using (DbConnection conn = this.ProviderFactory.CreateConnection())
                    {
                        conn.ConnectionString = _connectionString;
                        await conn.OpenAsync();

                        DbDataAdapter adapter = this.ProviderFactory.CreateDataAdapter();
                        adapter.SelectCommand             = this.ProviderFactory.CreateCommand();
                        adapter.SelectCommand.CommandText = @"select t.name as tabName, c.name as colName, types.name from sys.tables t join sys.columns c on (t.object_id = c.object_id) join sys.types types on (c.user_type_id = types.user_type_id) where types.name = 'geography'";
                        adapter.SelectCommand.Connection  = conn;
                        adapter.Fill(tables);

                        adapter.SelectCommand.CommandText = @"select t.name as tabName, c.name as colName, types.name from sys.views t join sys.columns c on (t.object_id = c.object_id) join sys.types types on (c.user_type_id = types.user_type_id) where types.name = 'geography'";
                        adapter.Fill(views);

                        conn.Close();
                    }
                }
                catch (Exception ex)
                {
                    _errMsg = ex.Message;
                    return(layers);
                }

                foreach (DataRow row in tables.Rows)
                {
                    IFeatureClass fc = await Featureclass.Create(this,
                                                                 row["tabName"].ToString(),
                                                                 IDFieldName(row["tabName"].ToString()),
                                                                 row["colName"].ToString(), false);

                    layers.Add(new DatasetElement(fc));
                }
                foreach (DataRow row in views.Rows)
                {
                    IFeatureClass fc = await Featureclass.Create(this,
                                                                 row["tabName"].ToString(),
                                                                 IDFieldName(row["tabName"].ToString()),
                                                                 row["colName"].ToString(), true);

                    layers.Add(new DatasetElement(fc));
                }

                _layers = layers;
            }
            return(_layers);
        }