public IExplorerFileObject CreateInstance(IExplorerObject parent, string filename)
        {
            string f = filename.ToLower();

            if (f.EndsWith(".jpg.mdb") ||
                f.EndsWith(".png.mdb") ||
                f.EndsWith(".tif.mdb") ||
                f.EndsWith(".tiff.mdb"))
            {
                return(null);
            }

            if (!f.ToLower().EndsWith(".mdb"))
            {
                return(null);
            }

            try
            {
                if (!(new FileInfo(f).Exists))
                {
                    return(null);
                }
                using (AccessFDB fdb = new AccessFDB())
                {
                    if (!fdb.Open(f) || !fdb.IsValidAccessFDB)
                    {
                        return(null);
                    }
                }
            }
            catch { return(null); }

            return(new AccessFDBExplorerObject(parent, filename));
        }
Esempio n. 2
0
        private void BuildList()
        {
            lstDatasets.Items.Clear();
            AccessFDB fdb = (_providerId == "mssql" ? new SqlFDB() : new AccessFDB());

            if (!fdb.Open(this.ConnectionString))
            {
                MessageBox.Show(fdb.lastErrorMsg, "Error");
                return;
            }

            string[] dsnames = fdb.DatasetNames;
            string   imageSpace;

            if (dsnames != null)
            {
                foreach (string dsname in dsnames)
                {
                    ListViewItem item = new ListViewItem(
                        dsname, fdb.IsImageDataset(dsname, out imageSpace) ? 1 : 0);
                    lstDatasets.Items.Add(item);

                    if (item.Text == _dsname)
                    {
                        lstDatasets.SelectedIndices.Add(lstDatasets.Items.Count - 1);
                    }
                }
            }
        }
