//////////////////////////////////////////////////////////////////////// // METHOD: Execute public int Execute(int jobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback) { // Verify whether the current job has a version or not // Get the current job IJTXJobManager pJobManager = m_ipDatabase.JobManager; IJTXJob2 pJob = pJobManager.GetJob(jobID) as IJTXJob2; // Check for a data workspace IJTXDataWorkspaceName pJobDataWorkspace = pJob.ActiveDatabase; if (pJobDataWorkspace == null) { MessageBox.Show("No data workspace selected for job"); return(3); } // Check if version exists if (pJob.VersionExists()) { MessageBox.Show("Job version has been defined"); return(1); } else { MessageBox.Show("No version defined for job"); return(2); } }
//////////////////////////////////////////////////////////////////////// // METHOD: SetJobProperties private IJTXJob SetJobProperties(IJTXJobManager pJobMan, IJTXJob pJob, IJTXJob2 pParentJob) { m_ipDatabase.LogMessage(5, 2000, "Before LogJobAction (CreateJobs)"); IJTXActivityType pActType = m_ipDatabase.ConfigurationManager.GetActivityType(Constants.ACTTYPE_COMMENT); pParentJob.LogJobAction(pActType, null, String.Format(Properties.Resources.ActTypeMessage, pJob.ID.ToString())); if (!string.IsNullOrEmpty(m_paramExtendedProperties)) { m_ipDatabase.LogMessage(5, 2000, "Before Create Extended Properties"); ExtendedPropertyIdentifier childExProps = new ExtendedPropertyIdentifier(); try { ParseExtendedPropertiesParam(out childExProps); } catch (Exception ex) { string msg = string.Format( "Unable to read parent job's extended property. Job ID: {0} ERROR: {1}", pParentJob.ID, ex.Message); m_ipDatabase.LogMessage(3, 1000, msg); } try { CreateExtendedPropertyRecord(pJob, childExProps); } catch (Exception ex) { string msg = string.Format( "Unable to set child job's extended property. Child Job ID: {0} ERROR: {1}", pJob.ID, ex.Message); m_ipDatabase.LogMessage(3, 1000, msg); } m_ipDatabase.LogMessage(5, 2000, "After Create Extended Properties"); } // Create dependencies on parent job if configured m_ipDatabase.LogMessage(5, 2000, "Before Setting Dependencies"); if (m_paramDependNextStep || m_paramDependThisStep) { IJTXJobDependencies ipDependencyManager = pJobMan as IJTXJobDependencies; CreateDependencyOnParentJob(ipDependencyManager, pParentJob, pJob.ID); } m_ipDatabase.LogMessage(5, 2000, "After Setting Dependencies"); // Create or assign version if configured m_ipDatabase.LogMessage(5, 2000, "Before Versioning"); if (m_paramCreateVersionType != CreateVersionType.None) { if (pParentJob.ActiveDatabase != null && !String.IsNullOrEmpty(pJob.ParentVersion) && (m_paramCreateVersionType != CreateVersionType.UseParentJobsVersion || pParentJob.VersionExists())) CreateChildVersion(ref pJob); else MessageBox.Show("Could not create version. Please ensure parent data workspace and versions are set correctly", Properties.Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (m_paramAssignVersionType != AssignVersionType.None) { if (pParentJob.ActiveDatabase != null) AssignChildVersion(pParentJob, ref pJob); else MessageBox.Show("Could not assign version. Please ensure parent data workspace is set correctly", Properties.Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } m_ipDatabase.LogMessage(5, 2000, "After Versioning"); // Store the job and save the changes m_ipDatabase.LogMessage(5, 2000, "Before Storing Job"); pJob.Store(); m_ipDatabase.LogMessage(5, 2000, "After Storing Job"); return pJob; }
//////////////////////////////////////////////////////////////////////// // METHOD: PopulateAOIListUsingOverlapFeatureClass private bool PopulateAOIListUsingOverlapFeatureClass(IJTXJob2 pParentJob, ref IArray aoiList) { try { // Make sure all the information exists to get the data workspace if (pParentJob.ActiveDatabase == null) { MessageBox.Show("Unable to proceed: Please set the data workspace for this job."); return false; } if (pParentJob.AOIExtent == null) { MessageBox.Show("Unable to proceed: Please assign the AOI for this job."); return false; } // Get the feature workspace from the current data workspace IJTXDatabase2 pJTXDB = (IJTXDatabase2)m_ipDatabase; string activeDBID = pParentJob.ActiveDatabase.DatabaseID; IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)pJTXDB.GetDataWorkspace(activeDBID, pParentJob.VersionExists() ? pParentJob.VersionName : ""); if (featureWorkspace == null) { MessageBox.Show("Unable to connect to Data Workspace"); return false; } IFeatureClass featureClass = null; try { featureClass = featureWorkspace.OpenFeatureClass(m_AOIOverlapFeatureClassName); } catch (Exception ex) { MessageBox.Show("Unable to connect to feature class to generate AOIs: " + m_AOIOverlapFeatureClassName + "\n Error: " + ex.ToString()); return false; } // Get all features that intersect the parent job's AOI // // Note: The parent job's AOI is shrunk very slightly so features that merely adjoin the parent's AOI // are *not* returned. Only features that have some part of their actual area intersecting the parent's // AOI are returned. ISpatialFilter spatialFilter = new SpatialFilterClass(); ITopologicalOperator topOp = (ITopologicalOperator)pParentJob.AOIExtent; IPolygon slightlySmallerExtent = (IPolygon)topOp.Buffer(-0.0001); spatialFilter.Geometry = slightlySmallerExtent; spatialFilter.GeometryField = featureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false); aoiList = new ArrayClass(); IFeature feature = null; while ((feature = featureCursor.NextFeature()) != null) { aoiList.Add(feature.Shape); } // Explicitly release the cursor. Marshal.ReleaseComObject(featureCursor); } catch (Exception ex) { throw new Exception("Unable to create AOIs based on feature class: " + m_AOIOverlapFeatureClassName + ". " + ex.ToString()); } return true; }
//////////////////////////////////////////////////////////////////////// // METHOD: SetJobProperties private IJTXJob SetJobProperties(IJTXJobManager pJobMan, IJTXJob pJob, IJTXJob2 pParentJob) { m_ipDatabase.LogMessage(5, 2000, "Before LogJobAction (CreateJobs)"); IJTXActivityType pActType = m_ipDatabase.ConfigurationManager.GetActivityType(Constants.ACTTYPE_COMMENT); pParentJob.LogJobAction(pActType, null, String.Format(Properties.Resources.ActTypeMessage, pJob.ID.ToString())); if (!string.IsNullOrEmpty(m_paramExtendedProperties)) { m_ipDatabase.LogMessage(5, 2000, "Before Create Extended Properties"); ExtendedPropertyIdentifier childExProps = new ExtendedPropertyIdentifier(); try { ParseExtendedPropertiesParam(out childExProps); } catch (Exception ex) { string msg = string.Format( "Unable to read parent job's extended property. Job ID: {0} ERROR: {1}", pParentJob.ID, ex.Message); m_ipDatabase.LogMessage(3, 1000, msg); } try { CreateExtendedPropertyRecord(pJob, childExProps); } catch (Exception ex) { string msg = string.Format( "Unable to set child job's extended property. Child Job ID: {0} ERROR: {1}", pJob.ID, ex.Message); m_ipDatabase.LogMessage(3, 1000, msg); } m_ipDatabase.LogMessage(5, 2000, "After Create Extended Properties"); } // Create dependencies on parent job if configured m_ipDatabase.LogMessage(5, 2000, "Before Setting Dependencies"); if (m_paramDependNextStep || m_paramDependThisStep) { IJTXJobDependencies ipDependencyManager = pJobMan as IJTXJobDependencies; CreateDependencyOnParentJob(ipDependencyManager, pParentJob, pJob.ID); } m_ipDatabase.LogMessage(5, 2000, "After Setting Dependencies"); // Create or assign version if configured m_ipDatabase.LogMessage(5, 2000, "Before Versioning"); if (m_paramCreateVersionType != CreateVersionType.None) { if (pParentJob.ActiveDatabase != null && !String.IsNullOrEmpty(pJob.ParentVersion) && (m_paramCreateVersionType != CreateVersionType.UseParentJobsVersion || pParentJob.VersionExists())) { CreateChildVersion(ref pJob); } else { MessageBox.Show("Could not create version. Please ensure parent data workspace and versions are set correctly", Properties.Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (m_paramAssignVersionType != AssignVersionType.None) { if (pParentJob.ActiveDatabase != null) { AssignChildVersion(pParentJob, ref pJob); } else { MessageBox.Show("Could not assign version. Please ensure parent data workspace is set correctly", Properties.Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } m_ipDatabase.LogMessage(5, 2000, "After Versioning"); // Store the job and save the changes m_ipDatabase.LogMessage(5, 2000, "Before Storing Job"); pJob.Store(); m_ipDatabase.LogMessage(5, 2000, "After Storing Job"); return(pJob); }
//////////////////////////////////////////////////////////////////////// // METHOD: PopulateAOIListUsingOverlapFeatureClass private bool PopulateAOIListUsingOverlapFeatureClass(IJTXJob2 pParentJob, ref IArray aoiList) { try { // Make sure all the information exists to get the data workspace if (pParentJob.ActiveDatabase == null) { MessageBox.Show("Unable to proceed: Please set the data workspace for this job."); return(false); } if (pParentJob.AOIExtent == null) { MessageBox.Show("Unable to proceed: Please assign the AOI for this job."); return(false); } // Get the feature workspace from the current data workspace IJTXDatabase2 pJTXDB = (IJTXDatabase2)m_ipDatabase; string activeDBID = pParentJob.ActiveDatabase.DatabaseID; IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)pJTXDB.GetDataWorkspace(activeDBID, pParentJob.VersionExists() ? pParentJob.VersionName : ""); if (featureWorkspace == null) { MessageBox.Show("Unable to connect to Data Workspace"); return(false); } IFeatureClass featureClass = null; try { featureClass = featureWorkspace.OpenFeatureClass(m_AOIOverlapFeatureClassName); } catch (Exception ex) { MessageBox.Show("Unable to connect to feature class to generate AOIs: " + m_AOIOverlapFeatureClassName + "\n Error: " + ex.ToString()); return(false); } // Get all features that intersect the parent job's AOI // // Note: The parent job's AOI is shrunk very slightly so features that merely adjoin the parent's AOI // are *not* returned. Only features that have some part of their actual area intersecting the parent's // AOI are returned. ISpatialFilter spatialFilter = new SpatialFilterClass(); ITopologicalOperator topOp = (ITopologicalOperator)pParentJob.AOIExtent; IPolygon slightlySmallerExtent = (IPolygon)topOp.Buffer(-0.0001); spatialFilter.Geometry = slightlySmallerExtent; spatialFilter.GeometryField = featureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false); aoiList = new ArrayClass(); IFeature feature = null; while ((feature = featureCursor.NextFeature()) != null) { aoiList.Add(feature.Shape); } // Explicitly release the cursor. Marshal.ReleaseComObject(featureCursor); } catch (Exception ex) { throw new Exception("Unable to create AOIs based on feature class: " + m_AOIOverlapFeatureClassName + ". " + ex.ToString()); } return(true); }