/// <summary>
        /// Method to validate the configured arguments for the step type.  The
        /// logic of this method depends on the implementation of the custom step
        /// but typically checks for proper argument names and syntax.
        /// </summary>
        /// <param name="argv">Array of arguments configured for the step type</param>
        /// <returns>Returns 'true' if arguments are valid, 'false' if otherwise</returns>
        public bool ValidateArguments(ref object[] argv)
        {
            IJTXDatabase pJTXDB = m_ipDatabase;

            // Get the arguments
            string sHoldTypeName = "";
            string sHoldRemarks  = "";

            bool bHoldType = StepUtilities.GetArgument(ref argv, "HoldType", true, out sHoldTypeName);

            if (!bHoldType)
            {
                MessageBox.Show("Invalid arguments entered. No hold type entered.");
                return(false);
            }
            bool bHoldRemarks = StepUtilities.GetArgument(ref argv, "HoldRemarks", true, out sHoldRemarks);

            // Get the hold type
            IJTXConfiguration pJTXConfig = pJTXDB.ConfigurationManager;
            IJTXHoldType      pHoldType  = pJTXConfig.GetHoldType(sHoldTypeName);

            if (pHoldType == null)
            {
                MessageBox.Show("Invalid hold type name entered: " + sHoldTypeName);
                return(false);
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Method to validate the configured arguments for the step type.  The
        /// logic of this method depends on the implementation of the custom step
        /// but typically checks for proper argument names and syntax.
        /// </summary>
        /// <param name="argv">Array of arguments configured for the step type</param>
        /// <returns>Returns 'true' if arguments are valid, 'false' if otherwise</returns>
        public bool ValidateArguments(ref object[] argv)
        {
            IJTXConfiguration ipConfig = m_ipDatabase.ConfigurationManager;

            string strAssignType = "";
            string strAssignTo   = "";

            if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strAssignType))
            {
                throw new ArgumentNullException(m_expectedArgs[0], string.Format("\nMissing the {0} parameter!", m_expectedArgs[0]));
            }

            if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[1], true, out strAssignTo))
            {
                throw new ArgumentNullException(m_expectedArgs[1], string.Format("\nMissing the {0} parameter!", m_expectedArgs[1]));
            }

            if (strAssignType == "group")
            {
                if (ipConfig.GetUserGroup(strAssignTo) == null)
                {
                    throw new ArgumentOutOfRangeException(m_expectedArgs[1], string.Format("\nThe group {0} is not a group defined in the JTX database!", strAssignTo));
                }
            }
            else
            {
                if (ipConfig.GetUser(strAssignTo) == null)
                {
                    throw new ArgumentOutOfRangeException(m_expectedArgs[1], string.Format("\nThe user {0} is not a user defined in the JTX database!", strAssignTo));
                }
            }
            return(true);
        }
Example #3
0
        /// <summary>
        /// Called when a step of this type is executed in the workflow.
        /// </summary>
        /// <param name="JobID">ID of the job being executed</param>
        /// <param name="StepID">ID of the step being executed</param>
        /// <param name="argv">Array of arguments passed into the step's execution</param>
        /// <param name="ipFeedback">Feedback object to return status messages and files</param>
        /// <returns>Return code of execution for workflow path traversal</returns>
        public int Execute(int JobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback)
        {
            System.Diagnostics.Debug.Assert(m_ipDatabase != null);

            IJTXJob pJob = m_ipDatabase.JobManager.GetJob(JobID);

            //Automatic status assignment
            IJTXConfiguration           pConfig      = m_ipDatabase.ConfigurationManager;
            IJTXConfigurationProperties pConfigProps = (IJTXConfigurationProperties)pConfig;

            IJTXWorkflowConfiguration pWFConfig = (IJTXWorkflowConfiguration)pJob;
            IJTXWorkflowExecution     pWFExec   = (IJTXWorkflowExecution)pJob;

            int[] iSteps = pWFExec.GetCurrentSteps();
            if (iSteps.Length == 1)
            {
                if (pWFExec.IsLastStep(iSteps[0]))
                {
                    pWFExec.MoveNext(iSteps[0], (int)nullReturnType.null_return);
                }
            }

            pJob.Close();
            pJob.EndDate = System.DateTime.Now;

            if (pConfigProps.PropertyExists(Constants.JTX_PROPERTY_AUTO_STATUS_ASSIGN))
            {
                string strAutoAssign = pConfigProps.GetProperty(Constants.JTX_PROPERTY_AUTO_STATUS_ASSIGN);
                if (strAutoAssign == "TRUE")
                {
                    pJob.Status = m_ipDatabase.ConfigurationManager.GetStatus("Closed");
                }
            }

            pJob.Store();

            IJTXActivityType pActType = pConfig.GetActivityType("CloseJob");

            if (pActType != null)
            {
                pJob.LogJobAction(pActType, null, "");
            }

            JTXUtilities.SendNotification(Constants.NOTIF_JOB_CLOSED, m_ipDatabase, pJob, null);

            return(0);
        }
