public void test_remove_event()
    {
        var count = 0;
        var done = false;
        var instance = new SimpleCollection();
        instance.AddEventHandler<TestEvent>((ep) =>
        {
            count += 1;
            if (done)
            {
                count += 100;
                ep.Api.Remove<TestEvent>();
            }
        });

        instance.Trigger(new TestEvent());
        Assert(count == 1);

        instance.Trigger(new TestEvent());
        Assert(count == 2);

        done = true;
        instance.Trigger(new TestEvent());
        Assert(count == 103);

        instance.Trigger(new TestEvent());
        Assert(count == 103);
    }
Ejemplo n.º 2
0
        void Update(object sender, EventArgs e)
        {
            ISimpleCollection newCollection = new SimpleCollection(objectsPath, linksPath, false);

            if (simpleCollection.Actual < newCollection.Actual)
            {
                newCollection.Load(objectsPath, linksPath);
                //Add new
                foreach (SimpleObject obj in newCollection.Objects)
                {
                    SimpleObject obj2 = null;
                    try
                    {
                        obj2 = simpleCollection.Objects.First(f => f.Id == obj.Id);
                    }
                    catch (Exception) //Doesn't matter
                    {
                        AddNew(obj);
                    }
                }
                //Delete old
                foreach (SimpleObject obj in simpleCollection.Objects)
                {
                    try
                    {
                        newCollection.Objects.First(f => f.Id == obj.Id);
                    } catch (Exception) //Doesn't matter
                    {
                        DeleteOld(obj);
                    }
                }
                //Add new links
                foreach (SimpleLink link in newCollection.Links)
                {
                    SimpleLink link2 = null;
                    try
                    {
                        link2 = simpleCollection.Links.First(f => f.Id == link.Start * maxId + link.End);
                    }
                    catch (Exception) //Doesn't matter
                    {
                        AddNewLink(link);
                    }
                }
                //Delete old links
                foreach (SimpleLink link in simpleCollection.Links)
                {
                    try
                    {
                        newCollection.Links.First(f => f.Id == link.Id);
                    }
                    catch (Exception) //Doesn't matter
                    {
                        DeleteOldLink(link);
                    }
                }

                simpleCollection = newCollection;
            }
        }
Ejemplo n.º 3
0
        public void AddBaseElementAtIndexSucceeds()
        {
            var collection = new SimpleCollection();

            collection.TestBaseAdd(-1, new SimpleElement());
            Assert.Equal(1, collection.Count);
        }
Ejemplo n.º 4
0
        public void BaseIndexReturnsZeroForOneItem()
        {
            var collection = new SimpleCollection();

            collection.TestBaseAdd(SimpleCollection.TestElement);
            Assert.Equal(0, collection.TestBaseIndexOf(SimpleCollection.TestElement));
        }
Ejemplo n.º 5
0
        public void SetEmitClear()
        {
            var collection = new SimpleCollection();

            collection.EmitClear = true;
            Assert.True(collection.EmitClear);
        }
Ejemplo n.º 6
0
        public void Read(BinaryReader br)
        {
            VTable           = br.ReadUInt32();
            NodeType         = (HtmlNodeType)br.ReadInt32();
            ParentNodeOffset = ResourceUtil.ReadOffset(br);

            ChildNodes = new PtrCollection <HtmlNode>(br);
            foreach (var node in ChildNodes)
            {
                node.ParentNode = this;
            }

            RenderState = new HtmlRenderState(br);

            if (NodeType != HtmlNodeType.HtmlDataNode)
            {
                Tag          = (HtmlTag)br.ReadInt32();
                _fDC         = br.ReadUInt32();
                _linkAddress = new SimpleCollection <byte>(br, reader => reader.ReadByte());
                if (NodeType == HtmlNodeType.HtmlTableElementNode)
                {
                    _fE8 = br.ReadInt32();
                    _fEC = br.ReadInt32();
                }
            }
            else
            {
                Data = new PtrString(br);
            }
        }
