Esempio n. 1
0
        /// <summary>
        /// Builds a domain consisting of the IDs of every job in the database that
        /// has not already been closed.
        /// </summary>
        /// <param name="wmxDb">A reference to the active Workflow Manager database</param>
        /// <returns>A coded value domain as an IGPDomain</returns>
        public static IGPDomain BuildNonClosedJobIdDomain(IJTXDatabase3 wmxDb)
        {
            IGPCodedValueDomain domain = new GPCodedValueDomainClass();

            // Set up a query filter to return only those jobs that are not closed
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.WhereClause =
                ESRI.ArcGIS.JTX.Utilities.Constants.FIELD_STAGE + " <> '" +
                ((int)jtxJobStage.jtxJobStageClosed).ToString() + "'";

            IJTXJobSet nonClosedJobs = wmxDb.JobManager.GetJobsByQuery(queryFilter);

            // Iterate through this job list, sorting the IDs
            SortedList <int, string> sortedJobIds = new SortedList <int, string>();

            for (int i = 0; i < nonClosedJobs.Count; i++)
            {
                IJTXJob3 job = nonClosedJobs.get_Item(i) as IJTXJob3;
                sortedJobIds[job.ID] = null;
            }

            // Build a GP domain from the sorted job IDs.
            foreach (int id in sortedJobIds.Keys)
            {
                IGPValue tempGpVal = new GPLongClass();
                tempGpVal.SetAsText(id.ToString());
                domain.AddCode(tempGpVal, id.ToString());
            }

            return(domain as IGPDomain);
        }
Esempio n. 2
0
        /// <summary>
        /// Builds a domain consisting of the IDs for every job in the database.
        /// </summary>
        /// <param name="wmxDb">A reference to the active Workflow Manager database</param>
        /// <returns>A coded value domain as an IGPDomain</returns>
        public static IGPDomain BuildJobIdDomain(IJTXDatabase3 wmxDb)
        {
            IGPCodedValueDomain domain = new GPCodedValueDomainClass();

            int[] allJobs = wmxDb.JobManager.GetAllJobIDs();
            System.Array.Sort(allJobs);
            foreach (int job in allJobs)
            {
                IGPValue tempGpVal = new GPLongClass();
                tempGpVal.SetAsText(job.ToString());
                domain.AddCode(tempGpVal, job.ToString());
            }

            return(domain as IGPDomain);
        }
Esempio 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)
        {
            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
                }
            }
        }