Пример #1
0
        async static Task <int> Main(string[] args)
        {
            PlugInManager.InitSilent = true;

            #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(1);
                    }
                    job = jobs.add;
                    break;

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

                case "-truncate":
                    if (job != jobs.unknown)
                    {
                        Usage();
                        Console.WriteLine("Can't do more than one job. Run programm twice...");
                        return(1);
                    }
                    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(1);
                    }
                    fileName = args[++i];
                    break;

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

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

                case "-debug":
                    PlugInManager.InitSilent = false;
                    break;
                }
            }
            #endregion

            #region Check Parameters
            if (connectinString == String.Empty)
            {
                Usage();
                Console.WriteLine("No connection string...");
                return(1);
            }
            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(1);
                }
                break;

            case jobs.unknown:
                Usage();
                Console.WriteLine("No job defined...");
                return(1);
            }
            #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();
            //    await fdb.Open(connStr);
            //    IFeatureDataset dataset = fdb[dsname];
            //    if (dataset == null)
            //    {
            //        Console.WriteLine("Error opening dataset: " + fdb.LastErrorMessage);
            //        return;
            //    }
            //    //dataset.ConnectionString = connectinString;
            //    if (!await dataset.Open())
            //    {
            //        Console.WriteLine("Error opening dataset: " + dataset.LastErrorMessage);
            //        return;
            //    }
            //    ds = dataset;
            //}
            //else
            if (dbType == "sql")
            {
                SqlFDB fdb = new SqlFDB();
                await fdb.Open(connStr);

                IFeatureDataset dataset = await fdb.GetDataset(dsname);

                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.LastErrorMessage);
                    return(1);
                }
                //dataset.ConnectionString = connectinString;
                if (!await dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.LastErrorMessage);
                    return(1);
                }
                ds = dataset;
            }
            else if (dbType == "postgres")
            {
                pgFDB fdb = new pgFDB();
                await fdb.Open(connStr);

                IFeatureDataset dataset = await fdb.GetDataset(dsname);

                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.LastErrorMessage);
                    return(1);
                }
                //dataset.ConnectionString = connectinString;
                if (!await dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.LastErrorMessage);
                    return(1);
                }
                ds = dataset;
            }
            else if (dbType == "sqlite")
            {
                SQLiteFDB fdb = new SQLiteFDB();
                await fdb.Open(connStr);

                IFeatureDataset dataset = await fdb.GetDataset(dsname);

                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.LastErrorMessage);
                    return(1);
                }
                //dataset.ConnectionString = connectinString;
                if (!await dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.LastErrorMessage);
                    return(1);
                }
                ds = dataset;
            }
            else
            {
                Console.WriteLine("Unknown fdb type");
                return(1);
            }

            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:
                await Truncate(ds, dsname + "_IMAGE_POLYGONS");

                break;

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

                break;

            case jobs.add:
                if (fileName != String.Empty)
                {
                    if (!await ImportFiles(ds, fileName.Split(';'), providers))
                    {
                        if (!continueOnError)
                        {
                            return(1);
                        }
                    }
                }
                else if (rootPath != String.Empty && Filters != String.Empty)
                {
                    if (!await ImportDirectory(ds, new DirectoryInfo(rootPath), Filters.Split(';'), providers))
                    {
                        if (!continueOnError)
                        {
                            return(1);
                        }
                    }
                }
                await CalculateExtent(ds);

                break;
            }
            Console.WriteLine("\n" + ((TimeSpan)(DateTime.Now - dt)).TotalSeconds + "s");
            Console.WriteLine("done...");

            return(0);
        }