public string GetDomainDisplay(string domain, object domainValu)
        {
            List <String>      listDomains = new List <string>();
            IDataset           dataset     = (IDataset)GetWorkspace;
            IWorkspaceDomains2 domains     = (IWorkspaceDomains2)dataset;
            ICodedValueDomain  dom         = null;

            try
            {
                dom = (ICodedValueDomain)domains.get_DomainByName(domain);
                for (int i = 0; i <= dom.CodeCount - 1; i++)
                {
                    if (dom.get_Value(i).Equals(domainValu))
                    {
                        return(dom.get_Name(i));
                    }
                }
            }
            catch (Exception ex)
            {
                //_log.Error("Ocorreu um problema ao tentar carregar os domínios do componente SegmentListComponent.");
            }
            finally
            {
                //if (domains != null)
                //    Marshal.ReleaseComObject(domains);

                //if (dom != null)
                //    Marshal.ReleaseComObject(dom);

                //Marshal.ReleaseComObject(dataset);
            }
            return("");
        }
示例#2
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
                {
                }
            }
        }
示例#3
0
        protected override void OnClick()
        {
            m_pApp = (IApplication)ArcMap.Application;
            if (m_pApp == null)
            {
                //if the app is null then could be running from ArcCatalog
                m_pApp = (IApplication)ArcCatalog.Application;
            }

            if (m_pApp == null)
            {
                MessageBox.Show("Could not access the application.", "No Application found");
                return;
            }
            IGxApplication pGXApp = (IGxApplication)m_pApp;

            stdole.IUnknown pUnk = null;
            try
            {
                pUnk = (stdole.IUnknown)pGXApp.SelectedObject.InternalObjectName.Open();
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode == (int)fdoError.FDO_E_DATASET_TYPE_NOT_SUPPORTED_IN_RELEASE ||
                    ex.ErrorCode == -2147220944)
                {
                    MessageBox.Show("The dataset is not supported in this release.", "Could not open the dataset");
                }
                else
                {
                    MessageBox.Show(ex.ErrorCode.ToString(), "Could not open the dataset");
                }
                return;
            }

            if (pUnk is ICadastralFabric)
            {
                m_pCadaFab = (ICadastralFabric)pUnk;
            }
            else
            {
                MessageBox.Show("Please select a parcel fabric and try again.", "Not a parcel fabric");
                return;
            }


            Utils FabricUTILS = new Utils();

            ITable     pTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans);
            IDataset   pDS    = (IDataset)pTable;
            IWorkspace pWS    = pDS.Workspace;

            //Do a Start and Stop editing to make sure we're not running in an edit session
            if (!FabricUTILS.StartEditing(pWS, true))
            {//if start editing fails then bail
                if (pUnk != null)
                {
                    Marshal.ReleaseComObject(pUnk);
                }
                Cleanup(pTable, pWS);
                FabricUTILS = null;
                return;
            }
            FabricUTILS.StopEditing(pWS);

            bool bAddedField = false;

            if (FabricUTILS.GetFabricVersion((ICadastralFabric2)m_pCadaFab) < 2)
            {
                bAddedField = FabricUTILS.CadastralTableAddFieldV1(m_pCadaFab, esriCadastralFabricTable.esriCFTPlans, esriFieldType.esriFieldTypeInteger,
                                                                   "KeepOnMerge", "KeepOnMerge", 1);
            }
            else
            {
                bAddedField = FabricUTILS.CadastralTableAddField(m_pCadaFab, esriCadastralFabricTable.esriCFTPlans, esriFieldType.esriFieldTypeInteger,
                                                                 "KeepOnMerge", "KeepOnMerge", 1);
            }

            if (bAddedField)
            {
                MessageBox.Show("Plan-merge helper field 'KeepOnMerge' added.", "Add Field");
            }
            else
            {
                MessageBox.Show("Field 'KeepOnMerge' could not be added." + Environment.NewLine + "The field may already exist.",
                                "Add Field");
            }

            if (bAddedField)
            {
                //if the field was added succesfully, add the Yes/No domain
                IDomain pDom = new CodedValueDomainClass();
                try
                {
                    IWorkspaceDomains2 pWSDoms = (IWorkspaceDomains2)pWS;
                    pDom.FieldType   = esriFieldType.esriFieldTypeInteger;
                    pDom.Name        = "Flag for Keep on Plan Merge";
                    pDom.Description = "Flag for Keep on Plan Merge";
                    ICodedValueDomain pCVDom = (ICodedValueDomain)pDom;
                    //pCVDom.AddCode(0, "No");
                    pCVDom.AddCode(1, "Keep On Merge");
                    pWSDoms.AddDomain(pDom);
                }
                catch (COMException ex)
                {
                    MessageBox.Show(ex.ErrorCode.ToString());
                }

                //Get the field
                int iFld = pTable.FindField("KeepOnMerge");
                if (iFld >= 0)
                {
                    IField pFld = pTable.Fields.get_Field(iFld);
                    // Check that the field and domain have the same field type.
                    if (pFld.Type == pDom.FieldType)
                    {
                        // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                        ISchemaLock      schemaLock      = (ISchemaLock)pTable;
                        IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pTable;

                        // Attempt to get an exclusive schema lock.
                        try
                        {
                            // Lock the class and alter the domain.
                            schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                            classSchemaEdit.AlterDomain("KeepOnMerge", pDom);
                            Console.WriteLine("The domain was successfully assigned.");
                        }
                        catch (COMException exc)
                        {
                            // Handle the exception in a way appropriate for the application.
                            Console.WriteLine(exc.Message);
                        }
                        finally
                        {
                            // Set the schema lock to be a shared lock.
                            schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                        }
                    }
                }

                if (pDom != null)
                {
                    Marshal.ReleaseComObject(pDom);
                }
            }
            Cleanup(pTable, pWS);
            FabricUTILS = null;
        }
