/// <summary>
        /// Pre validates the given set of values.
        /// This is where you populate derived parameters based on input, among other things.
        /// </summary>
        /// <param name="paramValues"></param>
        /// <param name="pEnvMgr"></param>
        public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr)
        {
            try
            {
                UpdateParametersCommon(paramValues, pEnvMgr);
            }
            catch (WmxDefaultDbNotSetException)
            {
                // If the default DB wasn't set, stop executing
                return;
            }
            catch (NullReferenceException)
            {
                // If one of the parameters was null, stop executing
                return;
            }

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

            IGPParameter3     privParam      = paramMap.GetParam(C_PARAM_PRIVILEGE_NAME);
            IGPParameterEdit3 privParamEdit  = paramMap.GetParamEdit(C_PARAM_PRIVILEGE_NAME);
            IGPParameter3     groupParam     = paramMap.GetParam(C_PARAM_GROUP_NAME);
            IGPParameterEdit3 groupParamEdit = paramMap.GetParamEdit(C_PARAM_GROUP_NAME);

            // Add a domain to the privilege parameter
            if (privParam.Domain == null || (privParam.Domain as IGPCodedValueDomain).CodeCount <= 0)
            {
                privParamEdit.Domain = Common.WmauGpDomainBuilder.BuildPrivilegesDomain(this.WmxDatabase, new string[] { C_OPT_ALL_PRIVILEGES });
            }

            // Add a domain to the groups parameter
            if (groupParam.Domain == null || (groupParam.Domain as IGPCodedValueDomain).CodeCount <= 0)
            {
                groupParamEdit.Domain = Common.WmauGpDomainBuilder.BuildGroupsDomain(this.WmxDatabase, new string[] { C_OPT_ALL_GROUPS });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Pre validates the given set of values.
        /// This is where you populate derived parameters based on input, among other things.
        /// </summary>
        /// <param name="paramValues"></param>
        /// <param name="pEnvMgr"></param>
        public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr)
        {
            try
            {
                UpdateParametersCommon(paramValues, pEnvMgr);
            }
            catch (WmxDefaultDbNotSetException)
            {
                // If the default DB wasn't set, stop executing
                return;
            }
            catch (NullReferenceException)
            {
                // If one of the parameters was null, stop executing
                return;
            }

            // Get the parameters as a map for easier access
            WmauParameterMap  paramMap         = new WmauParameterMap(paramValues);
            IGPParameter3     assigneeType     = paramMap.GetParam(C_PARAM_ASSIGNEE_TYPE);
            IGPParameterEdit3 assigneeTypeEdit = paramMap.GetParamEdit(C_PARAM_ASSIGNEE_TYPE);
            IGPParameter3     assignee         = paramMap.GetParam(C_PARAM_ASSIGNEE);
            IGPParameterEdit  assigneeEdit     = paramMap.GetParamEdit(C_PARAM_ASSIGNEE);

            // If the assignee type has changed, update the domain for the assignee
            // parameter
            //
            // NOTE: Updating the assignee value can cause things to get confused,
            // particularly when background geoprocessing is enabled.  So rather than
            // do this, let the assignee parameter value conflict with the domain
            // for that parameter, if need be.
            if (!assigneeType.Value.GetAsText().Equals(m_assigneeType))
            {
                m_assigneeType = assigneeType.Value.GetAsText();

                if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_GROUP))
                {
                    assigneeEdit.Domain = Common.WmauGpDomainBuilder.BuildAssignableGroupsDomain(this.WmxDatabase);
                }
                else if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_USER))
                {
                    assigneeEdit.Domain = Common.WmauGpDomainBuilder.BuildAssignableUsersDomain(this.WmxDatabase);
                }
                else if (m_assigneeType.Equals(C_OPT_UNASSIGNED) ||
                         String.IsNullOrEmpty(m_assigneeType))
                {
                    assigneeEdit.Domain = null;
                }
            }

            // Check to see if the data workspace parameter has changed; if so, store the
            // new workspace value and mark the domain for the workspace version to be reset.
            IGPParameter3 workspaceParam = paramMap.GetParam(C_PARAM_DATAWORKSPACE);

            if (this.IsDataWorkspaceParameterChanged(workspaceParam))
            {
                if (workspaceParam.Value == null)
                {
                    m_dataWorkspaceId = string.Empty;
                }
                else
                {
                    string temp = workspaceParam.Value.GetAsText();
                    m_dataWorkspaceId = Common.WmauHelperFunctions.LookupWorkspaceId(this.WmxDatabase, temp);
                }

                IGPParameterEdit3 versionParam = paramMap.GetParamEdit(C_PARAM_PARENTVERSION);

                // Keep the version parameter's value unchanged; changing it "smartly" to help
                // out a user can lead to trouble.  Instead, let any problem value be flagged
                // as something that's not a member of the domain.
                //versionParam.Value = null;
                versionParam.Domain = null;
                m_parentVersion     = string.Empty;
            }

            // Set the domains for any parameters that need them
            if (paramMap.GetParam(C_PARAM_JOB_TYPE).Domain == null)
            {
                paramMap.GetParamEdit(C_PARAM_JOB_TYPE).Domain = Common.WmauGpDomainBuilder.BuildJobTypeDomain(this.WmxDatabase);
            }
            if (paramMap.GetParam(C_PARAM_JOB_OWNER).Domain == null)
            {
                paramMap.GetParamEdit(C_PARAM_JOB_OWNER).Domain = Common.WmauGpDomainBuilder.BuildUsersDomain(this.WmxDatabase);
            }
            if (paramMap.GetParam(C_PARAM_PRIORITY).Domain == null)
            {
                paramMap.GetParamEdit(C_PARAM_PRIORITY).Domain = Common.WmauGpDomainBuilder.BuildPriorityDomain(this.WmxDatabase);
            }
            if (paramMap.GetParam(C_PARAM_PARENTJOBID).Domain == null)
            {
                paramMap.GetParamEdit(C_PARAM_PARENTJOBID).Domain = Common.WmauGpDomainBuilder.BuildJobIdDomain(this.WmxDatabase);
            }
            if (paramMap.GetParam(C_PARAM_DATAWORKSPACE).Domain == null)
            {
                if (CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_MANAGE_DATA_WORKSPACE))
                {
                    paramMap.GetParamEdit(C_PARAM_DATAWORKSPACE).Domain =
                        Common.WmauGpDomainBuilder.BuildWorkspaceDomain(this.WmxDatabase, new string[] { C_OPT_VAL_NOT_SET });
                }
                else
                {
                    paramMap.GetParamEdit(C_PARAM_DATAWORKSPACE).Domain = new GPCodedValueDomainClass() as IGPDomain;
                }
            }
            if (paramMap.GetParam(C_PARAM_PARENTVERSION).Domain == null)
            {
                if (!m_dataWorkspaceId.Equals(string.Empty) &&
                    !m_dataWorkspaceId.Equals(C_OPT_VAL_NOT_SET) &&
                    CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_MANAGE_VERSION))
                {
                    try
                    {
                        string dbName = this.WmxDatabase.GetDataWorkspaceName(m_dataWorkspaceId).Name;
                        paramMap.GetParamEdit(C_PARAM_PARENTVERSION).Domain =
                            Common.WmauGpDomainBuilder.BuildVersionsDomain(
                                this.WmxDatabase, dbName, new string[] { C_OPT_VAL_NOT_SET });
                    }
                    catch (WmauException)
                    {
                        // If we run into an exception, set the domain to be empty so that
                        // we can detect it and flag an error during parameter validation
                        paramMap.GetParamEdit(C_PARAM_PARENTVERSION).Domain = new GPCodedValueDomainClass();
                    }
                }
            }

            // After the domains have been set, check to see if any parameters should be
            // enabled/disabled based on the contents of these domains.
            assigneeEdit.Enabled = !m_assigneeType.Equals(C_OPT_UNASSIGNED);
            EnableDisableParamBasedOnDomain(paramMap.GetParam(C_PARAM_DATAWORKSPACE));
            EnableDisableParamBasedOnDomain(paramMap.GetParam(C_PARAM_PARENTVERSION));

            // Also check the AOI; if the user can't manage a job's AOI, then disable the
            // parameter
            paramMap.GetParamEdit(C_PARAM_AOI).Enabled = CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_MANAGE_AOI);
        }
