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);
    }
예제 #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;
            }
        }
예제 #3
0
        public void AddBaseElementAtIndexSucceeds()
        {
            var collection = new SimpleCollection();

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

            collection.TestBaseAdd(SimpleCollection.TestElement);
            Assert.Equal(0, collection.TestBaseIndexOf(SimpleCollection.TestElement));
        }
예제 #5
0
        public void SetEmitClear()
        {
            var collection = new SimpleCollection();

            collection.EmitClear = true;
            Assert.True(collection.EmitClear);
        }
예제 #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);
            }
        }
예제 #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);
    }
예제 #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);
    }
예제 #9
0
 public void EnumerateEmptyCollection()
 {
     var collection = new SimpleCollection();
     Assert.Empty(collection);
     var enumerator = collection.GetEnumerator();
     Assert.False(enumerator.MoveNext());
 }
예제 #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);
    }
예제 #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));
 }
예제 #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];
            }
        }
예제 #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());
 }
예제 #15
0
파일: ShaderGroup.cs 프로젝트: q4a/SparkIV
        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());
        }
예제 #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);
        }
예제 #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());
        }
예제 #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);
        }
예제 #19
0
 static void Main(string[] args)
 {
     SimpleCollection <string> simpleCollection = new SimpleCollection <string>();
 }
예제 #20
0
        public void CollectionChangedOnly()
        {
            var collection = new SimpleCollection <Guid>();

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

        Console.WriteLine(ind[0]);
    }
예제 #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);
            }
        }
예제 #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];
            }
        }