////////////////////////////////////////////////////////////////////////
        // METHOD: CreateJobs
        private int CreateJobs(IJTXJob2 pParentJob)
        {
            try
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                bool bAutoCommit = ConfigurationCache.AutoCommitWorkflow;

                m_ipDatabase.LogMessage(5, 2000, "CreateJobs");

                // Set the job template values
                IJTXJobManager2    pJobMan         = m_ipDatabase.JobManager as IJTXJobManager2;
                IJTXJobDescription pJobDescription = new JTXJobDescriptionClass();

                pJobDescription.Description = pParentJob.Description;
                pJobDescription.Priority    = pParentJob.Priority;
                pJobDescription.ParentJobId = pParentJob.ID;

                pJobDescription.StartDate = pParentJob.StartDate;

                if (m_dueDate != Constants.NullDate)
                {
                    pJobDescription.DueDate = m_dueDate;
                }
                else if (m_duration > 0)
                {
                    pJobDescription.DueDate = System.DateTime.Now.AddDays(m_duration);
                }
                else
                {
                    pJobDescription.DueDate = pParentJob.DueDate;
                }

                if (!String.IsNullOrEmpty(m_paramAssignToGroup))
                {
                    pJobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeGroup;
                    pJobDescription.AssignedTo   = m_paramAssignToGroup;
                }
                else if (!String.IsNullOrEmpty(m_paramAssignToUser))
                {
                    pJobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeUser;
                    pJobDescription.AssignedTo   = m_paramAssignToUser;
                }
                else
                {
                    pJobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeUnassigned;
                }

                pJobDescription.OwnedBy = ConfigurationCache.GetCurrentJTXUser().UserName;

                if (pParentJob.ActiveDatabase != null)
                {
                    pJobDescription.DataWorkspaceID = pParentJob.ActiveDatabase.DatabaseID;
                }

                // Set the parent version.  This only makes sense if the active workspace has been set
                if (pJobDescription.DataWorkspaceID != null)
                {
                    if (m_paramCreateVersionType == CreateVersionType.None ||
                        m_paramCreateVersionType == CreateVersionType.UseParentJobsVersion)
                    {
                        pJobDescription.ParentVersionName = pParentJob.VersionName;     // This has to be set here because setting the job workspace resets the value
                    }
                    else if (m_paramCreateVersionType == CreateVersionType.UseJobTypeDefaultSettings)
                    {
                        IJTXJobType pJobType = m_ipDatabase.ConfigurationManager.GetJobType(m_paramJobTypeName);
                        if (pJobType != null)
                        {
                            pJobDescription.ParentVersionName = pJobType.DefaultParentVersionName;
                        }
                    }
                    else if (m_paramCreateVersionType == CreateVersionType.UseParentJobsDefaultVersion)
                    {
                        pJobDescription.ParentVersionName = pParentJob.JobType.DefaultParentVersionName;
                    }
                    else if (m_paramCreateVersionType == CreateVersionType.UseParentJobsParentVersion)
                    {
                        pJobDescription.ParentVersionName = pParentJob.ParentVersion;
                    }
                }

                // Determine the number of jobs to make
                m_ipDatabase.LogMessage(5, 2000, "Before Determining Number of Jobs");

                IArray aoiList = null;
                int    numJobs;
                if (!GetNumberOfJobs(pParentJob, ref aoiList, out numJobs))
                {
                    return(1);
                }

                if (numJobs <= 0)
                {
                    MessageBox.Show(Properties.Resources.ZeroJobCount);
                    return(0);
                }
                pJobDescription.AOIList = aoiList;
                m_ipDatabase.LogMessage(5, 2000, "After Determining Number of Jobs");


                // Create the job objects
                m_ipDatabase.LogMessage(5, 2000, "Before CreateJobs");
                pJobDescription.JobTypeName = m_paramJobTypeName;
                IJTXExecuteInfo pExecInfo;
                m_ipJobs = pJobMan.CreateJobsFromDescription(pJobDescription, numJobs, true, out pExecInfo);
                m_ipDatabase.LogMessage(5, 2000, "After CreateJobs");


                // Populate the job data
                for (int i = 0; i < m_ipJobs.Count; ++i)
                {
                    IJTXJob pJob = m_ipJobs.get_Item(i);

                    SetJobProperties(pJobMan, pJob, pParentJob);
                }
                return(1);
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode == (int)fdoError.FDO_E_SE_INVALID_COLUMN_VALUE)
                {
                    MessageBox.Show(Properties.Resources.InvalidColumn, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
                return(0);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
            }
        }
Ejemplo n.º 2
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);

            string strValue  = "";
            int    jobTypeID = 0;

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

            if (!Int32.TryParse(strValue, out jobTypeID))
            {
                throw new ArgumentNullException(m_expectedArgs[0], "Argument must be an integrer!");
            }

            IJTXJobType    pJobType = m_ipDatabase.ConfigurationManager.GetJobTypeByID(jobTypeID);
            IJTXJobManager pJobMan  = m_ipDatabase.JobManager;
            IJTXJob        pNewJob  = pJobMan.CreateJob(pJobType, 0, true);

            IJTXActivityType pActType = m_ipDatabase.ConfigurationManager.GetActivityType(Constants.ACTTYPE_CREATE_JOB);

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

            JTXUtilities.SendNotification(Constants.NOTIF_JOB_CREATED, m_ipDatabase, pNewJob, null);

            // Assign a status to the job if the Auto Assign Job Status setting is enabled
            IJTXConfigurationProperties pConfigProps = (IJTXConfigurationProperties)m_ipDatabase.ConfigurationManager;

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

            // Associate the current job with the new job with a parent-child relationship
            pNewJob.ParentJob = JobID;

            // Assign the job as specified in the arguments
            string strAssignTo = "";

            if (StepUtilities.GetArgument(ref argv, m_expectedArgs[1], true, out strAssignTo))
            {
                pNewJob.AssignedType = jtxAssignmentType.jtxAssignmentTypeGroup;
                pNewJob.AssignedTo   = strAssignTo;
            }
            else if (StepUtilities.GetArgument(ref argv, m_expectedArgs[2], true, out strAssignTo))
            {
                pNewJob.AssignedType = jtxAssignmentType.jtxAssignmentTypeUser;
                pNewJob.AssignedTo   = strAssignTo;
            }
            pNewJob.Store();

            // Copy the workflow to the new job
            WorkflowUtilities.CopyWorkflowXML(m_ipDatabase, pNewJob);

            // Create 1-1 extended property entries
            IJTXAuxProperties pAuxProps = (IJTXAuxProperties)pNewJob;

            System.Array contNames     = pAuxProps.ContainerNames;
            IEnumerator  contNamesEnum = contNames.GetEnumerator();

            contNamesEnum.Reset();

            while (contNamesEnum.MoveNext())
            {
                string strContainerName = (string)contNamesEnum.Current;
                IJTXAuxRecordContainer pAuxContainer = pAuxProps.GetRecordContainer(strContainerName);
                if (pAuxContainer.RelationshipType == esriRelCardinality.esriRelCardinalityOneToOne)
                {
                    pAuxContainer.CreateRecord();
                }
            }

            m_ipDatabase.LogMessage(5, 1000, System.Diagnostics.Process.GetCurrentProcess().MainWindowTitle);

            // Update Application message about the new job
            if (System.Diagnostics.Process.GetCurrentProcess().MainWindowTitle.Length > 0) //if its not running in server
            {
                MessageBox.Show("Created " + pJobType.Name + " Job " + pNewJob.ID, "Job Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return(0);
        }