Ejemplo n.º 7
0
    public void test_remove_event()
    {
        var count    = 0;
        var done     = false;
        var instance = new SimpleCollection();

        instance.AddEventHandler <TestEvent>((ep) =>
        {
            count += 1;
            if (done)
            {
                count += 100;
                ep.Api.Remove <TestEvent>();
            }
        });

        instance.Trigger(new TestEvent());
        Assert(count == 1);

        instance.Trigger(new TestEvent());
        Assert(count == 2);

        done = true;
        instance.Trigger(new TestEvent());
        Assert(count == 103);

        instance.Trigger(new TestEvent());
        Assert(count == 103);
    }
Ejemplo n.º 8
0
    public void test_remove_specific_event()
    {
        var count    = 0;
        var scount   = 0;
        var instance = new SimpleCollection();

        instance.AddEventHandler <TestEvent>((ep) => { count += 1; });

        EventHandler <TestEvent> target = null;

        target = (ep) =>
        {
            if (count > 2)
            {
                if (ep.Api.EventHandler <TestEvent>() == target)
                {
                    scount += 1;
                    ep.Api.Remove <TestEvent>();
                }
            }
        };
        instance.AddEventHandler(target);

        instance.Trigger(new TestEvent());
        instance.Trigger(new TestEvent());
        Assert(count == 2);
        Assert(scount == 0);

        instance.Trigger(new TestEvent());
        instance.Trigger(new TestEvent());
        Assert(count == 4);
        Assert(scount == 1);
    }
Ejemplo n.º 9
0
 public void EnumerateEmptyCollection()
 {
     var collection = new SimpleCollection();
     Assert.Empty(collection);
     var enumerator = collection.GetEnumerator();
     Assert.False(enumerator.MoveNext());
 }
Ejemplo n.º 10
0
        public void DifferentCountNotEqual()
        {
            var collection = new SimpleCollection();

            collection.TestBaseAdd(SimpleCollection.TestElement);
            Assert.False(new SimpleCollection().Equals(collection));
        }
    public void test_remove_specific_event()
    {
        var count = 0;
        var scount = 0;
        var instance = new SimpleCollection();

        instance.AddEventHandler<TestEvent>((ep) => { count += 1; });

        EventHandler<TestEvent> target = null;
        target = (ep) =>
        {
            if (count > 2)
            {
                if (ep.Api.EventHandler<TestEvent>() == target)
                {
                    scount += 1;
                    ep.Api.Remove<TestEvent>();
                }
            }
        };
        instance.AddEventHandler(target);

        instance.Trigger(new TestEvent());
        instance.Trigger(new TestEvent());
        Assert(count == 2);
        Assert(scount == 0);

        instance.Trigger(new TestEvent());
        instance.Trigger(new TestEvent());
        Assert(count == 4);
        Assert(scount == 1);
    }
Ejemplo n.º 12
0
 public void CopyToCopiesItem()
 {
     var collection = new SimpleCollection();
     collection.TestBaseAdd(SimpleCollection.TestElement);
     ConfigurationElement[] array = new ConfigurationElement[1];
     collection.CopyTo(array, 0);
     Assert.Equal(SimpleCollection.TestElement, array.GetValue(0));
 }
