コード例 #1
0
ファイル: ProjectTransactionCmd.cs プロジェクト: EAWCS1/SUITT
        public static ISpatialReference ProjectWorkspaceContents(
			IWorkspace w,
			FileInfo pgdb,
			Dictionary<string,ISpatialReference> outputSRDict,
			int hWnd)
        {
            bool bHaveStartedProjecting = false;
            string theBackup = "";
            IStepProgressor theStepProgressor = null;
            ISpatialReference theReturn = null;

            try
            {
                // Get the default SR (if set)
                ISpatialReference theDefaultSR = null;
                if (outputSRDict.ContainsKey("*"))
                    theDefaultSR = outputSRDict["*"];

                // Check for schema locks
                IEnumDataset theEnumDataset = w.get_Datasets(esriDatasetType.esriDTFeatureDataset);
                ISchemaLock theSLock = theEnumDataset.Next() as ISchemaLock;
                int datasetCount = 0;

                while (theSLock != null)
                {
                    datasetCount++;
                    try
                    {
                        theSLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        theSLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                    catch (Exception ex)
                    {
                        string msg = "There is an exclusive lock. Please ensure you do not have ArcCatalog running.";
                        MessageBox.Show(msg);
                        throw new ExclusiveLockException(msg, ex);
                    }

                    theSLock = theEnumDataset.Next() as ISchemaLock;
                }

                if (hWnd != 0)
                {
                    IProgressDialogFactory theFactory = new ProgressDialogFactoryClass();
                    IProgressDialog2 thePDialog = (IProgressDialog2)theFactory.Create(null, hWnd);
                    theStepProgressor = (IStepProgressor)thePDialog;
                    thePDialog.Description = "";
                    thePDialog.Title = "Projecting Transaction";
                    thePDialog.Animation = esriProgressAnimationTypes.esriProgressGlobe;

                    theStepProgressor = (IStepProgressor)thePDialog;
                    theStepProgressor.MinRange = 0;
                    theStepProgressor.MaxRange = datasetCount + 2;
                    theStepProgressor.StepValue = 1;
                }

                // Make a backup copy of the database
                //if (theStepProgressor != null) theStepProgressor.Message = "Creating backup file";
                //theBackup = CreateBackup(pgdb);
                if (theStepProgressor != null) theStepProgressor.Step();

                if (theStepProgressor != null) theStepProgressor.Message = "Initializing Geoprocessor";
                Geoprocessor theGP = SetupGPEnvironment(pgdb.FullName);
                if (theStepProgressor != null) theStepProgressor.Step();

                IGPProcess theGPProc = null;

                // Do feature datasets
                theEnumDataset = w.get_Datasets(esriDatasetType.esriDTFeatureDataset);
                IFeatureDataset theInFDataset = theEnumDataset.Next() as IFeatureDataset;

                // Mark that we're starting to edit the transaction
                tm.dao.MetadataDAO mdao = new tm.dao.MetadataDAO((IFeatureWorkspace)w);
                mdao.markStartReprojecting();
                bHaveStartedProjecting = true;

                while (theInFDataset != null)
                {
                    // Choose the output SR
                    ISpatialReference theOutputSR = null;
                    if (outputSRDict.ContainsKey(theInFDataset.Name))
                        theOutputSR = outputSRDict[theInFDataset.Name];
                    else
                        theOutputSR = theDefaultSR;

                    if (theOutputSR != null)
                    {
                        // Write the output SR to a prj file
                        string prjFile = CreatePrjFile(theOutputSR);
                        theReturn = theOutputSR;

                        string inFDName = pgdb.FullName + System.IO.Path.DirectorySeparatorChar + theInFDataset.Name;
                        string outFDName = inFDName + "_isdut";

                        if (theStepProgressor != null) theStepProgressor.Message = "Projecting " + theInFDataset.Name;

                        theGPProc = new ESRI.ArcGIS.DataManagementTools.Project(inFDName, outFDName, prjFile);

                        if (RunTool(theGP, theGPProc, null))
                        {
                            //Debug.Print("Successful project of " + inFDName + " to " + outFDName);
                            IFeatureDataset theOutFDataset = ((IFeatureWorkspace)w).OpenFeatureDataset(theInFDataset.Name + "_isdut");
                            WriteOutputBack(theInFDataset, theOutFDataset);
                        }
                        else
                        {
                            Debug.Print("Project of " + inFDName + " unsuccessful");
                            throw new GPFailedException("Projection failed for " + inFDName, null);
                        }
                    }
                    else
                    {
                        util.Logger.Write("No SR was defined for feature dataset '" + theInFDataset.Name + "'", util.Logger.LogLevel.Warn);
                    }

                    if (theStepProgressor != null) theStepProgressor.Step();

                    theInFDataset = theEnumDataset.Next() as IFeatureDataset;
                }

                // Editing of the transaction is finished, clear the flag
                mdao.markEndReprojecting();

                try
                {
                    // If we got here, it's safe to delete the backup
                    System.IO.File.Delete(theBackup);
                }
                catch (Exception) { }
            }
            catch (Exception ex)
            {
                if (bHaveStartedProjecting)
                {
                    MessageBox.Show("ProjectWorkspaceContents experienced an error and has left the transaction in a halfway state." + Environment.NewLine
                        + "A backup file was created prior to the operation. Please delete the original file and replace it with the backup." + Environment.NewLine
                        + "The original file: " + pgdb.FullName + Environment.NewLine
                        + "The backup file: " + theBackup, "Projection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new ProjectFailedToFinishException("ProjectWorkspaceContents left Personal Geodatabase in a halfway state. Backup PGDB is '" + theBackup + "'.", ex);
                }
                else
                {
                    MessageBox.Show("ProjectWorkspaceContents experienced an error and has left the transaction untouched.");
                    throw new ProjectFailedToStartException("ProjectWorkspaceContents did not begin processing", ex);
                }
            }
            finally
            {
                if (theStepProgressor != null)
                    ((IProgressDialog2)theStepProgressor).HideDialog();
                theStepProgressor = null;
            }

            return theReturn;
        }
コード例 #2
0
ファイル: SEEDAO.cs プロジェクト: EAWCS1/SUITT
        public void close(Transaction current, string comment)
        {
            IFeatureClass fc = null;
            try
            {
                fc = osdb.OpenFeatureClass(OSDB_SEE_NAME);
            }
            catch(Exception e)
            {
                MessageBox.Show("OSDB Feature Class " + OSDB_SEE_NAME + " Not Found in SUITT",
                    "EXCEPTION", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                throw new HandledException(e);
            }
            IFeatureCursor fcrs = null;
            IQueryFilter filter = null;

            try
            {

                MetadataDAO mdao = new MetadataDAO((IFeatureWorkspace)current.PGDBConnection);

                filter = new QueryFilterClass();
                filter.WhereClause = SEE_ID_COL+" = " + mdao.getTransactionID();

                fcrs = fc.Update(filter,false);
                IFeature buffer = fcrs.NextFeature();

                if(buffer == null)
                {
                    Logger.Write("Transaction not found");
                    return;
                }

                // load it up
                buffer.set_Value(fcrs.FindField(PGDB_PATH_COL),current.PGDB.FullName);
                buffer.set_Value(fcrs.FindField(CLOSE_DATE_COL),DateTime.Now);
                buffer.set_Value(fcrs.FindField(EDIT_COMMENTS_COL),comment);

                fcrs.UpdateFeature(buffer);
            }
            finally
            {
                if (filter != null)
                {
                    Utils.Release(filter);
                }
                if(fcrs != null)
                {
                    Utils.Release(fcrs);
                }
            }
        }
コード例 #3
0
ファイル: SEEDAO.cs プロジェクト: EAWCS1/SUITT
        public void delete(Transaction current)
        {
            IFeatureClass fc = null;
            try
            {
                fc = osdb.OpenFeatureClass(OSDB_SEE_NAME);
            }
            catch(Exception e)
            {
                MessageBox.Show("OSDB Feature Class " + OSDB_SEE_NAME + " Not Found in SUITT",
                    "EXCEPTION", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                throw new HandledException(e);
            }

            IFeatureCursor fcrs = null;
            IQueryFilter filter = null;

            try
            {

                MetadataDAO mdao = new MetadataDAO((IFeatureWorkspace)current.PGDBConnection);
                int tid = mdao.getTransactionID();

                filter = new QueryFilterClass();
                filter.WhereClause = SEE_ID_COL+" = " + tid;

                fcrs = fc.Update(filter,false);
                IFeature buffer = fcrs.NextFeature();

                if(buffer == null)
                {
                    Logger.Write("Transaction ("+tid+") not found");
                    return;
                }

                fcrs.DeleteFeature();
            }
            finally
            {
                if (filter != null)
                {
                    Utils.Release(filter);
                }
                if(fcrs != null)
                {
                    Utils.Release(fcrs);
                }
            }
        }
コード例 #4
0
ファイル: ConflictDetector.cs プロジェクト: EAWCS1/SUITT
        public void ComputeConflicts()
        {
            Transaction transaction = this.transactionManager.Current();
            // for each table compute conflicts
            if(transaction.PGDBConnection!= null)
            {
                IEnumDatasetName names = transaction.PGDBConnection.get_DatasetNames(esriDatasetType.esriDTAny);
                if(names != null)
                {
                    ArrayList list = new ArrayList();
                    for(IDatasetName name = names.Next();name!=null;name = names.Next())
                    {
                        if(name != null)
                        {
                            string key = name.Name; // transactionManager.transactionConfig().get_KeyFromWorking(name.Name);
                            if (key != null && !key.ToUpper().Equals("METADATA")
                                            && !key.ToUpper().Equals("DATA_ERRORS")
                                            && !key.ToUpper().Equals("ISDUT_SPATIAL_EDIT_EXTENTS_SP")
                                            && !key.Equals("TEMP_TRANSPORT")
                                            && !key.Equals("TEMP_RR_LG_SUBLOTS"))
                            {
                                // compute conflicts for the layer
                                ICollection conflicts = compute(key, transaction);

                                // resolve+store conflicts against cache list
                                if(conflicts != null) persist(conflicts, transaction, key);
                            }
                        }
                    }
                }
                transaction.ConflictDate = DateTime.Now;

                // force a write action now
                MetadataDAO dao = new MetadataDAO((IFeatureWorkspace)transaction.PGDBConnection);
                dao.save(transaction);
            }
            GC.Collect();
        }
コード例 #5
0
ファイル: Transaction.cs プロジェクト: EAWCS1/SUITT
 public void persistMetadata()
 {
     if(meta_dirty)
     {
         MetadataDAO dao = new MetadataDAO((IFeatureWorkspace)this.pgdbConnection);
         dao.save(this);
     }
     meta_dirty = false;
 }
コード例 #6
0
ファイル: Transaction.cs プロジェクト: EAWCS1/SUITT
 public void loadMetadata()
 {
     try
     {
         meta_loading = true;
         MetadataDAO dao = new MetadataDAO((IFeatureWorkspace)this.pgdbConnection);
         dao.load(this);
         meta_loading = false;
         meta_loaded = true;
         meta_dirty = false;
     }
     catch (Exception e)
     {
         // UI uses this so eat + log
         Logger.Warn(e);
     }
 }