Exemplo n.º 1
0
        public static void Release(string sn)
        {
            SourceCode.Workflow.Client.Connection con = new Connection();
            try
            {
                ConnectionSetup conSetup = GetConnectionSetup();
                con.Open(conSetup);
                con.ImpersonateUser(_CurrentUser);

                SourceCode.Workflow.Client.WorklistItem listItem = con.OpenWorklistItem(sn);
                listItem.Release();
            }
            catch (Exception ex)
            {
                // TODO: throw?
                throw ex;
            }
            finally
            {
                try
                {
                    con.RevertUser();
                }
                catch
                {
                    throw;
                }

                if (con != null)
                {
                    con.Close();
                }
            }
        }
Exemplo n.º 2
0
        public static void Delegate(string sn, string targetUser)
        {
            SourceCode.Workflow.Client.Connection con = new Connection();
            try
            {
                ConnectionSetup conSetup = GetConnectionSetup();
                con.Open(conSetup);
                con.ImpersonateUser(_CurrentUser);

                SourceCode.Workflow.Client.WorklistItem listItem = con.OpenWorklistItem(sn);
                listItem.Release();

                Destination dest = new Destination();
                dest.DestinationType = DestinationType.User;
                for (int i = 0; i < listItem.Actions.Count; i++)
                {
                    dest.AllowedActions.Add(listItem.Actions[i].Name);
                }
                dest.Name = targetUser;

                listItem.Delegate(dest);
                DBManager.AddWorkListLog(_CurrentUser, targetUser, listItem.SerialNumber, listItem.ProcessInstance.ID, listItem.ActivityInstanceDestination.ID, "Delegate", _CurrentUser);
            }
            catch (Exception ex)
            {
                // TODO: throw?
                throw ex;
            }
            finally
            {
                try
                {
                    con.RevertUser();
                }
                catch
                {
                    throw;
                }

                if (con != null)
                {
                    con.Close();
                }
            }
        }
Exemplo n.º 3
0
        public static void Approve(string sn, string action, NameValueCollection dataFields)
        {
            SourceCode.Workflow.Client.Connection con = new Connection();
            try
            {
                ConnectionSetup conSetup = GetConnectionSetup();
                con.Open(conSetup);
                con.ImpersonateUser(_CurrentUser);

                SourceCode.Workflow.Client.WorklistItem listItem = con.OpenWorklistItem(sn);
                listItem.Release();
                if (dataFields != null)
                {
                    for (int i = 0; i < dataFields.Count; i++)
                    {
                        string key   = dataFields.GetKey(i).ToString();
                        string value = dataFields[key].ToString();
                        listItem.ProcessInstance.DataFields[key].Value = value;
                    }
                }
                listItem.Actions[action].Execute();
            }
            catch (Exception ex)
            {
                // TODO: throw?
                throw ex;
            }
            finally
            {
                try
                {
                    con.RevertUser();
                }
                catch
                { }

                if (con != null)
                {
                    con.Close();
                }
            }
        }