Exemplo n.º 3
0
        /// <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);
                }

                // Create the object needed to get at the data workspaces
                IJTXDatabaseConnectionManager dbConnectionManager = new JTXDatabaseConnectionManagerClass();
                IJTXDatabaseConnection        dbConnection        = dbConnectionManager.GetConnection(this.WmxDatabase.Alias);

                // Loop through the data workspaces until we find the one we're looking for, then
                // delete it
                bool removedWorkspace = false;
                for (int i = 0; i < dbConnection.DataWorkspaceCount; i++)
                {
                    IJTXWorkspaceConfiguration workspaceCfg = dbConnection.get_DataWorkspace(i);
                    if (workspaceCfg.Name.Equals(m_dataWorkspace))
                    {
                        dbConnection.RemoveDataWorkspace(i);
                        removedWorkspace = true;
                        break;
                    }
                }

                // Raise an error if we somehow couldn't find it (should never happen with
                // the domain on the input param)
                if (!removedWorkspace)
                {
                    throw new WmauException(WmauErrorCodes.C_WORKSPACE_NOT_FOUND_ERROR);
                }

                // Set the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_DATA_WORKSPACE);
                IGPString         outParamStr  = new GPStringClass();
                outParamStr.Value  = m_dataWorkspace;
                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_UNSPECIFIED_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);

            WorkspaceWorksheetReader reader = null;

            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);
                }

                reader = new WorkspaceWorksheetReader(this.m_excelFilePath, msgs);

                // Prepare to set/build the output parameter
                WmauParameterMap  paramMap      = new WmauParameterMap(paramValues);
                IGPParameter3     outParam      = paramMap.GetParam(C_PARAM_OUT_WORKSPACES_CREATED);
                IGPParameterEdit3 outParamEdit  = paramMap.GetParamEdit(C_PARAM_OUT_WORKSPACES_CREATED);
                IGPMultiValue     outMultiValue = new GPMultiValueClass();
                outMultiValue.MemberDataType = outParam.DataType;

                // Load the workspace info from the spreadsheet
                List <Common.WorkspaceInfo> dataWorkspaces = reader.GetWorkspacesFromSpreadsheet();

                // Loop through each of the workspaces
                IJTXDatabaseConnectionManager dbConnectionManager = new JTXDatabaseConnectionManagerClass();
                IJTXDatabaseConnection        dbConnection        = dbConnectionManager.GetConnection(WmxDatabase.Alias);
                foreach (Common.WorkspaceInfo wmauWorkspaceInfo in dataWorkspaces)
                {
                    string workspaceName = wmauWorkspaceInfo.Name;
                    if (Common.WmauHelperFunctions.LookupWorkspaceNameObj(this.WmxDatabase, workspaceName) != null)
                    {
                        msgs.AddWarning("Skipping existing workspace '" + workspaceName + "'");
                    }
                    else
                    {
                        IJTXWorkspaceConfiguration workspaceInfo = dbConnection.AddDataWorkspace();
                        this.CopyDataWorkspace(wmauWorkspaceInfo, ref workspaceInfo, msgs);
                        workspaceInfo.Store();
                        msgs.AddMessage("Added new workspace '" + workspaceName + "'");

                        IGPString outElement = new GPStringClass();
                        outElement.Value = workspaceName;
                        outMultiValue.AddValue(outElement as IGPValue);
                    }
                }

                // Set the value of the output parameter
                outParamEdit.Value = outMultiValue 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_WORKSPACE_LOAD_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens }
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
        /// <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);
            StreamWriter logFileWriter = null;

            try
            {
                int errorCount = 0;

                if (!string.IsNullOrEmpty(m_logFilePath))
                {
                    logFileWriter = new StreamWriter(m_logFilePath);
                }

                IJTXConfiguration3     configMgr  = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3;
                IJTXConfigurationEdit2 configEdit = configMgr as IJTXConfigurationEdit2;
                IJTXJobManager         jobMgr     = this.WmxDatabase.JobManager;

                // Workflow Manager intentionally caches the data workspaces in the system.  To ensure
                // that we have the most current list of data workspaces, invalidate this cache
                // before attempting to retrieve the list from the system.
                this.WmxDatabase.InvalidateDataWorkspaceNames();

                // Run checks against users
                ExecuteUserChecks(msgs, ref errorCount, logFileWriter);

                // Run checks against groups
                ExecuteGroupChecks(msgs, ref errorCount, logFileWriter);

                // Run checks against any existing jobs
                ExecuteJobChecks(msgs, ref errorCount, logFileWriter);

                // Check for any template job types with an invalid default assignment
                ExecuteJobTypeChecks(msgs, ref errorCount, logFileWriter);

                // Check the workflow steps for problems
                ExecuteWorkflowStepChecks(msgs, ref errorCount, logFileWriter);

                // Set the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_ISSUES_FOUND);
                IGPLong           outValue     = new GPLongClass();
                outValue.Value     = errorCount;
                outParamEdit.Value = outValue 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_UNSPECIFIED_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
            finally
            {
                // Release any COM objects here!
                if (logFileWriter != null)
                {
                    logFileWriter.Close();
                }
            }
        }
        /// <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);
                }

                // Stash away the executing user's information, if appropriate
                string             username      = ESRI.ArcGIS.JTXUI.ConfigurationCache.GetCurrentSystemUser(ESRI.ArcGIS.JTXUI.ConfigurationCache.UseUserDomain);
                IJTXConfiguration3 configMgr     = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3;
                IJTXUser3          executingUser = configMgr.GetUser(username) as IJTXUser3;

                // Import the AD information
                string domain         = System.Environment.UserDomainName;
                string domainUsername = string.Empty;
                string domainPassword = string.Empty;
                int    numUsers       = 0;
                int    numGroups      = 0;
                ActiveDirectoryHelper.SyncronizeJTXDatabaseWithActiveDirectory(this.WmxDatabase, domain, domainUsername, domainPassword, m_userGroup, m_groupGroup, out numGroups, out numUsers);

                // If the tool was set to preserve the current user's account and the user
                // was removed from the DB, then re-add their account
                if (configMgr.GetUser(username) == null)
                {
                    if (m_preserveCurrentUser)
                    {
                        IJTXConfigurationEdit2 configEdit = this.WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2;
                        IJTXUserConfig         newUser    = configEdit.CreateUser() as IJTXUserConfig;
                        newUser.FirstName_2 = executingUser.FirstName;
                        newUser.FullName_2  = executingUser.FullName;
                        newUser.LastName_2  = executingUser.LastName;
                        newUser.UserName_2  = executingUser.UserName;
                        (newUser as IJTXUser3).IsAdministrator = executingUser.IsAdministrator;
                        newUser.Store();

                        msgs.AddMessage("User '" + username + "' not found in Active Directory group '" + m_userGroup + "'; re-added placeholder to Workflow Manager database");
                    }
                    else
                    {
                        msgs.AddWarning("User '" + username + "' removed from Workflow Manager database");
                    }
                }

                // Update the output parameters
                WmauParameterMap  paramMap = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_NUM_USERS);
                IGPLong           value    = new GPLongClass();
                value.Value    = numUsers;
                outParam.Value = value as IGPValue;

                outParam       = paramMap.GetParamEdit(C_PARAM_OUT_NUM_GROUPS);
                value          = new GPLongClass();
                value.Value    = numGroups;
                outParam.Value = value 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_UNSPECIFIED_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
            finally
            {
                // Release any COM objects here!
            }
        }
