Ejemplo n.º 1
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);
        }
        /// <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>
        /// Find those map documents embedded in the database that are not being
        /// referenced in any way
        /// </summary>
        /// <returns>The total number of orphaned items found</returns>
        private int UpdateOrphanedMapDocuments()
        {
            SortedList <string, int> unusedItems = new SortedList <string, int>();
            IJTXDatabase3            wmxDb       = this.WmxDatabase;
            IJTXConfiguration3       configMgr   = wmxDb.ConfigurationManager as IJTXConfiguration3;
            IJTXConfigurationEdit2   configEdit  = wmxDb.ConfigurationManager as IJTXConfigurationEdit2;

            IJTXMapSet allMaps = configMgr.JTXMaps;
            Dictionary <string, int> allMapNames = new Dictionary <string, int>();

            for (int i = 0; i < allMaps.Count; i++)
            {
                IJTXMap map = allMaps.get_Item(i);
                allMapNames[map.Name] = map.ID;
            }

            Dictionary <string, int> usedItems = new Dictionary <string, int>();

            // Find the map types that are associated with job types
            IJTXJobTypeSet allJobTypes = configMgr.JobTypes;

            for (int i = 0; i < allJobTypes.Count; i++)
            {
                // TODO: Skip orphaned job types

                IJTXJobType3 jobType = allJobTypes.get_Item(i) as IJTXJobType3;
                if (jobType.AOIMap != null)
                {
                    usedItems[jobType.AOIMap.Name] = jobType.AOIMap.ID;
                }
                if (jobType.JobMap != null)
                {
                    usedItems[jobType.JobMap.Name] = jobType.JobMap.ID;
                }
            }

            // If necessary, find the map types launched by custom steps.  Look for
            // the "/mxd:" argument as an identifier.
            IJTXStepTypeSet allStepTypes = wmxDb.ConfigurationManager.StepTypes;

            for (int i = 0; i < allStepTypes.Count; i++)
            {
                IJTXStepType2 stepType = allStepTypes.get_Item(i) as IJTXStepType2;

                // Skip orphaned step types
                if (m_unusedStepTypes.Keys.Contains(stepType.ID))
                {
                    continue;
                }

                for (int j = 0; j < stepType.Arguments.Length; j++)
                {
                    string stepArg = stepType.Arguments[j].ToString();
                    if (stepArg.StartsWith(C_MAP_DOC_FLAG))
                    {
                        string suffix = stepArg.Substring(C_MAP_DOC_FLAG.Length);
                        suffix = suffix.Trim(new char[] { '"' });
                        if (allMapNames.Keys.Contains(suffix))
                        {
                            usedItems[suffix] = allMapNames[suffix];
                        }
                    }
                }
            }

            // Add in the map document that's used as the template map document
            // (if one exists)
            IJTXConfigurationProperties configProps = this.WmxDatabase.ConfigurationManager as IJTXConfigurationProperties;
            string mapIdStr = configProps.GetProperty(Constants.JTX_PROPERTY_MAPVIEW_MAP_GUID);

            if (mapIdStr != null && !mapIdStr.Equals(string.Empty))
            {
                for (int i = 0; i < allMaps.Count; i++)
                {
                    IJTXMap        tempMap   = allMaps.get_Item(i);
                    IJTXIdentifier tempMapId = tempMap as IJTXIdentifier;
                    if (tempMapId.GUID.Equals(mapIdStr))
                    {
                        usedItems[tempMap.Name] = tempMap.ID;
                        break;
                    }
                }
            }

            // Loop over all the map documents in the DB, looking for anything
            // that we didn't identify as "in use"
            foreach (string name in allMapNames.Keys)
            {
                if (!usedItems.ContainsKey(name))
                {
                    m_unusedMapDocs[name] = allMapNames[name];
                }
            }

            return(m_unusedMapDocs.Count);
        }
Ejemplo n.º 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)
        {
            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);
        }