Example #1
0
        /// <summary>
        /// Creates a new FDO connection
        /// </summary>
        /// <returns></returns>
        protected static IConnection CreateConnection(string provider, string connStr)
        {
            IConnection conn = FeatureAccessManager.GetConnectionManager().CreateConnection(provider);

            conn.ConnectionString = connStr;
            return(conn);
        }
Example #2
0
        internal void Export(string fileName)
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            /*
             * IProviderRegistry pr = FeatureAccessManager.GetProviderRegistry();
             * ProviderCollection pc = pr.GetProviders();
             * MessageBox.Show("Number of providers=" + pc.Count);
             */

            try
            {
                IConnectionManager cm = FeatureAccessManager.GetConnectionManager();
                m_Connection = cm.CreateConnection("SDFProvider.dll");
                //m_Connection = cm.CreateConnection("OSGeo.SDF.3.6");
                //m_Connection = cm.CreateConnection("OSGeo.SQLite.3.6");
                RunExport(fileName);
                MessageBox.Show(String.Format("nok={0}  nFail={1}", m_NumOk, m_NumFail));
            }

            finally
            {
                if (m_Connection != null)
                {
                    m_Connection.Dispose();
                    m_Connection = null;
                }
            }
        }
Example #3
0
        private IConnection CreateSqliteConnection()
        {
            var conn = FeatureAccessManager.GetConnectionManager().CreateConnection("OSGeo.SQLite");

            conn.ConnectionString = _ConnectionString;
            return(conn);
        }
Example #4
0
        public override int Execute()
        {
            IConnection conn = null;

            try
            {
                conn = FeatureAccessManager.GetConnectionManager().CreateConnection(_provider);
            }
            catch (OSGeo.FDO.Common.Exception ex)
            {
                WriteException(ex);
                return((int)CommandStatus.E_FAIL_CREATE_CONNECTION);
            }

            if (Array.IndexOf <int>(conn.CommandCapabilities.Commands, (int)OSGeo.FDO.Commands.CommandType.CommandType_DestroyDataStore) < 0)
            {
                Console.Error.WriteLine("This provider does not support destroying data stores");
                return((int)CommandStatus.E_FAIL_UNSUPPORTED_CAPABILITY);
            }

            using (IDestroyDataStore destroy = conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_DestroyDataStore) as IDestroyDataStore)
            {
                IDataStorePropertyDictionary dict = destroy.DataStoreProperties;
                Console.WriteLine("Data Store Properties:");
                WriteProperties(dict);
            }

            if (conn.ConnectionState != ConnectionState.ConnectionState_Closed)
            {
                conn.Close();
            }
            return((int)CommandStatus.E_OK);
        }
