Esempio n. 1
0
        static void Main(string[] args)
        {
            // s = ArcZona.AZUtil.ParseGeoDBName(@"sde:sqlserver:DPU-PBU-GIS77\sqlexpress");
            // s = ArcZona.AZUtil.ParseGeoDBName("sde:oracle10g:/:dpu_admin");
            // s = ArcZona.AZUtil.ParseGeoDBName("5151:dpu_admin");

            /* Sample Command Line Params:
             *  -n  ssDomainOwner -v -g "\OWNEDBY_Example.gdb"
             *
             * */
            try
            {
                ESRILicenseProductCode = esriLicenseProductCode.esriLicenseProductCodeArcView;
                ArgParser = new CommandLine.Utility.CommandArguments(System.Environment.GetCommandLineArgs());

                // display the usage when
                if (System.Environment.CommandLine.IndexOf("-h", 0, System.StringComparison.CurrentCultureIgnoreCase) >= 0 |
                    System.Environment.CommandLine.IndexOf("--help", 0, System.StringComparison.CurrentCultureIgnoreCase) >= 0 |
                    System.Environment.CommandLine.IndexOf("/?", 0, System.StringComparison.CurrentCultureIgnoreCase) >= 0 |
                    System.Environment.CommandLine.IndexOf("-help", 0, System.StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    Usage();
                    return;
                }

                if (ValidateArgs() == true)
                {
                    ESRILicenseInitializer = new GeoprocessingInDotNet.LicenseInitializer();

                    ConsoleWriteLine("Arguments Validated!!");
                    ConsoleWriteLine("Initializing ArcObjects License...");

                    ESRILicenseInitializer.InitializeApplication(ESRILicenseProductCode);

                    if (ESRILicenseInitializer.InitializedProduct > 0)
                    {
                        ConsoleWriteLine("License Initialized.");

                        IWorkspace         ws = UmbrielArcGISHelper.GetWorkspace(ArgParser);
                        IWorkspaceDomains2 workspaceDomains = (IWorkspaceDomains2)ws;


                        IDomain           domain      = workspaceDomains.get_DomainByName(DomainName);
                        ICodedValueDomain codedDomain = (ICodedValueDomain)domain;


                        Stack <string> domainValues = new Stack <string>();

                        for (int i = codedDomain.CodeCount - 1; i >= 0; i--)
                        {
                            codedDomain.DeleteCode(codedDomain.get_Value(i));
                        }

                        workspaceDomains.AlterDomain(domain);
                    }
                    else
                    {
                        Console.WriteLine("\a");
                        Console.WriteLine("Could not initialize ESRI License.");
                    }

                    // Do not make any call to ArcObjects after ShutDownApplication()
                    ConsoleWriteLine("Releasing ArcObjects License...");
                    ESRILicenseInitializer.ShutdownApplication();
                    ConsoleWriteLine("ArcObjects License Released.");
                }
                else
                {
                    Usage();
                    return;
                }
            }
            catch (Exception ex)
            {
                // beep!
                Console.WriteLine("\a");
                Console.WriteLine("An error has occurred: \n\n");
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                // try to shut down the ESRI license
                if (ESRILicenseInitializer != null)
                {
                    if (ESRILicenseInitializer.InitializedProduct > 0)
                    {
                        ESRILicenseInitializer.ShutdownApplication();
                    }
                }
            }



            /* SDEMeta sleeps for 2000 milliseconds by default,
             * so that when called from a batch, the license manager has a chance to return
             * the license to the pool before the next SDEMeta attempts to check it out.
             */
            if (!ArgParser.Contains("-nosleep"))
            {
                string sleep = ArgParser.GetValue("sleep");

                try
                {
                    int sleepDuration = 2000;
                    if (!String.IsNullOrEmpty(sleep))
                    {
                        sleepDuration = Convert.ToInt32(sleep);
                    }

                    System.Threading.Thread.Sleep(sleepDuration);
                }
                catch
                {
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the workspace.
        /// </summary>
        /// <returns>IWorkspace for the geodatabase</returns>
        internal static IWorkspace GetWorkspace(CommandLine.Utility.CommandArguments argParser)
        {
            try
            {
                IWorkspace ws = null; // workspace interface

                // Get the workspace reference
                if (argParser.Contains("-g"))
                {
                    string gdbPath = argParser.GetValue("-g");

                    // test for personal geodatabase (access database)
                    if (gdbPath.Trim().ToLower().EndsWith("mdb"))
                    {
                        if (File.Exists(gdbPath))
                        {
                            IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
                            ws = workspaceFactory.OpenFromFile(gdbPath, 0);
                        }
                        else
                        {
                            throw new FileNotFoundException("Missing geodatabase.", gdbPath);
                        }
                    }
                    else if (gdbPath.Trim().ToLower().EndsWith("gdb"))
                    {
                        // file geodatabase (directory ending in .gdb)
                        if (Directory.Exists(gdbPath))
                        {
                            IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
                            ws = workspaceFactory.OpenFromFile(gdbPath, 0);
                        }
                        else
                        {
                            throw new DirectoryNotFoundException("Missing geodatabase: " + gdbPath);
                        }
                    }
                }
                else
                {
                    // sde connection
                    string server   = string.Empty;
                    string instance = string.Empty;
                    string username = string.Empty;
                    string passwrd  = string.Empty;
                    string database = string.Empty;
                    string authmode = string.Empty;
                    string version  = string.Empty;

                    if (argParser.Contains("-s"))
                    {
                        server = argParser.GetValue("-s");
                    }
                    else
                    {
                        server = Environment.GetEnvironmentVariable("SDESERVER");
                    }


                    if (argParser.Contains("-i"))
                    {
                        instance = argParser.GetValue("-i");
                    }
                    else
                    {
                        instance = Environment.GetEnvironmentVariable("SDEINSTANCE");
                    }

                    if (argParser.Contains("-u"))
                    {
                        username = argParser.GetValue("-u");
                    }
                    else
                    {
                        username = Environment.GetEnvironmentVariable("SDEUSER");
                    }

                    if (argParser.Contains("-p"))
                    {
                        passwrd = argParser.GetValue("-p");
                    }
                    else
                    {
                        passwrd = Environment.GetEnvironmentVariable("SDEPASSWORD");
                    }


                    if (argParser.Contains("-D"))
                    {
                        database = argParser.GetValue("-D");
                    }
                    else
                    {
                        database = Environment.GetEnvironmentVariable("SDEDATABASE");
                    }

                    if (argParser.Contains("-u") && argParser.Contains("-p"))
                    {
                        authmode = "DBMS";
                    }
                    else
                    {
                        authmode = "OSA";
                    }

                    if (argParser.Contains("-V"))
                    {
                        version = argParser.GetValue("-V");
                    }

                    string servInstance = string.Empty;
                    if (server.Length > 0)
                    {
                        servInstance = server + ":" + instance;
                    }
                    else
                    {
                        servInstance = instance;
                    }

                    IPropertySet      ps = Utility.ArcSDEConnPropSet(server, instance, username, passwrd, database, version, authmode);
                    IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass();
                    try
                    {
                        ws = workspaceFactory.Open(ps, 0);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                    }
                }

                return(ws);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                throw;
            }
        }