示例#1
0
        private IVersionedObject FetchObjectByVersion(Guid id, long version)
        {
            // Get object deletions within scope of the version we're logging at
            long[] deletionsWithinVersionScope = _objectDeletionStates.ContainsKey(id) ? _objectDeletionStates[id].Where(s => s <= version).ToArray() : null;

            IVersionedObject objToReturn = null;

            if (_objectAdditionStates.ContainsKey(id))
            {
                var objVersions = _objectAdditionStates[id];

                // Loop through all the different versions of the object to find most recent one within scope of the version we're looking at
                foreach (var obj in objVersions)
                {
                    // We're only interested in objects within the scope of the version we're looking at
                    if (obj.CreationVersion.InternalVersionId <= version)
                    {
                        // Unless a deletion has happend, then the object is a candidate for returning
                        if (!(deletionsWithinVersionScope != null && deletionsWithinVersionScope.Any(s => s > obj.CreationVersion.InternalVersionId)))
                        {
                            objToReturn = obj;
                        }
                    }
                }
            }

            return(objToReturn);
        }
示例#2
0
        private void button12_Click(object sender, EventArgs e)
        {
            ILayer tocSelectedLayer = GetTocSelectedLayer();

            if (tocSelectedLayer != null)
            {
                IDataset         dataset = (tocSelectedLayer as IFeatureLayer).FeatureClass.FeatureDataset as IDataset;
                IVersionedObject verObj  = dataset as IVersionedObject;
                if (verObj == null || !verObj.IsRegisteredAsVersioned)
                {
                    try
                    {
                        verObj.RegisterAsVersioned(true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("未选择图层");
            }
        }
示例#3
0
        public bool IsUnVersionedFabric(ICadastralFabric TheFabric)
        {
            bool IsFileBasedGDB = false;
            bool IsUnVersioned  = false;

            ITable     pTable = TheFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels);
            IDataset   pDS    = (IDataset)TheFabric;
            IWorkspace pWS    = pDS.Workspace;

            IsFileBasedGDB = (!(pWS.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriRemoteDatabaseWorkspace));

            if (!(IsFileBasedGDB))
            {
                IVersionedObject pVersObj = (IVersionedObject)pTable;
                IsUnVersioned = (!(pVersObj.IsRegisteredAsVersioned));
                pTable        = null;
                pVersObj      = null;
            }
            if (IsUnVersioned && !IsFileBasedGDB)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
 private bool CheckIsEdit(IDataset pDataset)
 {
     if (this.m_pEditWorkspace != null)
     {
         IWorkspace workspace = pDataset.Workspace;
         if (workspace.ConnectionProperties.IsEqual(this.m_pEditWorkspace.ConnectionProperties))
         {
             if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
             {
                 if (workspace is IVersionedWorkspace)
                 {
                     IVersionedObject obj2 = pDataset as IVersionedObject;
                     if (obj2.IsRegisteredAsVersioned)
                     {
                         return(((AppConfigInfo.UserID.Length == 0) ||
                                 (AppConfigInfo.UserID.ToLower() == "admin")) ||
                                this.m_sysGrants.GetStaffAndRolesLayerPri(AppConfigInfo.UserID, 2, pDataset.Name));
                     }
                 }
             }
             else
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#5
0
 private void method_1(IArray iarray_1, ICompositeLayer icompositeLayer_0)
 {
     for (int i = 0; i < icompositeLayer_0.Count; i++)
     {
         ILayer layer = icompositeLayer_0.get_Layer(i);
         if (layer is IGroupLayer)
         {
             this.method_1(iarray_1, layer as ICompositeLayer);
         }
         else if (layer is IFeatureLayer)
         {
             IFeatureLayer layer2       = layer as IFeatureLayer;
             IDataset      featureClass = layer2.FeatureClass as IDataset;
             if ((featureClass != null) && !(featureClass is ICoverageFeatureClass))
             {
                 IWorkspace workspace = featureClass.Workspace;
                 if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                 {
                     IVersionedObject obj2 = layer2.FeatureClass as IVersionedObject;
                     if (obj2.IsRegisteredAsVersioned)
                     {
                         (this.method_3(iarray_1, workspace).EnumName as IEnumNameEdit).Add(featureClass.FullName);
                     }
                 }
             }
         }
     }
 }
示例#6
0
        /// <summary>
        /// 注册\反注册版本
        /// </summary>
        /// <param name="pWorkspace">工作区</param>
        /// <param name="bRegist">注册\反注册版本</param>
        public static void RegistVersion(IWorkspace pWorkspace, bool bRegist)
        {
            IVersionedObject verObj = (IVersionedObject)pWorkspace;

            if (verObj != null && (!verObj.IsRegisteredAsVersioned))
            {
                // 数据集可以被注册而且还没有被注册为版本数据集
                // 下面的方法 如果使用参数 false 那么表示注册为没有版本的数据也就是反注册
                verObj.RegisterAsVersioned(bRegist);
                // sde.Default
            }
        }
示例#7
0
        /// <summary>
        /// 验证是否版本号编辑
        /// </summary>
        /// <param name="targetFeatureClass"></param>
        /// <returns></returns>
        private bool CheckVersionEdit(IFeatureClass targetFeatureClass)
        {
            bool             result           = false;
            IVersionedObject pVersionedObject = (IVersionedObject)targetFeatureClass;

            if (pVersionedObject.IsRegisteredAsVersioned)
            {
                result = true;
            }
            else
            {
                result = false;
            }

            return(result);
        }
        public IVersionedObject Add(IVersionedObject @object, bool ignoreDublicates = false)
        {
            if (_transactionState != TransactionState.Running)
            {
                throw new OperationCanceledException($"Cannot add objects when transaction state = {_transactionState.ToString() }");
            }

            if (_objectManager.GetObject(@object.Id) != null)
            {
                if (ignoreDublicates)
                {
                    return(@object);
                }
                else
                {
                    throw new OperationCanceledException($"An object with id: {@object.Id} is already present in the object manager. If you want to update an existing object, please use Update instead.");
                }
            }

            if (_addedObjects.ContainsKey(@object.Id))
            {
                if (ignoreDublicates)
                {
                    return(@object);
                }
                else
                {
                    throw new OperationCanceledException($"An object with id: {@object.Id} is already added in this transaction.");
                }
            }

            // Check if pointer to same object has been added before
            if (_objectManager._objectAdditionStates.ContainsKey(@object.Id))
            {
                var objVersions = _objectManager._objectAdditionStates[@object.Id];

                if (objVersions.Contains(@object))
                {
                    throw new OperationCanceledException($"An object with id: {@object.Id} referencing the same object already exists inside the object manager. You cannot add the same object instance twice. You need to create a new object instance everytime you add an object.");
                }
            }

            _addedObjects.Add(@object.Id, @object);

            return(@object);
        }
        public bool SetupEditEnvironment(IWorkspace TheWorkspace, ICadastralFabric TheFabric, IEditor TheEditor,
                                         out bool IsFileBasedGDB, out bool IsUnVersioned, out bool UseNonVersionedEdit)
        {
            IsFileBasedGDB      = false;
            IsUnVersioned       = false;
            UseNonVersionedEdit = false;

            ITable pTable = TheFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels);

            IsFileBasedGDB = (!(TheWorkspace.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriRemoteDatabaseWorkspace));

            if (!(IsFileBasedGDB))
            {
                IVersionedObject pVersObj = (IVersionedObject)pTable;
                IsUnVersioned = (!(pVersObj.IsRegisteredAsVersioned));
                pTable        = null;
                pVersObj      = null;
            }
            if (IsUnVersioned && !IsFileBasedGDB)
            {//
                DialogResult dlgRes = MessageBox.Show("Fabric is not registered as versioned." +
                                                      "\r\n You will not be able to undo." +
                                                      "\r\n Click 'OK' to delete permanently.",
                                                      "Continue with delete?", MessageBoxButtons.OKCancel);
                if (dlgRes == DialogResult.OK)
                {
                    UseNonVersionedEdit = true;
                }
                else if (dlgRes == DialogResult.Cancel)
                {
                    return(false);
                }
                //MessageBox.Show("The fabric tables are non-versioned." +
                //   "\r\n Please register as versioned, and try again.");
                //return false;
            }
            else if ((TheEditor.EditState == esriEditState.esriStateNotEditing))
            {
                MessageBox.Show("Please start editing first and try again.", "Delete",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
            return(true);
        }
示例#10
0
        private bool method_1(IDataset idataset_0)
        {
            IWorkspace workspace = idataset_0.Workspace;

            if (!(workspace as IWorkspaceEdit).IsBeingEdited())
            {
                return(false);
            }
            if ((workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) && (workspace is IVersionedWorkspace))
            {
                IVersionedObject obj2 = idataset_0 as IVersionedObject;
                if (obj2.IsRegisteredAsVersioned)
                {
                    return(((AppConfigInfo.UserID.Length == 0) || (AppConfigInfo.UserID.ToLower() == "admin")) ||
                           this.sysGrants_0.GetStaffAndRolesLayerPri(AppConfigInfo.UserID, 2, idataset_0.Name));
                }
            }
            return(true);
        }
        public void GetFabricPlatform(IWorkspace TheWorkspace, ICadastralFabric TheFabric,
                                      out bool IsFileBasedGDB, out bool IsUnVersioned)
        {
            IsFileBasedGDB = false;
            IsUnVersioned  = false;

            ITable pTable = TheFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels);

            IsFileBasedGDB = (!(TheWorkspace.WorkspaceFactory.WorkspaceType == esriWorkspaceType.esriRemoteDatabaseWorkspace));

            if (!(IsFileBasedGDB))
            {
                IVersionedObject pVersObj = (IVersionedObject)pTable;
                IsUnVersioned = (!(pVersObj.IsRegisteredAsVersioned));
                pVersObj      = null;
            }
            if (pTable != null)
            {
                Marshal.ReleaseComObject(pTable);
            }
        }
        public void Update(IVersionedObject @object, bool ignoreDublicates = false)
        {
            if (_transactionState != TransactionState.Running)
            {
                throw new OperationCanceledException($"Cannot update objects when transaction state = {_transactionState.ToString() }");
            }

            if (_updatedObjects.ContainsKey(@object.Id))
            {
                if (ignoreDublicates)
                {
                    return;
                }
                else
                {
                    throw new OperationCanceledException($"An object with id: {@object.Id} is already updated once in this transaction.");
                }
            }

            if (!_objectManager._objectAdditionStates.ContainsKey(@object.Id))
            {
                throw new OperationCanceledException($"An object with id: {@object.Id} is not present in the object manager. You cannot update an object, unless it has been added in a previous transaction.");
            }

            // Check if pointer to same object has been added before
            if (_objectManager._objectAdditionStates.ContainsKey(@object.Id))
            {
                var objVersions = _objectManager._objectAdditionStates[@object.Id];

                if (objVersions.Contains(@object))
                {
                    throw new OperationCanceledException($"An object with id: {@object.Id} referencing the same object already exists inside the object manager. You cannot update an object using an existing instance. You need to create a new object instance everytime you want to update an object.");
                }
            }

            _updatedObjects.Add(@object.Id, @object);
        }
        public void Commit()
        {
            // Process added objects
            foreach (var obj in _addedObjects)
            {
                if (obj.Key == Guid.Parse("ee710eb4-958f-4c5b-856d-1d6734272388"))
                {
                }

                // Set creation state
                obj.Value.CreationVersion = _version;

                // Add id of deleted object to manager
                if (!_objectManager._objectAdditionStates.ContainsKey(obj.Value.Id))
                {
                    // Add object to manager
                    if (!_objectManager._objectAdditionStates.TryAdd(obj.Value.Id, new IVersionedObject[] { obj.Value }))
                    {
                        throw new ApplicationException($"Unxepected error adding object with id: {obj.Value.Id} to object additions concurrent dictionary using TryAdd. The returned false indicates that an object with that id already exists in the collection.");
                    }
                }
                else
                {
                    // Create new array with space for one extra object
                    IVersionedObject[] oldObjectArray = _objectManager._objectAdditionStates[obj.Value.Id];

                    IVersionedObject[] newObjectArray = new IVersionedObject[oldObjectArray.Length + 1];

                    // Copy values from old array to new
                    for (int i = 0; i < oldObjectArray.Length; i++)
                    {
                        newObjectArray[i] = oldObjectArray[i];
                    }

                    // Add new object to array
                    newObjectArray[oldObjectArray.Length] = obj.Value;

                    // Add new array to object dict
                    if (!_objectManager._objectAdditionStates.TryUpdate(obj.Value.Id, newObjectArray, oldObjectArray))
                    {
                        throw new ApplicationException($"Unxepected error updating object with id: {obj.Value.Id} to object additions concurrent dictionary using TryUpdate. The returned false indicates something went wrong.");
                    }
                }
            }

            // Process updated objects
            foreach (var obj in _updatedObjects)
            {
                // Mark current object to be deleted
                var objToDelete = _objectManager.GetObject(obj.Value.Id);

                if (objToDelete != null)
                {
                    objToDelete.DeletionVersion = _version;
                }

                // Set creation state
                obj.Value.CreationVersion = _version;

                // Add object to manager
                if (!_objectManager._objectAdditionStates.ContainsKey(obj.Value.Id))
                {
                    throw new ApplicationException($"Unxepected error processing updated objects. Object with id = {obj.Value.Id} do not exist in object manager.");
                }

                // Create new array with space for one extra object
                IVersionedObject[] oldObjectArray = _objectManager._objectAdditionStates[obj.Value.Id];

                IVersionedObject[] newObjectArray = new IVersionedObject[oldObjectArray.Length + 1];

                // Copy values from old array to new
                for (int i = 0; i < oldObjectArray.Length; i++)
                {
                    newObjectArray[i] = oldObjectArray[i];
                }

                // Add new object to array
                newObjectArray[oldObjectArray.Length] = obj.Value;

                // Add new array to object dict
                if (!_objectManager._objectAdditionStates.TryUpdate(obj.Value.Id, newObjectArray, oldObjectArray))
                {
                    throw new ApplicationException($"Unxepected error adding updated object with id: {obj.Value.Id} to object additions concurrent dictionary using TryUpdate. The returned false indicates something went wrong.");
                }
            }

            // Process deleted objects
            foreach (var id in _deletedIds)
            {
                var objToDelete = _objectManager.GetObject(id);

                if (objToDelete == null && _addedObjects.ContainsKey(id))
                {
                    objToDelete = _addedObjects[id];
                }


                if (objToDelete != null)
                {
                    objToDelete.DeletionVersion = _version;
                }
                else
                {
                    throw new ApplicationException($"Unxepected error handling deletion of object with id = {id}. The object does not exist in manager or transaction!");
                }

                // Add id of deleted object to manager
                if (!_objectManager._objectDeletionStates.ContainsKey(id))
                {
                    if (!_objectManager._objectDeletionStates.TryAdd(id, new long[] { _version.InternalVersionId }))
                    {
                        throw new ApplicationException($"Unxepected error adding object with id: {id} to deletion states concurrent dictionary using TryAdd. The returned false indicates that an object with that id already exists in the collection.");
                    }
                }
                else
                {
                    // Get old id list
                    long[] oldObjectArray = _objectManager._objectDeletionStates[id];

                    // Create new array with space for one extra id
                    long[] newObjectArray = new long[oldObjectArray.Length + 1];

                    // Copy data from old array to new array
                    for (int i = 0; i < oldObjectArray.Length; i++)
                    {
                        newObjectArray[i] = oldObjectArray[i];
                    }

                    // Add new id to array
                    newObjectArray[oldObjectArray.Length] = _version.InternalVersionId;

                    // Add new array to object dict
                    if (!_objectManager._objectDeletionStates.TryUpdate(id, newObjectArray, oldObjectArray))
                    {
                        throw new ApplicationException($"Unxepected error adding updated object with id: {id} in deletion states concurrent dictionary using TryUpdate. The returned false indicates something went wrong.");
                    }
                }
            }

            _transactionState = TransactionState.Commited;

            _objectManager._runningTransaction  = null;
            _objectManager._lastCommitedVersion = _version;
            _objectManager._versionsByInternalId.Add(_version.InternalVersionId, _version);

            if (_version.CustomVersionId != null)
            {
                _objectManager._versionsByCustomId.Add(_version.CustomVersionId, _version);
            }
        }
 public static void MoveToFirstVersion <T>(this IVersionedObject <T> @this) where T : class
 {
     @this.CurrentVersionId = 0;
 }
 public static void MoveToLatestVersion <T>(this IVersionedObject <T> @this) where T : class
 {
     @this.CurrentVersionId = @this.LastVersionId;
 }
示例#16
0
文件: Program.cs 项目: zj8487/HyDM
        static void Main()
        {
            //ESRI License Initializer generated code.
            if (!m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine },
                                                              new esriLicenseExtensionCode[] { }))
            {
                System.Windows.Forms.MessageBox.Show(m_AOLicenseInitializer.LicenseMessage() +
                                                     "\n\nThis application could not initialize with the correct ArcGIS license and will shutdown.",
                                                     "ArcGIS License Failure");
                m_AOLicenseInitializer.ShutdownApplication();
                Application.Exit();
                return;
            }


            string strHyDwg = @"E:\吴江\建库数据实验2013-06-18.dwg";

            HyDwgConvert.IDwgReader hyReader = new HyDwgConvert.DwgReaderClass();
            hyReader.set_FileName(strHyDwg);
            hyReader.Init();

            System.Array regAppNames = hyReader.GetRegAppNames();

            int    eCount = hyReader.GetEntityCount();
            int    index = 0;
            string strValue = "";
            object xType, xValue;

            for (HyDwgConvert.IDwgEntity dwgEntity1 = hyReader.Read(); dwgEntity1 != null; dwgEntity1 = hyReader.Read())
            {
                if (dwgEntity1.Shape == null)
                {
                }

                dwgEntity1.GetXData(null, out xType, out xValue);
                //foreach (var pValue in xValue)
                //{
                //    strValue += string.Format("{0}\r\n", pValue);
                //}
                strValue += "\r\n";
                index++;
            }
            hyReader.Close();


            HyDwgConvert.IDwgEntity dwgEntity = new HyDwgConvert.DwgEntityClass();
            dwgEntity.GeometryType = "我靠了";
            dwgEntity.Color        = 123;
            int color = dwgEntity.Color;

            dwgEntity.Handle = "adfas廿的了";
            MessageBox.Show(dwgEntity.GeometryType);

            string     strTarget  = @"e:\Dwg\Test.mdb";
            string     strDwgFile = @"e:\Dwg\TestCass.dwg";// @"E:\吴江\建库数据实验2013-06-18.dwg";
            IWorkspace wsTarget   = (new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass()).OpenFromFile(strTarget, 0);

            DwgConvertLib.DwgReaderClass dwgReader = new DwgConvertLib.DwgReaderClass();
            dwgReader.LogFilePath = @"E:\dwg\log.log";
            dwgReader.InitReadDwg(wsTarget, null);
            dwgReader.ReadPolygon      = true;
            dwgReader.ReadInvisible    = true;
            dwgReader.ReadBlockPoint   = true;
            dwgReader.CreateAnnotation = true;
            dwgReader.Line2Polygon     = false;
            dwgReader.ReadDwgFile(strDwgFile);
            dwgReader.JoinXDataAttrib = true;
            dwgReader.Close();

            string strSource    = @"e:\Dwg\TestSource.mdb";
            string strDwgTarget = @"e:\Dwg\TestOut.dwg";

            DwgConvertLib.DwgWriterClass dwgWriter = new DwgConvertLib.DwgWriterClass();
            dwgWriter.XDataXMLConfigFile = @"E:\dwg\CAD扩展属性配置.xml";
            dwgWriter.LogFilePath        = @"E:\dwg\logOut.log";
            dwgWriter.InitWriteDwg(strDwgTarget, @"E:\Dwg\template.dwg");
            IWorkspace   wsSource   = (new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass()).OpenFromFile(strSource, 0);
            IEnumDataset enDsSource = wsSource.get_Datasets(esriDatasetType.esriDTFeatureClass);

            for (IDataset dsSource = enDsSource.Next(); dsSource != null; dsSource = enDsSource.Next())
            {
                dwgWriter.FeatureClass2Dwgfile(dsSource as IFeatureClass);
            }

            Form  frmProcess = new Form();
            Label lblMessage = new Label();

            lblMessage.Location = new System.Drawing.Point(0, 0);
            frmProcess.Controls.Add(lblMessage);

            Label lblMessage2 = new Label();

            lblMessage2.Location = new System.Drawing.Point(0, 30);
            frmProcess.Controls.Add(lblMessage2);
            frmProcess.Show();
            Application.DoEvents();

            string      strVct = @"E:\HyDM\DataExchange\Data\样例.vct";
            string      strMDB = @"E:\HyDM\DataExchange\Data\Example.mdb";
            VctDocument vctDoc = new VctDocument();
            int         lineIndex = 0, vctRowIndex = 0;

            vctDoc.OnReadingLineChanged += delegate
            {
                lblMessage.Text = (++lineIndex).ToString();
                Application.DoEvents();
            };

            string strLog = "";

            vctDoc.OnMessage += delegate(string strMsg)
            {
                //lblMessage2.Text = strMsg;
                strLog += strMsg + Environment.NewLine;
                //Application.DoEvents();
            };

            vctDoc.OnImportingRowChanged += delegate
            {
                lblMessage2.Text = (++vctRowIndex).ToString();
                Application.DoEvents();
            };
            vctDoc.Open(strVct);
            vctDoc.ReadData();

            IWorkspace ws = (new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass()).OpenFromFile(strMDB, 0);

            foreach (VctLayer vctLayer in vctDoc.Map.Layers)
            {
                string strMsg = "";
                vctRowIndex = 0;
                if (!vctDoc.ConvertVctFileToSDE(vctLayer, ws, vctLayer.Name, "TTT", vctDoc.Header.GetSpatialReference(), ref strMsg))
                {
                    MessageBox.Show(strMsg);
                }
            }



            Hashtable htParameters = new Hashtable();

            htParameters.Add("SERVER", "172.16.1.9");
            htParameters.Add("USER", "wjzgis");
            htParameters.Add("PASSWORD", "wjzgis");
            htParameters.Add("VERSION", "SDE.DEFAULT");
            htParameters.Add("INSTANCE", "5151");

            IWorkspace wsVCT = GetWorkspace(htParameters, "esriDataSourcesGDB.SdeWorkspaceFactory");

            IEnumDataset dsen = ws.get_Datasets(esriDatasetType.esriDTFeatureDataset);

            IDataset ds = dsen.Next();

            ds = (wsVCT as IFeatureWorkspace).OpenFeatureDataset("WJZGIS.FdsTest");
            IVersionedObject vo = ds as IVersionedObject;

            if (vo != null)
            {
            }



            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
示例#17
0
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            if (mEngineEditor.EditState == esriEngineEditState.esriEngineStateNotEditing)
            {
                AxMapControl mMap = this.axMapControl1;
                currentLayer = GetTocSelectedLayer();
                if (currentLayer is IFeatureLayer)
                {
                    IFeatureLayer featureLayer = currentLayer as IFeatureLayer;
                    mLayerType = featureLayer.FeatureClass.ShapeType;

                    IDataset dataset = featureLayer.FeatureClass as IDataset;



                    IVersionedObject verObj = dataset as IVersionedObject;
                    if (verObj != null)
                    {
                        try
                        {
                            verObj.RegisterAsVersioned(true);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    //if (verObj != null)
                    //{

                    //    MessageBox.Show("数据集未注册为版本!");
                    //    return;
                    //}
                    IWorkspace workspace;
                    try
                    {
                        mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned;


                        workspace = dataset.Workspace;
                        mEngineEditor.StartEditing(workspace, mMap.Map);
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeNonVersioned;


                            workspace = dataset.Workspace;
                            mEngineEditor.StartEditing(workspace, mMap.Map);
                        }
                        catch (Exception ex1)
                        {
                            XtraMessageBox.Show(ex1.Message, "提示信息", MessageBoxButtons.OK);
                        }
                    }

                    ((IEngineEditLayers)mEngineEditor).SetTargetLayer(featureLayer, 0);
                }
            }
        }
示例#18
0
        /// <summary>
        /// Handles the Click event of the buttonCalculate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void buttonCalculate_Click(object sender, EventArgs e)
        {
            IFeatureClass featureClass = this.FeatureLayer.FeatureClass;
            IDataset      dataset      = (IDataset)featureClass;
            IDatasetEdit  datasetEdit  = (IDatasetEdit)dataset;

            bool versionedWorkspace = false;

            IWorkspace workspace = dataset.Workspace;

            if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
            {
                IVersionedObject versionedObject = (IVersionedObject)dataset;
                versionedWorkspace = versionedObject.IsRegisteredAsVersioned;
            }

            IEditor editor = (IEditor)this.ArcMapApplication.FindExtensionByName("ESRI Object Editor");



            if (versionedWorkspace &&
                editor.EditState.Equals(esriEditState.esriStateNotEditing))
            {
                MessageBox.Show("You must be in an edit session when editing versioned feature classes.", "Geohash Calculator", MessageBoxButtons.OK);
            }
            else if (versionedWorkspace &&
                     editor.EditState.Equals(esriEditState.esriStateEditing) &&
                     !datasetEdit.IsBeingEdited())
            {
                MessageBox.Show("You must be editing the same workspace as the highlighted layer.", "Geohash Calculator", MessageBoxButtons.OK);
            }
            else
            {
                Stack <int> objectIDs = this.GetObjectIds();

                if (objectIDs.Count > 0)
                {
                    int fieldIndex = featureClass.FindField(comboBoxFields.Text);

                    if (fieldIndex > -1)
                    {
                        int c = 0;

                        foreach (int objectID in objectIDs)
                        {
                            c++;
                            toolStripStatusLabel.Text = "Calculating   " + c.ToString() + " of " + objectIDs.Count.ToString() + " features.";
                            statusStrip.Refresh();

                            IFeature  feature  = featureClass.GetFeature(objectID);
                            IGeometry geometry = (IGeometry)feature.Shape;

                            string currentGeohashValue = "<Null>";

                            if (!System.DBNull.Value.Equals(feature.get_Value(fieldIndex)))
                            {
                                currentGeohashValue = feature.get_Value(fieldIndex).ToString();
                            }

                            if (geometry is IPoint)
                            {
                                IPoint point   = (IPoint)geometry;
                                string geohash = Umbriel.ArcMap.Editor.Util.Geohasher.CreateGeohash(point, 13);

                                if (!currentGeohashValue.Equals(geohash))
                                {
                                    if (versionedWorkspace)
                                    {
                                        editor.StartOperation();
                                    }

                                    feature.set_Value(fieldIndex, geohash);
                                    feature.Store();

                                    if (versionedWorkspace)
                                    {
                                        editor.StopOperation("Update Geohash Field.");
                                    }
                                }
                                else
                                {
                                    toolStripStatusLabel.Text = "-- Same geohash. No Update Required --";
                                    this.statusStrip.Refresh();
                                }
                            }

                            Application.DoEvents();

                            if (this.CancelCalculation)
                            {
                                break;
                            }
                        }

                        if (this.CancelCalculation)
                        {
                            toolStripStatusLabel.Text = "-- Calculation Halted --";
                        }
                        else
                        {
                            toolStripStatusLabel.Text = "-- Calculate Finished --";
                        }
                    }
                }
                else
                {
                    MessageBox.Show("There are no features to calculate.", "Geohash Calculator", MessageBoxButtons.OK);
                }
            }
        }
示例#19
0
        private static bool LayerCanEdit(IFeatureLayer ifeatureLayer_0)
        {
            bool result;

            if (Editor.Editor.EditWorkspace == null)
            {
                result = false;
            }
            else
            {
                IDataset dataset = ifeatureLayer_0.FeatureClass as IDataset;
                if (dataset == null)
                {
                    result = false;
                }
                else if (dataset is ICoverageFeatureClass)
                {
                    result = false;
                }
                else
                {
                    IWorkspace   workspace            = dataset.Workspace;
                    IPropertySet connectionProperties = workspace.ConnectionProperties;
                    IWorkspace   workspace2           = Editor.Editor.EditWorkspace as IWorkspace;
                    if (connectionProperties.IsEqual(workspace2.ConnectionProperties))
                    {
                        if (workspace2.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                        {
                            if (workspace2 is IVersionedWorkspace)
                            {
                                IVersionedObject versionedObject = dataset as IVersionedObject;
                                if (versionedObject.IsRegisteredAsVersioned)
                                {
                                    if (AppConfigInfo.UserID.Length == 0 || AppConfigInfo.UserID.ToLower() == "admin")
                                    {
                                        result = true;
                                        return(result);
                                    }
                                    if (Editor.Editor.m_SysGrants.GetStaffAndRolesDatasetPri(AppConfigInfo.UserID, 2,
                                                                                             dataset.Name))
                                    {
                                        result = true;
                                        return(result);
                                    }
                                }
                            }
                            else
                            {
                                if (AppConfigInfo.UserID.Length == 0 || AppConfigInfo.UserID.ToLower() == "admin")
                                {
                                    result = true;
                                    return(result);
                                }
                                if (Editor.Editor.LayerIsHasEditprivilege(ifeatureLayer_0))
                                {
                                    result = true;
                                    return(result);
                                }
                            }
                        }
                        else
                        {
                            if (AppConfigInfo.UserID.Length == 0 || AppConfigInfo.UserID.ToLower() == "admin")
                            {
                                result = true;
                                return(result);
                            }
                            if (Editor.Editor.LayerIsHasEditprivilege(ifeatureLayer_0))
                            {
                                result = true;
                                return(result);
                            }
                        }
                    }
                    result = false;
                }
            }
            return(result);
        }
示例#20
0
        public override void OnClick()
        {
            IWorkspace pCurWorkspace = null;// m_CurWorkspace;

            //当工作空间为多个时需提供选择对话框
            if (m_AllLayers == null || m_AllLayers.Count == 0)
            {
                return;
            }
            if (m_AllLayers.Count > 1)
            {
                FrmStartEdit frmStarEdit = new FrmStartEdit();
                frmStarEdit.AllEditInfo = m_AllLayers;
                frmStarEdit.ShowDialog();
                if (frmStarEdit.DialogResult == DialogResult.OK)
                {
                    pCurWorkspace = frmStarEdit.SelectWorkspace;
                }
                else
                {
                    return;
                }
            }
            else
            {
                foreach (IWorkspace pWorkspace in m_AllLayers.Keys)
                {
                    pCurWorkspace = pWorkspace;
                }
            }

            if (pCurWorkspace == null)
            {
                return;
            }

            //================================================================
            //chenyafei  20110105  add:在编辑前注册版本
            //只针对SDE数据
            if (pCurWorkspace.WorkspaceFactory.WorkspaceType != esriWorkspaceType.esriRemoteDatabaseWorkspace)
            {
                //若不是SDE数据,则不允许编辑
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请加载SDE数据进行编辑");
                return;
            }
            //只针对注册版本的数据
            IEnumDataset pEnumDataset = pCurWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);

            if (pEnumDataset == null)
            {
                return;
            }

            IDataset pFeaDt = pEnumDataset.Next();

            while (pFeaDt != null)
            {
                if (pFeaDt.Name.ToUpper().EndsWith("_GOH"))
                {
                    pFeaDt = pEnumDataset.Next();
                    continue;
                }
                IVersionedObject pVerObj = pFeaDt as IVersionedObject;
                if (!pVerObj.IsRegisteredAsVersioned)
                {
                    //注册版本
                    if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "该数据还未注册版本,是否注册版本以便进行编辑?"))
                    {
                        pVerObj.RegisterAsVersioned(true);
                        break;
                    }
                    else
                    {
                        return;
                    }
                }
                //else
                //{
                //    pVerObj.RegisterAsVersioned(false);
                //}
                pFeaDt = pEnumDataset.Next();
            }

            //==================================================================

            IWorkspaceEdit pWorkspaceEdit = pCurWorkspace as IWorkspaceEdit;

            if (!pWorkspaceEdit.IsBeingEdited())
            {
                try
                {
                    pWorkspaceEdit.StartEditing(true);
                    pWorkspaceEdit.EnableUndoRedo();
                }
                catch (Exception eError)
                {
                    //******************************************
                    //guozheng added System Exception log
                    if (SysCommon.Log.Module.SysLog == null)
                    {
                        SysCommon.Log.Module.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    }
                    SysCommon.Log.Module.SysLog.Write(eError);
                    //******************************************
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "不能编辑该工作空间,请检查是否为只读或被其它用户占用!");
                    return;
                }
            }

            MoData.v_CurWorkspaceEdit = pWorkspaceEdit;

            //将开启编辑的图层加到图层下拉框中
            if (Plugin.ModuleCommon.DicCommands.ContainsKey("GeoEdit.LayerControl"))
            {
                LayerControl pLayerControl = Plugin.ModuleCommon.DicCommands["GeoEdit.LayerControl"] as LayerControl;
                if (pLayerControl != null)
                {
                    pLayerControl.GetLayers();
                }
            }
            //******************************************************************
            //guozheng 2010-11-4 added 开启编辑成功后获取当前的数据库版本
            Exception ex = null;
            clsUpdataEnvironmentOper UpOper = new clsUpdataEnvironmentOper();

            UpOper.HisWs     = pCurWorkspace;
            MoData.DBVersion = UpOper.GetVersion(out ex);
            if (ex != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据库版本失败。\n原因:" + ex.Message);
            }
            //******************************************************************
            ////打开日志记录表,开启事务
            //Exception exError = null;
            //XmlNode DBNode = m_Hook.DBXmlDocument.SelectSingleNode(".//数据库工程");
            //XmlElement DBElement = DBNode as XmlElement;
            //string strLogMdbPath = DBElement.GetAttribute("路径") + "\\Log\\更新日志.mdb";
            //MoData.v_LogTable = new SysCommon.DataBase.SysTable();
            //MoData.v_LogTable.SetDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strLogMdbPath+";Mode=Share Deny None;Persist Security Info=False", SysCommon.enumDBConType.OLEDB, SysCommon.enumDBType.ACCESS, out exError);
            //MoData.v_LogTable.StartTransaction();

            //委托主窗体关闭事件
            Plugin.Application.IAppFormRef pAppFormRef = m_Hook as Plugin.Application.IAppFormRef;
            pAppFormRef.MainForm.FormClosing += new FormClosingEventHandler(MainForm_FormClosing);
        }
示例#21
0
 public ObjectModification(Guid id, IVersionedObject previousState, IVersionedObject newState) : base(id)
 {
     _previousState = previousState;
     _newState      = newState;
 }