Example #5
0
        public static DataTable GetDataFromFile(string filename)
        {
            Guard.ArgumentNotNull(filename, "filename");

            // Create an FDO connection to the SHP provider
            var mgr = FeatureAccessManager.GetConnectionManager();

            using (var connection = mgr.CreateConnection("OSGeo.SHP"))
            {
                // Set connection properties
                var props = connection.ConnectionInfo.ConnectionProperties;
                props.SetProperty("DefaultFileLocation", filename);

                // Open the connection
                connection.Open();

                // Check the connection state
                if (connection.ConnectionState == ConnectionState.ConnectionState_Open)
                {
                    Console.WriteLine("Connection was opened successfully.");
                }
                else
                {
                    Console.WriteLine("Connection failed to open.");
                }

                // Create the Select command
                using (ISelect select = (ISelect)connection.CreateCommand(CommandType.CommandType_Select))
                {
                    //TODO: fix
                    //Invalid Feature schema element name 'ef02f72c-67e8-4967-89d5-610b57aa5bcf.6.48F1FC14219145F1663E0030FCAA50D5'; must not contain '.'.
                    // Set the feature class name
                    select.SetFeatureClassName(System.IO.Path.GetFileNameWithoutExtension(filename));

                    // Execute the Select command
                    using (IFeatureReader reader = select.Execute())
                    {
                        DataTable table = new DataTable();
                        PrepareGrid(table, reader);

                        // Read the features
                        try
                        {
                            while (reader.ReadNext())
                            {
                                ProcessSQLReader(table, reader);
                            }
                            return(table);
                        }
                        catch (OSGeo.FDO.Common.Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }
        }
 public override int Execute()
 {
     FeatureAccessManager.GetProviderRegistry().RegisterProvider(
         _name,
         _displayName,
         _description,
         _version,
         _fdoVersion,
         _libraryPath,
         _isManaged);
     WriteLine("New provider registered: {0}", _name);
     return((int)CommandStatus.E_OK);
 }
Example #7
0
        /// <summary>
        /// Creates a FDO data source. The provider must be a flat-file provider
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="path">The path.</param>
        /// <param name="deleteIfExists">if set to <c>true</c> deletes the specified file if it exists.</param>
        /// <returns></returns>
        public static bool CreateFlatFileDataSource(string provider, string path, bool deleteIfExists)
        {
            bool result = false;
            bool sdf    = provider.StartsWith("OSGeo.SDF");
            bool sqlite = provider.StartsWith("OSGeo.SQLite");

            IConnection conn = FeatureAccessManager.GetConnectionManager().CreateConnection(provider);

            if (conn.ConnectionInfo.ProviderDatastoreType != ProviderDatastoreType.ProviderDatastoreType_File)
            {
                return(false); //ERR_NOT_FLAT_FILE
            }
            string pName = GetFileParameter(provider);

            if (string.IsNullOrEmpty(pName))
            {
                return(false); //ERR_FILE_PARAMETER_UNKNOWN
            }
            if (deleteIfExists && File.Exists(path))
            {
                File.Delete(path);
            }

            using (conn)
            {
                using (ICreateDataStore cmd = conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_CreateDataStore) as ICreateDataStore)
                {
                    try
                    {
                        var dsprops = cmd.DataStoreProperties;
                        dsprops.SetProperty(pName, path);
                        //Ensures that FDO logical schemas being applied to SQLite are mostly intact.
                        //See FDO trac ticket #739 for details.
                        if (sqlite)
                        {
                            dsprops.SetProperty("UseFdoMetadata", "TRUE");
                        }
                        cmd.Execute();
                        result = true;
                    }
                    catch (OSGeo.FDO.Common.Exception)
                    {
                        result = false;
                    }
                }
            }
            return(result);
        }
Example #8
0
        public override int Execute()
        {
            CommandStatus retCode;

            IConnection conn = null;

            try
            {
                conn = FeatureAccessManager.GetConnectionManager().CreateConnection(_provider);
            }
            catch (OSGeo.FDO.Common.Exception ex)
            {
                WriteException(ex);
                return((int)CommandStatus.E_FAIL_CREATE_CONNECTION);
            }

            IConnectionPropertyDictionary dict = conn.ConnectionInfo.ConnectionProperties;

            Console.WriteLine("Connection properties for: {0}", _provider);
            foreach (string name in dict.PropertyNames)
            {
                Console.WriteLine("\nProperty Name: {0}\n\n\tLocalized Name: {1}", name, dict.GetLocalizedName(name));
                Console.WriteLine("\tRequired: {0}\n\tProtected: {1}\n\tEnumerable: {2}",
                                  dict.IsPropertyRequired(name),
                                  dict.IsPropertyProtected(name),
                                  dict.IsPropertyEnumerable(name));
                if (dict.IsPropertyEnumerable(name))
                {
                    Console.WriteLine("\tValues for property:");
                    try
                    {
                        string[] values = dict.EnumeratePropertyValues(name);
                        foreach (string str in values)
                        {
                            Console.WriteLine("\t\t- {0}", str);
                        }
                    }
                    catch (OSGeo.FDO.Common.Exception)
                    {
                        Console.Error.WriteLine("\t\tProperty values not available");
                    }
                }
            }
            retCode = CommandStatus.E_OK;
            return((int)retCode);
        }
Example #9
0
        public static IConnection OpenShapefileConnection(string providerName, string shpDirectory)
        {
            providerName.RequireArgument <string>("providerName").NotNullOrEmpty();
            shpDirectory.RequireArgument <string>("shpDirectory").NotNullOrEmpty();
            if (!Directory.Exists(shpDirectory))
            {
                throw new ArgumentException(string.Format("The directory {0} is either invalid or could not be found.", shpDirectory));
            }

            IConnectionManager connectionManager = FeatureAccessManager.GetConnectionManager();
            IConnection        conn = connectionManager.CreateConnection(providerName);

            conn.ConnectionString = @"DefaultFileLocation=" + shpDirectory;
            ConnectionState state = conn.Open();

            return(conn);
        }
        public override int Execute()
        {
            ProviderCollection providers = FeatureAccessManager.GetProviderRegistry().GetProviders();

            using (providers)
            {
                foreach (Provider provider in providers)
                {
                    Console.WriteLine("\nProvider Name: {0}\n", provider.Name);
                    Console.WriteLine("\tDisplay Name: {0}\n\tDescription: {1}\n\tLibrary Path: {2}\n\tVersion: {3}\n\tFDO Version: {4}\n\tIs Managed: {5}",
                                      provider.DisplayName,
                                      provider.Description,
                                      provider.LibraryPath,
                                      provider.Version,
                                      provider.FeatureDataObjectsVersion,
                                      provider.IsManaged);
                }
            }
            return((int)CommandStatus.E_OK);
        }
        public void ProviderChanged()
        {
            FdoProviderInfo prov = _view.SelectedProvider;

            if (prov != null)
            {
                _view.ResetGrid();
                _pendingProperties.Clear();
                IList <DictionaryProperty> props = FdoFeatureService.GetConnectProperties(prov.Name);
                if (props != null)
                {
                    foreach (DictionaryProperty p in props)
                    {
                        if (p.Enumerable)
                        {
                            EnumerableDictionaryProperty ep = p as EnumerableDictionaryProperty;
                            if (!ep.RequiresConnection)
                            {
                                _view.AddEnumerableProperty(ep.Name, ep.DefaultValue, ep.Values);
                            }
                            else
                            {
                                _pendingProperties.Add(ep);
                            }
                        }
                        else
                        {
                            _view.AddProperty(p);
                        }
                    }
                }

                using (var conn = FeatureAccessManager.GetConnectionManager().CreateConnection(prov.Name))
                {
                    _view.ConfigEnabled = conn.ConnectionCapabilities.SupportsConfiguration();
                }
            }
        }
Example #12
0
        public static IConnection SDFConnection(string SDFFile)
        {
            try
            {
                Debug.Write("\nSDF File to connect: >> " + SDFFile + "\n");
                //first get an instance of the connection manager
                IConnectionManager connman = FeatureAccessManager.GetConnectionManager();
                con = connman.CreateConnection("OSGeo.SDF");


                //check connection state

                //get connection dictionary
                IConnectionPropertyDictionary props = con.ConnectionInfo.ConnectionProperties;

                props.SetProperty("File", SDFFile);
                props.SetProperty("ReadOnly", "FALSE");

                if (con.ConnectionState == OSGeo.FDO.Connections.ConnectionState.ConnectionState_Open)
                {
                    con.Close();
                }
            }
            catch (OSGeo.FDO.Common.Exception ge)
            {
                bool ok = ge.Message.Contains("read-only");
                Debug.Write(ge.ToString());
            }
            catch (SystemException ex)
            {
                bool ok = ex.Message.Contains("read-only");
                Debug.Write(ex.ToString());
            }

            return(con);
        }
        public override IEnumerable <FdoRow> Execute(IEnumerable <FdoRow> rows)
        {
            if (counter < 1) //Shouldn't be reentrant, but just play it safe.
            {
                Info("Creating a connection to: " + _provider);
                using (var conn = FeatureAccessManager.GetConnectionManager().CreateConnection(_provider))
                {
                    if (!string.IsNullOrEmpty(_pendingConnStr))
                    {
                        conn.ConnectionString = _pendingConnStr;
                        conn.Open();
                    }

                    using (var create = (ICreateDataStore)conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_CreateDataStore))
                    {
                        var props = create.DataStoreProperties;
                        foreach (string key in _properties.Keys)
                        {
                            string name  = key;
                            string value = _properties[key];
                            Info("Setting property: " + name + " = " + value);
                            props.SetProperty(name, value);
                        }
                        create.Execute();
                        Info("Data Store created");
                    }

                    if (conn.ConnectionState != OSGeo.FDO.Connections.ConnectionState.ConnectionState_Closed)
                    {
                        conn.Close();
                    }
                }
                counter++;
            }
            return(rows);
        }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FdoConnection"/> class.
 /// </summary>
 /// <param name="provider">The provider name.</param>
 public FdoConnection(string provider)
 {
     this.HasConfiguration   = false;
     this.InternalConnection = FeatureAccessManager.GetConnectionManager().CreateConnection(provider);
 }
 public override int Execute()
 {
     FeatureAccessManager.GetProviderRegistry().UnregisterProvider(_name);
     WriteLine("Provider un-registered: {0}", _name);
     return((int)CommandStatus.E_OK);
 }
Example #16
0
        private IConnection CreateConnection()
        {
            IConnection conn = FeatureAccessManager.GetConnectionManager().CreateConnection(_provider);

            return(conn);
        }
Example #17
0
        public static string addSchemtoSDF(string SDFFile, string schemaName, string schemaDesc)
        {
            try
            {
                FeatureSchema      schema1    = new FeatureSchema(schemaName, schemaDesc);
                IConnectionManager conmanager = FeatureAccessManager.GetConnectionManager();

                //sdf fdo connection
                using (IConnection connect = SDFConnection(SDFFile))
                {
                    //get connection dict
                    IConnectionPropertyDictionary conprop = connect.ConnectionInfo.ConnectionProperties;

                    connect.Open();

                    //check connection state
                    OSGeo.FDO.Connections.ConnectionState connstate = connect.ConnectionState;
                    if (connstate != OSGeo.FDO.Connections.ConnectionState.ConnectionState_Open)
                    {
                        result = "\nCannot read SDF File \n" + SDFFile;
                    }
                    else
                    {
                        //add spatial context to the schema
                        SDF.SDFSchemaManager.spatial_context(connect);

                        result = "Read SDF File \n" + SDFFile;

                        //create command to alter schema
                        IApplySchema applyschema = (IApplySchema)connect.CreateCommand(CommandType.CommandType_ApplySchema) as IApplySchema;

                        //FeatureClassCollection fcoll;
                        ClassCollection fcoll = schema1.Classes;

                        //create all feature class
                        FeatureClass class_points     = new FeatureClass("Points", "Point information");
                        FeatureClass class_alignment  = new FeatureClass("Alignments", "Alignment information");
                        FeatureClass class_parcels    = new FeatureClass("Parcels", "Parcels information");
                        FeatureClass class_pipes      = new FeatureClass("Pipes", "Pipes information");
                        FeatureClass class_structures = new FeatureClass("Structures", "Structures information");

                        //add properties here
                        Schema_manager.add_property(class_points, connect);
                        Schema_manager.add_property(class_alignment, connect);
                        Schema_manager.add_property(class_parcels, connect);
                        Schema_manager.add_property(class_pipes, connect);
                        Schema_manager.add_property(class_structures, connect);

                        schema1.Classes.Add(class_points);
                        schema1.Classes.Add(class_alignment);
                        schema1.Classes.Add(class_parcels);
                        schema1.Classes.Add(class_pipes);
                        schema1.Classes.Add(class_structures);

                        //create property definition for each feature class

                        applyschema.FeatureSchema = schema1;
                        applyschema.Execute();
                        result = "Successfully Created SDF file with blank Schema \n" + SDFFile;
                    }
                    connect.Close();
                }
            }
            catch (SystemException ex)
            {
            }
            return(result);
        }