コード例 #1
0
        /// <summary>
        /// Action workflow item.
        /// </summary>
        /// <param name="serialNumber">The identity workflow.</param>
        /// <param name="action">The action workflow value.</param>
        /// <param name="datafields">The data fields workflow.</param>
        /// <param name="allocatedUser">The allocated user.</param>
        /// <returns></returns>
        public string ActionWorkflow(string serialNumber, string action, Dictionary <string, object> datafields, string allocatedUser)
        {
            try
            {
                bool isSharingItem = false;
                if ((!string.IsNullOrEmpty(allocatedUser) && !string.IsNullOrEmpty(_model.K2Profile.UserName)) &&
                    !string.Equals(allocatedUser, _model.K2Profile.UserName, StringComparison.OrdinalIgnoreCase))
                {
                    isSharingItem = true;
                }
                WorklistItem worklistItem;
                if (isSharingItem)
                {
                    worklistItem = _connection.OpenSharedWorklistItem(allocatedUser, _model.K2Profile.UserName, serialNumber);
                }
                else
                {
                    worklistItem = _connection.OpenWorklistItem(serialNumber, "ASP", true);
                }
                if (worklistItem == null)
                {
                    throw new ArgumentNullException(ConstantValueService.MSG_ERR_CANNOT_FOUND_WORKLISTITEM);
                }
                foreach (var datafield in datafields)
                {
                    worklistItem.ProcessInstance.DataFields[datafield.Key].Value = datafield.Value;
                    worklistItem.ProcessInstance.Update();
                }
                worklistItem.Actions[action].Execute();

                //Force to Reject for round robin case.
                if (string.Equals(action, ConstantValueService.K2_REJECT, StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        worklistItem.GotoActivity(ConstantValueService.K2_REJECT);
                    }
                    catch (Exception)
                    {
                        /* Ignore this exception */
                    }
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(ex.Message, ex);
            }
            return(ConstantValueService.MSG_WORKFLOW_ACTION_COMPLETE);
        }