protected override void OnStart(string[] args) { bool isBound = ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); if (!isBound) { return; } IAoInitialize aoInitialize = new AoInitializeClass(); aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced); aoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeWorkflowManager); IJTXDatabaseManager databaseMan = new JTXDatabaseManagerClass(); m_database = (IJTXDatabase2)databaseMan.GetActiveDatabase(false); //m_lastDate = (DateTime.Now; m_dataWorkspaceNames = m_database.GetDataWorkspaceNames(null); IJTXSpatialNotificationManager spatNotifMan = m_database.SpatialNotificationManager; m_regLayers = spatNotifMan.RegisteredLayerInfos; for (int i = 0; i < m_dataWorkspaceNames.Count; i++) { IWorkspace ws = m_database.GetDataWorkspace(m_dataWorkspaceNames.get_Item(i).DatabaseID, ""); DateTime now = (DateTime)((IDatabaseConnectionInfo2)ws).ConnectionCurrentDateTime; m_workspaces.Add(new WorkspaceInfo(m_dataWorkspaceNames.get_Item(i).DatabaseID, ws, now)); } m_timer.Enabled = true; }
private IJTXChangeRule GetChangeRuleByName(string name) { IJTXChangeRule retVal = null; IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; IJTXChangeRuleSet allChangeRules = snManager.ChangeRules; // Find the type of change rule specified for (int i = 0; i < allChangeRules.Count; i++) { IJTXChangeRule rule = allChangeRules.get_Item(i); if (rule.Name.Equals(name)) { retVal = rule; break; } } return(retVal); }
/// <summary> /// Helper function to create a new instance of the specified type of condition evaluator /// </summary> /// <param name="evalType"></param> /// <returns></returns> private IJTXConditionEvaluator CreateEvaluator(string evalType) { IJTXConditionEvaluator retVal = null; IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; IJTXConditionEvaluatorNameSet allEvaluators = snManager.ConditionEvaluators; // Find the type of evaluator specified for (int i = 0; i < allEvaluators.Count; i++) { IJTXConditionEvaluatorName tempEval = allEvaluators.get_Item(i); if (tempEval.Name.Equals(evalType)) { // Once found, create a new instance of this evaluator retVal = snManager.CreateConditionEvaluator(tempEval); break; } } return(retVal); }
/// <summary> /// Creates a new spatial notifier object based on the specified type. /// </summary> /// <param name="name"> /// The type of notifier object to create. Note that this is NOT /// the same as a change rule. (Change rules include spatial notifiers, as the notifiers /// are the actual mechanism used to communicate information to a list of subscribers.) /// </param> /// <returns> /// A new spatial notifier object of the given type, or null if the type was /// not found. /// </returns> IJTXSpatialNotifier CreateSpatialNotifierByName(string name) { IJTXSpatialNotifier retVal = null; IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; IJTXSpatialNotifierNameSet allSpatialNotifiers = snManager.SpatialNotifiers; // Loop through all of the spatial notifier name objects ("E-mail notifier", etc.) // If/when we find a match, create a spatial notifier object of the correct name/type. // (Remember that the name objects are *not* strings!) for (int i = 0; i < allSpatialNotifiers.Count; i++) { IJTXSpatialNotifierName tempNameObj = allSpatialNotifiers.get_Item(i); if (tempNameObj.Name.Equals(name)) { retVal = snManager.CreateSpatialNotifier(tempNameObj); break; } } return(retVal); }
private void ProcessObjectClass(WorkspaceInfo wsInfo, IObjectClass objClass) { IJTXGDBHistoryChanges gdbHistoryChanges = new JTXGDBHistoryChangesClass(); DateTime now = (DateTime)((IDatabaseConnectionInfo2)wsInfo.workspace).ConnectionCurrentDateTime; IJTXChangeSet changeSet = gdbHistoryChanges.GetChanges(m_database, wsInfo.workspaceID, objClass, wsInfo.lastProcessed, now); wsInfo.lastProcessed = now; if (changeSet.Count > 0) { m_database.LogMessage(5, 2000, "Changes found"); } IJTXSpatialNotificationManager snMan = m_database.SpatialNotificationManager; bool bHasMatches; IJTXChangeRuleMatchSet matches = snMan.EvaluateSet(null, changeSet, out bHasMatches); if (bHasMatches) { m_database.LogMessage(5, 2000, "Matches found"); snMan.Notify(matches); } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; IJTXSpatialNotifierNameSet allSnNames = snManager.SpatialNotifiers; IJTXNotificationConfiguration notificationConfig = this.WmxDatabase.ConfigurationManager as IJTXNotificationConfiguration; // Create a new spatial notification IJTXChangeRule2 changeRule = snManager.AddChangeRule() as IJTXChangeRule2; // Set the name changeRule.Name = m_snName; // Set the notifier IJTXNotificationType srcNotifType = notificationConfig.GetNotificationType(m_emailNotifier); // Set the properties of the spatial notification's e-mail notification to match that // of the source e-mail notification (phew!) IJTXEmailSpatialNotifier emailNotifier = this.CreateSpatialNotifierByName(C_TYPE_EMAIL_NOTIFIER) as IJTXEmailSpatialNotifier; emailNotifier.Subject = srcNotifType.SubjectTemplate; emailNotifier.Body = srcNotifType.MessageTemplate; emailNotifier.SenderEmail = srcNotifType.SenderTemplate; emailNotifier.SenderDisplayName = srcNotifType.SenderDisplayNameTemplate; string[] subscribers = srcNotifType.get_Subscribers(); IStringArray subscribersObj = new StrArrayClass(); foreach (string subscriber in subscribers) { subscribersObj.Add(subscriber); } emailNotifier.Subscribers = subscribersObj; changeRule.Notifier = emailNotifier as IJTXSpatialNotifier; // Set the description, if applicable if (!string.IsNullOrEmpty(m_snDescription)) { changeRule.Description = m_snDescription; } // Set the summarization behavior changeRule.SummarizeNotifications = m_summarize; // Store the resulting change rule changeRule.Store(); // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_NAME); IGPString strValue = new GPStringClass(); strValue.Value = m_snName; outParam.Value = strValue as IGPValue; msgs.AddWarning("To avoid database corruption, at least one dataset or area evaluator must be added to notification '" + m_snName + "' immediately!"); msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_SN_CREATION_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { ICursor cursor = null; // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; // Find the rule that we're modifying IJTXChangeRule2 changeRule = GetChangeRuleByName(m_spatialNotification) as IJTXChangeRule2; // Create and configure the area evaluator IJTXAOIConditionEvaluator areaEvaluator = CreateEvaluator(C_TYPE_AREA_EVALUATOR) as IJTXAOIConditionEvaluator; areaEvaluator.SpatialRel = m_geometricOperations[m_geometricOperation]; areaEvaluator.UseInverse = m_useInverse; areaEvaluator.UseJobAOI = m_useJobAoi; // Set the AOI of the job, if there is one // Ensure that there's nothing wrong with the AOI feature that is selected, if any if (!m_useJobAoi) { if (m_alternateAoi != null) { IFeatureLayer featLayer = m_alternateAoi as IFeatureLayer; IFeatureSelection featSel = m_alternateAoi as IFeatureSelection; ISelectionSet selSet = featSel.SelectionSet as ISelectionSet; if (featLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon) { throw new WmauException(new WmauError(WmauErrorCodes.C_AOI_NOT_POLYGON_ERROR)); } else if (selSet.Count != 1) { throw new WmauException(new WmauError(WmauErrorCodes.C_EXPECTED_ONE_SELECTED_FEATURE_ERROR)); } // If we get this far, we know that there's exactly one selected feature, so we // don't have to loop through the selection set selSet.Search(null, true, out cursor); IFeatureCursor featureCursor = cursor as IFeatureCursor; IFeature aoiCandidate = featureCursor.NextFeature(); // We also know that the feature is a polygon, so just make the cast areaEvaluator.AreaOfInterest = aoiCandidate.Shape as IPolygon; } } // Associate the evaluator with the change rule and save the changes changeRule.Evaluators.Add(areaEvaluator as IJTXConditionEvaluator); changeRule.Store(); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_SPATIAL_NOTIFICATION); IGPString outParamStr = new GPStringClass(); outParamStr.Value = m_spatialNotification; outParamEdit.Value = outParamStr as IGPValue; msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_ADD_AREA_EVAL_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); } } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; // Look up the change rule that we'll be modifying IJTXChangeRule2 changeRule = GetChangeRuleByName(m_spatialNotification) as IJTXChangeRule2; IJTXMultiDatasetConditionEvaluator datasetEvaluator = null; // Try to get an existing dataset evaluator if one exists. if (m_tryExistingEvaluator) { IJTXConditionEvaluatorSet allEvaluators = changeRule.Evaluators; for (int i = 0; i < allEvaluators.Count; i++) { IJTXConditionEvaluator tempEval = allEvaluators.get_Item(i); if (tempEval.Name.Equals(C_TYPE_DATASET_EVALUATOR) && tempEval is IJTXMultiDatasetConditionEvaluator) { datasetEvaluator = tempEval as IJTXMultiDatasetConditionEvaluator; break; } } } // If we don't have an evaluator at this point, then we need to create one if (datasetEvaluator == null) { datasetEvaluator = CreateEvaluator(C_TYPE_DATASET_EVALUATOR) as IJTXMultiDatasetConditionEvaluator; datasetEvaluator.DatasetConfigurations = new JTXDatasetConditionConfigurationSetClass(); changeRule.Evaluators.Add(datasetEvaluator as IJTXConditionEvaluator); } // Create a new dataset configuration IJTXDatasetConditionConfiguration datasetCondition = new JTXDatasetConditionConfigurationClass(); datasetCondition.DatabaseID = m_dataWorkspace; datasetCondition.DatasetName = m_featureClass; datasetCondition.ChangeCondition = m_whenToMonitor; datasetCondition.WhereConditions = m_whereClauses; datasetCondition.ChangeFields = m_monitorAllColumns ? "*" : m_columns.Replace(';', ','); datasetCondition.Name = this.WmxDatabase.GetDataWorkspaceName(m_dataWorkspace).Name + "/" + m_featureClass; // Store the configuration in the dataset evaluator datasetEvaluator.DatasetConfigurations.Add(datasetCondition); changeRule.Store(); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_SPATIAL_NOTIFICATION); IGPString outParamStr = new GPStringClass(); outParamStr.Value = m_spatialNotification; outParamEdit.Value = outParamStr as IGPValue; msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_ADD_DATASET_COND_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; IJTXSpatialNotifierNameSet allSnNames = snManager.SpatialNotifiers; IJTXNotificationConfiguration notificationConfig = this.WmxDatabase.ConfigurationManager as IJTXNotificationConfiguration; // Create a new spatial notification IJTXChangeRule2 changeRule = snManager.AddChangeRule() as IJTXChangeRule2; // Set the name changeRule.Name = m_snName; // Set the properties of the spatial notification's e-mail notification IJTXEmailSpatialNotifier emailNotifier = CreateSpatialNotifierByName(C_TYPE_EMAIL_NOTIFIER) as IJTXEmailSpatialNotifier; emailNotifier.Subject = m_subject; emailNotifier.Body = m_message; // Default the sender's name and e-mail, if none is specified if (string.IsNullOrEmpty(m_senderEmail)) { IJTXConfigurationProperties configProps = this.WmxDatabase.ConfigurationManager as IJTXConfigurationProperties; emailNotifier.SenderEmail = configProps.GetProperty(Constants.JTX_PROPERTY_DEFAULT_SENDER_EMAIL); } else { emailNotifier.SenderEmail = m_senderEmail; } if (string.IsNullOrEmpty(m_senderName)) { IJTXConfigurationProperties configProps = this.WmxDatabase.ConfigurationManager as IJTXConfigurationProperties; emailNotifier.SenderDisplayName = configProps.GetProperty(Constants.JTX_PROPERTY_DEFAULT_SENDER_NAME); } else { emailNotifier.SenderDisplayName = m_senderName; } // Split the subscribers into a list (assume semicolon-deliminted) string[] subscribers = m_subscribers.Split(new char[] { C_DELIM_SUBSCRIBERS }); IStringArray subscribersObj = new StrArrayClass(); foreach (string subscriber in subscribers) { string tempStr = subscriber.Trim(); if (!tempStr.Equals(string.Empty)) { subscribersObj.Add(subscriber.Trim()); } } emailNotifier.Subscribers = subscribersObj; changeRule.Notifier = emailNotifier as IJTXSpatialNotifier; // Set the description, if applicable if (!string.IsNullOrEmpty(m_snDescription)) { changeRule.Description = m_snDescription; } // Set the summarization behavior changeRule.SummarizeNotifications = m_summarize; // Store the resulting change rule changeRule.Store(); // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_NAME); IGPString strValue = new GPStringClass(); strValue.Value = m_snName; outParam.Value = strValue as IGPValue; msgs.AddWarning("To avoid database corruption, at least one dataset or area evaluator must be added to notification '" + m_snName + "' immediately!"); msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_SN_CREATION_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! } }