Exemplo n.º 7
0
        /// <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>
        /// Pre validates the given set of values.
        /// This is where you populate derived parameters based on input, among other things.
        /// </summary>
        /// <param name="paramValues"></param>
        /// <param name="pEnvMgr"></param>
        public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr)
        {
            try
            {
                UpdateParametersCommon(paramValues, pEnvMgr);
            }
            catch (WmxDefaultDbNotSetException)
            {
                // If the default DB wasn't set, stop executing
                return;
            }
            catch (NullReferenceException)
            {
                // If one of the parameters was null, stop executing
                return;
            }

            // Get the parameters as a map for easier access
            WmauParameterMap  paramMap          = new WmauParameterMap(paramValues);
            IGPParameter3     jobTypeParam      = paramMap.GetParam(C_PARAM_JOB_TYPE);
            IGPParameterEdit3 jobTypeParamEdit  = paramMap.GetParamEdit(C_PARAM_JOB_TYPE);
            IGPParameter3     dataWorkspace     = paramMap.GetParam(C_PARAM_DATA_WORKSPACE);
            IGPParameterEdit3 dataWorkspaceEdit = paramMap.GetParamEdit(C_PARAM_DATA_WORKSPACE);
            IGPParameter3     parentVersion     = paramMap.GetParam(C_PARAM_PARENT_VERSION);
            IGPParameterEdit3 parentVersionEdit = paramMap.GetParamEdit(C_PARAM_PARENT_VERSION);

            // Set the domains for any parameters that need them
            if (jobTypeParam.Domain == null)
            {
                jobTypeParamEdit.Domain = Common.WmauGpDomainBuilder.BuildJobTypeDomain(this.WmxDatabase);
            }
            if (dataWorkspace.Domain == null)
            {
                dataWorkspaceEdit.Domain = Common.WmauGpDomainBuilder.BuildWorkspaceDomain(
                    this.WmxDatabase,
                    new string[] { C_OPT_NONE });
            }

            // Only update the domain for the parent version field if it hasn't yet been
            // populated, or if the value of the data workspace parameter has changed
            string newDataWorkspace = dataWorkspace.Value.GetAsText();

            if (parentVersion.Domain == null ||
                !m_dataWorkspaceName.Equals(newDataWorkspace))
            {
                IGPDomain    versionDomain = null;
                string       newJobType    = jobTypeParam.Value.GetAsText();
                IJTXJobType3 jobType       = this.WmxDatabase.ConfigurationManager.GetJobType(newJobType) as IJTXJobType3;

                if (newDataWorkspace.Equals(C_OPT_NONE) ||
                    newDataWorkspace.Equals(string.Empty))
                {
                    // Case 1: the only acceptable option for the parent version is "none".
                    IGPCodedValueDomain cvDomain = new GPCodedValueDomainClass();
                    cvDomain.AddStringCode(C_OPT_NONE, C_OPT_NONE);
                    versionDomain = cvDomain as IGPDomain;
                }
                else
                {
                    // Case 2: we need to retrieve the version list for an existing
                    // data workspace
                    try
                    {
                        versionDomain = Common.WmauGpDomainBuilder.BuildVersionsDomain(
                            this.WmxDatabase, newDataWorkspace, new string[] { C_OPT_NONE });
                    }
                    catch (WmauException)
                    {
                        // Use the "null" as an error value; we'll check for this later
                        versionDomain = null;
                    }
                }
                parentVersionEdit.Domain = versionDomain;
            }
        }