Esempio n. 3
0
        static int Main(string[] args)
        {
            string mdb = "", dataset = "";
            bool   delExisting = true;

            for (int i = 0; i < args.Length - 1; i++)
            {
                if (args[i] == "-mdb")
                {
                    mdb = args[++i];
                }
                if (args[i] == "-ds")
                {
                    dataset = args[++i];
                }
                else if (args[i] == "-delexisting")
                {
                    try { delExisting = Convert.ToBoolean(args[++i]); }
                    catch { }
                }
            }

            if (mdb == "" || dataset == "")
            {
                Console.WriteLine("USAGE:");
                Console.WriteLine("gView.Cmd.CreateAccessFDBDataset -mdb <Filename> -ds <Datasetname>");
                Console.WriteLine("                      [-delexisting <true|false>]");
                return(1);
            }

            try
            {
                AccessFDB fdb = new AccessFDB();
                if (!fdb.Open(mdb))
                {
                    Console.WriteLine("\n\nERROR: " + fdb.lastErrorMsg);
                    return(1);
                }

                //SpatialReference sRef = new SpatialReference();

                if (fdb.CreateDataset(dataset, null) < 1)
                {
                    Console.WriteLine("\n\nERROR: " + fdb.lastErrorMsg);
                    fdb.Dispose();
                    return(1);
                }
                fdb.Dispose();
                Console.WriteLine(mdb + ": Dataset " + dataset + " created...");

                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n\nERROR: " + ex.Message);

                return(1);
            }
        }
        public IExplorerObject CreateExplorerObject(IExplorerObject parentExObject)
        {
            if (!CanCreate(parentExObject))
            {
                return(null);
            }

            FormNewDataset dlg = new FormNewDataset();

            dlg.IndexTypeIsEditable = false;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            AccessFDB fdb = new AccessFDB();

            fdb.Open(parentExObject.FullName);
            int dsID = -1;

            string datasetName = dlg.DatasetName;

            switch (dlg.DatasetType)
            {
            case FormNewDataset.datasetType.FeatureDataset:
                dsID = fdb.CreateDataset(datasetName, dlg.SpatialReferene);
                break;

            case FormNewDataset.datasetType.ImageDataset:
                dsID        = fdb.CreateImageDataset(datasetName, dlg.SpatialReferene, null, dlg.ImageSpace, dlg.AdditionalFields);
                datasetName = "#" + datasetName;
                break;
            }

            if (dsID == -1)
            {
                MessageBox.Show(fdb.lastErrorMsg, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            return(new AccessFDBDatasetExplorerObject(parentExObject, parentExObject.FullName, datasetName));
        }
Esempio n. 5
0
        async public Task <bool> SetConnectionString(string value)
        {
            _connString = value;
            if (value == null)
            {
                return(false);
            }

            while (_connString.IndexOf(";;") != -1)
            {
                _connString = _connString.Replace(";;", ";");
            }

            _dsname = ConfigTextStream.ExtractValue(value, "dsname");
            _addedLayers.Clear();
            foreach (string layername in ConfigTextStream.ExtractValue(value, "layers").Split('@'))
            {
                if (layername == "")
                {
                    continue;
                }
                if (_addedLayers.IndexOf(layername) != -1)
                {
                    continue;
                }
                _addedLayers.Add(layername);
            }

            if (_fdb == null)
            {
                throw new NullReferenceException("_fdb==null");
            }

            _fdb.DatasetRenamed      += new AccessFDB.DatasetRenamedEventHandler(AccessFDB_DatasetRenamed);
            _fdb.FeatureClassRenamed += new AccessFDB.FeatureClassRenamedEventHandler(AccessFDB_FeatureClassRenamed);
            _fdb.TableAltered        += new AccessFDB.AlterTableEventHandler(SqlFDB_TableAltered);
            await _fdb.Open(ConfigTextStream.ExtractValue(_connString, "mdb"));

            return(true);
        }
Esempio n. 6
0
        private void btnChangeConnectionString_Click(object sender, EventArgs e)
        {
            AccessFDB fdb = (_providerId == "mssql" ? new SqlFDB() : new AccessFDB());

            fdb.Open(_connectionString);

            DbConnectionString dbConnStr = new DbConnectionString();

            dbConnStr.UseProviderInConnectionString = false;
            FormConnectionString dlg = (dbConnStr.TryFromConnectionString("mssql", fdb.ConnectionString) ?
                                        new FormConnectionString(dbConnStr) : new FormConnectionString());

            dlg.ProviderID = _providerId;
            dlg.UseProviderInConnectionString = false;

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                dbConnStr         = dlg.DbConnectionString;
                _connectionString = dbConnStr.ConnectionString;

                BuildList();
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            string  connString = String.Empty, fcName = String.Empty, fields = String.Empty, name = String.Empty;
            Guid    dsGuid  = new Guid();
            Command command = Command.Unknown;

            for (int i = 0; i < args.Length - 1; i++)
            {
                if (args[i] == "-connstr")
                {
                    connString = args[++i];
                }

                else if (args[i] == "-guid")
                {
                    dsGuid = new Guid(args[++i]);
                }

                else if (args[i] == "-fc")
                {
                    fcName = args[++i];
                }

                else if (args[i] == "-fields")
                {
                    fields = args[++i];
                }

                else if (args[i] == "-name")
                {
                    name = args[++i];
                }

                else if (args[i] == "-c")
                {
                    switch (args[++i].ToLower())
                    {
                    case "createindex":
                        command = Command.CreateIndex;
                        break;

                    case "dropindex":
                        command = Command.DropIndex;
                        break;
                    }
                }
            }

            if (String.IsNullOrWhiteSpace(connString) || dsGuid.Equals(new Guid()) ||
                command == Command.Unknown)
            {
                Console.WriteLine("USAGE:");
                Console.WriteLine("gView.Cmd.Fdb -connstr <ConnectionString> -guid <DatasetGuid>");
                Console.WriteLine("              -c <CreateIndex|DropIndex>");
                return;
            }

            IFeatureDataset dataset;

            PlugInManager compMan = new PlugInManager();
            object        comp    = compMan.CreateInstance(dsGuid);

            if (!(comp is IFeatureDataset))
            {
                Console.WriteLine("Component with GUID '" + dsGuid.ToString() + "' is not a feature dataset...");
                return;
            }

            dataset = (IFeatureDataset)comp;

            if (!(dataset.Database is AccessFDB))
            {
                Console.WriteLine("Component dataset is not a gView Feature-Database...");
                return;
            }

            AccessFDB fdb = (AccessFDB)dataset.Database;

            if (!fdb.Open(connString))
            {
                Console.WriteLine("Can't open database");
                return;
            }

            if (command == Command.CreateIndex)
            {
                #region Create Index

                if (String.IsNullOrEmpty(fcName) || String.IsNullOrEmpty(fields))
                {
                    Console.WriteLine("USAGE:");
                    Console.WriteLine("gView.Cmd.Fdb -connstr <ConnectionString> -guid <DatasetGuid>");
                    Console.WriteLine("              -c <CreateIndex>");
                    Console.WriteLine("              -fc <FeatureClassName> -fields <Fields>");
                    return;
                }

                string indexName = "IDX_FC_" + fcName + "_" + fields.Replace(",", "_").Replace(" ", "");
                try
                {
                    Console.WriteLine("Try drop index...");
                    fdb.DropIndex(indexName);
                }
                catch { }

                Console.WriteLine("Try create index...");
                if (!fdb.CreateIndex(indexName,
                                     "FC_" + fcName, fields, false))
                {
                    Console.WriteLine("ERROR:");
                    Console.WriteLine(fdb.lastErrorMsg);
                    return;
                }

                Console.WriteLine("Index created...");
                return;

                #endregion
            }
            else if (command == Command.DropIndex)
            {
                #region Drop Index

                if (String.IsNullOrEmpty(name))
                {
                    Console.WriteLine("USAGE:");
                    Console.WriteLine("gView.Cmd.Fdb -connstr <ConnectionString> -guid <DatasetGuid>");
                    Console.WriteLine("              -c <DropIndex>");
                    Console.WriteLine("              -name <IndexName>");
                    return;
                }

                Console.WriteLine("Try drop index...");
                if (!fdb.DropIndex(name))
                {
                    Console.WriteLine("ERROR:");
                    Console.WriteLine(fdb.lastErrorMsg);
                    return;
                }

                Console.WriteLine("Index dropped...");
                return;

                #endregion
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            #region Parse Parameters
            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-add":
                    if (job != jobs.unknown)
                    {
                        Console.WriteLine("Can't do more than one job. Run programm twice...");
                        return;
                    }
                    job = jobs.add;
                    break;

                case "-clean":
                    if (job != jobs.unknown)
                    {
                        Console.WriteLine("Can't do more than one job. Run programm twice...");
                        return;
                    }
                    job = jobs.removeUnexisting;
                    break;

                case "-truncate":
                    if (job != jobs.unknown)
                    {
                        Usage();
                        Console.WriteLine("Can't do more than one job. Run programm twice...");
                        return;
                    }
                    job = jobs.truncate;
                    break;

                case "-s":
                    connectinString = args[++i];
                    break;

                case "-db":
                    dbType = args[++i].ToLower();
                    break;

                case "-provider":
                    provider = args[++i].ToLower();
                    break;

                case "-fn":
                    if (rootPath != String.Empty)
                    {
                        Usage();
                        Console.WriteLine("Filename OR Rootdirectory...");
                        return;
                    }
                    fileName = args[++i];
                    break;

                case "-rd":
                    if (fileName != String.Empty)
                    {
                        Usage();
                        Console.WriteLine("Filename OR Rootdirectory...");
                        return;
                    }
                    rootPath = args[++i];
                    break;

                case "-f":
                    Filters = args[++i];
                    break;
                }
            }
            #endregion

            #region Check Parameters
            if (connectinString == String.Empty)
            {
                Usage();
                Console.WriteLine("No connection string...");
                return;
            }
            switch (job)
            {
            case jobs.removeUnexisting:
            case jobs.truncate:
                break;

            case jobs.add:
                if (fileName == String.Empty &&
                    (rootPath == String.Empty || Filters == String.Empty))
                {
                    Usage();
                    Console.WriteLine("No file or rootdirectory and filter defined...");
                    return;
                }
                break;

            case jobs.unknown:
                Usage();
                Console.WriteLine("No job defined...");
                return;
            }
            #endregion

            DateTime dt = DateTime.Now;

            string mdb     = ConfigTextStream.ExtractValue(connectinString, "mdb");
            string dsname  = ConfigTextStream.ExtractValue(connectinString, "dsname");
            string connStr = ConfigTextStream.RemoveValue(connectinString, "dsname");

            IFeatureDataset ds = null;
            if (mdb != String.Empty)
            {
                AccessFDB fdb = new AccessFDB();
                fdb.Open(connStr);
                IFeatureDataset dataset = fdb[dsname];
                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg);
                    return;
                }
                //dataset.ConnectionString = connectinString;
                if (!dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg);
                    return;
                }
                ds = dataset;
            }
            else if (dbType == "sql")
            {
                SqlFDB fdb = new SqlFDB();
                fdb.Open(connStr);
                IFeatureDataset dataset = fdb[dsname];
                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg);
                    return;
                }
                //dataset.ConnectionString = connectinString;
                if (!dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg);
                    return;
                }
                ds = dataset;
            }
            else if (dbType == "postgres")
            {
                pgFDB fdb = new pgFDB();
                fdb.Open(connStr);
                IFeatureDataset dataset = fdb[dsname];
                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg);
                    return;
                }
                //dataset.ConnectionString = connectinString;
                if (!dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg);
                    return;
                }
                ds = dataset;
            }
            else if (dbType == "sqlite")
            {
                SQLiteFDB fdb = new SQLiteFDB();
                fdb.Open(connStr);
                IFeatureDataset dataset = fdb[dsname];
                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg);
                    return;
                }
                //dataset.ConnectionString = connectinString;
                if (!dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg);
                    return;
                }
                ds = dataset;
            }

            IRasterFileDataset rds = null;
            if (provider == "gdal")
            {
                rds = PlugInManager.Create(new Guid("43DFABF1-3D19-438c-84DA-F8BA0B266592")) as IRasterFileDataset;
            }
            else if (provider == "raster")
            {
                rds = PlugInManager.Create(new Guid("D4812641-3F53-48eb-A66C-FC0203980C79")) as IRasterFileDataset;
            }

            Dictionary <string, Guid> providers = new Dictionary <string, Guid>();
            if (rds != null)
            {
                foreach (string format in rds.SupportedFileFilter.Split('|'))
                {
                    string extension = format;

                    int pos = format.LastIndexOf(".");
                    if (pos > 0)
                    {
                        extension = format.Substring(pos, format.Length - pos);
                    }

                    providers.Add(extension, PlugInManager.PlugInID(rds));
                    Console.WriteLine("Provider " + extension + ": " + rds.ToString() + " {" + PlugInManager.PlugInID(rds).ToString() + "}");
                }
            }
            if (providers.Count == 0)
            {
                providers = null;
            }

            switch (job)
            {
            case jobs.truncate:
                Truncate(ds, dsname + "_IMAGE_POLYGONS");
                break;

            case jobs.removeUnexisting:
                RemoveUnexisting(ds);
                CalculateExtent(ds);
                break;

            case jobs.add:
                if (fileName != String.Empty)
                {
                    if (!ImportFiles(ds, fileName.Split(';'), providers))
                    {
                        if (!continueOnError)
                        {
                            return;
                        }
                    }
                }
                else if (rootPath != String.Empty && Filters != String.Empty)
                {
                    if (!ImportDirectory(ds, new DirectoryInfo(rootPath), Filters.Split(';'), providers))
                    {
                        if (!continueOnError)
                        {
                            return;
                        }
                    }
                }
                CalculateExtent(ds);
                break;
            }
            Console.WriteLine("\n" + ((TimeSpan)(DateTime.Now - dt)).TotalSeconds + "s");
            Console.WriteLine("done...");
        }