Exemple #1
0
        /// <summary>
        /// Perform MEF initialization
        /// </summary>
        private void ComposeMefParts()
        {
            var catalog = Utils.Mef.GetMefCatalogs();

            try
            {
                catalog.Catalogs.Add(new AssemblyCatalog("RVRMeander.Model.Mc.dll"));
            }
            catch (Exception ex)
            {
                log.Fatal("Unable to find one of the assemblies that MainFormCore adds to the assembly catalog: {0}", ex.Message);
            }
            //catalog.Catalogs.Add(new DirectoryCatalog(System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "*.dll"));
            //catalog.Catalogs.Add(new DirectoryCatalog(System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "*.exe"));
            this.compContainer = new CompositionContainer(catalog);

            try
            {
                this.compContainer.ComposeParts(this);
            }
            catch (System.Reflection.ReflectionTypeLoadException ex)
            {
                foreach (Exception inner in ex.LoaderExceptions)
                {
                    log.Warning("Reflection error: {0}", inner.Message);
                }
            }
            catch (CompositionException ex)
            {
                log.Fatal(ex.ToString());
                //Close();
            }

            this.container = this;
        }
Exemple #2
0
        /// <summary>
        /// Reads the feature set from the database, satisfying the given SQL query
        /// </summary>
        /// <param name="connString">sqlite db connection string</param>
        /// <param name="featureSetInfo">information about the table</param>
        /// <param name="sqlFilter">the sql query; to select all: "SELECT * FROM TableName"</param>
        /// <returns>the resulting feature set</returns>
        public bool TryReadFeatureSet(SQLiteConnection conn, FeatureSetTableInfo featureSetInfo, string sqlFilter, out IFeatureSet featureSet)
        {
            featureSet = null;
            if (featureSetInfo == null)
            {
                return(false);
            }

            var fs = new SpatiaLiteFeatureSet(featureSetInfo.GeometryType);

            fs.IndexMode = false; //setting the initial index mode..

            SQLiteCommand cmd = null;

            try
            {
                cmd = new SQLiteCommand(sqlFilter, conn);

                var wkbr = new SpatiaLiteWkbReader();

                var rdr = cmd.ExecuteReader();

                var columnNames = PopulateTableSchema(fs, featureSetInfo.GeometryColumnName, rdr);
                while (rdr.Read())
                {
                    var wkb  = rdr[featureSetInfo.GeometryColumnName] as byte[];
                    var geom = wkbr.Read(wkb);

                    var newFeature = fs.AddFeature(geom);

                    //populate the attributes
                    foreach (var colName in columnNames)
                    {
                        newFeature.DataRow[colName] = rdr[colName];
                    }
                }

                fs.Name = featureSetInfo.TableName;

                //TODO: look into this...
                //HACK required for selection to work properly
                fs.IndexMode = true;

                // assign projection
                ProjectionInfo proj;
                if (featureSetInfo.SRID >= 0)
                {
                    try
                    {
                        proj = ProjectionInfo.FromEpsgCode(featureSetInfo.SRID);
                    }
                    catch (Exception ex)
                    {
                        log.Warning("Unable to find projection info from EPSG code {0}, using default: {1}", featureSetInfo.SRID, ex.Message);
                        proj = new ProjectionInfo();
                    }
                }
                else
                {
                    proj = new ProjectionInfo();
                }
                fs.Projection = proj;

                featureSet = fs;
                return(true);
            }
            catch (Exception ex)
            {
                log.Error("Unable to read feature set {0} using SQL \"{1}\": {2}", featureSetInfo.TableName, sqlFilter, ex.Message);
                return(false);
            }
            finally
            {
                if (cmd != null)
                {
                    cmd.Dispose();
                }
            }
        }