Exemplo n.º 9
0
        /// <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!
            }
        }
        /// <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);
                }

                // Retrieve the parameter in which the data workspace names will be stored
                WmauParameterMap  paramMap  = new WmauParameterMap(paramValues);
                IGPParameter3     param     = paramMap.GetParam(C_PARAM_WORKSPACE_LIST);
                IGPParameterEdit3 paramEdit = paramMap.GetParamEdit(C_PARAM_WORKSPACE_LIST);

                // Set up the multi-value objects
                IGPMultiValue mvValue = new GPMultiValueClass();
                mvValue.MemberDataType = param.DataType;

                // Workflow Manager intentionally caches the data workspaces in the system.  To ensure
                // that we have the most current list of data workspaces, invalidate this cache
                // before attempting to retrieve the list from the system.
                this.WmxDatabase.InvalidateDataWorkspaceNames();

                // Get the list of names
                SortedList <string, string> sortedValues = new SortedList <string, string>();
                IJTXDataWorkspaceNameSet    allValues    = this.WmxDatabase.GetDataWorkspaceNames(null);
                for (int i = 0; i < allValues.Count; i++)
                {
                    IJTXDataWorkspaceName ws = allValues.get_Item(i);
                    sortedValues.Add(ws.Name, null);
                }

                // Add the names to the output parameter
                foreach (string name in sortedValues.Keys)
                {
                    IGPString strVal = new GPStringClass();
                    strVal.Value = name;
                    mvValue.AddValue(strVal as IGPValue);
                    msgs.AddMessage("Workspace: " + name);
                }
                paramEdit.Value = (IGPValue)mvValue;

                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_UNSPECIFIED_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);
                }

                IJTXConfigurationEdit2 configEdit = this.WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2;

                // Look up the appropriate privilege(s) and group(s)
                IJTXPrivilegeSet privileges = null;
                if (m_privilegeName.Equals(C_OPT_ALL_PRIVILEGES))
                {
                    privileges = configEdit.Privileges;
                }
                else
                {
                    privileges = new JTXPrivilegeSetClass();
                    (privileges as IJTXPrivilegeSetEdit).Add(configEdit.GetPrivilege(m_privilegeName));
                }

                IJTXUserGroupSet groups = null;
                if (m_groupName.Equals(C_OPT_ALL_GROUPS))
                {
                    groups = configEdit.UserGroups;
                }
                else
                {
                    groups = new JTXUserGroupSetClass();
                    (groups as IJTXUserGroupSetEdit).Add(configEdit.GetUserGroup(m_groupName));
                }

                // Add/remove the privilege(s) to the group(s)
                for (int i = 0; i < privileges.Count; i++)
                {
                    IJTXPrivilege2 privilege = privileges.get_Item(i) as IJTXPrivilege2;
                    for (int j = 0; j < groups.Count; j++)
                    {
                        IJTXUserGroupConfig2 targetGroup = groups.get_Item(j) as IJTXUserGroupConfig2;
                        if (m_privilegeAction.Equals(C_OPT_GRANT))
                        {
                            targetGroup.AssignPrivilegeToGroup2(privilege.UID);
                        }
                        else
                        {
                            targetGroup.RemovePrivilegeFromGroup2(privilege.UID);
                        }
                        targetGroup.Store();
                    }
                }

                // Update the output parameter
                WmauParameterMap  paramMap = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_PRIVILEGE_NAME);
                IGPString         strValue = new GPStringClass();
                strValue.Value = m_privilegeName;
                outParam.Value = strValue 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_UNSPECIFIED_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
            finally
            {
                // Release any COM objects here!
            }
        }
Exemplo n.º 13
0
        /// <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);
                }

                IJTXConfigurationEdit2 configEdit = this.WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2;

                // Look up the appropriate user(s)
                IJTXUserSet users = null;
                if (m_userName.Equals(C_OPT_ALL_USERS))
                {
                    users = configEdit.Users;
                }
                else
                {
                    users = new JTXUserSetClass();
                    (users as IJTXUserSetEdit).Add(configEdit.GetUser(m_userName));
                }

                // Grant/revoke admin access to the specified users
                for (int i = 0; i < users.Count; i++)
                {
                    IJTXUser3 user = users.get_Item(i) as IJTXUser3;
                    user.IsAdministrator = m_privilegeAction.Equals(C_OPT_GRANT) ? true : false;
                    (user as IJTXUserConfig).Store();
                }

                // If the tool was set to preserve the current user's access and the tool removed it,
                // re-grant their access
                string    username = ESRI.ArcGIS.JTXUI.ConfigurationCache.GetCurrentSystemUser(ESRI.ArcGIS.JTXUI.ConfigurationCache.UseUserDomain);
                IJTXUser3 userObj  = configEdit.GetUser(username) as IJTXUser3;
                if (!userObj.IsAdministrator)
                {
                    if (m_preserveCurrentUser)
                    {
                        userObj.IsAdministrator = true;
                        (userObj as IJTXUserConfig).Store();
                        msgs.AddMessage("Re-granting admin access for user '" + username + "'");
                    }
                    else
                    {
                        msgs.AddWarning("User '" + username + "' is no longer an administrator on this Workflow Manager database");
                    }
                }

                // Update the output parameter
                WmauParameterMap  paramMap = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_USER_NAME);
                IGPString         strValue = new GPStringClass();
                strValue.Value = m_userName;
                outParam.Value = strValue 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_UNSPECIFIED_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);

            //////////////////////////////////////////////////////////////////////
            // TODO: Update the job-deletion logic.
            //
            // In subsequent builds of Workflow Manager (post-10.0), there may be
            // a new API that deletes jobs and handles some of the logic included
            // in this class (ex: checking permissions, deleting versions, etc.).
            // If so, this GP tool should be revised to make use of this
            // simplified interface.
            //
            // Anyone using this tool as a reference, particularly with regards
            // to deleting Workflow Manager jobs, should keep this in mind.
            //////////////////////////////////////////////////////////////////////

            // Delete the requested job
            try
            {
                IJTXJobManager jobManager = this.WmxDatabase.JobManager;
                IJTXJob3       job        = jobManager.GetJob(m_jobToDelete) as IJTXJob3;

                msgs.AddMessage("Deleting job " + m_jobToDelete + " (" + job.Name + ")");
                job.DeleteMXD();
                if (job.VersionExists())
                {
                    if (CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_DELETE_VERSION))
                    {
                        try
                        {
                            job.DeleteVersion(null);
                        }
                        catch (System.Runtime.InteropServices.COMException comEx)
                        {
                            if (comEx.ErrorCode == (int)fdoError.FDO_E_SE_VERSION_NOEXIST)
                            {
                                // The "VersionExists" method above can apparently be fooled; if it is, an exception with this
                                // error code is thrown.  In this case, add a warning and continue on.
                                msgs.AddWarning("Version '" + job.VersionName + "' is assigned to job " + job.ID.ToString() + " but could not be found");
                            }
                            else
                            {
                                // If there's a different error, then re-throw it for someone else to deal with
                                throw comEx;
                            }
                        }
                    }
                    else
                    {
                        string username = ESRI.ArcGIS.JTXUI.ConfigurationCache.GetCurrentSystemUser(ESRI.ArcGIS.JTXUI.ConfigurationCache.UseUserDomain);
                        msgs.AddWarning("User '" + username + "' does not have permissions to " +
                                        "delete job versions; version '" + job.VersionName + "' will not be deleted");
                    }
                }
                jobManager.DeleteJob(m_jobToDelete, true);

                // Set the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_JOB_DELETED);
                IGPLong           outValue     = new GPLongClass();
                outValue.Value     = m_jobToDelete;
                outParamEdit.Value = outValue as IGPValue;

                msgs.AddMessage(Properties.Resources.MSG_DONE);
            }
            catch (Exception ex)
            {
                WmauError error = new WmauError(WmauErrorCodes.C_DELETE_JOB_VERSION_ERROR);
                msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
            }
        }
