Exemplo n.º 1
0
        private void SendUpdateToServer <T>()
        {
            var _SocketServerManager = VEFModule.UnityContainer.Resolve(typeof(SocketServerManager), "") as SocketServerManager;

            if (Parent == null)
            {
                return;
            }

            var     body   = Parent as CharacterComponent;
            EntityX entity = body.Parent as EntityX;

            if (entity != null)
            {
                List <Type> types = new List <Type>()
                {
                    typeof(T)
                };

                FlatBufferBuilder fbb = new FlatBufferBuilder(4);
                if (entity.FB_Entity == null)
                {
                    return;
                }

                var fbEntity = entity.FB_Entity.CreateFBData(types, fbb);

                var mon = NetMsg.MessageRoot.CreateMessageRoot(fbb, entity.NetID, 1, NetMsg.Data.Entity, fbEntity._offset);
                NetMsg.MessageRoot.FinishMessageRootBuffer(fbb, mon);

                _SocketServerManager.Client.SendToServer(0, fbb.SizedByteArray(), ENet.PacketFlags.Reliable);
            }
        }
    public async Task Update_UpdateRecord_ValidateResult()
    {
        using (SqlXRepository repository = new SqlXRepository(_connectionString)) {
            var newX = new EntityX {
                Name  = "Update1",
                Price = 1
            };
            try {
                await repository.CreateAsync(newX);

                newX = await repository.ReadAsync(newX.Id);

                newX.Name  = "Update2";
                newX.Price = 2;
                await repository.UpdateAsync(newX);

                var readX = await repository.ReadAsync(newX.Id);

                Assert.AreEqual(newX.Name, readX.Name);
                Assert.AreEqual(newX.Id, readX.Id);
                Assert.AreEqual(newX.Price, readX.Price);
                Assert.IsFalse(newX.RowVersion == readX.RowVersion);
            } finally {
                await repository.DeleteAsync(newX.Id);
            }
        }
    }
