Exemplo n.º 1
0
        /// <summary>
        /// Call and execute worklist item's action
        /// </summary>
        /// <param name="serialNumber">The worklist item's serial number</param>
        /// <param name="action">The worklist item's action name</param>
        /// <param name="synchronous">The execution by synchronus or asynchronous</param>
        /// <param name="allowNonBatch">The allow non batch</param>
        /// <param name="item">The worklist item</param>
        /// <param name="sharedUser">The shared users</param>
        /// <param name="managedUser">The manager user</param>
        private void ExecuteAction(string serialNumber, string action, bool synchronous, bool allowNonBatch, Cores.WorklistItem item, string sharedUser, string managedUser)
        {
            string text = action.ToUpperInvariant();

            if (text.StartsWith("A:") || text.StartsWith("ACTION:"))
            {
                action = RemovePrefix(action);
            }
            else
            {
                if (text.StartsWith("R:") || text.StartsWith("REDIRECT:"))
                {
                    this.Redirect(serialNumber, RemovePrefix(action));
                    return;
                }
                if (text.StartsWith("D:") || text.StartsWith("DELEGATE:"))
                {
                    this.DelegateWorklistItem(serialNumber, RemovePrefix(action));
                    return;
                }
            }
            using (Connection workflowClient = this.GetWorkflowClient()) {
                K2.WorklistItem worklistItem = this.OpenWorklistItem(workflowClient, serialNumber, sharedUser, managedUser);

                K2.Action newAction = worklistItem.Actions[action];

                if (newAction == null)
                {
                    throw new InvalidOperationException(string.Format("Not Found", action));
                }

                if (!newAction.Batchable && !allowNonBatch)
                {
                    throw new InvalidOperationException(string.Format("Not Batchable", action));
                }

                if (item != null)
                {
                    item.ToApi(worklistItem);
                }

                newAction.Execute(synchronous);
            }
        }
Exemplo n.º 2
0
        public virtual void Excute(string actionName)
        {
            //Get the WorklistItem object
            WorklistItem wi = _conn.OpenWorklistItem(this._sn);

            //get the processing instance object
            ProcessInstance pi = wi.ProcessInstance;

            foreach (KeyValuePair <string, object> pair in DataFields)
            {
                pi.DataFields[pair.Key].Value = pair.Value;
            }

            //determine the action object for the chosen item
            SourceCode.Workflow.Client.Action action = wi.Actions[actionName];

            //execute the action
            action.Execute();
        }