Ejemplo n.º 13
0
        public void Read(BinaryReader br)
        {
            uint bonesOffset       = ResourceUtil.ReadOffset(br);
            uint unknownIntsOffset = ResourceUtil.ReadOffset(br);
            uint transforms1Offset = ResourceUtil.ReadOffset(br);
            uint transforms2Offset = ResourceUtil.ReadOffset(br);
            uint transforms3Offset = ResourceUtil.ReadOffset(br);

            BoneCount = br.ReadUInt16();
            Unknown0  = br.ReadInt16();
            Unknown1  = br.ReadInt32();
            Unknown2  = br.ReadInt32();

            BoneIDMappings = new SimpleCollection <BoneIDMapping>(br, r => new BoneIDMapping(r));

            Unknown3    = br.ReadInt32();
            UnknownHash = br.ReadUInt32();
            Unknown4    = br.ReadInt32();

            UnknownSubStruct = new SubStruct(br);

            // Data:

            br.BaseStream.Seek(bonesOffset, SeekOrigin.Begin);
            Bones = new SimpleArray <Bone>(br, BoneCount, r => new Bone(r));

            br.BaseStream.Seek(unknownIntsOffset, SeekOrigin.Begin);
            UnknownInts = new SimpleArray <int>(br, BoneCount, r => r.ReadInt32());

            br.BaseStream.Seek(transforms1Offset, SeekOrigin.Begin);
            Transforms1 = new SimpleArray <Matrix44>(br, BoneCount, r => new Matrix44(r));

            br.BaseStream.Seek(transforms2Offset, SeekOrigin.Begin);
            Transforms2 = new SimpleArray <Matrix44>(br, BoneCount, r => new Matrix44(r));

            br.BaseStream.Seek(transforms3Offset, SeekOrigin.Begin);
            Transforms3 = new SimpleArray <Matrix44>(br, BoneCount, r => new Matrix44(r));

            // Fun stuff...
            // Build a mapping of Offset -> Bone
            var boneOffsetMapping = new Dictionary <uint, Bone>();

            boneOffsetMapping.Add(0, null);
            foreach (var bone in Bones)
            {
                boneOffsetMapping.Add((uint)bone.Offset, bone);
            }

            // Now resolve all the bone offsets to the real bones
            foreach (var bone in Bones)
            {
                bone.Parent      = boneOffsetMapping[bone.ParentOffset];
                bone.FirstChild  = boneOffsetMapping[bone.FirstChildOffset];
                bone.NextSibling = boneOffsetMapping[bone.NextSiblingOffset];
            }
        }
Ejemplo n.º 14
0
 public void EnumerateNonEmptyCollection()
 {
     var collection = new SimpleCollection();
     collection.TestBaseAdd(SimpleCollection.TestElement);
     Assert.NotEmpty(collection);
     var enumerator = collection.GetEnumerator();
     Assert.True(enumerator.MoveNext());
     Assert.Equal(SimpleCollection.TestElement, enumerator.Current);
     Assert.False(enumerator.MoveNext());
 }
Ejemplo n.º 15
0
        public new void Read(BinaryReader br)
        {
            base.Read(br);

            TextureDictionaryOffset = ResourceUtil.ReadOffset(br);

            // CPtrCollection<T>
            Shaders = new PtrCollection <ShaderFx>(br);

            Zeros = new SimpleArray <uint>(br, 12, r => r.ReadUInt32());

            VertexDeclarationUsageFlags = new SimpleCollection <uint>(br, reader => reader.ReadUInt32());

            Data3 = new SimpleCollection <uint>(br, reader => reader.ReadUInt32());
        }
Ejemplo n.º 16
0
        public StickerBoardViewModel()
        {
            Name     = "NEW BOARD";
            Stickers = new SimpleCollection <StickerViewModel>();
            Stickers.ParentViewModel = this;

            Commands = new SimpleCollection <CommandViewModel>();
            var addCmd = new CommandViewModel();

            addCmd.Command          = Stickers.AddCommand;
            addCmd.CommandParameter = null;
            addCmd.Text             = "Add Sticker";
            addCmd.Image            = new BitmapImage(new Uri("pack://application:,,,/StickerPlugin;component/Icons/add.png"));
            Commands.Add(addCmd);
        }
Ejemplo n.º 17
0
        public new void Read(BinaryReader br)
        {
            base.Read(br);

            TextureDictionaryOffset = ResourceUtil.ReadOffset(br);

            // CPtrCollection<T>
            Shaders = new PtrCollection<ShaderFx>(br);

            Zeros = new SimpleArray<uint>(br, 12, r => r.ReadUInt32());

            VertexDeclarationUsageFlags = new SimpleCollection<uint>(br, reader => reader.ReadUInt32());

            Data3 = new SimpleCollection<uint>(br, reader => reader.ReadUInt32());
        }
Ejemplo n.º 18
0
        public MainViewModel()
        {
            DataTemplateSelector = new StickerPluginDataTemplateSelector();

            StickerBoards = new SimpleSelectedCollection <StickerBoardViewModel>();
            StickerBoards.ParentViewModel = this;

            Commands = new SimpleCollection <CommandViewModel>();
            var addCmd = new CommandViewModel();

            addCmd.Command          = StickerBoards.AddCommand;
            addCmd.CommandParameter = null;
            addCmd.Text             = "";
            addCmd.Image            = new BitmapImage(new Uri("pack://application:,,,/StickerPlugin;component/Icons/add.png"));
            Commands.Add(addCmd);
        }
