示例#1
0
        /// <summary>
        /// 从矩阵中获得对象。这主要取决于上下文中的参数
        /// </summary>
        /// <returns></returns>
        public OguDataCollection <IOguObject> GetObjectsFromMatrix()
        {
            OguDataCollection <IOguObject> result = new OguDataCollection <IOguObject>();

            SOARoleContext context = SOARoleContext.Current;

            if (context != null && context.QueryParams.Count > 0)
            {
                SOARolePropertyRowCollection matchedRows = this.Rows.Query(context.QueryParams);

                matchedRows = matchedRows.ExtractMatrixRows();
                foreach (SOARolePropertyRowUsers rowUsers in matchedRows.GenerateRowsUsers())
                {
                    foreach (IUser user in rowUsers.Users)
                    {
                        if (result.Contains(user) == false)
                        {
                            result.Add(user);
                        }
                    }
                }
            }

            return(result);
        }
        private bool ExtractSOARoleMatrixRows(SOARole innerRole, SOARolePropertyRowCollection extractedRows)
        {
            bool extracted = false;

            SOARoleContext.DoAction(innerRole, SOARoleContext.CurrentProcess, (context) =>
            {
                SOARolePropertyRowCollection subRows = innerRole.Rows.Query(context.QueryParams);

                if (this.Role != null)
                {
                    if (((SOARole)this.Role).MatrixType == WfMatrixType.ActivityMatrix && innerRole.MatrixType != WfMatrixType.ActivityMatrix)
                    {
                        subRows = MergeActivityRowPropertiesByRows(subRows);
                    }

                    foreach (SOARolePropertyRow subRow in subRows)
                    {
                        SOARolePropertyRowCollection subExtractedRows = subRow.ExtractMatrixRows();

                        extractedRows.CopyFrom(subExtractedRows);
                    }
                }

                extracted = true;
            });

            return(extracted);
        }
        private SOARolePropertyRowCollection MergeActivityRowPropertiesByOperators(IEnumerable <string> operators)
        {
            SOARolePropertyRowCollection result = new SOARolePropertyRowCollection();

            int index      = 0;
            int activitySN = this.Values.GetValue(SOARolePropertyDefinition.ActivitySNColumn, 0);

            foreach (string op in operators)
            {
                SOARolePropertyRow newRow = new SOARolePropertyRow(this, 0);

                if (this.GetPropertyDefinitions().MatrixType == WfMatrixType.ActivityMatrix)
                {
                    SOARolePropertyValue pv = newRow.Values.Find(v => string.Compare(v.Column.Name, SOARolePropertyDefinition.ActivitySNColumn, true) == 0);

                    if (pv == null)
                    {
                        pv = new SOARolePropertyValue(this.GetPropertyDefinitions()[SOARolePropertyDefinition.ActivitySNColumn]);
                        newRow.Values.Add(pv);
                    }

                    pv.Value = string.Format("{0}.{1:0000}", activitySN, ++index);
                }

                newRow.OperatorType = SOARoleOperatorType.User;
                newRow.Operator     = op;

                result.Add(newRow);
            }

            return(result);
        }
示例#4
0
 public void FillClonedRows(SOARolePropertyRowCollection cloned)
 {
     foreach (SOARolePropertyRow row in this)
     {
         cloned.Add(new SOARolePropertyRow(row, row.RowNumber));
     }
 }
