Пример #1
0
        private void RenameClassObject(IDataset dsCurrent, int standardID)
        {
            if (dsCurrent == null)
            {
                return;
            }

            Hy.Check.Define.StandardLayer standardLayer = LayerReader.GetLayerByName(dsCurrent.Name, standardID);
            //string strAliasName = Hy.Check.Rule.Helper.LayerReader.GetAliasName(dsCurrent.Name, standardID);
            if (standardLayer != null)// dsCurrent.Name != strAliasName)
            {
                ISchemaLock schemaLock = dsCurrent as ISchemaLock;
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                IClassSchemaEdit classSchemaEdit = dsCurrent as IClassSchemaEdit;
                if (classSchemaEdit != null)
                {
                    classSchemaEdit.AlterAliasName(standardLayer.AliasName);

                    ITable tCurrent = dsCurrent as ITable;
                    if (tCurrent != null)
                    {
                        List <Hy.Check.Define.StandardField> fields = FieldReader.GetFieldsByLayer(standardLayer.ID);
                        for (int i = 0; i < fields.Count; i++)
                        {
                            if (tCurrent.Fields.FindField(fields[i].Name) > -1)
                            {
                                classSchemaEdit.AlterFieldAliasName(fields[i].Name, fields[i].AliasName);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private bool RemoveClsInstance(IClass classInstance, UID uid)
        {
            ISchemaLock schemaLock = (ISchemaLock)classInstance;
            bool        result     = false;

            try
            {
                // Attempt to get an exclusive schema lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Cast the object class to the IClassSchemaEdit2 interface.
                IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)classInstance;

                classSchemaEdit.AlterInstanceCLSID(uid);

                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }

            return(result);
        }
        /// <summary>
        /// Add new field.
        /// </summary>
        /// <param name="featureClass"></param>
        /// <param name="fieldName"></param>
        /// <param name="fieldType"></param>
        /// <param name="fldLength"></param>
        /// <param name="isNullable"></param>
        /// <param name="defaultValue"></param>
        public static void AddNewField(this IFeatureClass featureClass, string fieldName, esriFieldType fieldType, int fldLength = 1, bool isNullable = true, object defaultValue = null)
        {
            ISchemaLock schemaLock = (ISchemaLock)featureClass;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                IFieldEdit2 field = new Field() as IFieldEdit2;
                field.Name_2         = fieldName;
                field.Type_2         = fieldType;
                field.IsNullable_2   = isNullable;
                field.DefaultValue_2 = defaultValue;
                if (fieldType == esriFieldType.esriFieldTypeString)
                {
                    field.Length_2 = fldLength;
                }

                featureClass.AddField(field);
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
        private bool RemoveClsExt(IClass classExtension)
        {
            ISchemaLock schemaLock = (ISchemaLock)classExtension;
            bool        result     = false;

            try
            {
                // Attempt to get an exclusive schema lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Cast the object class to the IClassSchemaEdit2 interface.
                IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)classExtension;

                // Clear the class extension.
                classSchemaEdit.AlterClassExtensionCLSID(null, null);

                IObjectClassDescription featureClassDescription = new FeatureClassDescriptionClass();
                classSchemaEdit.AlterInstanceCLSID(featureClassDescription.InstanceCLSID);

                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }

            return(result);
        }
Пример #5
0
        // 删除字段

        private void  除字段ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string fieldName = dataGridView1.Columns[_index].Name;


            if (_layer != null)
            {
                var featureClass = _layer.FeatureClass;

                int n = featureClass.FindField(fieldName);

                if (n != -1)
                {
                    ISchemaLock schemaLock = featureClass as ISchemaLock;

                    if (schemaLock != null)
                    {
                        //schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                        IField field = featureClass.Fields.Field[n];

                        featureClass.DeleteField(field);

                        //schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }

            //ShowFeatureLayerAttrib(_layer);

            ShowFeatures(_layer, null, false);
        }
Пример #6
0
        private void Progarm()
        {
            IWorkspace workspace = ArcClass.GetmdbWorkspace(mdbFilePath);

            if (workspace == null)
            {
                return;
            }
            IFeatureDataset featureDataset = ArcClass.GetFeatureDataset(workspace, "WJL");
            ISchemaLock     schemalock     = featureDataset as ISchemaLock;

            try
            {
                schemalock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                ITopologyContainer topologyContainer = featureDataset as ITopologyContainer;
                ITopology          topology          = topologyContainer.CreateTopology("ttt", topologyContainer.DefaultClusterTolerance, -1, "");
                IFeatureClass      featureClass      = ArcClass.GetFeatureClass(workspace, "PARK");

                AddRuleToTopology(topology, esriTopologyRuleType.esriTRTAreaNoOverlap, "NO Block OverLap", featureClass);

                IGeoDataset geoDataset = topology as IGeoDataset;
                IEnvelope   envelop    = geoDataset.Extent;
                ValidateTopology(topology, envelop);
            }catch (COMException)
            {
            }
        }
Пример #7
0
        /// <summary>
        /// Register the newly created table with the Geodatabase.
        /// </summary>
        /// <param name="pTable"></param>
        /// <param name="oidFieldName"></param>
        private static void RegisterWithGeodatabase(ITable pTable, string oidFieldName)
        {
            if (!(IsArcInfoLicense()))
            {
                return;
            }

            IObjectClass oc = (IObjectClass)pTable;

            if (oidFieldName == "")
            {
                oidFieldName = "OBJECTID";
            }
            // Attempt to acquire an exclusive schema lock for the object class.
            ISchemaLock schemaLock = (ISchemaLock)oc;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                // If this point is reached, the exclusive lock was acquired. We can cast the object
                // class to IClassSchemaEdit and call RegisterAsObjectClass.
                IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)oc;
                classSchemaEdit.RegisterAsObjectClass(oidFieldName, "");
            }
            catch (COMException comExc)
            {
                // Re-throw the exception.
                throw comExc;
            }
            finally
            {
                // Reset the lock on the object class to a shared lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        } // method RegisterWithGeodatabase
        public bool IsFeatureClassLockable(IFeatureClass checkFeatureClass)
        {
            IObjectClass objectClass = checkFeatureClass as IObjectClass;

            if (objectClass == null)
            {
                return(false);
            }

            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            if (schemaLock == null)
            {
                return(false);
            }

            // Get an enumerator over the current schema locks.
            IEnumSchemaLockInfo enumSchemaLockInfo = null;

            schemaLock.GetCurrentSchemaLocks(out enumSchemaLockInfo);

            // Iterate through the locks.
            ISchemaLockInfo schemaLockInfo = null;
            int             lockCount      = 0;

            while ((schemaLockInfo = enumSchemaLockInfo.Next()) != null)
            {
                lockCount++;
                Trace.WriteLine(string.Format("{0} : {1} : {2}", schemaLockInfo.TableName,
                                              schemaLockInfo.UserName, schemaLockInfo.SchemaLockType));
            }

            // Note: 1 sharedLock for this process is normal, so we test for > 1 lock
            return(lockCount < 2);
        }
Пример #9
0
        } // doWork method

        protected void RegisterWithGeodatabase(
            IObjectClass objectClass,
            String oidFieldName)
        {
            if (oidFieldName == "")
            {
                oidFieldName = "OBJECTID";
            }
            // Attempt to acquire an exclusive schema lock for the object class.
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            try {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                // If this point is reached, the exclusive lock was acquired. We can cast the object
                // class to IClassSchemaEdit and call RegisterAsObjectClass.
                IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)objectClass;
                classSchemaEdit.RegisterAsObjectClass(oidFieldName, "");
            }
            catch (COMException comExc) {
                // Re-throw the exception.
                throw comExc;
            }
            finally {
                // Reset the lock on the object class to a shared lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        } // RegisterWithGeodatabase method
Пример #10
0
        private void TopologyGeneralPropertyPage_Load(object sender, EventArgs e)
        {
            ISchemaLock         @lock          = this.itopology_0 as ISchemaLock;
            IEnumSchemaLockInfo schemaLockInfo = null;

            @lock.GetCurrentSchemaLocks(out schemaLockInfo);
            schemaLockInfo.Reset();
            if (schemaLockInfo.Next() == null)
            {
                this.txtName.Properties.ReadOnly             = true;
                this.txtClusterTolerance.Properties.ReadOnly = true;
            }
            this.txtName.Text             = (this.itopology_0 as IDataset).Name;
            this.txtClusterTolerance.Text = this.itopology_0.ClusterTolerance.ToString();
            this.bool_0 = true;
            switch (this.itopology_0.State)
            {
            case esriTopologyState.esriTSUnanalyzed:
                this.lblTopoError1.Text = "没有校验";
                this.lblTopoError2.Text = "在拓扑中存在一个或多个脏区。脏区是指被编辑过的区域";
                break;

            case esriTopologyState.esriTSAnalyzedWithErrors:
                this.lblTopoError1.Text = "已经校验 - 存在错误";
                this.lblTopoError2.Text = "所有编辑过的拓扑已经被校验过。有一个或多个拓扑错误存在";
                break;

            case esriTopologyState.esriTSAnalyzedWithoutErrors:
                this.lblTopoError1.Text = "已经校验 - 没有错误误";
                this.lblTopoError2.Text = "所有编辑过的拓扑已经被校验过。没有拓扑错误存在";
                break;
            }
        }
Пример #11
0
        public bool DeleteSpatialIndex(IFeatureClass featureClass)
        {
            bool        result      = true;
            ISchemaLock pSchemaLock = featureClass as ISchemaLock;

            try
            {
                pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                IIndexes   indexes        = featureClass.Indexes;
                String     shapeFieldName = featureClass.ShapeFieldName;
                IEnumIndex enumIndex      = indexes.FindIndexesByFieldName(shapeFieldName);
                enumIndex.Reset();
                IIndex index = enumIndex.Next();
                if (index != null)
                {
                    featureClass.DeleteIndex(index);
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.ToString();
                result       = false;
            }
            finally
            {
                pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
            return(result);
        }
Пример #12
0
        public static void InsertLoadOnly(IFeatureClass featureCls, IList <IGeometry> geoList)
        {
            IFeatureClassLoad featureClsLoad = (IFeatureClassLoad)featureCls;
            ISchemaLock       schemaLock     = (ISchemaLock)featureCls;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                featureClsLoad.LoadOnlyMode = true;
                using (var comReleaser = new ComReleaser())
                {
                    IFeatureBuffer featureBuffer = featureCls.CreateFeatureBuffer();
                    IFeatureCursor featureCursor = featureCls.Insert(true);
                    comReleaser.ManageLifetime(featureCursor);
                    featureBuffer.set_Value(featureBuffer.Fields.FindField("InstBy"), "B Pierce");
                    for (int ic = 0; ic < geoList.Count; ic++)
                    {
                        featureBuffer.Shape = geoList[0];
                        var featureOID = featureCursor.InsertFeature(featureBuffer);
                        if (ic % 10 == 0)
                        {
                            featureCursor.Flush();
                        }
                    }
                    featureCursor.Flush();
                }
            }
            finally
            {
                featureClsLoad.LoadOnlyMode = false;
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
Пример #13
0
        public static bool UpdateExtent(IFeatureClass fc)
        {
            bool        rbc        = false;
            ISchemaLock schemaLock = (ISchemaLock)fc;

            try
            {
                IFeatureClassManage fcManage = (IFeatureClassManage)fc;
                if (fcManage != null)
                {
                    //schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                    fcManage.UpdateExtent();
                    schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    //Console.WriteLine("Update finished");
                    rbc = true;
                }
            }
            catch (Exception e)
            {
                //error occured
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                //Console.WriteLine(e.Message);
                Log.WriteLine(e);
            }
            return(rbc);
        }
Пример #14
0
        // 删除


        private void DeleteAttriToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string fieldName = dataGridView1.Columns[_index].Name;

            var featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;

            if (featureLayer != null)
            {
                var featureClass = featureLayer.FeatureClass;

                int n = featureClass.FindField(fieldName);

                if (n != -1)
                {
                    ISchemaLock schemaLock = featureClass as ISchemaLock;

                    if (schemaLock != null)
                    {
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                        IField field = featureClass.Fields.Field[n];

                        featureClass.DeleteField(field);

                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }

            ShowFeatureLayerAttrib(featureLayer);

            ShowFeatures(featureLayer, null, false);
        }
Пример #15
0
        private static void UpdateCodedValueDomain(IWorkspace theWorkspace, string DomainName, string SourceClassName, string CodeFieldName, string ValueFieldName)
        {
            // Get reference to the table to read codes and values from
            ITable theTable = commonFunctions.OpenTable(theWorkspace, SourceClassName);

            // Get reference to the domain itself
            IWorkspaceDomains wsDomains = (IWorkspaceDomains)theWorkspace;
            ICodedValueDomain theDomain = (ICodedValueDomain)wsDomains.get_DomainByName(DomainName);

            // Requires exclusive schema lock
            ISchemaLock schemaLock = (ISchemaLock)theDomain;

            try
            {
                // Get an exclusive lock
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Clear everything out of the domain first
                int codedValues = theDomain.CodeCount;
                for (int i = 0; i <= codedValues - 1; i++)
                {
                    theDomain.DeleteCode(theDomain.Value[0]);
                }

                // Sort the table
                ITableSort tableSorter = new TableSortClass();
                tableSorter.Fields = ValueFieldName;
                tableSorter.set_Ascending(ValueFieldName, true);
                tableSorter.Table = theTable;
                tableSorter.Sort(null);

                // Loop through the sorted rows, add to the domain
                int codeFld  = theTable.FindField(CodeFieldName);
                int valueFld = theTable.FindField(ValueFieldName);

                ICursor theCursor = tableSorter.Rows;
                IRow    theRow    = theCursor.NextRow();

                while (theRow != null)
                {
                    theDomain.AddCode(theRow.get_Value(codeFld), theRow.get_Value(valueFld).ToString());
                    theRow = theCursor.NextRow();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(DomainName + " was not updated. This is likely because an exclusive schema lock could not be obtained.", "NCGMP Tools");
            }
            finally
            {
                // Release the exclusive lock, if it was acquired.
                //  This block of code (finally) is called whether or not there is a problem
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
        /// <summary>Method to perform the actual schema lock</summary>
        /// <remarks>
        /// - If the schema is already locked by a different user, an exception is thrown with lock info (name / table)
        /// - If the schema is already locked by the current user, no lock is performed
        /// - When an exclusive lock is successfully established, the lock is added to the list of managed locks
        ///   for demotion at disposal
        /// </remarks>
        public void LockDatasetSchema(ITable fc)
        {
            ResourceManager resourceManager = new ResourceManager(
                "ESRI.ArcGIS.OSM.OSMClassExtension.OSMClassExtensionStrings", this.GetType().Assembly);

            ISchemaLock schemaLock = fc as ISchemaLock;

            if (schemaLock == null)
            {
                throw new ArgumentNullException("schemaLock");
            }

            // make sure that are not any existing exclusive locks
            IEnumSchemaLockInfo currentlyExistingLocks;

            try
            {
                schemaLock.GetCurrentSchemaLocks(out currentlyExistingLocks);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(resourceManager.GetString("OSMClassExtensionManager_Reading_Lock_Exception"));
            }

            bool            gdbAlreadyLockedbyUser = false;
            ISchemaLockInfo schemaLockInfo         = null;

            while ((schemaLockInfo = currentlyExistingLocks.Next()) != null)
            {
                if (schemaLockInfo.SchemaLockType == esriSchemaLock.esriExclusiveSchemaLock &&
                    !String.IsNullOrEmpty(schemaLockInfo.UserName))
                {
                    throw new ApplicationException(string.Format(
                                                       resourceManager.GetString("OSMClassExtensionManager_Exclusive_Lock_Exception"),
                                                       schemaLockInfo.TableName, schemaLockInfo.UserName));
                }
                else if (schemaLockInfo.SchemaLockType == esriSchemaLock.esriExclusiveSchemaLock)
                {
                    gdbAlreadyLockedbyUser = true;
                    break;
                }
            }

            if (!gdbAlreadyLockedbyUser)
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
            }

            _managedLocks.Add(schemaLock);
        }
Пример #17
0
 public override void OnClick()
 {
     try
     {
         ITable table = (((IGxSelection)_context.GxSelection).FirstObject as IGxDataset).Dataset as ITable;
         if (table is IFeatureClass)
         {
             Geoprocessor geoprocessor_ = new Geoprocessor();
             string       text          = (table as IDataset).Workspace.PathName;
             bool         flag          = false;
             if (string.IsNullOrEmpty(text))
             {
                 string startupPath = System.Windows.Forms.Application.StartupPath;
                 string text2       = Guid.NewGuid().ToString() + ".sde";
                 (table as IDataset).Workspace.WorkspaceFactory.Create(startupPath, text2,
                                                                       (table as IDataset).Workspace.ConnectionProperties, 0);
                 text = System.IO.Path.Combine(startupPath, text2);
                 flag = true;
             }
             string text3 = text;
             if ((table as IFeatureClass).FeatureDataset != null)
             {
                 text3 = System.IO.Path.Combine(text3, (table as IFeatureClass).FeatureDataset.Name);
             }
             text3 = System.IO.Path.Combine(text3, (table as IDataset).Name);
             if ((table as IFeatureClass).ShapeType != esriGeometryType.esriGeometryAny)
             {
                 CommonHelper.RunTool(geoprocessor_, new RegisterWithGeodatabase
                 {
                     in_dataset = text3
                 }, null);
                 if (flag)
                 {
                     File.Delete(text);
                 }
             }
         }
         else
         {
             ISchemaLock schemaLock = (ISchemaLock)table;
             schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
             (table as IClassSchemaEdit).RegisterAsObjectClass("ObjectID", "");
             schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
         }
     }
     catch (Exception ex)
     {
         ex.ToString();
     }
 }
Пример #18
0
        /// <summary>
        /// 检查数据集是否有被锁定
        /// </summary>
        /// <param name="ipFeatClass">被检查是否有表的图层</param>
        /// <returns>是否有锁</returns>
        public static bool CheckFeatureClassHasLock(IFeatureClass ipFeatClass)
        {
            ISchemaLock ipSchemaLock = (ISchemaLock)ipFeatClass;

            if (ipSchemaLock == null)
            {
                return(false);
            }

            //通过设置锁成功与否判断该图层是否被其他人使用
            ipSchemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);

            return(false);
        }
Пример #19
0
        /// <summary>
        /// 创建拓扑集成方法
        /// </summary>
        /// <param name="TopoName"></param>
        /// <param name="pFeatureDS"></param>
        /// <param name="FeatureClassList"></param>
        /// <param name="TopoDT"></param>
        /// <returns></returns>
        public ITopology2 CreateToplolgy(string TopoName, IFeatureDataset pFeatureDS, List <IFeatureClass> FeatureClassList, DataTable TopoDT)
        {
            ISchemaLock pSchemaLock = (ISchemaLock)pFeatureDS;

            try
            {
                pFeatureClassList = FeatureClassList;
                pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                //创建拓扑
                ITopologyContainer2 pTopoContainer = pFeatureDS as ITopologyContainer2;
                ITopology2          pTopology      = pTopoContainer.CreateTopology(TopoName, pTopoContainer.DefaultClusterTolerance, -1, "") as ITopology2;

                //添加要素
                foreach (IFeatureClass pFeatureClass in FeatureClassList)
                {
                    pTopology.AddClass(pFeatureClass, 5, 1, 1, false);
                }

                //添加规则
                for (int i = 0; i < TopoDT.Rows.Count; i++)
                {
                    string s = TopoDT.Rows[i][0].ToString();
                    if (TopoDT.Rows[i][2].ToString() == "")
                    {
                        AddTopoRules(pTopology, TopoDT.Rows[i][0].ToString(), TopoDT.Rows[i][1].ToString());
                    }
                    else
                    {
                        AddTopoRules(pTopology, TopoDT.Rows[i][0].ToString(), TopoDT.Rows[i][1].ToString(), TopoDT.Rows[i][2].ToString());
                    }
                }

                //验证拓扑
                IGeoDataset pGeoDataset = pTopology as IGeoDataset;
                IEnvelope   pEnvelope   = pGeoDataset.Extent;
                VaildateTopo(pTopology, pEnvelope);
                return(pTopology);
            }
            catch (COMException COMEx)
            {
                MessageBox.Show(COMEx.Message);
                return(null);
            }
            finally
            {
                pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
Пример #20
0
        /// <summary>
        ///     Deletes the table. You must have exlusive rights to the table in order to delete it.
        ///     Otherwise an error will be thrown.
        /// </summary>
        public static void Delete(this ITable source)
        {
            IDataset    ds         = (IDataset)source;
            ISchemaLock schemaLock = (ISchemaLock)ds;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                ds.Delete();
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
Пример #21
0
        /// <summary>
        /// 判断对象是否被占用
        /// </summary>
        /// <param name="objectClass"></param>
        /// <param name="message">被占用情况信息,未被占用则值为null</param>
        /// <returns>对象被占用返回True,未被占用返回False</returns>
        public static bool CheckClassLock(this IObjectClass objectClass, out string message)
        {
            var         sb         = new StringBuilder();
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            schemaLock.GetCurrentSchemaLocks(out var enumSchemaLockInfo);
            ISchemaLockInfo schemaLockInfo;

            while ((schemaLockInfo = enumSchemaLockInfo.Next()) != null)
            {
                sb.AppendFormat("{0} : {1} : {2}\r\n", schemaLockInfo.TableName, schemaLockInfo.UserName, schemaLockInfo.SchemaLockType);
            }

            message = sb.Length > 0 ? sb.ToString() : null;
            return(sb.Length > 0);
        }
Пример #22
0
        //更改表模型名 函数
        public static bool AlterModelName(ITable table, string NewModelName)
        {
            bool             rbc    = false;
            ISchemaLock      sLock  = table as ISchemaLock;
            IClassSchemaEdit csEdit = table as IClassSchemaEdit;

            if (sLock != null && csEdit != null)
            {
                sLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                //改变要素模型名
                csEdit.AlterModelName(NewModelName);
                //释放锁定
                sLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                rbc = true;
            }
            return(rbc);
        }
Пример #23
0
        //更改要素类中字段模型名 函数
        public static bool AlterFieldModelName(IFeatureClass fc, string FieldName, string NewModelName)
        {
            bool             rbc    = false;
            ISchemaLock      sLock  = fc as ISchemaLock;
            IClassSchemaEdit csEdit = fc as IClassSchemaEdit;

            if (sLock != null && csEdit != null)
            {
                sLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                //改变要素类中字段模型名
                csEdit.AlterFieldModelName(FieldName, NewModelName);
                //释放锁定
                sLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                rbc = true;
            }
            return(rbc);
        }
Пример #24
0
        //更改要素类中字段默认值 函数
        public static bool AlterFieldDefaultValue(IFeatureClass fc, string FieldName, object defaultvalue)
        {
            bool             rbc    = false;
            ISchemaLock      sLock  = fc as ISchemaLock;
            IClassSchemaEdit csEdit = fc as IClassSchemaEdit;

            if (sLock != null && csEdit != null)
            {
                sLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                //改变要素类中字段别名
                csEdit.AlterDefaultValue(FieldName, defaultvalue);
                //释放锁定
                sLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                rbc = true;
            }
            return(rbc);
        }
        public void IClassSchemaEdit_Example(IObjectClass objectClass)
        {
            //This function shows how you can use the IClassSchemaEdit
            //interface to alter the COM class extension for an object class.
            //cast for the IClassSchemaEdit
            IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)objectClass;
            //set and exclusive lock on the class
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
            ESRI.ArcGIS.esriSystem.UID classUID = new ESRI.ArcGIS.esriSystem.UIDClass();
            //GUID for the C# project.
            classUID.Value = "{65a43962-8cc0-49c0-bfa3-015d0ff8350e}";
            classSchemaEdit.AlterClassExtensionCLSID(classUID, null);
            //release the exclusive lock
            schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
        }
        /// <summary>
        /// Perform the work contained in the delegate inside an exclusive schema lock.
        /// </summary>
        /// <param name="fc">The feature class whose schema is to be exclusively locked.</param>
        /// <param name="work">The work to be performed.</param>
        static void DoInSchemaLock(IFeatureClass fc, MethodInvoker work)
        {
            ISchemaLock schemaLock = (ISchemaLock)fc;

            try
            {
                // Exclusively lock the class schema.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Do the work inside the schema lock
                work();
            }
            finally
            {
                // Release the exclusive lock on the featureclass' schema.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
Пример #27
0
        public static void AddFeildToMeery(IFeatureClass featureCls)
        {
            ISchemaLock schemaLock = featureCls as ISchemaLock;

            schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

            //
            var    field    = CreateStringField("Name", "", 8);
            IClass addFeild = (IClass)featureCls;

            addFeild.AddField(field);

            //加载到内存,上下文中
            IFields    fields     = featureCls.Fields;
            IFieldEdit fieldsEdit = fields as IFieldEdit;

            featureCls.AddField(field);
            //fieldsEdit.AddField(field);
        }
        /// <summary>
        /// Changes the member variables and extension properties to store the provided field names
        /// as the created, modified and user fields (positions are also refreshed). Empty strings
        /// indicate the values should not be saved in a field.
        /// </summary>
        /// <param name="createdField">The name of the "created" field.</param>
        /// <param name="modifiedField">The name of the "modified" field.</param>
        /// <param name="userField">The name of the "user" field.</param>
        public void SetTimestampFields(String createdField, String modifiedField, String userField)
        {
            IClass      baseClass  = classHelper.Class;
            ISchemaLock schemaLock = (ISchemaLock)baseClass;

            try
            {
                // Get an exclusive lock. We want to do this prior to making any changes
                // to ensure the member variables and extension properties remain synchronized.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Set the name member variables.
                createdFieldName  = createdField;
                modifiedFieldName = modifiedField;
                userFieldName     = userField;

                // Set the positions of the fields.
                SetFieldIndexes();

                // Modify the extension properties.
                extensionProperties.SetProperty(Resources.CreatedFieldKey, createdFieldName);
                extensionProperties.SetProperty(Resources.ModifiedFieldKey, modifiedFieldName);
                extensionProperties.SetProperty(Resources.UserFieldKey, userFieldName);

                // Change the properties.
                IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)baseClass;
                classSchemaEdit.AlterClassExtensionProperties(extensionProperties);
            }
            catch (COMException comExc)
            {
                throw new Exception(Resources.FailedToSavePropertiesMsg, comExc);
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
        public bool ChangeSchemaLockFeatureClass(IFeatureClass checkFeatureClass, bool exclusiveLock)
        {
            bool success = false;

            try
            {
                IObjectClass objectClass = checkFeatureClass as IObjectClass;
                if (objectClass == null)
                {
                    return(false);
                }

                ISchemaLock schemaLock = (ISchemaLock)objectClass;
                if (schemaLock == null)
                {
                    return(false);
                }

                if (exclusiveLock)
                {
                    schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                }
                else
                {
                    schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                }

                success = true;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(success);
        }
Пример #30
0
        /// <summary>
        /// 创建拓扑
        /// </summary>
        /// <param name="workspaceName">被检查文件的路径名称</param>
        public void CreateTopology(string workspaceName)
        {
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory   workspaceFactory  = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            IWorkspace          workspace         = workspaceFactory.OpenFromFile(Application.StartupPath + @"\Convert\GeoDataBase.gdb", 0);
            IFeatureWorkspace   featureWorkspace  = (IFeatureWorkspace)workspace;
            IFeatureDataset     featureDataset    = featureWorkspace.OpenFeatureDataset("ContourData");
            ITopologyContainer2 topologyContainer = (ITopologyContainer2)featureDataset;
            IFeatureClass       CurrContour       = null;

            try
            {
                CurrContour = featureWorkspace.OpenFeatureClass("CurrContour");
                ITopology topology = topologyContainer.get_TopologyByName("eeee");
                IDataset  fDataset = (IDataset)topology;
                fDataset.Delete();
            }
            catch (Exception)
            {
                // throw;
            }

            if (CurrContour != null)
            {
                IDataset fDataset = (IDataset)CurrContour;

                fDataset.Delete();
            }

            Geoprocessor gp = new Geoprocessor();
            FeatureClassToFeatureClass pFFeatureClassToFeatureClass = new FeatureClassToFeatureClass();

            pFFeatureClassToFeatureClass.in_features = Application.StartupPath + "\\Convert\\ContourResult\\" + workspaceName + "\\Contour.shp";
            pFFeatureClassToFeatureClass.out_path    = Application.StartupPath + "\\Convert\\GeoDataBase.gdb\\ContourData";

            pFFeatureClassToFeatureClass.out_name = "CurrContour";


            IGeoProcessorResult geoProcessorResult = (IGeoProcessorResult)gp.Execute(pFFeatureClassToFeatureClass, null);

            CurrContour = featureWorkspace.OpenFeatureClass("CurrContour");

            ISchemaLock schemaLock = (ISchemaLock)featureDataset;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Create the topology.

                ITopology topology = topologyContainer.CreateTopology("eeee",
                                                                      topologyContainer.DefaultClusterTolerance, -1, "");

                // Add feature classes and rules to the topology.
                topology.AddClass((IClass)CurrContour, 5, 1, 1, false);

                AddRuleToTopology(topology, esriTopologyRuleType.esriTRTLineNoIntersection,
                                  "must not intersect", CurrContour);

                int ErrorCount = 0;

                // Get an envelope with the topology's extents and validate the topology.
                IGeoDataset geoDataset = (IGeoDataset)topology;
                ESRI.ArcGIS.Geometry.IEnvelope envelope = geoDataset.Extent;
                ValidateTopology(topology, envelope);
                IGeoDataset               geoDS          = topology as IGeoDataset;
                IErrorFeatureContainer    errorContainer = topology as IErrorFeatureContainer;
                IEnumTopologyErrorFeature eErrorFeat;
                eErrorFeat = errorContainer.get_ErrorFeaturesByRuleType(geoDS.SpatialReference,
                                                                        esriTopologyRuleType.esriTRTAreaNoGaps, null, true, false);
                ITopologyErrorFeature topoError;
                topoError = eErrorFeat.Next();
                while (topoError != null)
                {
                    ErrorCount++;
                    topoError = eErrorFeat.Next();
                }
                if (ErrorCount == 0)
                {
                    MessageBox.Show("无拓扑错误!", "Sunz", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("拓扑错误" + "" + ErrorCount + "" + "个!");
                }
            }
            catch (COMException comExc)
            {
                throw new Exception(String.Format(
                                        "Error creating topology: {0} Message: {1}", comExc.ErrorCode,
                                        comExc.Message), comExc);
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }