コード例 #1
0
ファイル: WorkspaceHelper.cs プロジェクト: zj8487/HyDM
        /// <summary>
        /// 创建FileGDB和PGDB Workspace
        /// @remark
        /// 1.Shp创建Workspace没有意义
        /// 2.不支持SDE创建
        /// </summary>
        /// <param name="wsType"></param>
        /// <param name="strPath"></param>
        /// <param name="strName"></param>
        /// <returns></returns>
        public static IWorkspace CreateWorkspace(enumWorkspaceType wsType, string strPath, string strName)
        {
            try
            {
                IWorkspaceFactory wsf = null;
                switch (wsType)
                {
                case enumWorkspaceType.SDE:
                    throw new Exception("CreateWorkspace方法被设计为不支持SDE方式创建");

                case enumWorkspaceType.FileGDB:
                    wsf = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                    break;

                case enumWorkspaceType.PGDB:
                    wsf = new AccessWorkspaceFactoryClass();
                    break;

                case enumWorkspaceType.File:
                    wsf = new ShapefileWorkspaceFactoryClass();
                    break;
                }
                IWorkspaceName wsName = wsf.Create(strPath, strName, null, 0);
                return((wsName as IName).Open() as IWorkspace);
            }
            catch
            {
                return(null);
            }
        }
コード例 #2
0
ファイル: WorkspaceHelper.cs プロジェクト: hy1314200/HyDM
        /// <summary>
        /// 创建FileGDB和PGDB Workspace
        /// @remark 
        /// 1.Shp创建Workspace没有意义
        /// 2.不支持SDE创建
        /// </summary>
        /// <param name="wsType"></param>
        /// <param name="strPath"></param>
        /// <param name="strName"></param>
        /// <returns></returns>
        public static IWorkspace CreateWorkspace(enumWorkspaceType wsType, string strPath, string strName)
        {
            try
            {
                IWorkspaceFactory wsf = null;
                switch (wsType)
                {
                    case enumWorkspaceType.SDE:
                        throw new Exception("CreateWorkspace方法被设计为不支持SDE方式创建");

                    case enumWorkspaceType.FileGDB:
                        wsf = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                        break;

                    case enumWorkspaceType.PGDB:
                        wsf = new AccessWorkspaceFactoryClass();
                        break;

                    case enumWorkspaceType.File:
                        wsf = new ShapefileWorkspaceFactoryClass();
                        break;

                }
                IWorkspaceName wsName = wsf.Create(strPath, strName, null, 0);
                return (wsName as IName).Open() as IWorkspace;
            }
            catch
            {
                return null;
            }
        }
コード例 #3
0
ファイル: frmOraBk_Rc.cs プロジェクト: siszoey/geosufan
        public IWorkspace CreateFileGDBWorkSpace(string filename)
        {
            IWorkspaceFactory pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();

            IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create("" + txtGdbPath.Text + "", "" + filename + "", null, 0);
            IName          name           = (ESRI.ArcGIS.esriSystem.IName)pWorkspaceName;

            IWorkspace fileGDB_workspace = (IWorkspace)name.Open();

            return(fileGDB_workspace);
        }
コード例 #4
0
 /// <summary>
 /// 打开gdb文件
 /// </summary>
 /// <param name="database"></param>
 /// <returns></returns>
 public static IWorkspace OpenFileGdbWorkspace(string database)
 {
     try
     {
         ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
         propertySet.SetProperty("DATABASE", database);
         IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
         return(workspaceFactory.Open(propertySet, 0));
     }
     catch (Exception ex)
     {
         LOG.Error("空间数据库打开错误,详情:" + ex.Message);
         // Console.WriteLine("空间数据库打开错误");
         return(null);
     }
 }
コード例 #5
0
        public IWorkspace GetWorkspace(String _pDatabase, GDBType pGDBType = GDBType.FGDB)
        {
            ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWsFactory = null;

            IWorkspace pWkspace = null;

            if (pGDBType == GDBType.SHP)
            {
                pWsFactory = new ShapefileWorkspaceFactory();
            }
            else if (pGDBType == GDBType.RWS)
            {
                pWsFactory = new RasterWorkspaceFactoryClass();
            }
            else if (pGDBType == GDBType.MDB)
            {
                pWsFactory = new AccessWorkspaceFactoryClass();
            }
            else if (pGDBType == GDBType.FGDB)
            {
                pWsFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            }
            else if (pGDBType == GDBType.SDE)
            {
                pWsFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
            }



            try
            {
                pWkspace = pWsFactory.OpenFromFile(_pDatabase, 0);
            }
            catch (Exception EX)
            {
                //MessageBox.Show(EX.ToString());
            }

            return(pWkspace);
        }
コード例 #6
0
ファイル: GDBInput.cs プロジェクト: Krystal001025/temp
        /// <summary>
        /// 获取工作空间SDE,文件型数据库,MDB,以及shapefile文件所在工作空间,这里可以用一个枚举
        /// </summary>
        /// <param name="_pDatabase"></param>
        /// <returns></returns>
        public IWorkspace GetWorkspace(String _pDatabase, GDBType pGDBType = GDBType.FGDB)
        {
            ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWsFactory = null;

            IWorkspace pWkspace = null;

            if (pGDBType == GDBType.SHP)
            {

                pWsFactory = new ShapefileWorkspaceFactory();

            }
            else if (pGDBType == GDBType.RWS)
            {

                pWsFactory = new RasterWorkspaceFactoryClass();

            }
            else if (pGDBType == GDBType.MDB)
            {
                pWsFactory = new AccessWorkspaceFactoryClass();
            }
            else if (pGDBType == GDBType.FGDB)
            {

                pWsFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            }
            else if (pGDBType == GDBType.SDE)
            {

                pWsFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
            }

            try
            {

                pWkspace = pWsFactory.OpenFromFile(_pDatabase, 0);

            }
            catch (Exception EX)
            {
                //MessageBox.Show(EX.ToString());

            }

            return pWkspace;
        }