示例#5
0
        public SOARolePropertyRowCollection Clone()
        {
            SOARolePropertyRowCollection cloned = new SOARolePropertyRowCollection();

            this.FillClonedRows(cloned);

            return(cloned);
        }
        private bool ExtractUserMatrixRows(string operators, SOARolePropertyRowCollection extractedRows)
        {
            List <string> userIDs = GenerateObjectIDs(operators);

            extractedRows.CopyFrom(this.MergeActivityRowPropertiesByOperators(userIDs));

            return(userIDs.Count > 0);
        }
        private bool ExtractDynamicRoleMatrixRows(string roleName, SOARolePropertyRowCollection extractedRows)
        {
            OguDataCollection <IUser> users = new OguDataCollection <IUser>();

            FillInternalDynamicRoleUsers(roleName, users);

            extractedRows.CopyFrom(this.MergeActivityRowPropertiesByUsers(users));

            return(users.Count > 0);
        }
        /// <summary>
        /// 如果行的内容是角色,则将这些行扩展出来
        /// </summary>
        public SOARolePropertyRowCollection ExtractMatrixRows()
        {
            SOARolePropertyRowCollection extractedRows = new SOARolePropertyRowCollection();
            bool extracted = false;

            if (this.Operator.IsNotEmpty())
            {
                if (this.Operator.IndexOf(":") != -1)
                {
                    switch (this.OperatorType)
                    {
                    case SOARoleOperatorType.Role:
                        extracted = this.ExtractSOARoleRows(new SOARole(this.Operator), extractedRows);
                        break;

                    case SOARoleOperatorType.AURole:
                        WrappedAUSchemaRole wrappedRole = WrappedAUSchemaRole.FromCodeName(this.Operator);

                        if (wrappedRole != null)
                        {
                            wrappedRole.DoCurrentRoleAction(SOARoleContext.CurrentProcess,
                                                            (role, auCodeName) => extracted = this.ExtractSOARoleRows(role, extractedRows));
                        }
                        break;
                    }
                }
                else
                {
                    if (this.Values.GetValue(SOARolePropertyDefinition.AutoExtractColumn, false))
                    {
                        switch (this.OperatorType)
                        {
                        case SOARoleOperatorType.Role:
                            extracted = this.ExtractDynamicRoleMatrixRows(this.Operator, extractedRows);
                            break;

                        case SOARoleOperatorType.User:
                            extracted = this.ExtractUserMatrixRows(this.Operator, extractedRows);
                            break;
                        }
                    }
                }
            }

            //如果没有展开行,则将当前行添加到结果中
            if (extracted == false)
            {
                extractedRows.Add(this);
            }

            return(extractedRows);
        }
示例#9
0
        public void FillCreateActivityParams(WfCreateActivityParamCollection capc, PropertyDefineCollection definedProperties)
        {
            SOARoleContext context = SOARoleContext.Current;

            if (context != null && context.QueryParams.Count > 0)
            {
                SOARolePropertyRowCollection matchedRows = this.Rows.Query(context.QueryParams);

                matchedRows = matchedRows.ExtractMatrixRows();

                matchedRows.FillCreateActivityParams(capc, this.PropertyDefinitions, definedProperties);
            }
        }
        private static void PrepareRowsSql(string roleID, SOARolePropertyRowCollection rows, StringBuilder strB)
        {
            foreach (SOARolePropertyRow row in rows)
            {
                strB.Append(TSqlBuilder.Instance.DBStatementSeperator);

                strB.Append(PrepareRowSql(roleID, row));

                foreach (SOARolePropertyValue propValue in row.Values)
                {
                    strB.Append(TSqlBuilder.Instance.DBStatementSeperator);

                    strB.Append(PrepareValueSql(roleID, row, propValue));
                }
            }
        }
示例#11
0
        /// <summary>
        /// 将包含的子角色矩阵进行展开
        /// </summary>
        /// <returns></returns>
        public SOARolePropertyRowCollection ExtractMatrixRows()
        {
            SOARolePropertyRowCollection result = new SOARolePropertyRowCollection();

            foreach (SOARolePropertyRow row in this)
            {
                SOARolePropertyRowCollection extractedRows = row.ExtractMatrixRows();

                extractedRows.FillClonedRows(result);
                //result.CopyFrom(extractedRows);
            }

            result.SortActivitySN();

            return(result);
        }
        public SOARolePropertyRowCollection GetByRole(IRole role, SOARolePropertyDefinitionCollection definition)
        {
            role.NullCheck("role");

            SOARolePropertyRowCollection result = SOARolePropertiesCache.Instance.GetOrAddNewValue(role.ID.ToRoleIDCacheKey(), (cache, key) =>
            {
                SOARolePropertyRowCollection properties = LoadByRole(role, definition);

                MixedDependency dependency = new MixedDependency(new UdpNotifierCacheDependency(), new MemoryMappedFileNotifierCacheDependency());

                cache.Add(key, properties, dependency);

                return(properties);
            });

            return(result);
        }
        private SOARolePropertyRowCollection MergeActivityRowPropertiesByRows(SOARolePropertyRowCollection subExtractedRows)
        {
            SOARolePropertyRowCollection result = new SOARolePropertyRowCollection();

            foreach (SOARolePropertyRow subRow in subExtractedRows)
            {
                SOARolePropertyRow newRow = new SOARolePropertyRow(this.Role);

                newRow.Values.CopyFrom(this.Values);
                newRow.OperatorType = subRow.OperatorType;
                newRow.Operator     = subRow.Operator;

                result.Add(newRow);
            }

            return(result);
        }
        private static OguDataCollection <IUser> CalculateRowOperators()
        {
            OguDataCollection <IUser> result = new OguDataCollection <IUser>();

            if (ObjectContextCache.Instance.ContainsKey("RoleMatrixCurrentRow"))
            {
                SOARolePropertyRow row = (SOARolePropertyRow)ObjectContextCache.Instance["RoleMatrixCurrentRow"];

                SOARolePropertyRowCollection rows = new SOARolePropertyRowCollection();
                rows.Add(row);

                SOARolePropertyRowUsersCollection rowsUsers = rows.GenerateRowsUsers();

                rowsUsers.ForEach(ru => result.CopyFrom(ru.Users));
            }

            return(result);
        }
