public static RelationSecurityInfo GetRelationSecurityInfo(SqlConnection dbConnection, int contentId, int[] ids) { var result = new RelationSecurityInfo(); var pathRows = GetRelationSecurityFields(dbConnection); var securityPathes = new List <List <RelationSecurityPathItem> >(); var finder = new RelationSecurityPathFinder(pathRows.ToList(), contentId); finder.Compute(); securityPathes.Add(finder.CurrentPath); foreach (var extra in finder.ExtraFinders) { extra.Compute(); securityPathes.Add(extra.CurrentPath); } foreach (var securityPath in securityPathes) { if (securityPath.Count <= 0) { var isEndNode = finder.PathRows.Any(n => (int)(n.Field <decimal?>("rel_content_id") ?? 0) == contentId); if (!isEndNode) { result.MakeEmpty(); } else { result.AddContentInItemMapping(contentId, ids.ToDictionary(n => n, m => Enumerable.Repeat(m, 1).ToArray())); } return(result); } var lastItem = securityPath.Last(); var lastItemWithSecondary = Enumerable.Repeat(lastItem, 1).Concat(lastItem.Secondary).ToList(); var contentIds = lastItemWithSecondary.Where(n => !n.IsClassifier).Select(n => n.RelContentId).ToArray(); var attNames = lastItemWithSecondary.Where(n => n.IsClassifier).Select(n => n.AttributeName).ToArray(); foreach (var item in contentIds) { result.AddContentInItemMapping(item, new Dictionary <int, int[]>()); } var sql = GetSecurityPathSql(securityPath, contentId); using (var cmd = SqlCommandFactory.Create(sql, dbConnection)) { cmd.Parameters.Add(new SqlParameter("@ids", SqlDbType.Structured) { TypeName = "Ids", Value = Common.IdsToDataTable(ids) }); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { ProcessSecurityPathSqlReader(reader, contentIds, attNames, result); } } } AppendNotFound(ids, contentIds, result); } return(result); }
public static RelationSecurityInfo GetRelationSecurityInfo(DbConnection dbConnection, int contentId, int[] ids) { var dbType = DatabaseTypeHelper.ResolveDatabaseType(dbConnection); var result = new RelationSecurityInfo(); var pathRows = GetRelationSecurityFields(dbConnection); var securityPathes = new List <List <RelationSecurityPathItem> >(); var finder = new RelationSecurityPathFinder(pathRows.ToList(), contentId); finder.Compute(); securityPathes.Add(finder.CurrentPath); foreach (var extra in finder.ExtraFinders) { extra.Compute(); securityPathes.Add(extra.CurrentPath); } foreach (var securityPath in securityPathes) { if (securityPath.Count <= 0) { var isEndNode = finder.PathRows.Any(n => (Converter.ToNullableInt32(n["rel_content_id"]) ?? 0) == contentId); if (!isEndNode) { result.MakeEmpty(); } else { result.AddContentInItemMapping(contentId, ids.ToDictionary(n => n, m => Enumerable.Repeat(m, 1).ToArray())); } return(result); } var lastItem = securityPath.Last(); var lastItemWithSecondary = Enumerable.Repeat(lastItem, 1).Concat(lastItem.Secondary).ToList(); var contentIds = lastItemWithSecondary.Where(n => !n.IsClassifier).Select(n => n.RelContentId).ToArray(); var attNames = lastItemWithSecondary.Where(n => n.IsClassifier).Select(n => n.AttributeName).ToArray(); foreach (var item in contentIds) { result.AddContentInItemMapping(item, new Dictionary <int, int[]>()); } var sql = GetSecurityPathSql(dbType, securityPath, contentId); using (var cmd = DbCommandFactory.Create(sql, dbConnection)) { cmd.Parameters.Add(SqlQuerySyntaxHelper.GetIdsDatatableParam("@ids", ids, dbType)); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { ProcessSecurityPathSqlReader(reader, contentIds, attNames, result); } } } AppendNotFound(ids, contentIds, result); } return(result); }