Exemple #1
0
        /// <summary>
        /// Post validates the given set of values.
        /// This is where you flag parameters with warnings and error messages, among other things.
        /// </summary>
        /// <param name="paramValues"></param>
        /// <param name="pEnvMgr"></param>
        /// <param name="msgs"></param>
        public override void UpdateMessages(IArray paramValues, IGPEnvironmentManager pEnvMgr, IGPMessages msgs)
        {
            // Call the base class function first
            try
            {
                UpdateMessagesCommon(paramValues, pEnvMgr, msgs);
            }
            catch (WmxDefaultDbNotSetException)
            {
                // If the default DB wasn't set, stop executing
                return;
            }

            // Build a hash of which parameter is at which index, for ease of access
            WmauParameterMap paramMap = new WmauParameterMap(paramValues);

            IGPParameter3     snName     = paramMap.GetParam(C_PARAM_SPATIAL_NOTIFICATION);
            IGPParameter3     altAoi     = paramMap.GetParam(C_PARAM_ALTERNATE_AOI);
            IGPParameterEdit3 altAoiEdit = paramMap.GetParamEdit(C_PARAM_ALTERNATE_AOI);

            // Ensure that there is at least one existing spatial notification in the database
            if (snName.Domain == null || (snName.Domain as IGPCodedValueDomain).CodeCount <= 0)
            {
                WmauError error = new WmauError(WmauErrorCodes.C_NO_SPATIAL_NOTIFICATIONS_FOUND);
                msgs.ReplaceError(paramMap.GetIndex(C_PARAM_SPATIAL_NOTIFICATION), error.ErrorCodeAsInt, error.Message);
            }

            // Check the AOI; ensure that there is exactly one feature selected
            if (altAoi.Value != null && !altAoi.Value.GetAsText().Equals(string.Empty))
            {
                try
                {
                    ILayer            aoiLayer  = m_gpUtilities.DecodeLayer(altAoi.Value);
                    IFeatureLayer     featLayer = aoiLayer as IFeatureLayer;
                    IFeatureSelection featSel   = aoiLayer as IFeatureSelection;
                    ISelectionSet     selSet    = featSel.SelectionSet as ISelectionSet;

                    if (featLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon)
                    {
                        WmauError error = new WmauError(WmauErrorCodes.C_AOI_NOT_POLYGON_ERROR);
                        msgs.ReplaceWarning(paramMap.GetIndex(C_PARAM_ALTERNATE_AOI), error.Message);
                    }
                    else if (selSet.Count != 1)
                    {
                        WmauError error = new WmauError(WmauErrorCodes.C_EXPECTED_ONE_SELECTED_FEATURE_ERROR);
                        msgs.ReplaceWarning(paramMap.GetIndex(C_PARAM_ALTERNATE_AOI), error.Message);
                    }
                }
                catch (System.Runtime.InteropServices.COMException comEx)
                {
                    WmauError error = new WmauError(WmauErrorCodes.C_AOI_INPUT_ERROR);
                    msgs.ReplaceError(paramMap.GetIndex(C_PARAM_ALTERNATE_AOI), error.ErrorCodeAsInt, error.Message + "; " + comEx.Message);
                }
            }
        }
        // Called after returning from the update parameters routine.
        // You can examine the messages created from internal validation and change them if desired.
        public void UpdateMessages(IArray paramvalues, IGPEnvironmentManager pEnvMgr, IGPMessages Messages)
        {
            // Check for error messages
            IGPMessage msg = (IGPMessage)Messages;

            if (msg.IsError())
            {
                return;
            }

            // Get the first Input Parameter
            IGPParameter parameter = (IGPParameter)paramvalues.get_Element(0);

            // UnPackGPValue. This ensures you get the value either form the dataelement or GpVariable (ModelBuilder)
            IGPValue parameterValue = m_GPUtilities.UnpackGPValue(parameter);

            // Open the Input Dataset - Use DecodeFeatureLayer as the input might be a layer file or a feature layer from ArcMap.
            IFeatureClass inputFeatureClass;
            IQueryFilter  qf;

            m_GPUtilities.DecodeFeatureLayer(parameterValue, out inputFeatureClass, out qf);

            IGPParameter3 fieldParameter = (IGPParameter3)paramvalues.get_Element(1);
            string        fieldName      = fieldParameter.Value.GetAsText();

            // Check if the field already exists and provide a warning.
            int indexA = inputFeatureClass.FindField(fieldName);

            if (indexA > 0)
            {
                Messages.ReplaceWarning(1, "Field already exists. It will be overwritten.");
            }

            return;
        }
        // Called after returning from the update parameters routine. 
        // You can examine the messages created from internal validation and change them if desired. 
        public void UpdateMessages(IArray paramvalues, IGPEnvironmentManager pEnvMgr, IGPMessages Messages)
        {
            // Check for error messages
            IGPMessage msg = (IGPMessage)Messages;
            if (msg.IsError())
                return;    

            // Get the first Input Parameter
            IGPParameter parameter = (IGPParameter)paramvalues.get_Element(0);

            // UnPackGPValue. This ensures you get the value either form the dataelement or GpVariable (ModelBuilder)
            IGPValue parameterValue = m_GPUtilities.UnpackGPValue(parameter);

            // Open the Input Dataset - Use DecodeFeatureLayer as the input might be a layer file or a feature layer from ArcMap.
            IFeatureClass inputFeatureClass;
            IQueryFilter qf;
            m_GPUtilities.DecodeFeatureLayer(parameterValue, out inputFeatureClass, out qf);

            IGPParameter3 fieldParameter = (IGPParameter3)paramvalues.get_Element(1);
            string fieldName = fieldParameter.Value.GetAsText();

            // Check if the field already exists and provide a warning.
            int indexA = inputFeatureClass.FindField(fieldName);
            if (indexA > 0)
            {
                Messages.ReplaceWarning(1, "Field already exists. It will be overwritten.");
            }

            return;
        }