Exemplo n.º 15
0
        /// <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)
        {
            IJTXJob4 job = null;

            // Do some common error-checking
            base.Execute(paramValues, trackCancel, envMgr, msgs);

            //////////////////////////////////////////////////////////////////////
            // TODO: Update the job-creation logic.
            //
            // In subsequent builds of Workflow Manager (post-10.0), there may be
            // a new API that creates jobs and handles much of the logic included
            // in this function (and this class at large).  If so, this GP tool
            // should be revised to make use of this simplified interface.
            //
            // Anyone using this tool as a reference, particularly with regards
            // to creating Workflow Manager jobs, should keep this in mind.
            //////////////////////////////////////////////////////////////////////

            // Try to create the job, as requested
            try
            {
                IJTXJobManager2   jobManager = this.WmxDatabase.JobManager as IJTXJobManager2;
                IJTXConfiguration configMgr  = this.WmxDatabase.ConfigurationManager as IJTXConfiguration;
                IJTXJobType4      jobTypeObj = configMgr.GetJobType(m_jobTypeAsString) as IJTXJobType4;

                // Set up the description object to be used to create this job
                IJTXJobDescription jobDescription = new JTXJobDescriptionClass();
                jobDescription.JobTypeName = m_jobTypeAsString;
                jobDescription.AOI         = GetPolygonFromSpecifiedLayer(m_aoiLayer);

                // Set up the ownership & assignment of the job
                jobDescription.OwnedBy = m_jobOwner;
                if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_GROUP))
                {
                    jobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeGroup;
                    jobDescription.AssignedTo   = m_assignee;
                }
                else if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_USER))
                {
                    jobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeUser;
                    jobDescription.AssignedTo   = m_assignee;
                }
                else if (m_assigneeType.Equals(C_OPT_UNASSIGNED))
                {
                    jobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeUnassigned;
                    jobDescription.AssignedTo   = string.Empty;
                }
                else
                {
                    // Do nothing; let the job type defaults take over
                    msgs.AddMessage("Using job type defaults for job assignment");
                    jobDescription.AssignedType = jobTypeObj.DefaultAssignedType;
                    jobDescription.AssignedTo   = jobTypeObj.DefaultAssignedTo;
                }

                // Start date
                if (m_startDate != null && m_startDate.Value != null)
                {
                    string tempStr = m_startDate.Value.ToString();

                    // Workflow Manager stores times as UTC times; input times must
                    // therefore be pre-converted
                    DateTime tempDate = DateTime.Parse(tempStr);
                    jobDescription.StartDate = TimeZone.CurrentTimeZone.ToUniversalTime(tempDate);
                }
                else
                {
                    msgs.AddMessage("Using job type defaults for start date");
                    jobDescription.StartDate = jobTypeObj.DefaultStartDate;
                }

                // Due date
                if (m_dueDate != null && m_dueDate.Value != null)
                {
                    string tempStr = m_dueDate.Value.ToString();

                    // Workflow Manager stores times as UTC times; input times must
                    // therefore be pre-converted
                    DateTime tempDate = DateTime.Parse(tempStr);
                    jobDescription.DueDate = TimeZone.CurrentTimeZone.ToUniversalTime(tempDate);
                }
                else
                {
                    msgs.AddMessage("Using job type defaults for due date");
                    jobDescription.DueDate = jobTypeObj.DefaultDueDate;
                }

                // Priority
                if (!m_priority.Equals(string.Empty))
                {
                    IJTXPriority priority = configMgr.GetPriority(m_priority);
                    jobDescription.Priority = priority;
                }
                else
                {
                    msgs.AddMessage("Using job type defaults for priority");
                    jobDescription.Priority = jobTypeObj.DefaultPriority;
                }

                // Parent job
                if (m_parentJobId > 0)
                {
                    jobDescription.ParentJobId = m_parentJobId;
                }

                // Data workspace
                if (m_dataWorkspaceId.Equals(C_OPT_VAL_NOT_SET))
                {
                    jobDescription.DataWorkspaceID = string.Empty;
                }
                else if (!m_dataWorkspaceId.Equals(string.Empty))
                {
                    jobDescription.DataWorkspaceID = m_dataWorkspaceId;
                }
                else
                {
                    msgs.AddMessage("Using job type defaults for data workspace");
                    if (jobTypeObj.DefaultDataWorkspace != null)
                    {
                        jobDescription.DataWorkspaceID = jobTypeObj.DefaultDataWorkspace.DatabaseID;
                    }
                }

                // Parent version
                if (m_parentVersion.Equals(C_OPT_VAL_NOT_SET))
                {
                    jobDescription.ParentVersionName = string.Empty;
                }
                else if (!m_parentVersion.Equals(string.Empty))
                {
                    jobDescription.ParentVersionName = m_parentVersion;
                }
                else
                {
                    msgs.AddMessage("Using job type defaults for parent version");
                    jobDescription.ParentVersionName = jobTypeObj.DefaultParentVersionName;
                }

                // Auto-execution
                jobDescription.AutoExecuteOnCreate = m_executeNewJob;

                // Create the new job
                int             expectedNumJobs = 1;
                bool            checkAoi        = true;
                IJTXJobSet      jobSet          = null;
                IJTXExecuteInfo execInfo;
                try
                {
                    jobSet = jobManager.CreateJobsFromDescription(jobDescription, expectedNumJobs, checkAoi, out execInfo);
                }
                catch (System.Runtime.InteropServices.COMException comEx)
                {
                    throw new WmauException(WmauErrorCodes.C_CREATE_JOB_ERROR, comEx);
                }

                if ((execInfo != null && execInfo.ThrewError) ||
                    jobSet == null ||
                    jobSet.Count != expectedNumJobs)
                {
                    if (execInfo != null && !string.IsNullOrEmpty(execInfo.ErrorDescription))
                    {
                        throw new WmauException(
                                  WmauErrorCodes.C_CREATE_JOB_ERROR,
                                  new Exception(execInfo.ErrorCode.ToString() + ": " + execInfo.ErrorDescription));
                    }
                    else
                    {
                        throw new WmauException(WmauErrorCodes.C_CREATE_JOB_ERROR);
                    }
                }

                // If it gets all the way down here without errors, set the output ID with the
                // ID of the job that was created.
                job = jobSet.Next() as IJTXJob4;
                WmauParameterMap paramMap   = new WmauParameterMap(paramValues);
                IGPValue         jobIdGpVal = new GPLongClass();
                jobIdGpVal.SetAsText(job.ID.ToString());
                IGPParameterEdit3 jobIdParam = paramMap.GetParamEdit(C_PARAM_NEWJOBID);
                jobIdParam.Value = jobIdGpVal;
                msgs.AddMessage("Created job: " + job.ID.ToString() + " (" + job.Name + ")");

                msgs.AddMessage(Properties.Resources.MSG_DONE);
            }
            catch (WmauException wmEx)
            {
                try
                {
                    msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message);
                    if (job != null)
                    {
                        this.WmxDatabase.JobManager.DeleteJob(job.ID, true);
                    }
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
            catch (Exception ex)
            {
                try
                {
                    WmauError error = new WmauError(WmauErrorCodes.C_CREATE_JOB_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                    if (job != null)
                    {
                        this.WmxDatabase.JobManager.DeleteJob(job.ID, true);
                    }
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
        }
        /// <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);
                }

                // Indicate if changes are not actually being made
                string actionStr = "  Deleting";
                if (m_previewChanges)
                {
                    msgs.AddMessage("PREVIEWING CHANGES ONLY; no changes will be made");
                    actionStr = "  Found";
                }

                IJTXConfiguration3     configMgr  = WmxDatabase.ConfigurationManager as IJTXConfiguration3;
                IJTXConfigurationEdit2 configEdit = WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2;

                // Find all of the orphans in the database
                msgs.AddMessage("Searching for orphaned items...");
                int orphanCount = UpdateAllOrphans();
                msgs.AddMessage("Found " + orphanCount.ToString() + " total orphaned items");

                // If requested, delete any workflows first
                if (m_cleanWorkflows)
                {
                    List <int> unusedWorkflowIds = m_unusedWorkflows.Keys.ToList();
                    unusedWorkflowIds.Sort();
                    foreach (int id in unusedWorkflowIds)
                    {
                        msgs.AddMessage(actionStr + " workflow " + id.ToString() + " (" + m_unusedWorkflows[id] + ")");
                        if (!this.m_previewChanges)
                        {
                            configMgr.DeleteWorkflow(id);
                        }
                    }
                }

                // If requested, delete any step types
                if (m_cleanStepTypes)
                {
                    List <int> unusedStepTypeIds = m_unusedStepTypes.Keys.ToList();
                    unusedStepTypeIds.Sort();
                    foreach (int stepTypeId in unusedStepTypeIds)
                    {
                        msgs.AddMessage(actionStr + " step type " + stepTypeId.ToString() + " (" + m_unusedStepTypes[stepTypeId] + ")");
                        if (!this.m_previewChanges)
                        {
                            configEdit.DeleteStepType(stepTypeId);
                        }
                    }
                }

                // If requested, delete any status types
                if (m_cleanStatusTypes)
                {
                    List <int> unusedStatusTypeIds = m_unusedStatusTypes.Keys.ToList();
                    unusedStatusTypeIds.Sort();
                    foreach (int statusTypeId in unusedStatusTypeIds)
                    {
                        msgs.AddMessage(actionStr + " status type " + statusTypeId.ToString() + " (" + m_unusedStatusTypes[statusTypeId] + ")");
                        if (!this.m_previewChanges)
                        {
                            configEdit.DeleteStatus(statusTypeId);
                        }
                    }
                }

                // If requested, delete any priority types
                if (m_cleanPriorities)
                {
                    List <int> unusedPriorityTypeIds = m_unusedPriorities.Keys.ToList();
                    unusedPriorityTypeIds.Sort();
                    foreach (int priority in unusedPriorityTypeIds)
                    {
                        msgs.AddMessage(actionStr + " priority " + priority.ToString() + " (" + m_unusedPriorities[priority] + ")");
                        if (!m_previewChanges)
                        {
                            configEdit.DeletePriority(priority);
                        }
                    }
                }

                // If requested, delete any unused Task Assistant workbooks
                if (m_cleanTaWorkbooks)
                {
                    List <string> unusedTaWorkbookNames = m_unusedTaWorkbooks.Keys.ToList();
                    unusedTaWorkbookNames.Sort();
                    foreach (string workbookName in unusedTaWorkbookNames)
                    {
                        msgs.AddMessage(actionStr + " workbook " + workbookName);
                        if (!m_previewChanges)
                        {
                            configMgr.RemoveTaskAssistantWorkflowRecord(workbookName);
                        }
                    }
                }

                // If requested, delete any unused users
                if (m_cleanUsers)
                {
                    List <string> unusedUserNames = m_unusedUsers.Keys.ToList();
                    unusedUserNames.Sort();
                    foreach (string user in unusedUserNames)
                    {
                        msgs.AddMessage(actionStr + " user " + user + " (" + m_unusedUsers[user] + ")");
                        if (!m_previewChanges)
                        {
                            configEdit.DeleteUser(user);
                        }
                    }
                }

                // If requested, delete any unused map documents
                if (m_cleanMapDocs)
                {
                    List <string> unusedMapDocs = m_unusedMapDocs.Keys.ToList();
                    unusedMapDocs.Sort();
                    foreach (string mapName in unusedMapDocs)
                    {
                        msgs.AddMessage(actionStr + " map document " + mapName + " (" + m_unusedMapDocs[mapName].ToString() + ")");
                        if (!m_previewChanges)
                        {
                            configMgr.DeleteJTXMap(m_unusedMapDocs[mapName]);
                        }
                    }
                }

                // Set the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_NUM_ITEMS_DELETED);
                IGPLong           outValue     = new GPLongClass();
                outValue.Value     = orphanCount;
                outParamEdit.Value = outValue 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_UNSPECIFIED_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
        }
Exemplo n.º 17
0
        /// <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);
                }

                // Retrieve the TA workbook
                IJTXConfiguration3 defaultDbReadonly      = WmxDatabase.ConfigurationManager as IJTXConfiguration3;
                IJTXTaskAssistantWorkflowRecord tamRecord = defaultDbReadonly.GetTaskAssistantWorkflowRecord(this.m_targetName);
                string styleFileName = this.DetermineStyleFileName(this.m_xmlFilePath);

                // If we're not allowed to overwrite an existing TA record, then do some error checking
                if (!this.m_overwriteExisting && tamRecord != null)
                {
                    msgs.AddWarning("Did not overwrite Task Assistant workbook: " + this.m_targetName);
                    return;
                }
                else if (tamRecord != null)
                {
                    msgs.AddMessage("Replacing Task Assistant workbook '" + m_targetName + "' in database...");
                    defaultDbReadonly.ReplaceTaskAssistantWorkflowRecord(this.m_targetName, this.m_targetName, this.m_xmlFilePath, styleFileName);
                }
                else // tamRecord == null
                {
                    msgs.AddMessage("Adding Task Assistant workbook '" + m_targetName + "' to database...");
                    defaultDbReadonly.AddTaskAssistantWorkflowRecord(this.m_targetName, this.m_xmlFilePath, styleFileName);
                }

                // Update the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_TARGET_NAME);
                IGPString         outValue     = new GPStringClass();
                outValue.Value     = m_targetName;
                outParamEdit.Value = outValue 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_TAM_UPLOAD_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Pre validates the given set of values.
        /// This is where you populate derived parameters based on input, among other things.
        /// </summary>
        /// <param name="paramValues"></param>
        /// <param name="pEnvMgr"></param>
        public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr)
        {
            try
            {
                UpdateParametersCommon(paramValues, pEnvMgr);
            }
            catch (WmxDefaultDbNotSetException)
            {
                // If the default DB wasn't set, stop executing
                return;
            }
            catch (NullReferenceException)
            {
                // If one of the parameters was null, stop executing
                return;
            }

            // Get the parameters as a map for easier access
            WmauParameterMap  paramMap         = new WmauParameterMap(paramValues);
            IGPParameter3     jobId            = paramMap.GetParam(C_PARAM_JOB_ID);
            IGPParameterEdit3 jobIdEdit        = paramMap.GetParamEdit(C_PARAM_JOB_ID);
            IGPParameter3     assigneeType     = paramMap.GetParam(C_PARAM_ASSIGNEE_TYPE);
            IGPParameterEdit3 assigneeTypeEdit = paramMap.GetParamEdit(C_PARAM_ASSIGNEE_TYPE);
            IGPParameter3     assignee         = paramMap.GetParam(C_PARAM_ASSIGNEE);
            IGPParameterEdit  assigneeEdit     = paramMap.GetParamEdit(C_PARAM_ASSIGNEE);

            // Set the domains for any parameters that need them

            // Set the job ID domain if it hasn't already been populated
            if (jobId.Domain == null)
            {
                jobIdEdit.Domain = Common.WmauGpDomainBuilder.BuildNonClosedJobIdDomain(this.WmxDatabase);
            }

            // If the assignee type has changed, update the domain for the assignee
            // parameter
            //
            // NOTE: Updating the assignee value can cause things to get confused,
            // particularly when background geoprocessing is enabled.  So rather than
            // do this, let the assignee parameter value conflict with the domain
            // for that parameter, if need be.
            if (!assigneeType.Value.GetAsText().Equals(m_assigneeType) || assignee.Domain == null)
            {
                m_assigneeType = assigneeType.Value.GetAsText();
                //assignee.Value.Empty();

                if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_GROUP))
                {
                    assigneeEdit.Domain = Common.WmauGpDomainBuilder.BuildAssignableGroupsDomain(this.WmxDatabase);
                }
                else if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_USER))
                {
                    assigneeEdit.Domain = Common.WmauGpDomainBuilder.BuildAssignableUsersDomain(this.WmxDatabase);
                }
                else if (m_assigneeType.Equals(C_OPT_UNASSIGNED))
                {
                    assigneeEdit.Domain = null;
                    //assignee.Value.SetAsText(C_OPT_VAL_UNASSIGNED);
                }
            }

            // After the domains have been set, check to see if any parameters should be
            // enabled/disabled based on the contents of these domains.
            assigneeEdit.Enabled = !m_assigneeType.Equals(C_OPT_UNASSIGNED);
        }
        /// <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);

            // Set the default properties for the specified job type
            try
            {
                IJTXConfiguration3     configMgr  = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3;
                IJTXConfigurationEdit2 configEdit = this.WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2;
                IJTXJobTypeEdit3       jobType    = configEdit.GetJobType(m_jobTypeName) as IJTXJobTypeEdit3;

                // Set the default data workspace for the selected job type
                if (m_dataWorkspaceName.Equals(C_OPT_NONE))
                {
                    jobType.DefaultDataWorkspace = null;
                    msgs.AddMessage("Clearing default data workspace for job type '" + m_jobTypeName + "'");
                }
                else
                {
                    // Translate the workspace name to a DB name object
                    IJTXDataWorkspaceName dwName =
                        Common.WmauHelperFunctions.LookupWorkspaceNameObj(this.WmxDatabase, m_dataWorkspaceName);

                    msgs.AddMessage("Default data workspace for job type '" + m_jobTypeName + "' is now '" + dwName.Name + "'");
                    jobType.DefaultDataWorkspace = dwName;
                }

                // Set the default parent version for the selected job type
                if (m_parentVersion.Equals(C_OPT_NONE))
                {
                    msgs.AddMessage("Clearing default parent version for job type '" + m_jobTypeName + "'");
                    jobType.DefaultParentVersionName_2 = string.Empty;
                }
                else
                {
                    msgs.AddMessage("Default parent version for job type '" + m_jobTypeName + "' is now '" + m_parentVersion + "'");
                    jobType.DefaultParentVersionName_2 = m_parentVersion;
                }

                // Save the changes to the job type
                jobType.Store();

                // Set the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_DATA_WORKSPACE);
                IGPString         outValue     = new GPStringClass();
                outValue.Value     = m_jobTypeName;
                outParamEdit.Value = outValue 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)
            {
                WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR);
                msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
            }
        }
