Exemplo n.º 1
0
        public void Item_WithNoneAuthorized_IsntFilteredByDefault()
        {
            ItemDefinition autoDefinition = definitions.GetDefinition(typeof(DefinitionAutoCreatedItem));
            var            autoDefinitionIsAllowedSomewhere = definitions.GetDefinitions()
                                                              .SelectMany(d => definitions.GetAllowedChildren(Activator.CreateInstance(d.ItemType) as ContentItem, string.Empty))
                                                              .Any(d => d == autoDefinition);

            Assert.That(autoDefinitionIsAllowedSomewhere);
        }
Exemplo n.º 2
0
        public void Item_WithNoneAuthorized_IsntAllowed()
        {
            ItemDefinition autoDefinition = definitions.GetDefinition(typeof(DefinitionAutoCreatedItem));

            foreach (ItemDefinition definition in definitions.GetDefinitions())
            {
                IEnumerable <ItemDefinition> allowedDefinitions = definitions.GetAllowedChildren(Activator.CreateInstance(definition.ItemType) as ContentItem, string.Empty, user);
                EnumerableAssert.DoesntContain(allowedDefinitions, autoDefinition);
            }
        }
Exemplo n.º 3
0
        public static void Setup(out IDefinitionProvider[] definitionProviders, out IDefinitionManager definitions, out ContentActivator activator, out IItemNotifier notifier, out InterceptingProxyFactory proxyFactory, params Type[] itemTypes)
        {
            var map = new DefinitionMap();

            definitionProviders = SetupDefinitionProviders(map, itemTypes);
            notifier            = new ItemNotifier();
            proxyFactory        = new InterceptingProxyFactory();
            activator           = new ContentActivator(new N2.Edit.Workflow.StateChanger(), notifier, proxyFactory);
            definitions         = new DefinitionManager(definitionProviders, activator, new StateChanger(), new DefinitionMap());
            ((DefinitionManager)definitions).Start();
            activator.Initialize(definitions.GetDefinitions());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deserialisiert die Chunksäule aus dem angegebenen Stream.
        /// </summary>
        /// <param name="stream">Quellstream</param>
        /// <param name="definitionManager">Der verwendete DefinitionManager</param>
        /// <param name="columnIndex">Die Position der Säule</param>
        /// <param name="planetId">Der Index des Planeten</param>
        public void Deserialize(BinaryReader reader)
        {
            var longIndex = reader.ReadByte() > 0;

            // Phase 1 (Column Meta: Heightmap, populated, chunkcount)
            Chunks = new Chunk[reader.ReadByte()]; // Chunk Count

            Populated = reader.ReadBoolean();      // Populated

            Index = new Index2(reader.ReadInt32(), reader.ReadInt32());
            int planetId = reader.ReadInt32();

            var resManager = TypeContainer.Get <IResourceManager>();

            Planet = resManager.GetPlanet(planetId);

            for (var y = 0; y < Chunk.CHUNKSIZE_Y; y++) // Heightmap
            {
                for (var x = 0; x < Chunk.CHUNKSIZE_X; x++)
                {
                    Heights[x, y] = reader.ReadUInt16();
                }
            }


            // Phase 2 (Block Definitionen)
            var types = new List <IDefinition>();
            var map   = new Dictionary <ushort, ushort>();

            int typecount = longIndex ? reader.ReadUInt16() : reader.ReadByte();

            for (var i = 0; i < typecount; i++)
            {
                var           typeName        = reader.ReadString();
                IDefinition[] definitions     = DefinitionManager.GetDefinitions().ToArray();
                IDefinition   blockDefinition = definitions.FirstOrDefault(d => d.GetType().FullName == typeName);
                types.Add(blockDefinition);

                map.Add((ushort)types.Count, (ushort)(Array.IndexOf(definitions, blockDefinition) + 1));
            }

            // Phase 3 (Chunk Infos)
            for (var c = 0; c < Chunks.Length; c++)
            {
                IChunk chunk = Chunks[c] = new Chunk(new Index3(Index, c), Planet);
                chunk.Changed += OnChunkChanged;
                chunk.SetColumn(this);

                for (var i = 0; i < chunk.Blocks.Length; i++)
                {
                    var typeIndex = longIndex ? reader.ReadUInt16() : reader.ReadByte();
                    chunk.MetaData[i] = 0;
                    if (typeIndex > 0)
                    {
                        chunk.Blocks[i] = map[typeIndex];

                        var definition = (IBlockDefinition)DefinitionManager.GetDefinitionByIndex(map[typeIndex]);

                        if (definition.HasMetaData)
                        {
                            chunk.MetaData[i] = reader.ReadInt32();
                        }
                    }
                }
            }
        }