示例#15
0
        public SOARolePropertyRowCollection Query(Predicate <SOARolePropertyRow> predicate)
        {
            SOARolePropertyRowCollection result = new SOARolePropertyRowCollection(this._Role);

            foreach (SOARolePropertyRow row in this)
            {
                bool matched = true;

                matched = predicate(row);

                //if (matched)
                //    result.Add(row);
                if (matched)
                {
                    result.Add(new SOARolePropertyRow(row, row.RowNumber));
                }
            }

            return(result);
        }
示例#16
0
        private static void FillSheetData(SOARole role, WorkSheet ws)
        {
            int rowIndex = 4;
            SOARolePropertyRowCollection rows = SOARolePropertiesAdapter.Instance.LoadByRole(role, role.PropertyDefinitions);

            foreach (SOARolePropertyRow row in rows)
            {
                foreach (DefinedName name in ws.Names)
                {
                    SOARolePropertyValue propertyValue = row.Values.FindByColumnName(name.Name);

                    string dataValue = null;

                    if (propertyValue != null)
                    {
                        dataValue = propertyValue.Value;
                    }
                    else
                    {
                        switch (name.Name.ToLower())
                        {
                        case "operatortype":
                            dataValue = row.OperatorType.ToString();
                            break;

                        case "operator":
                            dataValue = row.Operator;
                            break;
                        }
                    }

                    if (dataValue != null)
                    {
                        ws.Cells[rowIndex, name.Address.StartColumn].Value = dataValue;
                    }
                }

                rowIndex++;
            }
        }
        /// <summary>
        /// 根据RoleID加载行信息
        /// </summary>
        /// <param name="roleID"></param>
        /// <param name="role"></param>
        /// <param name="definition">列定义</param>
        /// <returns></returns>
        public SOARolePropertyRowCollection LoadByRoleID(string roleID, IRole role, SOARolePropertyDefinitionCollection definition)
        {
            roleID.CheckStringIsNullOrEmpty("roleID");
            definition.NullCheck("definition");

            StringBuilder strB = new StringBuilder();

            strB.AppendFormat("SELECT * FROM WF.ROLE_PROPERTIES_ROWS WHERE {0} ORDER BY ROW_NUMBER", roleID.ToRoleIDCriteria());

            strB.Append(TSqlBuilder.Instance.DBStatementSeperator);

            strB.AppendFormat("SELECT * FROM WF.ROLE_PROPERTIES_CELLS WHERE {0} ORDER BY PROPERTIES_ROW_ID", roleID.ToRoleIDCriteria());

            SOARolePropertyRowCollection result = new SOARolePropertyRowCollection(role);

            using (TransactionScope scope = TransactionScopeFactory.Create(TransactionScopeOption.Suppress))
            {
                DataSet ds = DbHelper.RunSqlReturnDS(strB.ToString(), GetConnectionName());
                Dictionary <int, SOARolePropertyValueCollection> propertyValues = SOARolePropertyValueCollection.LoadAndGroup(ds.Tables[1].DefaultView, definition);

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    SOARolePropertyRow property = new SOARolePropertyRow(role);

                    ORMapping.DataRowToObject(row, property);

                    SOARolePropertyValueCollection values = null;

                    if (propertyValues.TryGetValue(property.RowNumber, out values))
                    {
                        property.Values.CopyFrom(values);
                    }

                    result.Add(property);
                }
            }

            return(result);
        }
        /// <summary>
        /// 展开内部角色的行
        /// </summary>
        /// <param name="innerRole"></param>
        /// <param name="extractedRows"></param>
        /// <returns></returns>
        private bool ExtractSOARoleRows(SOARole innerRole, SOARolePropertyRowCollection extractedRows)
        {
            bool extracted = false;

            if (innerRole.PropertyDefinitions.Count > 0)
            {
                SOARoleContext originalContext = SOARoleContext.Current;
                SOARoleContext.Current = null;
                try
                {
                    using (SOARoleContext innerContext = SOARoleContext.CreateContext(innerRole, originalContext.Process))
                    {
                        extracted = this.ExtractSOARoleMatrixRows(innerRole, extractedRows);
                    }
                }
                finally
                {
                    SOARoleContext.Current = originalContext;
                }
            }

            return(extracted);
        }
        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);
        }