Exemplo n.º 20
0
        /// <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);

            // Assign the requested job
            try
            {
                IJTXJobManager     jobManager = this.WmxDatabase.JobManager;
                IJTXJob3           job        = jobManager.GetJob(m_jobId) as IJTXJob3;
                IJTXConfiguration3 configMgr  = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3;

                jtxAssignmentType assigneeType;
                string            descriptionStr;
                string            assigneeStr;
                if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_GROUP))
                {
                    assigneeType   = jtxAssignmentType.jtxAssignmentTypeGroup;
                    assigneeStr    = m_assignee;
                    descriptionStr = "group '" + assigneeStr + "'";
                }
                else if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_USER))
                {
                    assigneeType   = jtxAssignmentType.jtxAssignmentTypeUser;
                    assigneeStr    = m_assignee;
                    descriptionStr = "user '" + assigneeStr + "'";
                }
                else
                {
                    assigneeType   = jtxAssignmentType.jtxAssignmentTypeUnassigned;
                    assigneeStr    = string.Empty;
                    descriptionStr = "no one (unassigned)";
                }

                msgs.AddMessage("Assigning job " + m_jobId + " (" + job.Name + ") to " + descriptionStr);
                job.AssignedType = assigneeType;
                job.AssignedTo   = assigneeStr;
                job.Store();

                // Do the other things that still need to be handled manually, such as logging
                // the job's reassignment and sending any necessary notifications.
                job.LogJobAction(
                    configMgr.GetActivityType(ESRI.ArcGIS.JTX.Utilities.Constants.ACTTYPE_ASSIGN_JOB),
                    null,
                    string.Empty);
                Common.WmauHelperFunctions.SendNotification(
                    ESRI.ArcGIS.JTX.Utilities.Constants.NOTIF_JOB_ASSIGNED,
                    this.WmxDatabase,
                    job);

                // Set the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_JOB_ID);
                IGPLong           outValue     = new GPLongClass();
                outValue.Value     = m_jobId;
                outParamEdit.Value = outValue 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)
            {
                WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR);
                msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
            }
        }
        /// <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);
                }

                IJTXConfiguration3 configMgr = WmxDatabase.ConfigurationManager as IJTXConfiguration3;
                IJTXMapEdit        wmxMapDoc = configMgr.GetJTXMap(this.m_targetName) as IJTXMapEdit;

                // If we're not allowed to overwrite an existing map document, then do some error checking
                if (!this.m_overwriteExisting && wmxMapDoc != null)
                {
                    msgs.AddWarning("Did not overwrite Map Document: " + this.m_targetName);
                    return;
                }
                else if (wmxMapDoc != null)
                {
                    msgs.AddMessage("Replacing Map Document '" + this.m_targetName + "' in database...");
                }
                else // wmxMapDoc == null
                {
                    msgs.AddMessage("Adding Map Document '" + this.m_targetName + "' to database...");
                    wmxMapDoc = configMgr.CreateJTXMap() as IJTXMapEdit;
                }

                IMapDocument mapDoc = new MapDocumentClass() as IMapDocument;
                mapDoc.Open(this.m_mxdFilePath, string.Empty);
                wmxMapDoc.Name = this.m_targetName;
                if (!string.IsNullOrEmpty(this.m_targetCategory))
                {
                    wmxMapDoc.Category = this.m_targetCategory;
                }
                if (!string.IsNullOrEmpty(this.m_description))
                {
                    wmxMapDoc.Description = this.m_description;
                }
                wmxMapDoc.Directory   = string.Empty;
                wmxMapDoc.FileName    = string.Empty;
                wmxMapDoc.MapDocument = mapDoc;
                wmxMapDoc.Store();
                mapDoc.Close();

                // Update the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_TARGET_NAME);
                IGPString         outValue     = new GPStringClass();
                outValue.Value     = m_targetName;
                outParamEdit.Value = outValue 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_MXD_UPLOAD_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
        }