Exemple #4
0
        /// <summary>
        /// Post validates the given set of values.
        /// This is where you flag parameters with warnings and error messages, among other things.
        /// </summary>
        /// <param name="paramValues"></param>
        /// <param name="pEnvMgr"></param>
        /// <param name="msgs"></param>
        public override void UpdateMessages(IArray paramValues, IGPEnvironmentManager pEnvMgr, IGPMessages msgs)
        {
            // Call the base class function first
            try
            {
                UpdateMessagesCommon(paramValues, pEnvMgr, msgs);
            }
            catch (WmxDefaultDbNotSetException)
            {
                // If the default DB wasn't set, stop executing
                return;
            }

            // Build a hash of which parameter is at which index for ease of access
            WmauParameterMap paramMap      = new WmauParameterMap(paramValues);
            IGPParameter3    assigneeType  = paramMap.GetParam(C_PARAM_ASSIGNEE_TYPE);
            IGPParameter3    assignee      = paramMap.GetParam(C_PARAM_ASSIGNEE);
            IGPParameter3    aoi           = paramMap.GetParam(C_PARAM_AOI);
            IGPParameter3    startDate     = paramMap.GetParam(C_PARAM_START_DATE);
            IGPParameter3    dueDate       = paramMap.GetParam(C_PARAM_DUE_DATE);
            IGPParameter3    dataWorkspace = paramMap.GetParam(C_PARAM_DATAWORKSPACE);
            IGPParameter3    parentVersion = paramMap.GetParam(C_PARAM_PARENTVERSION);

            // Ensure that the current user has permissions to be creating jobs
            if (!CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_CREATE_JOB))
            {
                WmauError error = new WmauError(WmauErrorCodes.C_NO_CREATE_JOB_PRIV_ERROR);
                msgs.ReplaceError(paramMap.GetIndex(C_PARAM_JOB_TYPE), error.ErrorCodeAsInt, error.Message);
            }

            // Check assignments; if a name is specified but a type is not, print a warning
            if (String.IsNullOrEmpty(assigneeType.Value.GetAsText()) &&
                !String.IsNullOrEmpty(assignee.Value.GetAsText()))
            {
                WmauError error = new WmauError(WmauErrorCodes.C_JOB_ASSIGNMENT_IGNORED_ERROR);
                msgs.ReplaceWarning(paramMap.GetIndex(C_PARAM_ASSIGNEE), error.Message);
            }

            // Check the AOI; ensure that there is exactly one feature selected
            if (aoi.Value != null && !aoi.Value.GetAsText().Equals(string.Empty))
            {
                try
                {
                    ILayer            aoiLayer  = m_gpUtilities.DecodeLayer(aoi.Value);
                    IFeatureLayer     featLayer = aoiLayer as IFeatureLayer;
                    IFeatureSelection featSel   = aoiLayer as IFeatureSelection;
                    ISelectionSet     selSet    = featSel.SelectionSet as ISelectionSet;

                    if (featLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon)
                    {
                        WmauError error = new WmauError(WmauErrorCodes.C_AOI_NOT_POLYGON_ERROR);
                        msgs.ReplaceWarning(paramMap.GetIndex(C_PARAM_AOI), error.Message);
                    }
                    else if (selSet.Count != 1)
                    {
                        WmauError error = new WmauError(WmauErrorCodes.C_EXPECTED_ONE_SELECTED_FEATURE_ERROR);
                        msgs.ReplaceWarning(paramMap.GetIndex(C_PARAM_AOI), error.Message);
                    }
                }
                catch (System.Runtime.InteropServices.COMException comEx)
                {
                    WmauError error = new WmauError(WmauErrorCodes.C_AOI_INPUT_ERROR);
                    msgs.ReplaceError(paramMap.GetIndex(C_PARAM_AOI), error.ErrorCodeAsInt, error.Message + "; " + comEx.Message);
                }
            }

            // Check start date and due date; if they're both defined, make sure that start
            // date is <= due date
            if (startDate.Value != null && !startDate.Value.GetAsText().Equals(string.Empty) &&
                dueDate.Value != null && !dueDate.Value.GetAsText().Equals(string.Empty) &&
                DateTime.Parse(dueDate.Value.GetAsText()) < DateTime.Parse(startDate.Value.GetAsText()))
            {
                WmauError error = new WmauError(WmauErrorCodes.C_DUE_DATE_LT_START_DATE_ERROR);
                msgs.ReplaceError(paramMap.GetIndex(C_PARAM_DUE_DATE), error.ErrorCodeAsInt, error.Message);
            }

            // If a workspace has been chosen but the version field is disabled and the user has
            // permissions to manage versions, something went wrong
            if (dataWorkspace.Value != null &&
                !dataWorkspace.Value.GetAsText().Equals(string.Empty) &&
                !dataWorkspace.Value.GetAsText().Equals(C_OPT_VAL_NOT_SET) &&
                !parentVersion.Enabled &&
                CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_MANAGE_VERSION))
            {
                WmauError error = new WmauError(WmauErrorCodes.C_WORKSPACE_ERROR);
                msgs.ReplaceError(paramMap.GetIndex(C_PARAM_DATAWORKSPACE), error.ErrorCodeAsInt, error.Message);
            }
        }
Exemple #5
0
 protected void Warning(string err)
 {
     m_msgs.ReplaceWarning(m_msgidx, err);
 }