Ejemplo n.º 19
0
 static void Main(string[] args)
 {
     SimpleCollection <string> simpleCollection = new SimpleCollection <string>();
 }
Ejemplo n.º 20
0
        public void CollectionChangedOnly()
        {
            var collection = new SimpleCollection <Guid>();

            using (var enumerable = new ActiveEnumerable <Guid>(collection))
                collection.Add(default);
Ejemplo n.º 21
0
    public static void Test()
    {
        var ind = new SimpleCollection <string>();

        Console.WriteLine(ind[0]);
    }
Ejemplo n.º 22
0
        public void Read(BinaryReader br)
        {
            VTable = br.ReadUInt32();
            NodeType = (HtmlNodeType)br.ReadInt32();
            ParentNodeOffset = ResourceUtil.ReadOffset(br);
            
            ChildNodes = new PtrCollection<HtmlNode>(br);
            foreach (var node in ChildNodes)
            {
                node.ParentNode = this;
            }

            RenderState = new HtmlRenderState(br);

            if (NodeType != HtmlNodeType.HtmlDataNode)
            {
                Tag = (HtmlTag)br.ReadInt32();
                _fDC = br.ReadUInt32();
                _linkAddress = new SimpleCollection<byte>(br, reader => reader.ReadByte());
                if (NodeType == HtmlNodeType.HtmlTableElementNode)
                {
                    _fE8 = br.ReadInt32();
                    _fEC = br.ReadInt32();
                }
            }
            else
            {
                Data = new PtrString(br);
            }
        }
Ejemplo n.º 23
0
        public void Read(BinaryReader br)
        {
            uint bonesOffset = ResourceUtil.ReadOffset(br);
            uint unknownIntsOffset = ResourceUtil.ReadOffset(br);
            uint transforms1Offset = ResourceUtil.ReadOffset(br);
            uint transforms2Offset = ResourceUtil.ReadOffset(br);
            uint transforms3Offset = ResourceUtil.ReadOffset(br);

            BoneCount = br.ReadUInt16();
            Unknown0 = br.ReadInt16();
            Unknown1 = br.ReadInt32();
            Unknown2 = br.ReadInt32();

            BoneIDMappings = new SimpleCollection<BoneIDMapping>(br, r => new BoneIDMapping(r));

            Unknown3 = br.ReadInt32();
            UnknownHash = br.ReadUInt32();
            Unknown4 = br.ReadInt32();

            UnknownSubStruct = new SubStruct(br);

            // Data:

            br.BaseStream.Seek(bonesOffset, SeekOrigin.Begin);
            Bones = new SimpleArray<Bone>(br, BoneCount, r => new Bone(r));

            br.BaseStream.Seek(unknownIntsOffset, SeekOrigin.Begin);
            UnknownInts = new SimpleArray<int>(br, BoneCount, r => r.ReadInt32());

            br.BaseStream.Seek(transforms1Offset, SeekOrigin.Begin);
            Transforms1 = new SimpleArray<Matrix44>(br, BoneCount, r => new Matrix44(r));

            br.BaseStream.Seek(transforms2Offset, SeekOrigin.Begin);
            Transforms2 = new SimpleArray<Matrix44>(br, BoneCount, r => new Matrix44(r));

            br.BaseStream.Seek(transforms3Offset, SeekOrigin.Begin);
            Transforms3 = new SimpleArray<Matrix44>(br, BoneCount, r => new Matrix44(r));

            // Fun stuff...
            // Build a mapping of Offset -> Bone
            var boneOffsetMapping = new Dictionary<uint, Bone>();
            boneOffsetMapping.Add(0, null);
            foreach (var bone in Bones)
            {
                boneOffsetMapping.Add((uint)bone.Offset, bone);
            }

            // Now resolve all the bone offsets to the real bones
            foreach (var bone in Bones)
            {
                bone.Parent = boneOffsetMapping[bone.ParentOffset];
                bone.FirstChild = boneOffsetMapping[bone.FirstChildOffset];
                bone.NextSibling = boneOffsetMapping[bone.NextSiblingOffset];
            }
        }