Exemplo n.º 3
0
 public bool AddEntity(EntityX node)
 {
     if (!Entities.Contains(node))
     {
         Entities.Add(node);
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 public async Task <ActionResult> Create(EntityX model)
 {
     try {
         using (SqlXRepository repository = new SqlXRepository()) {
             await repository.CreateAsync(model).ConfigureAwait(false);
         }
         TempData["Message"] = $"{model.Name} created.";
         return(RedirectToAction("Index"));
     } catch {
         return(View());
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MDModel" /> class.
        /// </summary>
        /// <param name="commandManager">The injected command manager.</param>
        /// <param name="menuService">The menu service.</param>
        public SocketServerToolModel()
        {
            var commandManager = VEFModule.UnityContainer.Resolve(typeof(ICommandManager), "") as ICommandManager;
            var menuService    = VEFModule.UnityContainer.Resolve(typeof(IMenuService), "") as IMenuService;

            _HostInfo = new HostInfo();

            EntityX testEnt = new EntityX();

            testEnt.Components.Add(new RenderableComponent());
            testEnt.EntityID = 4;
            testEnt.Name     = "Character";
            RenderableComponent renderableComp = testEnt.GetComponentX <RenderableComponent>() as RenderableComponent;

            //var newfiles = new ObservableCollection<LocalFile>();

            //var f1 = new MeshObject()
            //{
            //  //  Entity = testEnt,
            //    FileLocation = XFBType.FileLocation.FILELOC_Asset,
            //    FilePath = "assets/Sinbad.mesh"
            //};

            //var f2 = new MeshObject()
            //{
            //    FileLocation = XFBType.FileLocation.FILELOC_Asset,
            //    FilePath = "assets/Sinbad.skeleton"
            //};

            //var f3 = new MeshObject()
            //{
            //    FileLocation = XFBType.FileLocation.FILELOC_Asset,
            //    FilePath = "assets/sinbad_body.tga"
            //};

            //f1.init();
            //f2.init();
            //f3.init();
            //newfiles.Add(f1);
            //newfiles.Add(f2);
            //newfiles.Add(f3);
            //renderableComp.LocalFiles.Add(f1);
            //renderableComp.LocalFiles.Add(f2);
            //renderableComp.LocalFiles.Add(f3);

            _sourceItems = new ObservableCollection <SourceItem>();

            //    _sourceItems.Add(new SourceItem() { Entity = testEnt, Component = renderableComp, LocalFiles = newfiles });
        }
Exemplo n.º 6
0
            public void Execute(object parameter)
            {
                Type t = parameter as Type;


                EntityX newEntity = new EntityX()
                {
                    Name = "New Entity"
                };

                newEntity.EntityID = (uint)mpm.Items.Count + 1;
                newEntity.Parent   = mpm;
                mpm.Items.Add(newEntity);

                //    (VEFModule.UnityContainer.Resolve(typeof(ILoggerService), "") as ILoggerService).Log("Error: CmdCreateStaticObj id =  (" + id.ToString() + ")", LogCategory.Error, LogPriority.High);
            }
    public async Task Update_UpdateRecordParallelOptimistic_ValidateResult()
    {
        var newX = new EntityX {
            Name  = "Update1",
            Price = 1
        };

        using (SqlXRepository repository1 = new SqlXRepository(_connectionString))
            using (SqlXRepository repository2 = new SqlXRepository(_connectionString)) {
                try {
                    await repository1.CreateAsync(newX);

                    //Read Item by 1-st user
                    newX = await repository1.ReadAsync(newX.Id);

                    //Read the same item by 2-nd user
                    var readX2 = await repository2.ReadAsync(newX.Id);

                    //Modify and save updated by first user
                    newX.Name  = "Update2";
                    newX.Price = 2;
                    await repository1.UpdateAsync(newX);

                    //try to update the same record by 2-nd user
                    readX2.Name  = "Update3";
                    readX2.Price = 3;
                    //update should fail here
                    try {
                        await repository2.UpdateAsync(readX2);
                    } catch (ConcurrencyException ex) {
                        Assert.IsTrue(ex.Message == "The value was already changed");
                    } catch {
                        Assert.Fail();
                    }
                    //the result should be from the 1-st user update
                    var readX = await repository1.ReadAsync(newX.Id);

                    Assert.AreEqual(newX.Name, readX.Name);
                    Assert.AreEqual(newX.Id, readX.Id);
                    Assert.AreEqual(newX.Price, readX.Price);
                    Assert.IsFalse(newX.RowVersion == readX.RowVersion);
                } finally {
                    await repository1.DeleteAsync(newX.Id);
                }
            }
    }
    public async Task CreateListRemove_Crud_Validate()
    {
        using (SqlXRepository repository = new SqlXRepository(_connectionString)) {
            var newX = new EntityX {
                Name  = "Test",
                Price = 1
            };
            await repository.CreateAsync(newX);

            Assert.IsTrue(newX.Id > 0);
            var readX = await repository.ReadAsync(newX.Id);

            Assert.AreEqual(newX.Name, readX.Name);
            Assert.AreEqual(newX.Id, readX.Id);
            Assert.AreEqual(newX.Price, readX.Price);
            Assert.IsFalse(readX.RowVersion == Guid.Empty);
            await repository.DeleteAsync(newX.Id);
        }
    }
Exemplo n.º 9
0
        public void SharedEntities_AccessSharedInheritance()
        {
            this.EnqueueLoadEntityX();

            this.EnqueueCallback(
                () =>
            {
                EntityX x = (EntityY)this.DomainChildContext.EntityXes.First();
                EntityY y = (EntityY)x;
                Assert.IsNotNull(y.EntityZ, "y.EntityZ should be set");
                Assert.AreEqual(y.IdZ, y.EntityZ.Id, "y.IdZ should reflect EntityZ.Id");
                Assert.AreNotEqual(y.IdZ, 0, "y.IdZ should not be 0");
                // When Y is serialized DCS serializes X' properties then Y's properties.
                // If the surrogates were loaded correctly, X' ZProp should be read before Y's IdZ.
                // If surrogates were not loaded correctly, ZProp would not be set.
                Assert.AreNotEqual(x.ZProp, 0, "x.ZProp cannot be zero.");
            });

            this.EnqueueTestComplete();
        }
Exemplo n.º 10
0
        public async Task <ActionResult> Edit(EntityX model)
        {
            try {
                using (SqlXRepository repository = new SqlXRepository()) {
                    try {
                        await repository.UpdateAsync(model).ConfigureAwait(false);

                        TempData["Message"] = $"{model.Name} updated successfully.";
                    } catch (ConcurrencyException ex) {
                        var merge = new MergeEntityX {
                            NewItem   = model,
                            SavedItem = await repository.ReadAsync(model.Id),
                        };
                        return(View("EditMerge", merge));
                    } catch (Exception ex) {
                        TempData["Message"] = $"There was an error updating record: {model.Id}";
                    }
                }
                return(RedirectToAction("Index"));
            } catch (Exception ex) {
                TempData["Message"] = $"Cannot update {model.Name}.";
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 11
0
        public void Fetch()
        {
            var ec1 = new EntityC {
                A = new EntityA(), B = new EntityB(), X = new EntityX(), Y = new EntityY()
            };

            TestBase.TestSerialization(ec1);

            var ec2 = new EntityC {
                A = new EntityA(), B = new EntityB(), X = new EntityX(), Y = new EntityY()
            };

            TestBase.TestSerialization(ec2);

            var ex1 = new EntityX();

            TestBase.TestSerialization(ex1);

            var ex2 = new EntityX();

            TestBase.TestSerialization(ex2);

            var ex21 = new EntityX2();

            TestBase.TestSerialization(ex21);

            var ex22 = new EntityX2();

            TestBase.TestSerialization(ex22);

            using (var em = Emf.CreateEntityManager())
            {
                em.Persist(ec1);
                em.Persist(ec2);

                em.Persist(ex1);
                em.Persist(ex2);
                em.Persist(ex21);
                em.Persist(ex22);
            }

            using (var em = Emf.CreateEntityManager())
            {
                {
                    var _ec = em.Fetch <EntityC>();
                    Assert.IsNotNull(_ec);
                    ISet <EntityC> s = new HashSet <EntityC>(_ec.ToList());
                    Assert.AreEqual(2, s.Count);
                    Assert.IsTrue(s.Contains(ec1));
                    Assert.IsTrue(s.Contains(ec2));
                }

                {
                    var _ec = em.Fetch <EntityBase>(new[] { typeof(EntityC) });
                    Assert.IsNotNull(_ec);
                    ISet <EntityBase> s = new HashSet <EntityBase>(_ec.ToList());
                    Assert.AreEqual(2, s.Count);
                    Assert.IsTrue(s.Contains(ec1));
                    Assert.IsTrue(s.Contains(ec2));
                }

                Assert.AreEqual(2, em.Fetch <EntityA>().Count());
                Assert.AreEqual(2, em.Fetch <EntityB>().Count());
                Assert.AreEqual(2, em.Fetch <EntityC>().Count());
                Assert.AreEqual(4, em.Fetch <EntityX>().Count());
                Assert.AreEqual(2, em.Fetch <EntityX2>().Count());
                Assert.AreEqual(6, em.Fetch <EntityXBase>().Count());
                Assert.AreEqual(2, em.Fetch <EntityY>().Count());
                Assert.AreEqual(10, em.Fetch <EntityBase>().Count());
                Assert.AreEqual(6, em.Fetch <EntityBase>(new[] { typeof(EntityX), typeof(EntityX2) }).Count());
                Assert.AreEqual(2, em.Fetch <EntityBase>(new[] { typeof(EntityY) }).Count());

                // pre-fetch
                // TODOAssert.AreEqual(2, em.Fetch<EntityC>(new[] { typeof(EntityC), typeof(EntityX), typeof(EntityY) }).Count());
            }
        }
Exemplo n.º 12
0
        // This will be called whenever the list changes.
        private void ServerEvent(object sender, SampleEventArgs e)
        {
            Console.WriteLine("-> ServerEvent incoming Message");

            // Verify the message contents are trustworthy.

            try
            {
                ByteBuffer byteBuffer = new ByteBuffer(e.Data);

                var message = NetMsg.MessageRoot.GetRootAsMessageRoot(byteBuffer); // read

                Console.WriteLine("-> ServerEvent incoming Message.DataType:" + message.DataType);

                switch (message.DataType)
                {
                case NetMsg.Data.ReturnStatus:

                    NetMsg.ReturnStatus status = new NetMsg.ReturnStatus();
                    status = message.GetData <NetMsg.ReturnStatus>(status);

                    switch (status.Status)
                    {
                    case NetMsg.MsgStatus.S_LoginSuccess:
                        _SocketServerManager.Client.HostInfo.isLoggedIn = true;
                        break;
                    }

                    break;

                case NetMsg.Data.Chatmessage:
                    NetMsg.Chatmessage msg = new NetMsg.Chatmessage();
                    msg = message.GetData <NetMsg.Chatmessage>(msg);

                    Console.WriteLine("NetMsg.Data.Chatmessage:" + msg.Text);

                    break;

                case NetMsg.Data.Scene:
                    XFBType.Scene scene = new XFBType.Scene();
                    scene = message.GetData <XFBType.Scene>(scene);

                    Console.WriteLine("NetMsg.Data.Scene:" + scene.Sceneid);

                    break;

                case NetMsg.Data.Entity:

                    Entity ent = new Entity();
                    ent = message.GetData <Entity>(ent);


                    Application.Current.Dispatcher.BeginInvoke(
                        DispatcherPriority.Normal,
                        new Action(() =>
                    {
                        var model = this.DataContext as SocketServerToolModel;

                        var entityExists = model.SceneItems.Where(x => x.Entity.EntityID == ent.EntityID);
                        if (entityExists.Any())
                        {
                            var existingEntity = entityExists.First();

                            for (int i = 0; i < ent.ComponentsLength; i++)
                            {
                                var comp = ent.GetComponents(i);

                                Console.WriteLine("NetMsg.Data.Entity -> ComponentType:" + comp.CompType);

                                if (comp.CompType == UComponent.BodyComponent)
                                {
                                    XFBType.BodyComponent fbBody = new XFBType.BodyComponent();
                                    comp.GetComp(fbBody);

                                    var body = existingEntity.Entity.GetComponentX <BodyComponent>() as BodyComponent;
                                    body.FB_BodyComponent.Location = new Interface.Scene.Services.Vector3()
                                    {
                                        X = fbBody.Position.X, Y = fbBody.Position.Y, Z = fbBody.Position.Z
                                    };
                                    body.FB_BodyComponent.Rotation = new Interface.Scene.Services.Quaternion()
                                    {
                                        W = fbBody.Rotation.W, X = fbBody.Rotation.X, Y = fbBody.Rotation.Y, Z = fbBody.Rotation.Z
                                    };
                                    body.FB_BodyComponent.Scale = new Interface.Scene.Services.Vector3()
                                    {
                                        X = fbBody.Scale.X, Y = fbBody.Scale.Y, Z = fbBody.Scale.Z
                                    };
                                }
                            }
                        }
                        else               // new entity

                        {
                            var newEntity = new EntityX()
                            {
                                EntityID = ent.EntityID,
                                NetID    = message.Netid,
                                SceneID  = message.Scene
                            };

                            for (int i = 0; i < ent.ComponentsLength; i++)
                            {
                                var comp = ent.GetComponents(i);

                                Console.WriteLine("NetMsg.Data.Entity -> ComponentType:" + comp.CompType);

                                if (comp.CompType == UComponent.BodyComponent)
                                {
                                    XFBType.BodyComponent fbBody = new XFBType.BodyComponent();
                                    comp.GetComp(fbBody);

                                    var body = new BodyComponent()
                                    {
                                        Parent = newEntity
                                    };
                                    body.FB_BodyComponent.Location = new Interface.Scene.Services.Vector3()
                                    {
                                        X = fbBody.Position.X, Y = fbBody.Position.Y, Z = fbBody.Position.Z
                                    };
                                    body.FB_BodyComponent.Rotation = new Interface.Scene.Services.Quaternion()
                                    {
                                        W = fbBody.Rotation.W, X = fbBody.Rotation.X, Y = fbBody.Rotation.Y, Z = fbBody.Rotation.Z
                                    };
                                    body.FB_BodyComponent.Scale = new Interface.Scene.Services.Vector3()
                                    {
                                        X = fbBody.Scale.X, Y = fbBody.Scale.Y, Z = fbBody.Scale.Z
                                    };
                                    newEntity.Components.Add(body);
                                }
                            }

                            model.SceneItems.Add(new SourceItem()
                            {
                                Entity = newEntity
                            });
                        }
                    }));

                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(e.Data);
            }
        }