Example #4
0
        /// <summary>
        /// Called when a step of this type is executed in the workflow.
        /// </summary>
        /// <param name="JobID">ID of the job being executed</param>
        /// <param name="StepID">ID of the step being executed</param>
        /// <param name="argv">Array of arguments passed into the step's execution</param>
        /// <param name="ipFeedback">Feedback object to return status messages and files</param>
        /// <returns>Return code of execution for workflow path traversal</returns>
        public int Execute(int jobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback)
        {
            IJTXJobManager    ipJobManager = m_ipDatabase.JobManager;
            IJTXConfiguration ipConfig     = m_ipDatabase.ConfigurationManager;
            IJTXJob           ipJob        = ipJobManager.GetJob(jobID);

            string strAssignType = "";
            string strAssignTo   = "";

            if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strAssignType))
            {
                throw new ArgumentNullException(m_expectedArgs[0], string.Format("\nMissing the {0} parameter!", m_expectedArgs[0]));
            }

            if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[1], true, out strAssignTo))
            {
                throw new ArgumentNullException(m_expectedArgs[1], string.Format("\nMissing the {0} parameter!", m_expectedArgs[1]));
            }

            if (strAssignType == "group")
            {
                if (ipConfig.GetUserGroup(strAssignTo) == null)
                {
                    throw new ArgumentOutOfRangeException(m_expectedArgs[1], string.Format("\nThe group {0} is not a group defined in the JTX database!", strAssignTo));
                }

                ipJob.AssignedType = jtxAssignmentType.jtxAssignmentTypeGroup;
            }
            else
            {
                if (ipConfig.GetUser(strAssignTo) == null)
                {
                    throw new ArgumentOutOfRangeException(m_expectedArgs[1], string.Format("\nThe user {0} is not a user defined in the JTX database!", strAssignTo));
                }

                ipJob.AssignedType = jtxAssignmentType.jtxAssignmentTypeUser;
            }

            ipJob.AssignedTo = strAssignTo;
            ipJob.Store();

            return(0);
        }
        /// <summary>
        /// Called when a step of this type is executed in the workflow.
        /// </summary>
        /// <param name="JobID">ID of the job being executed</param>
        /// <param name="StepID">ID of the step being executed</param>
        /// <param name="argv">Array of arguments passed into the step's execution</param>
        /// <param name="ipFeedback">Feedback object to return status messages and files</param>
        /// <returns>Return code of execution for workflow path traversal</returns>
        public int Execute(int jobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback)
        {
            // Get the arguments
            string sHoldTypeName = "";
            string sHoldRemarks  = "";

            bool bHoldType = StepUtilities.GetArgument(ref argv, "HoldType", true, out sHoldTypeName);

            if (!bHoldType)
            {
                MessageBox.Show("Invalid arguments entered. No hold type entered.");
                return(-1);
            }
            bool bHoldRemarks = StepUtilities.GetArgument(ref argv, "HoldRemarks", true, out sHoldRemarks);

            // Get the hold type
            IJTXConfiguration pJTXConfig = m_ipDatabase.ConfigurationManager;
            IJTXHoldType      pHoldType  = pJTXConfig.GetHoldType(sHoldTypeName);

            if (pHoldType == null)
            {
                MessageBox.Show("Invalid hold type name entered: " + sHoldTypeName);
                return(-1);
            }

            // Get the job
            IJTXJobManager pJobManager = m_ipDatabase.JobManager;
            IJTXJob        pJob        = pJobManager.GetJob(jobID);
            IJTXJobHolds   pJobHolds   = pJob as IJTXJobHolds;

            // Add new job hold
            IJTXJobHold pNewHold = pJobHolds.CreateHold(pHoldType);

            if (bHoldRemarks)
            {
                pNewHold.HoldComments = sHoldRemarks;
                pNewHold.Store();
            }

            return(0);
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cmbJobTypes.SelectedItem.ToString() != "")
            {
                IJTXConfiguration ipJTXConfig = m_ipDatabase.ConfigurationManager;
                IJTXJobType       ipJobType   = ipJTXConfig.GetJobType(cmbJobTypes.SelectedItem.ToString());
                m_Arguments.Add(StepUtilities.CreateSingleArgument(m_expectedArgs[0], ipJobType.ID.ToString()));
            }

            if (chkGroup.Checked)
            {
                m_Arguments.Add(StepUtilities.CreateSingleArgument(m_expectedArgs[1], cmbGroups.SelectedItem.ToString()));
            }
            else if (chkUser.Checked)
            {
                m_Arguments.Add(StepUtilities.CreateSingleArgument(m_expectedArgs[2], cmbUsers.SelectedItem.ToString()));
            }

            DialogResult = DialogResult.OK;
            this.Hide();
        }
        public void OnClick()
        {
            // Confirm the user wants to do this
            DialogResult result = MessageBox.Show("Are you sure you want to clear the AOI from the selected jobs?", "Clear AOI", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                // Get the job set from the list of jobs
                IJTXJobViewPanel pJobViewPanel = ((IJTXJobViewPanel)m_pApplication.CurrentView.ViewPanel);
                List <IJTXJob>   pSelectedJobs = pJobViewPanel.SelectedJobs;
                foreach (IJTXJob pJob in pSelectedJobs)
                {
                    pJob.AOIExtent = null;
                    pJob.Store();

                    // Update the activity log and send notifications
                    IJTXConfiguration pConfig  = m_pApplication.CurrentDatabase.ConfigurationManager;
                    IJTXActivityType  pActType = pConfig.GetActivityType(Constants.ACTTYPE_UPDATE_AOI);
                    if (pActType != null)
                    {
                        pJob.LogJobAction(pActType, null, "");
                    }
                    JTXUtilities.SendNotification(Constants.NOTIF_AOI_UPDATED, m_pApplication.CurrentDatabase, pJob, null);
                }

                // If only 1 job is selected, refresh the panels
                if (pSelectedJobs.Count == 1)
                {
                    foreach (IJTXJobPanel ipJobPanel in pJobViewPanel.JobPanels)
                    {
                        ipJobPanel.RefreshJob();
                    }
                }

                MessageBox.Show("Cleared the AOI from selected jobs");
            }
        }
