Exemple #1
0
        /// <summary>
        /// Imports environment data from the specified dataset. Prior to call, you should
        /// first call <see cref="RemoveAll"/>.
        /// </summary>
        /// <param name="server">The server holding the data</param>
        /// <param name="ds">The dataset to import</param>
        public void Import(IDataServer server, BacksightDataSet ds)
        {
            using (IConnection ic = server.GetConnection())
            {
                SqlConnection c = ic.Value;

                foreach (DataTable dt in ds.Tables)
                {
                    if (dt.Rows.Count > 0)
                    {
                        SqlBulkCopy bc        = new SqlBulkCopy(c);
                        string      tableName = "[ced].[" + GetTableName(dt) + "]";
                        bc.DestinationTableName = tableName;
                        bc.BatchSize            = dt.Rows.Count;
                        bc.WriteToServer(dt);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Attaches miscellaneous attribute data to the features that have been loaded.
        /// </summary>
        /// <param name="keyIds">Index of the IDs to look for (indexed by formatted key)</param>
        /// <returns>The number of rows that were found (-1 if no database tables have
        /// been associated with Backsight)</returns>
        static int Load(Dictionary <string, FeatureId> keyIds)
        {
            // Locate information about the tables associated with Backsight
            ITable[] tables = EnvironmentContainer.Current.Tables;
            if (tables.Length == 0)
            {
                return(-1);
            }

            IDataServer ds = EditingController.Current.DataServer;

            if (ds == null)
            {
                return(-1);
            }

            // Copy the required keys into a temp table
            Trace.WriteLine(String.Format("Locating attributes for {0} feature IDs in {1} tables", keyIds.Count, tables.Length));

            int nFound = 0;

            ds.RunTransaction(delegate
            {
                IConnection ic = ds.GetConnection();
                const string KEYS_TABLE_NAME = "#Ids";
                CopyKeysToTable(ic, keyIds, KEYS_TABLE_NAME);

                foreach (ITable t in tables)
                {
                    string sql = String.Format("SELECT * FROM {0} WHERE [{1}] IN (SELECT [FeatureId] FROM [{2}])",
                                               t.TableName, t.IdColumnName, KEYS_TABLE_NAME);
                    DataTable tab = ds.ExecuteSelect(sql);
                    tab.TableName = t.TableName;

                    int featureIdIndex = tab.Columns[t.IdColumnName].Ordinal;
                    Debug.Assert(featureIdIndex >= 0);
                    foreach (DataRow row in tab.Select())
                    {
                        string key = row[featureIdIndex].ToString().TrimEnd();
                        FeatureId fid;
                        if (keyIds.TryGetValue(key, out fid))
                        {
                            // Don't create a row if the ID is already associated with the
                            // table (this is meant to cover situations where the edit has actively
                            // formed the attributes, and is calling this method only to cover the
                            // fact that further attributes may be involved).

                            if (!fid.RefersToTable(t))
                            {
                                Row r = new Row(fid, t, row);
                                nFound++;
                            }
                        }
                        else
                        {
                            string msg = String.Format("Cannot find '{0}' in dictionary", key);
                            throw new Exception(msg);
                        }
                    }
                }
            });

            return(nFound);
        }