示例#4
0
        public static void Main(string[] args)
        {
            // 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 ||
                !args.Length.Equals(3))
            {
                Usage();
                return;
            }

            // ESRI License Initializer generated code.
            esriLicenseInitializer.InitializeApplication(
                new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeArcEditor },
                new esriLicenseExtensionCode[] { });

            DomainList domains = new DomainList();

            IWorkspace originalWorkspace = args[0].ToWorkspace();
            IWorkspace targetWorkspace   = args[1].ToWorkspace();

            IWorkspaceDomains2 originalWorkspaceDomains = originalWorkspace as IWorkspaceDomains2;
            IWorkspaceDomains2 targetWorkspaceDomains   = targetWorkspace as IWorkspaceDomains2;

            string domain = args[2];

            if (domain.Trim().Equals("*"))
            {
                domains = originalWorkspaceDomains.Domains.ToDomainList();
            }
            else if (domain.IndexOf(',') > 0)
            {
                string[] tokens = domain.Split(',');

                foreach (string item in tokens)
                {
                    try
                    {
                        domains.Add(originalWorkspaceDomains.get_DomainByName(item));
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Trace.WriteLine(e.StackTrace);
                    }
                }
            }
            else
            {
                // assume the domain is a single domain
                try
                {
                    domains.Add(originalWorkspaceDomains.get_DomainByName(domain));
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.WriteLine(e.StackTrace);
                }
            }

            foreach (IDomain d in domains)
            {
                Console.Write(Constants.CopyStartMessage.FormatString(d.Name));

                try
                {
                    IClone  clone     = d as IClone;
                    IDomain newdomain = clone.Clone() as IDomain;
                    targetWorkspaceDomains.AddDomain(newdomain);
                    Console.WriteLine("success!\n");
                }
                catch (Exception e)
                {
                    Console.WriteLine("failed.");
                    Console.WriteLine(Constants.GeneralErrorMessage.FormatString(e.Message));
                    Console.WriteLine();
                    System.Diagnostics.Trace.WriteLine(e.StackTrace);
                }
            }

            // Do not make any call to ArcObjects after ShutDownApplication()
            esriLicenseInitializer.ShutdownApplication();
        }