Esempio n. 1
0
 private static void AppendNotFound(int[] ids, int[] contentIds, RelationSecurityInfo result)
 {
     if (contentIds.Any())
     {
         var firstContentId = contentIds.First();
         var notFound       = ids.Where(n => !result.IsItemMappingExists(firstContentId, n)).ToArray();
         foreach (var item in contentIds)
         {
             foreach (var nfItem in notFound)
             {
                 result.AppendToItemMapping(item, nfItem, null);
             }
         }
     }
 }
Esempio n. 2
0
        private static void ProcessSecurityPathSqlReader(SqlDataReader reader, int[] contentIds, string[] classifierNames,
                                                         RelationSecurityInfo result)
        {
            var id = (int)(decimal)reader["id"];

            foreach (var item in contentIds)
            {
                var ints = Converter.ToInt32Collection((string)reader[item.ToString()], ',');
                result.AppendToItemMapping(item, id, ints);
            }

            if (classifierNames != null)
            {
                foreach (var clName in classifierNames)
                {
                    var clValue = Converter.ToInt32((decimal)reader[clName]);
                    result.AppendToContentMapping(clValue, id);
                }
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }