Esempio n. 1
0
        /// <summary>
        /// 得到OperationType为Role的角色信息
        /// </summary>
        /// <returns></returns>
        public SOARolePropertyRowRolesCollection GenerateRowsRolesDirectly()
        {
            SOARolePropertyRowRolesCollection result = new SOARolePropertyRowRolesCollection();

            foreach (SOARolePropertyRow row in this)
            {
                if (row.OperatorType == SOARoleOperatorType.Role)
                {
                    SOARolePropertyRowRoles rowRoles = new SOARolePropertyRowRoles(row);

                    //不考虑动态角色
                    if (rowRoles.Row.Operator.IndexOf(":") >= 0)
                    {
                        SOARole role = new SOARole(rowRoles.Row.Operator);

                        ExceptionHelper.DoSilentAction(() =>
                        {
                            //尝试读取一下,如果没有角色则吃掉异常
                            Trace.WriteLine(role.CodeName);

                            rowRoles.Roles.Add(role);
                        });
                    }

                    result.Add(rowRoles);
                }
            }

            return(result);
        }
        private void PrepareRoleContainers(string roleID, SOARolePropertyRowRolesCollection rowsRoles, StringBuilder strB)
        {
            foreach (SOARolePropertyRowRoles rowRoles in rowsRoles)
            {
                foreach (IRole role in rowRoles.Roles)
                {
                    InsertSqlClauseBuilder builder = new InsertSqlClauseBuilder();

                    strB.Append(TSqlBuilder.Instance.DBStatementSeperator);

                    builder.AppendItem("ROLE_ID", roleID);
                    builder.AppendItem("ROW_NUMBER", rowRoles.Row.RowNumber);
                    builder.AppendItem("OPERATOR_TYPE", (int)rowRoles.Row.OperatorType);
                    builder.AppendItem("OPERATOR_ID", role.ID);
                    builder.AppendItem("OPERATOR_NAME", role.FullCodeName);

                    builder.AppendTenantCode();

                    string sql = string.Format("INSERT INTO WF.ROLE_PROPERTIES_USER_CONTAINERS {0}", builder.ToSqlString(TSqlBuilder.Instance));

                    strB.Append(sql);
                }
            }
        }
        public void Update(string roleID, SOARolePropertyRowCollection rows)
        {
            roleID.CheckStringIsNullOrEmpty("roleID");
            rows.NullCheck("rows");

            StringBuilder strB = new StringBuilder(1024);

            strB.AppendFormat("DELETE WF.ROLE_PROPERTIES_ROWS WHERE {0}", roleID.ToRoleIDCriteria());

            strB.Append(TSqlBuilder.Instance.DBStatementSeperator);

            strB.AppendFormat("DELETE WF.ROLE_PROPERTIES_CELLS WHERE {0}", roleID.ToRoleIDCriteria());

            strB.Append(TSqlBuilder.Instance.DBStatementSeperator);

            strB.AppendFormat("DELETE WF.ROLE_PROPERTIES_USER_CONTAINERS WHERE {0}", roleID.ToRoleIDCriteria());

            PrepareRowsSql(roleID, rows, strB);

            SOARolePropertyRowUsersCollection rowsUsers = rows.GenerateRowsUsersDirectly();
            SOARolePropertyRowRolesCollection rowsRoles = rows.GenerateRowsRolesDirectly();

            PrepareUserContainers(roleID, rowsUsers, strB);
            PrepareRoleContainers(roleID, rowsRoles, strB);

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DbHelper.RunSql(strB.ToString(), GetConnectionName());
                scope.Complete();
            }

            CacheNotifyData notifyData = new CacheNotifyData(typeof(SOARolePropertiesCache), roleID.ToRoleIDCacheKey(), CacheNotifyType.Invalid);

            UdpCacheNotifier.Instance.SendNotifyAsync(notifyData);
            MmfCacheNotifier.Instance.SendNotify(notifyData);
        }