public static IDictionary <int, SecurityEntity> LoadSecurityEntities_1(ISecurityDataProvider dataProvider)
        {
            var entities  = new ConcurrentDictionary <int, SecurityEntity>();
            var relations = new List <Tuple <int, int> >(); // first is Id, second is ParentId

            foreach (var storedEntity in dataProvider.LoadSecurityEntities())
            {
                var entity = new SecurityEntity
                {
                    Id          = storedEntity.Id,
                    IsInherited = storedEntity.IsInherited,
                    OwnerId     = storedEntity.OwnerId
                };

                entities.AddOrUpdate(entity.Id, entity, (key, val) => val);

                // memorize relations
                if (storedEntity.ParentId != default(int))
                {
                    //entity.Parent = entities[storedEntity.ParentId];
                    relations.Add(new Tuple <int, int>(storedEntity.Id, storedEntity.ParentId));
                }
            }

            // set parent/child relationship
            foreach (var rel in relations)
            {
                entities[rel.Item1].Parent = entities[rel.Item2];
                entities[rel.Item2].AddChild(entities[rel.Item1]);
            }

            return(entities);
        }
        public static IDictionary <int, SecurityEntity> LoadSecurityEntities_3(ISecurityDataProvider dataProvider)
        {
            var timer = Stopwatch.StartNew();

            var count    = dataProvider.GetEstimatedEntityCount();
            var capacity = count + count / 10;

            var entities  = new Dictionary <int, SecurityEntity>(capacity);
            var relations = new List <Tuple <SecurityEntity, int> >(capacity); // first is Id, second is ParentId

            foreach (var storedEntity in dataProvider.LoadSecurityEntities())
            {
                var entity = new SecurityEntity
                {
                    Id          = storedEntity.Id,
                    IsInherited = storedEntity.IsInherited,
                    OwnerId     = storedEntity.OwnerId
                };

                entities.Add(entity.Id, entity);

                // memorize relations
                if (storedEntity.ParentId != default(int))
                {
                    //entity.Parent = entities[storedEntity.ParentId];
                    relations.Add(new Tuple <SecurityEntity, int>(entity, storedEntity.ParentId));
                }
            }
            _log.Append("Load: ").Append(timer.Elapsed).Append(", ");
            timer.Stop();
            timer = Stopwatch.StartNew();

            // set parent/child relationship
            foreach (var rel in relations)
            {
                var parentEntity = entities[rel.Item2];
                rel.Item1.Parent = parentEntity;
                parentEntity.AddChild_Unsafe(rel.Item1);
            }
            _log.Append("Rel:").Append(timer.Elapsed).Append(", ");
            timer.Stop();
            timer = Stopwatch.StartNew();

            var result = new ConcurrentDictionary <int, SecurityEntity>(entities);

            _log.Append("Copy:").Append(timer.Elapsed);

            return(result);
        }
Exemple #3
0
        public IDictionary <int, SecurityEntity> LoadSecurityEntities()
        {
            if (!IsDatabaseReadyAsync(CancellationToken.None).GetAwaiter().GetResult())
            {
                return(new Dictionary <int, SecurityEntity>());
            }

            var count    = _dataProvider.GetEstimatedEntityCount();
            var capacity = count + count / 10;

            var entities  = new Dictionary <int, SecurityEntity>(capacity);
            var relations = new List <Tuple <SecurityEntity, int> >(capacity); // first is Id, second is ParentId

            foreach (var storedEntity in _dataProvider.LoadSecurityEntities())
            {
                var entity = new SecurityEntity
                {
                    Id          = storedEntity.Id,
                    IsInherited = storedEntity.IsInherited,
                    OwnerId     = storedEntity.OwnerId
                };

                entities.Add(entity.Id, entity);

                // memorize relations
                if (storedEntity.ParentId != default)
                {
                    relations.Add(new Tuple <SecurityEntity, int>(entity, storedEntity.ParentId));
                }
            }

            // set parent/child relationship
            foreach (var(securityEntity, parentId) in relations)
            {
                var parentEntity = entities[parentId];
                securityEntity.Parent = parentEntity;
                parentEntity.AddChild_Unsafe(securityEntity);
            }

            return(new ConcurrentDictionary <int, SecurityEntity>(entities));
        }
        private static void SavePermissions(ISecurityDataProvider db, string tempFolderPath)
        {
            using (var writer = new StreamWriter(Path.Combine(tempFolderPath, "permissions.txt"), false, Encoding.UTF8))
            {
                var breaks = db.LoadSecurityEntities()
                             .Where(e => !e.IsInherited)
                             .Select(e => e.Id)
                             .ToArray();

                var aces = db.LoadAllAces()
                           .OrderBy(a => a.EntityId)
                           .ThenBy(e => e.IdentityId);

                foreach (var ace in aces)
                {
                    writer.WriteLine("            \"{0}{1}\",",
                                     breaks.Contains(ace.EntityId) ? "-" : "+",
                                     ace.ToString().Replace("(", "").Replace(")", ""));
                }
            }
        }
Exemple #5
0
        public static IDictionary <int, SecurityEntity> LoadSecurityEntities(ISecurityDataProvider dataProvider)
        {
            var count    = dataProvider.GetEstimatedEntityCount();
            var capacity = count + count / 10;

            var entities  = new Dictionary <int, SecurityEntity>(capacity);
            var relations = new List <Tuple <SecurityEntity, int> >(capacity); // first is Id, second is ParentId

            foreach (var storedEntity in dataProvider.LoadSecurityEntities())
            {
                var entity = new SecurityEntity
                {
                    Id          = storedEntity.Id,
                    IsInherited = storedEntity.IsInherited,
                    OwnerId     = storedEntity.OwnerId
                };

                entities.Add(entity.Id, entity);

                // memorize relations
                if (storedEntity.ParentId != default(int))
                {
                    relations.Add(new Tuple <SecurityEntity, int>(entity, storedEntity.ParentId));
                }
            }

            // set parent/child relationship
            foreach (var rel in relations)
            {
                var parentEntity = entities[rel.Item2];
                rel.Item1.Parent = parentEntity;
                parentEntity.AddChild_Unsafe(rel.Item1);
            }

            return(new ConcurrentDictionary <int, SecurityEntity>(entities));
        }