Exemplo n.º 4
0
        public List <string> GetSharedUsers(string sn)
        {
            List <string> destUsers = new List <string>();

            K2.WorklistItem wItem = null;
            try
            {
                wItem = _client.GetWorklistItem(sn);

                if (wItem == null)
                {
                    throw new System.InvalidOperationException(string.Format("Not Found", sn));
                }

                var delegateUsers = wItem.DelegatedUsers;

                if (delegateUsers != null && delegateUsers.Count > 0)
                {
                    foreach (K2.Destination dest in delegateUsers)
                    {
                        if (dest.Name.IsCaseInsensitiveEqual(_userAccount))
                        {
                            continue;
                        }

                        var criteria = K2Service.Cores.SecurityLabelUtils.GetNameWithoutLabel(dest.Name).ToLower();

                        destUsers.Add(criteria);
                    }
                }
                wItem.Release();

                return(destUsers);
            }
            catch (Exception)
            {
                return(destUsers);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 恢复任务
        /// </summary>
        /// <param name="sn">任务SN</param>
        /// <param name="currentUser"></param>
        public static void ReleaseWorkListItem(string sn, string currentUser)
        {
            using (Connection conn = new Connection())
            {
                try
                {
                    ConnectionSetup conSetup = GetConnectionSetup();
                    conn.Open(conSetup);
                    conn.ImpersonateUser(currentUser);

                    SourceCode.Workflow.Client.WorklistItem listItem = conn.OpenWorklistItem(sn);
                    listItem.Release();
                }
                catch
                {
                    // TODO: throw?
                    throw;
                }
                finally
                {
                    try
                    {
                        conn.RevertUser();
                    }
                    catch
                    {
                        throw;
                    }

                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static void Redirect(string sn, string targetUser)
        {
            SourceCode.Workflow.Client.Connection con = new Connection();
            try
            {
                ConnectionSetup conSetup = GetConnectionSetup();
                con.Open(conSetup);
                con.ImpersonateUser(_CurrentUser);

                SourceCode.Workflow.Client.WorklistItem listItem = con.OpenWorklistItem(sn);
                listItem.Release();
                listItem.Redirect(targetUser);
                DBManager.AddWorkListLog(_CurrentUser, targetUser, listItem.SerialNumber, listItem.ProcessInstance.ID, listItem.ActivityInstanceDestination.ID, "Redirect", _CurrentUser);
            }
            catch (Exception ex)
            {
                // TODO: throw?
                throw ex;
            }
            finally
            {
                try
                {
                    con.RevertUser();
                }
                catch
                {
                    throw;
                }

                if (con != null)
                {
                    con.Close();
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 委托代办
        /// </summary>
        /// <param name="sn"></param>
        /// <param name="sourceUser"></param>
        /// <param name="targetUser"></param>
        public static string DelegateWorkListItem(string sn, string sourceUser, string targetUser)
        {
            using (Connection conn = new Connection())
            {
                string result             = "";
                bool   ContainsTargetUser = false;
                try
                {
                    string          targetUserSL = SecurityLabelName + ":" + targetUser;
                    ConnectionSetup conSetup     = GetConnectionSetup();
                    conn.Open(conSetup);
                    conn.ImpersonateUser(sourceUser);

                    SourceCode.Workflow.Client.WorklistItem listItem = conn.OpenWorklistItem(sn);

                    //重置任务状态为Available,只有Available状态下的任务才有权限代理
                    listItem.Release();
                    //判断该任务是否已经代理给targetUser
                    foreach (Destination destuser in listItem.DelegatedUsers)
                    {
                        if (destuser.Name.Equals(targetUserSL, StringComparison.InvariantCultureIgnoreCase))
                        {
                            ContainsTargetUser = true;
                            result             = "任务不能重复代理给[" + targetUser + "]";
                            break;
                        }
                    }
                    if (!ContainsTargetUser)
                    {
                        //如果该任务是其它人代理给sourceUser的,则sourceUser不能再次代理给targetUser,即禁止传递代理
                        DataTable DelegationLog = K2DBHelper.GetDelegationsLog(listItem.SerialNumber).Tables[0];
                        foreach (DataRow dr in DelegationLog.Rows)
                        {
                            if (sourceUser.Equals(dr["ToUser"].ToString(), StringComparison.InvariantCultureIgnoreCase))
                            {
                                ContainsTargetUser = true;
                                result             = "该任务由[" + dr["FromUser"].ToString() + "]代理给[" + sourceUser + "]";
                                break;
                            }
                        }
                    }
                    if (!ContainsTargetUser)
                    {
                        Destination dest = new Destination();
                        dest.DestinationType = DestinationType.User;
                        for (int i = 0; i < listItem.Actions.Count; i++)
                        {
                            dest.AllowedActions.Add(listItem.Actions[i].Name);
                        }
                        dest.Name = targetUserSL;
                        //代理任务
                        listItem.Delegate(dest);

                        //Todo:给代理人邮件

                        //Todo:添加代理历史记录
                        int parentProcInstID = K2DBHelper.GetRootParentsID(listItem.ProcessInstance.ID);
                        K2DBHelper.AddDelegationsLog(listItem.ProcessInstance.ID, parentProcInstID, sn, sourceUser, targetUser, sourceUser);
                        result = "任务代理成功";
                    }
                    return(result);
                }
                catch
                {
                    // TODO: throw?
                    throw;
                }
                finally
                {
                    try
                    {
                        conn.RevertUser();
                    }
                    catch
                    {
                        throw;
                    }

                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
            }
        }