Exemplo n.º 22
0
        /// <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);

            // Assign the requested job
            try
            {
                IJTXJobManager     jobManager = this.WmxDatabase.JobManager;
                IJTXJob3           job        = jobManager.GetJob(m_jobId) as IJTXJob3;
                IJTXConfiguration3 configMgr  = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3;

                // As of Jan. 2011, the core Workflow Manager libraries do not
                // seem to check if the user has the privilege to add an attachment
                // if a job as a hold on it.  So run the check here.
                IJTXJobHolds jobHolds = job as IJTXJobHolds;
                if (jobHolds.Holds != null &&
                    jobHolds.Holds.Count > 0 &&
                    !CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_CAN_ADD_ATTACHES_FOR_HELD_JOBS))
                {
                    throw new WmauException(WmauErrorCodes.C_NO_ADD_ATTACHMENTS_HELD_JOBS_ERROR);
                }

                // If we get this far, then figure out how to associate the attachment
                // with the job, and add the attachment.
                jtxFileStorageType attachmentType;
                if (m_attachmentType.Equals(C_OPT_EMBEDDED))
                {
                    attachmentType = jtxFileStorageType.jtxStoreInDB;
                }
                else
                {
                    attachmentType = jtxFileStorageType.jtxStoreAsLink;
                }

                msgs.AddMessage("Adding attachment '" + m_attachmentPath + "' to job " + m_jobId + " (" + job.Name + ")");
                job.AddAttachment(m_attachmentPath, attachmentType, m_attachmentType);
                job.Store();

                // Do the other things that still need to be handled manually, such as logging
                // the job's reassignment and sending any necessary notifications.
                IPropertySet propSet = new PropertySetClass();
                propSet.SetProperty(C_PROP_VAL_ATTACHMENT, "'" + m_attachmentPath + "'");
                job.LogJobAction(
                    configMgr.GetActivityType(ESRI.ArcGIS.JTX.Utilities.Constants.ACTTYPE_ADD_ATTACHMENT),
                    propSet,
                    string.Empty);
                Common.WmauHelperFunctions.SendNotification(
                    ESRI.ArcGIS.JTX.Utilities.Constants.NOTIF_ATTACHMENT_ADDED,
                    this.WmxDatabase,
                    job);

                // Set the output parameter
                WmauParameterMap  paramMap     = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_JOB_ID);
                IGPLong           outValue     = new GPLongClass();
                outValue.Value     = m_jobId;
                outParamEdit.Value = outValue 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)
            {
                WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR);
                msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
            }
        }
        /// <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);
                }

                IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3;

                // Prep to retrieve the users in the specified groups (if any were specified)
                string[] userNames = null;
                if (!string.IsNullOrEmpty(m_groupName))
                {
                    msgs.AddMessage("Users in group '" + m_groupName + "':");
                    string[] groupNameArray = new string[] { m_groupName };
                    userNames = configMgr.GetUserNamesForGroups(groupNameArray);
                }
                else
                {
                    msgs.AddMessage("All users:");
                    userNames = new string[configMgr.Users.Count];
                    for (int i = 0; i < configMgr.Users.Count; i++)
                    {
                        userNames[i] = configMgr.Users.get_Item(i).UserName;
                    }
                }

                // Sort the user list
                SortedList <string, string> sortedNames = new SortedList <string, string>();
                foreach (string s in userNames)
                {
                    sortedNames.Add(s, null);
                }

                // Retrieve the parameter in which the list of user names will be stored
                WmauParameterMap  paramMap  = new WmauParameterMap(paramValues);
                IGPParameter3     param     = paramMap.GetParam(C_PARAM_USER_LIST);
                IGPParameterEdit3 paramEdit = paramMap.GetParamEdit(C_PARAM_USER_LIST);

                // Set up the multi-value objects
                IGPMultiValue mvValue = new GPMultiValueClass();
                mvValue.MemberDataType = param.DataType;

                // Add the user list to the multivalue param
                foreach (string user in sortedNames.Keys)
                {
                    msgs.AddMessage("  " + user);
                    IGPString strVal = new GPStringClass();
                    strVal.Value = user;
                    mvValue.AddValue(strVal as IGPValue);
                }
                paramEdit.Value = (IGPValue)mvValue;

                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_UNSPECIFIED_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
            finally
            {
                // Release any COM objects here!
            }
        }