Example #8
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
                }
            }
        }
        static void Main(string[] args)
        {
            JTXOverdueNotification prog = new JTXOverdueNotification();

            if (prog.CheckoutLicense())
            {
                try
                {
                    // Arguments list
                    // /NotifType:<Notification type to send>
                    // example: JTXOverdueNotification.exe /NotifType:OverdueJob

                    object[] pArgObjects = args as object[];

                    // Get some variables ready
                    string sNotificationTypeName = "";

                    StepUtilities.GetArgument(ref pArgObjects, "NotifType", true, out sNotificationTypeName);
                    if (sNotificationTypeName == "")
                    {
                        Console.WriteLine("A notification type must be entered.");
                        return;
                    }

                    IJTXDatabaseManager jtxDBMan   = new JTXDatabaseManagerClass();
                    IJTXDatabase        pJTXDB     = jtxDBMan.GetActiveDatabase(false);
                    IJTXConfiguration   pJTXConfig = pJTXDB.ConfigurationManager;

                    // Create a simple query to find jobs that were due before today
                    IQueryFilter pQF = new QueryFilterClass();

                    // NOTE #1: Verify the date format matches your selected RDBMS
                    // NOTE #2: Verify the status id for 'Closed' with the JTX Administrator
                    pQF.WhereClause = "DUE_DATE < '" + DateTime.Today.ToString() + "'" + " AND STATUS <> 9";
                    Console.WriteLine(pQF.WhereClause);

                    // Get the notification type for the notification that will be sent
                    IJTXNotificationConfiguration pNotificationConfig = pJTXConfig as IJTXNotificationConfiguration;
                    IJTXNotificationType          pNotificationType   = pNotificationConfig.GetNotificationType(sNotificationTypeName);
                    if (pNotificationType == null)
                    {
                        Console.WriteLine("Please enter a valid notification type.");
                        return;
                    }

                    // Get the job manager to execute the query and find the jobs in question
                    IJTXJobManager pJobManager = pJTXDB.JobManager;
                    IJTXJobSet     pJobs       = pJobManager.GetJobsByQuery(pQF);

                    pJobs.Reset();
                    for (int a = 0; a < pJobs.Count; a++)
                    {
                        IJTXJob pJob = pJobs.Next();
                        Console.WriteLine(pJob.Name);

                        // Send it!
                        JTXUtilities.SendNotification(sNotificationTypeName, pJTXDB, pJob, null);
                    }
                }
                catch (Exception except)
                {
                    Console.WriteLine("An error occurred: " + except.Message);
                }
                prog.CheckinLicense();
                Console.WriteLine("Completed.");
            }
        }