コード例 #7
0
ファイル: QAManager.cs プロジェクト: EAWCS1/SUITT
        /**
         * Loads a collection the QA test objects. Returns the collection of tests. Null indicates an error.
         * Passing an empty or null operationalArea will return all QA tests
         */
        private QATestCollection LoadTests(string operationalArea)
        {
            QATestCollection theTestColl = null;

            // no longer stored in the DB. Need to store either in local PGDB, or hard-code
            try
            {
                string path = Extension.get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

                IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                IWorkspace theIsdutWorkspace = workspaceFactory.OpenFromFile(path, 0);

                if (theIsdutWorkspace != null)
                {
                    util.IsdutHourGlass theHourGlass = new ISDUTLib.util.IsdutHourGlass(this._app);

                    try
                    {
                        theHourGlass.start("Loading QA test information");
                        theTestColl = new QATestCollection(theIsdutWorkspace, operationalArea);
                    }
                    catch (util.PermissionsException pex)
                    {
                        util.Logger.Write("qa.QAManager::LoadTests - Exception thrown reading permissions on QA config tables."
                            + Environment.NewLine + pex.Message + Environment.NewLine + pex.ToString(), util.Logger.LogLevel.Warn);
                    }
                    catch (Exception ex)
                    {
                        util.Logger.Write("qa.QAManager::LoadTests - Failed to open database connection to QA config tables."
                            + Environment.NewLine + ex.Message + Environment.NewLine + ex.ToString(), util.Logger.LogLevel.Warn);
                    }
                    finally
                    {
                        theHourGlass.end();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("An error has occured loading the QA tests and defaults. " + e.Message);
                Logger.Write(e);
            }

            return theTestColl;
        }
コード例 #8
0
ファイル: QAManager.cs プロジェクト: EAWCS1/SUITT
        /**
         * Loads a collection of the available OperationalDatasetNames (TANT, FADM).
         * Returns the collection of names. Null indicates an error.
         */
        internal dao.OperationalDatasetCollection LoadOperationalDatasetNames()
        {
            OperationalDatasetCollection theNameColl = null;

            string path = Extension.get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

            IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            IWorkspace theIsdutWorkspace = workspaceFactory.OpenFromFile(path, 0);

            if (theIsdutWorkspace != null)
            {
                util.IsdutHourGlass theHourGlass = new ISDUTLib.util.IsdutHourGlass(this._app);

                try
                {
                    theHourGlass.start("Loading Operational Dataset information");
                    theNameColl = new OperationalDatasetCollection(theIsdutWorkspace);
                }
                catch (util.PermissionsException pex)
                {
                    util.Logger.Write("qa.QAManager::LoadOperationalDatasetNames - Exception thrown reading permissions on QA config tables."
                        + Environment.NewLine + pex.Message + Environment.NewLine + pex.ToString(), util.Logger.LogLevel.Warn);
                }
                catch (Exception ex)
                {
                    util.Logger.Write("qa.QAManager::LoadOperationalDatasetNames - Failed to open database connection to QA config tables."
                        + Environment.NewLine + ex.Message + Environment.NewLine + ex.ToString(), util.Logger.LogLevel.Warn);
                }
                finally
                {
                    theHourGlass.end();
                }
            }

            return theNameColl;
        }
コード例 #9
0
ファイル: QAManager.cs プロジェクト: EAWCS1/SUITT
        /**
         * Executes each of the DataQualityTests in order and collects their results
         */
        public int Execute()
        {
            // Establish the place to store the errors
            try
            {
                tm.TransactionManager theTM = this.Extension.TransactionManager;
                string theFCName = this.Extension.get_SystemValue("tm.template.dataerrors.table");

                if (theTM.Current() == null)
                {
                    // This isn't tied to any transaction, so prompt the user to save a pgdb
                    SaveFileDialog theSaveDialog = new SaveFileDialog();

                    theSaveDialog.Filter = "Personal Geodatabase files (*.mdb)|*.mdb";
                    theSaveDialog.FilterIndex = 1;
                    theSaveDialog.RestoreDirectory = true;
                    theSaveDialog.Title = "Save Test Results";

                    if(theSaveDialog.ShowDialog() == DialogResult.OK)
                    {
                        string theTemplate = this.Extension.get_SystemValue("tm.template.tant.pgdb");
                        this._errors = new QAErrorStorage(theTemplate, theSaveDialog.FileName, theFCName);
                    }
                    else
                        return -2;
                }
                else
                {
                    if (this._errors == null || this._errors.StorageWorkspace != theTM.Current().PGDBConnection)
                    {
                        this._errors = new QAErrorStorage(theTM.Current().PGDBConnection, theFCName);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error raised when establishing place to save errors:" + Environment.NewLine
                    + ex.Message,
                    "Error Storage Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                util.Logger.Write("Error raised when establishing place to save errors:" + Environment.NewLine
                    + ex.Message + Environment.NewLine + ex.StackTrace);
                return -1;
            }

            bool bShowErrorManager = false;
            ArrayList theNewErrors = new ArrayList();

            // Initialize log file
            string logDirectory = this.Extension.get_SystemValue(util.Logger.LOG_DIRECTORY_KEY)
                + Path.DirectorySeparatorChar;
            String logFileName = logDirectory + "isdut_qa_" + DateTime.Now.ToString("s").Replace(":", "-") + ".log";

            // Will put up a progress dialog, with a proper CancelTracker
            IProgressDialog2 thePDialog = null;

            try
            {
                ITrackCancel theCancelTracker = new CancelTrackerClass();
                IProgressDialogFactory theFactory = new ProgressDialogFactoryClass();
                thePDialog = (IProgressDialog2)theFactory.Create(theCancelTracker, this._app.hWnd);
                thePDialog.CancelEnabled = true;
                thePDialog.Description = "";
                thePDialog.Title = "Running QA Tests";
                thePDialog.Animation = esriProgressAnimationTypes.esriProgressGlobe;

                IStepProgressor theStepProgressor = (IStepProgressor)thePDialog;
                theStepProgressor.MinRange = 0;
                theStepProgressor.MaxRange = this.TestCount + 2;
                theStepProgressor.StepValue = 1;

                bool bContinue = true;
                bool bProblemWithTest = false;

                for (int i = 0; i < this.TestCount; i++)
                {
                    QATest theQATest = this._tests.get_Test(i);

                    theStepProgressor.Message = theQATest.Name;

                    if (theQATest != null && theQATest.IsActive)
                    {
                        IDataQualityTest theTest = theQATest.Test;
                        if (theTest != null)
                        {
                            int errCount = theTest.Execute(logFileName);

                            bContinue = theCancelTracker.Continue();
                            if (bContinue == false)
                                break;

                            if (errCount < 0)
                            {
                                bProblemWithTest = true;
                            }

                            if (theTest.ErrorCount > 0)
                            {
                                DataQualityError theDQError;
                                for (int j = 0; j < theTest.ErrorCount; j++)
                                {
                                    theDQError = theTest.get_Error(j);
                                    theDQError.Status = DataQualityError.STATUS_NEW;
                                    theNewErrors.Add(theDQError);
                                }
                            }

                            theTest.ClearErrors();
                        }
                    }
                    theStepProgressor.Step();
                }

                theStepProgressor.Message = "Filtering exceptions...";

                string path = RestTransactionManager.Instance.BaseTransactionManager.extension().get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

                IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                IWorkspace theIsdutWorkspace = workspaceFactory.OpenFromFile(path, 0);

                this._exceptions = new QAExceptionStorage(
                    theIsdutWorkspace,
                    this.Extension.get_SystemValue("db.isdut.schema"),
                    this._operationalAreaForLoadedTests);

                // Check each error to see if it is an exception
                foreach (object obj in theNewErrors)
                {
                    DataQualityError theError = (DataQualityError)obj;

                    if (_exceptions != null)
                    {
                        QAException theException = this._exceptions.FindException(theError);
                        if (theException != null) theError.Status = theException.Status;
                    }
                }

                theStepProgressor.Message = "Storing results...";

                // Pass the new errors to the QAErrorStorage
                this._errors.ClearErrors();
                this._errors.SetNewErrors(theNewErrors, this._operationalAreaForLoadedTests); // IsValid is true at this point

                theStepProgressor.Step();

                bShowErrorManager = true;

                // If any of the tests returned an error value, invalidate
                if (bProblemWithTest)
                {
                    this._errors.Invalidate();
                    MessageBox.Show("At least one test returned an error code, The test results have been written, but are not valid.",
                        "Problem Testing",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);
                }
            }
            catch (ErrorStorageException ese)
            {
                MessageBox.Show("There was an error storing the errors:" +Environment.NewLine
                    + ese.Message + Environment.NewLine + ese.StackTrace,
                    "Error Storage Problem",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }
            catch (Exception e)
            {
                if (theNewErrors.Count > 0)
                {
                    util.Logger.Write("Error raised while testing data: " + Environment.NewLine
                        + e.Message + Environment.NewLine + e.StackTrace,
                        util.Logger.LogLevel.Debug);
                    DialogResult theResult =
                        MessageBox.Show("An error occurred when testing data. Would you like to store the partial results?",
                        "Partial QA Results", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                    if (theResult == DialogResult.Yes)
                    {
                        this._errors.SetNewErrors(theNewErrors, this._operationalAreaForLoadedTests);
                        bShowErrorManager = true;
                    }
                }
                this._errors.Invalidate();
            }
            finally
            {
                if (thePDialog != null)
                    thePDialog.HideDialog();
                thePDialog = null;
            }

            if (bShowErrorManager)
            {
                UID theUID = new UIDClass();
                theUID.Value = "{73519A57-E89E-4773-87DA-E93661E23F6D}"; //ErrorManagerCmd
                // TODO:
                ICommandItem theCItem = this._app.Document.CommandBars.Find(theUID, false, false);
                if (theCItem != null)
                {
                    ((ui.ErrorManagerCmd)theCItem.Command).Open();
                }
                else
                    MessageBox.Show("Could not locate the Error Manager command button", "COM Registration", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return this.ErrorCount;
        }
コード例 #10
0
ファイル: QAManager.cs プロジェクト: EAWCS1/SUITT
        /**
         * Removes exceptions in preparation for deleting a test
         */
        public bool DeleteExceptionsForTest(dao.QATest test)
        {
            // What's the OperDSName of the incoming errors?
            string dsName = "";

            // Make sure we've got a connection to ISDUT for exceptions
            string path = RestTransactionManager.Instance.BaseTransactionManager.extension().get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

            IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            IWorkspace theIsdutWorkspace = workspaceFactory.OpenFromFile(path, 0);

            // Initialize an exception storage object
            if (this._exceptions == null || this._exceptions.OperationalDatasetName.Equals(dsName) == false)
                this._exceptions = new QAExceptionStorage(
                    theIsdutWorkspace,
                    this.Extension.get_SystemValue("db.isdut.schema"),
                    dsName);

            return this._exceptions.RemoveAll(test.Name);
        }
コード例 #11
0
ファイル: QAManager.cs プロジェクト: EAWCS1/SUITT
        /**
         * Applies new status, saves errors and creates/deletes exceptions as necessary
         */
        public void ApplyNewStatusToErrors(dao.QAError[] errors, string newStatus)
        {
            if (errors == null || errors.Length == 0)
                return;

            // Make sure we've got a connection to ISDUT for exceptions
            string path = RestTransactionManager.Instance.BaseTransactionManager.extension().get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

            IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            IWorkspace theIsdutWorkspace = workspaceFactory.OpenFromFile(path, 0);

            // What's the OperDSName of the incoming errors?
            string dsName = errors[0].OperationalDatasetName;

            // Initialize an exception storage object
            if (this._exceptions == null || this._exceptions.OperationalDatasetName.Equals(dsName) == false)
                this._exceptions = new QAExceptionStorage(
                    theIsdutWorkspace,
                    this.Extension.get_SystemValue("db.isdut.schema"),
                    dsName);

            // Loop through each error
            for (int i = 0; i < errors.Length; i++)
            {
                if (errors[i].Error.Status.Equals(newStatus) == false)
                {
                    // Currently an exception? Remove it.
                    if (errors[i].Error.Status.Equals(DataQualityError.STATUS_EXCEPTION)
                        || errors[i].Error.Status.Equals(DataQualityError.STATUS_DEFERRED)
                        || newStatus.Equals(DataQualityError.STATUS_EXCEPTION)
                        || newStatus.Equals(DataQualityError.STATUS_DEFERRED))
                    {
                        QAException theException = this._exceptions.FindException(errors[i].Error);
                        this._exceptions.RemoveException(theException);
                    }

                    // Update the status
                    errors[i].Error.Status = newStatus;
                    this._errors.StoreError(errors[i]);

                    // New status is an exception? Create one.
                    if (newStatus.Equals(DataQualityError.STATUS_EXCEPTION)
                        || newStatus.Equals(DataQualityError.STATUS_DEFERRED))
                    {
                        this._exceptions.AddException(errors[i], newStatus);
                    }
                }
            }
        }
コード例 #12
0
ファイル: CompilationLogCmd.cs プロジェクト: EAWCS1/SUITT
        public override void OnClick()
        {
            m_featureSelected = false;
            m_graphicSelected = false;

            try
            {
                IFeatureSelection pFeatureSelection;

                // use this for a local connection... debugging/development only
                //IWorkspaceFactory pWSF = new FileGDBWorkspaceFactoryClass();
                //IWorkspace pWorkspace = pWSF.OpenFromFile(@"D:\Project\64235_SUT\development\testdata\Subdivision.mdb",m_app.hWnd);
                string path = m_pISDUTExt.get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

                IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                IWorkspace pWorkspace = workspaceFactory.OpenFromFile(path, 0);
                IMap pMap = m_pISDUTExt.FocusMap; //pMxDoc.FocusMap;

                // on the TOC?
                try
                {
                    m_pFeatureLayer = ISDUTLib.tools.utils.FindTOCFeatureLayerByDatasetName(ISDUT_LOGLAYER, pMap);
                }
                catch (Exception e)
                {
                    // ignore any exception here, we'll just reload
                }
                // If not, load it
                if(m_pFeatureLayer == null) m_pFeatureLayer = ISDUTLib.tools.utils.LoadFeatureLayerByDatasetName(ISDUT_LOGLAYER, pMap, pWorkspace);

                // if we find a matching feature layer then we should reconnect it using the TM workspace
                // to make sure the layer permissions match the user permissions
                //if (m_pFeatureLayer != null)
                //{

                //    IDataset pDSTemp = (IDataset)m_pFeatureLayer.FeatureClass;
                //    Debug.WriteLine("Current dataset workspace user = "******"user").ToString());

                //    IPropertySet pPropSet = pWorkspace.ConnectionProperties;
                //    Debug.WriteLine("TM workspace user = "******"user").ToString());

                //    if (pDSTemp.Workspace.ConnectionProperties.GetProperty("user").ToString().ToLower() != pPropSet.GetProperty("user").ToString().ToLower())
                //    {
                //        if (MessageBox.Show("Currently the layer: " + m_pFeatureLayer.Name + "\n" +
                //            "in the Table of Contents is connected with different permissions \n" +
                //            "than the ISDUT connection set with the Transaction Manager. \n\n" +
                //            "To use this tool, it must correct the connection but it will clear \n" +
                //            "any feature selection you have made.  Proceed?", "ISDUT Question", System.Windows.Forms.MessageBoxButtons.YesNo) ==
                //            DialogResult.Yes)
                //        {

                //            pFeatureSelection = (IFeatureSelection)m_pFeatureLayer;
                //            pFeatureSelection.Clear();

                //            if (tools.utils.SwitchSource((IDataLayer2)m_pFeatureLayer, pPropSet, ISDUT_LOGLAYER) == false)
                //            {

                //                throw new Exception("Cannot connect to layer: " + ISDUTschema + ISDUT_LOGLAYER + "\n" +
                //                    "with the database connection information defined in the Transaction Manager");

                //            }

                //            IActiveView pAV = (IActiveView)m_pISDUTExt.MxDocument.FocusMap;
                //            pAV.Refresh();
                //            m_pFeatureLayer.Selectable = true;
                //            return;
                //        }
                //        else
                //        {
                //            return;
                //        }
                //    }
                //}

            //    // if the layer is not found, add it to the TOC using the correct connection from the TM
            //    if (m_pFeatureLayer == null)
            //    {
            //        m_pFeatureLayer = ISDUTLib.tools.utils.LoadFeatureLayerByDatasetName(ISDUTschema + ISDUT_LOGLAYER, pMap, pWorkspace);
            //    }

                if (m_pFeatureLayer == null)
                {
                    MessageBox.Show("Cannot access the database layer: \n" +
                                    ISDUT_LOGLAYER + "\n" +
                                    "Please locate the layer or fix your database connections\n" +
                                    "before using this tool.", "ISDUT Error");
                    return;
                }

                // check permissions
                IDataset pDataset = (IDataset)m_pFeatureLayer.FeatureClass;
                int privs = util.PermissionsAnalyzer.Analyze(pDataset);

                //m_canSUID = (privs == 15);
                //m_canSI = (privs == 5) || m_canSUID;

                m_canSUID = true;
                m_canSI = true;

                Debug.WriteLine(ISDUT_LOGLAYER + " permissions");
                Debug.WriteLine("can select, insert = " + m_canSI);
                Debug.WriteLine("can select, insert, update, delete = " + m_canSUID);

                /*				IDataset pDataset = (IDataset)m_pFeatureLayer.FeatureClass;
                                int privs = util.PermissionsAnalyzer.Analyze(pDataset);

                                m_canWrite = (privs == util.PermissionsAnalyzer.READWRITE_PERMISSION);
                                m_canRead = (privs == util.PermissionsAnalyzer.READONLY_PERMISSION) || m_canWrite;

                                Debug.WriteLine(ISDUT_LOGLAYER + " permissions");
                                Debug.WriteLine("canWrite = " + m_canWrite);
                                Debug.WriteLine("canRed = " + m_canRead); */

                pFeatureSelection = (IFeatureSelection)m_pFeatureLayer;

                // determine if we have 1 or more 2d graphics elements selected

                IGraphicsContainerSelect theGSel = (IGraphicsContainerSelect)m_pISDUTExt.FocusMap;// pMxDoc.FocusMap;
                if (theGSel.ElementSelectionCount > 0)
                {
                    bool bMultipart;
                    int theDimensionality = get_Dimensionality(theGSel.SelectedElements, out bMultipart);
                    if (theDimensionality == 2)
                    {
                        m_graphicSelected = true;
                    }
                }

                IFeature pFeature = null;
                string lognote = string.Empty;
                string operationalDS = string.Empty;

                // determine if these is a single feature selected in the log layer feature class
                if (pFeatureSelection.SelectionSet.Count == 1)
                {
                    m_featureSelected = true;

                    // get existing feature information

                    IQueryFilter pQueryFilter = new SpatialFilterClass();
                    IEnumIDs pEnumIDs = pFeatureSelection.SelectionSet.IDs;
                    pFeature = m_pFeatureLayer.FeatureClass.GetFeature(pEnumIDs.Next());

                    lognote = pFeature.get_Value(pFeature.Fields.FindField("LOG_NOTE")).ToString();
                    operationalDS = pFeature.get_Value(pFeature.Fields.FindField("OPERATIONAL_DATASET_NAME")).ToString();

                }

                // get operational dataset types
                //IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                //ITable pTableOpDataset = pFeatureWorkspace.OpenTable(ISDUTschema + ISDUT_OPDATASET);
                //ICursor pCursor = pTableOpDataset.Search(null, false);

                ArrayList aryOperationDS = new ArrayList();

                //IRow pRow = pCursor.NextRow();
                //while (pRow != null)
                //{
                //    OperationDSDataClass OpDSData = new OperationDSDataClass();
                //    OpDSData.description = pRow.get_Value(pRow.Fields.FindField("DESCRIPTION")).ToString();
                //    OpDSData.code = pRow.get_Value(pRow.Fields.FindField("OPERATIONAL_DATASET_NAME")).ToString();

                //    aryOperationDS.Add(OpDSData);
                //    pRow = pCursor.NextRow();
                //}

                OperationDSDataClass OpDSData = new OperationDSDataClass();
                OpDSData.description = "Tantalis";
                OpDSData.code = "TANT";
                aryOperationDS.Add(OpDSData);

                m_frmCompilationLog = new CompilationLogForm();
                m_frmCompilationLog.CompilationLogFormEvent += new LogNote_EventHander(CompilationFormEventHandler);

                // if use can write then we evalute normal logic for update,create,delete
                if (m_canSUID == true)
                {
                    // decision logic for enabling form functionality
                    if (m_graphicSelected == true && m_featureSelected == true)
                    {
                        m_frmCompilationLog.EnableButtons(true, true, true); //update,delete,create
                    }
                    else if (m_graphicSelected == true && m_featureSelected == false)
                    {
                        m_frmCompilationLog.EnableButtons(false, false, true); // create only
                    }
                    else if (m_graphicSelected == false && m_featureSelected == true)
                    {
                        m_frmCompilationLog.EnableButtons(true, true, false); // update,delete only
                    }
                }
                else //otherwise make it readonly
                {
                    //					if (m_featureSelected == true)
                    //					{
                    //						m_frmCompilationLog.EnableButtons(false,false,false); 	// cancel or 'read' only mode;
                    //					}

                    // decision logic for enabling form functionality
                    if (m_graphicSelected == true && m_featureSelected == true)
                    {
                        m_frmCompilationLog.EnableButtons(false, false, true); //create only
                    }
                    else if (m_graphicSelected == true && m_featureSelected == false)
                    {
                        m_frmCompilationLog.EnableButtons(false, false, true); // create only
                    }
                    else if (m_graphicSelected == false && m_featureSelected == true)
                    {
                        m_frmCompilationLog.EnableButtons(false, false, false); // read-only
                    }
                }

                m_frmCompilationLog.SetFormData(aryOperationDS, lognote, operationalDS);
                m_frmCompilationLog.ShowDialog();
                //SetWindowLongA(m_frmCompilationLog.Handle.ToInt32(), GWL_HWNDPARENT, m_app.hWnd);

            }
            catch (Exception ex)
            {
                util.Logger.Write(" Descrip  : looking for data, getting access permissions, setting up Compilation log form and displaying it." +
                "\n Message  : " + ex.Message +
                "\n StackTrc : " + ex.StackTrace, util.Logger.LogLevel.Debug);

                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                //util.Utils.Release(pMxDoc);
            }
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: jmk201/ArcGISOnlineUpdater
        static void Main(string[] args)
        {
            try
            {
                pathToLocalFileGDB = ConfigurationManager.AppSettings.Get("LocalFileGDBPath").ToString();
                apiBase = ConfigurationManager.AppSettings.Get("AGOLAPIBase").ToString();

                DeleteAllFeatureFromFeatureService();

                aoLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeArcView },
                new esriLicenseExtensionCode[] { });

                IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                IFeatureWorkspace ws = (IFeatureWorkspace)workspaceFactory.OpenFromFile(pathToLocalFileGDB, 0);
                IFeatureClass recSitesFeatureClass = ws.OpenFeatureClass("wenatchee_rec_sites");
                int typeFieldIndex = recSitesFeatureClass.FindField("TYPE");
                int areaFieldIndex = recSitesFeatureClass.FindField("AREA");
                int perimeterFieldIndex = recSitesFeatureClass.FindField("PERIMETER");
                int nameFieldIndex = recSitesFeatureClass.FindField("REC_NAME");
                //string featureJSONArrayString = "[";
                IFeatureCursor fcur = recSitesFeatureClass.Search(null, false);
                IFeature recFeature = fcur.NextFeature();
                while (recFeature != null)
                {
                    IPoint pt = (IPoint)recFeature.Shape;
                    string jsonFeature = string.Empty;
                    jsonFeature += "[{'geometry': {'x': " + pt.X + ",'y': " + pt.Y + ",'spatialReference': {'wkid': 4326}},'attributes': {'TYPE': '";
                    jsonFeature += recFeature.get_Value(typeFieldIndex) + "','AREA': '" + recFeature.get_Value(areaFieldIndex);
                    jsonFeature += "','PERIMETER': '" + "','REC_NAME': '" + recFeature.get_Value(nameFieldIndex) + "'}}]";

                    //string jsonf = "[{'geometry': {'x': -120.663242,'y': 47.784908,'spatialReference': {'wkid': 4326}},"
                     //+ "'attributes': {'TYPE': 'Picnic Area','AREA': '0','PERIMETER': '0','REC_NAME': 'Chumstick!!!'}}]";

                    string reqString = apiBase + "/WenatcheeNationalForestRecSites/FeatureServer/0/addFeatures?f=json&features=" + jsonFeature;
                    HttpWebRequest req = WebRequest.Create(new Uri(reqString)) as HttpWebRequest;
                    req.Method = "POST";
                    req.ContentType = "application/json";

                    // Encode the parameters as form data:
                    byte[] formData = UTF8Encoding.UTF8.GetBytes(reqString);
                    // Send the request:
                    using (Stream post = req.GetRequestStream())
                    {
                        post.Write(formData, 0, formData.Length);
                    }
                    // Pick up the response:
                    string result = null;
                    using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
                    {
                        StreamReader reader =
                            new StreamReader(resp.GetResponseStream());
                        result = reader.ReadToEnd();
                        Console.WriteLine(result.ToString());
                    }
                    recFeature = fcur.NextFeature();
                }
            }
            catch(Exception e)
            {
                string ouch = e.Message;
                return;
            }
            finally
            {
            aoLicenseInitializer.ShutdownApplication();
            }
        }
コード例 #14
0
ファイル: GPSManageForm.cs プロジェクト: EAWCS1/SUITT
        // form startup goodies
        private void GeoRefSelectionForm_Load(object sender, System.EventArgs e)
        {
            try
            {
                // use this for a local connection... debugging/development only
                //IWorkspaceFactory pWSF = new FileGDBWorkspaceFactoryClass();
                //IWorkspace pWorkspace = pWSF.OpenFromFile(@"D:\Project\64235_SUT\development\testdata\ISDUT.mdb",m_pApp.hWnd);
                //IWorkspace pWorkspace = m_pISDUTExt.TransactionManager.ConnectionManager.Isdut;

                IMap pMap = m_pISDUTExt.FocusMap; //m_pMxDoc.FocusMap;

                // try to find the layer in the TOC
                m_pFeatureLayer = ISDUTLib.tools.utils.FindTOCFeatureLayerByDatasetName(ISDUT_GPSLAYER, pMap);

                // if we find a matching feature layer then we should reconnect it using the TM workspace
                // to make sure the layer permissions match the user permissions
                if (m_pFeatureLayer != null)
                {
                    IDataset pDSTemp = (IDataset)m_pFeatureLayer.FeatureClass;

                    //IPropertySet pPropSet = pWorkspace.ConnectionProperties;
                    //Debug.WriteLine("TM workspace user = "******"user").ToString());

                    //if(tools.utils.SwitchSource((IDataLayer2)m_pFeatureLayer,pPropSet,ISDUT_GPSLAYER) == false)
                    //{
                    //	throw new Exception("Cannot connect to layer: " + ISDUT_GPSLAYER + "\n" +
                    //		"with the database connection information defined in the Transaction Manager");
                    //}

                    // TODO:
                    //IMxDocument pMxDoc = (IMxDocument)m_pApp.Document;
                    //pMxDoc.ActiveView.Refresh();
                    m_pISDUTExt.MxDocument.ActiveView.Refresh();
                    //util.Utils.Release(pMxDoc);
                    m_pFeatureLayer.Selectable = true;

                }

                // if the layer is not found, add it to the TOC
                if (m_pFeatureLayer == null)
                {
                    string path = m_pISDUTExt.get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

                    IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                    IWorkspace pWorkspace = workspaceFactory.OpenFromFile(path, 0);

                    m_pFeatureLayer = ISDUTLib.tools.utils.LoadFeatureLayerByDatasetName(ISDUT_GPSLAYER, pMap, pWorkspace);
                }

                // if still not found we have to exit the tool
                if (m_pFeatureLayer == null)
                    throw new Exception("Cannot locate layer: " + ISDUT_GPSLAYER + "\nPlease check your database connections.");

                // check permissions - NO LONGER NEEDED IF ON A PGDB AND NOT DATABASE ACCESS

                m_canSUID = true;
                m_canSI = true;

                /*
                IDataset pDataset = (IDataset)m_pFeatureLayer.FeatureClass;
                int privs = util.PermissionsAnalyzer.Analyze(pDataset);

                m_canSUID = (privs == 15);
                m_canSI = (privs == 5) || m_canSUID;

                Debug.WriteLine(ISDUT_GPSLAYER + " permissions");
                Debug.WriteLine("can select, insert = " + m_canSI);
                Debug.WriteLine("can select, insert, update, delete = " + m_canSUID);
                */
            //				if (m_canWrite == false)
            //				{
            //					MessageBox.Show("You do not have write permissions on the GPS dataset.\n\n" +
            //						"The edit dialog will be shown in read-only mode","ISDUT");
            //
            //					btnNew.Enabled = false;
            //				}

                /*if (m_canSUID == false)
                {
                    if (m_canSI == true)
                    {
                        this.Text += " - Create and View Only Mode";
                    }
                    else
                    {
                        throw new Exception("Permissions Error for current ISDUT user on the \n"
                                            + ISDUT_GPSLAYER + " table.\n\n" +
                                            "Please check your ISDUT database connection.");
                    }
                }*/

                if (LoadBCGSLayer() == false)
                {
                    // Add the 20K mapsheet.
                    string path = m_pISDUTExt.get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

                    IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                    IWorkspace pWorkspace = workspaceFactory.OpenFromFile(path, 0);

                    ISDUTLib.tools.utils.LoadFeatureLayerByDatasetName(BCGSMAPLAYER, pMap, pWorkspace);

                    //MessageBox.Show("The layer: '" + BCGSMAPLAYER + "' could not be found in the current map.\n" +
                    //	"It is needed for creating and editing GPS points. " +
                    //	"Please add it using normal means (e.g. TSAT Tools).\n\n" +
                    //	"The edit dialog will be shown in read-only mode","ISDUT");
                }

                 // ****** set some form related data up  *******

                lvGPS.Sorting = SortOrder.None;  // automatic sorting disable because we have a custom sort implemented

                cboSearchColumn.Items.Clear();
                for(int i = 0; i < lvGPS.Columns.Count;i++)
                {
                    cboSearchColumn.Items.Add(lvGPS.Columns[i].Text);
                }
                cboSearchColumn.SelectedIndex = 1;

                PopulateHashTable();
                PopulateListView();

                //timerFilter.Enabled = true;
                //timerFilter.Stop();
            }
            catch(Exception ex)
            {
                util.Logger.Write(" Descrip  : Permforming prelim data access and management form setup " +
                                "\n Message  : " + ex.Message +
                                "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug);

                MessageBox.Show(ex.Message,"ISDUT");
                this.Close();
            }
        }
コード例 #15
0
ファイル: CmdExpand.cs プロジェクト: EAWCS1/SUITT
        // can be called from tool when activated
        void finishTransaction()
        {
            startHourGlass("Update Spatial Edit Extent");
            // cleanup visuals

            if(featureClass != null)
            {
                SEEUserInterfaceUtils.removeSEELayer(featureClass,ext);

                // TEST Apr 3, 2008
                // Setting featureclass to null is causing an exception
                // when the user clicks on the expands the see and manually draws a larger SEE area
                // featureClass = null;
            }

            if (see == null)
            {
                endHourGlass();
                return; // cancelled
            }
            else
            {
                try
                {
                    // open the SEE pgdb
                    IFeatureClass fc = null;

                    string path = ext.get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

                    IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                    IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(path, 0);
                    fc = workspace.OpenFeatureClass(SEEDAO.OSDB_SEE_NAME);

                    see.Project(fc);
                }
                finally
                {
                    endHourGlass();
                }
            }

            System.IntPtr myIntPtr = new IntPtr(app.hWnd);
            Utils.Win32WindowWrapper wrapper = new Utils.Win32WindowWrapper(myIntPtr);

            try
            {
                checkUTM(see);

                startHourGlass("Expanding Transaction");
                try
                {
                    // fetch the original transaction
                    string sourcePath = RestTransactionManager.Instance.BaseTransactionManager.Current().PGDB.FullName;
                    string sourceMxdPath = RestTransactionManager.Instance.BaseTransactionManager.Current().MXD.FullName;
                    IWorkspace sourceWorkspace = RestTransactionManager.Instance.BaseTransactionManager.Current().PGDBConnection;
                    string sourceSeeID = RestTransactionManager.Instance.BaseTransactionManager.Current().SeeID;

                    // Create a new transaction from the expanded SEE area
                    BusinessArea ba = BusinessArea.Null; // (BusinessArea)metadata[BUSINESS_AREA_KEY];
                    string filePath = this.ext.TransactionManager.Current().PGDB.Directory.FullName;
                    string name = this.ext.TransactionManager.Current().PGDB.Name.TrimEnd(".gdb".ToCharArray()) + "_Expanded";
                    string description = this.ext.TransactionManager.Current().Description;
                    string userName = this.ext.TransactionManager.Current().UserName;
                    bool generated = false;

                    RestTransactionManager.Instance.CreateTransaction(name, description, filePath, userName, see, generated);

                    // merge the old PGDB with the new PGDB
                    IWorkspace destinationeWorkspace = RestTransactionManager.Instance.BaseTransactionManager.Current().PGDBConnection;
                    string destinationSeeID = RestTransactionManager.Instance.BaseTransactionManager.Current().SeeID;

                    // do the merge here
                    startHourGlass("Merging transaction states");
                    MergeTransactions(sourceWorkspace, destinationeWorkspace);

                    // delete the old PGDB
                    Marshal.ReleaseComObject(sourceWorkspace);
                    sourceWorkspace = null;
                    File.Delete(sourcePath);
                    File.Delete(sourceMxdPath);

                    RestTransactionManager.Instance.SetTransactionStatus("CANCELLED", "AOI was expanded. Old transaction cancelled", sourceSeeID);

                    //this.ext.TransactionManager.Current().Expand(see);
                }
                catch (Exception e)
                {
                }
                finally
                {
                    endHourGlass();
                }

                //FormSEEConflicts form = new FormSEEConflicts();
                //SEEConflictDAO dao2 = new SEEConflictDAO(this.ext);
                //ArrayList l = null;

                //startHourGlass("Checking for SEE Conflicts");
                //try
                //{
                //    l = dao2.getConflicts(this.ext.TransactionManager.Current().TxId, see.Shape, this.ext.TransactionManager.Current().OperationalDatasetName);
                //}
                //finally
                //{
                //    endHourGlass();
                //}

                //form.Conflicts = l;
                //if (l != null && l.Count > 0)
                //{
                //    form.ShowDialog((IWin32Window)wrapper);
                //}
            }
            catch (Exception e)
            {
                // log stack trace and re-throw
                Logger.Warn(e);
                throw e;
            }
            finally
            {
                app.CurrentTool = null;
            }
        }
コード例 #16
0
ファイル: CmdNew.cs プロジェクト: EAWCS1/SUITT
        // can be called from tool when activated
        void finishCreatingTransaction()
        {
            System.IntPtr myIntPtr = new IntPtr(app.hWnd);
            Utils.Win32WindowWrapper wrapper = new Utils.Win32WindowWrapper(myIntPtr);

            bool deac = false;
            try
            {
                // cleanup visuals

                SEEUserInterfaceUtils.removeSEELayer(featureClass,ext);
                featureClass = null;

                if (see == null)
                {
                    return; // cancelled
                }
                else
                {
                    // open the SEE pgdb
                    IFeatureClass fc = null;

                    string path = ext.get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

                    IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                    IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(path, 0);
                    fc = workspace.OpenFeatureClass(SEEDAO.OSDB_SEE_NAME);

                    see.Project(fc);

                    // This code stores the data to the database and grabs the feature class. We don't want to do this anymore
                    // write to the ISDUT pdgb instead?
                    /*string prefix = ext.get_SystemValue(DAOUtils.ISDUT_SCHEMA_KEY);
                    if (prefix != null && !prefix.Equals("") && !prefix.EndsWith("."))
                    {
                        prefix = prefix + ".";
                    }

                    IFeatureClass fc = null;
                    try
                    {
                        fc = ((IFeatureWorkspace)ext.TransactionManager.ConnectionManager.Isdut)
                            .OpenFeatureClass(prefix + SEEDAO.OSDB_SEE_NAME);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("OSDB Feature Class " + prefix + SEEDAO.OSDB_SEE_NAME +
                            " Not Found in Isdut", "EXCEPTION", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        throw new HandledException(e);
                    }

                    see.Project(fc);*/
                }

                // get metadata -- including transaction type
                Hashtable metadata = getMetadata(wrapper);

                BusinessArea ba = BusinessArea.Null;// (BusinessArea)metadata[BUSINESS_AREA_KEY];
                string filePath = (string)metadata[FILE_PATH_KEY];
                string name = (string)metadata[FILE_NAME_KEY];
                string description = (string)metadata[DESCRIPTION_KEY];
                string userName = (string)metadata[USERNAME_KEY];
                bool generated = (bool)metadata[FILE_PATH_GENERATED_KEY];

                RestTransactionManager.Instance.CreateTransaction(name, description, filePath, userName, see, generated);

                // REPLACE THIS METHOD WITH REST SERVICE METHOD
                // create transaction -- involved
                //this.ext.TransactionManager.Create(filePath, generated, ba, see,
                //    (string)metadata[DESCRIPTION_KEY], (string)metadata[USERNAME_KEY]);

                //FormSEEConflicts form = new FormSEEConflicts();
                //SEEConflictDAO dao = new SEEConflictDAO(this.ext);
                //ArrayList l = null;

                //startHourGlass("Checking for SEE Conflicts");
                //try
                //{
                //    l = dao.getConflicts(this.ext.TransactionManager.Current().TxId, see.Shape, this.ext.TransactionManager.Current().OperationalDatasetName);
                //}
                //finally
                //{
                //    endHourGlass();
                //}

                //form.Conflicts = l;

                //if (l != null && l.Count > 0)
                //{
                //    form.ShowDialog((IWin32Window)wrapper);
                //}

                //deac = true;
                //app.CurrentTool = null;

                //this.ext.TransactionManager.initMap(BusinessArea.Tantalis, (string)metadata[DESCRIPTION_KEY], (string)metadata[USERNAME_KEY]);
            }
            catch (Exception e)
            {
                // log stack trace and re-throw
                Logger.Warn(e);
                Logger.DeactivateLogger();
                throw e;
            }
            finally
            {
                //if(!deac)
                    //app.CurrentTool = null;
            }
        }