Esempio n. 1
0
        public override IEnumerable <IOTData> GetData()
        {
            List <IOTData> iOTs;

            lock (Lockobj)
            {
                iOTs = DeepClone.Clone <IOTData>(iOTDatas);
                iOTDatas.Clear();
            }
            return(iOTs);
        }
Esempio n. 2
0
        public void DeepCloneTest()
        {
            DeepClone sample = new DeepClone();

            sample.Name = "A";
            sample.Users.Add("1");
            DeepClone cloned = (DeepClone)sample.Clone();

            Assert.AreEqual(sample.Name, cloned.Name);
            cloned.Users.Add("2");

            Assert.AreNotEqual(sample.Users.Count, cloned.Users.Count);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            System s1 = new ShallowClone(new TELO("A", 1));
            System s2 = s1.Clone();

            s1.telo.Lenght = 4;
            Console.WriteLine(s1.telo.Lenght + "  " + s2.telo.Lenght);

            System s3 = new DeepClone(new TELO("B", 2));
            System s4 = s3.Clone();

            s3.telo.Lenght = 5;
            Console.WriteLine(s3.telo.Lenght + "  " + s4.telo.Lenght);
            Console.Read();
        }
Esempio n. 4
0
        public void SubClassArray()
        {
            FieldCloneSubNodeModel model = new FieldCloneSubNodeModel();

            model.Node = new FieldCloneNormalModel()
            {
                Age = 1, Name = "111"
            };

            CloneBuilder <FieldCloneSubNodeModel> .CreateCloneDelegate();

            var newModel = DeepClone <FieldCloneSubNodeModel> .Clone(model);


            Assert.Equal(model.Node.Name, newModel.Node.Name);
            Assert.Equal(model.Node.Age, newModel.Node.Age);
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="length"></param>
        /// <param name="nItem">first item = 1</param>
        static void Clone_LoopBack_List_Test(int length, int nItem)
        {
            var item = Helper.CreateLoopBackItems(length, nItem);

            var clonedItem = (LinkedListItem)DeepClone.Clone(item);

            var originalHandler = new LinkedListHandler(item);
            var clonedHandler   = new LinkedListHandler(clonedItem);

            var isUnique = originalHandler.IsUnique(clonedHandler);
            var areEqual = originalHandler.AreEqual(clonedHandler);

            var s = $"Cloning Loopback list - (length={length}, loopback Item={nItem})...is unique? = {isUnique}, are equal? = {areEqual}";

            Console.WriteLine(s);
            Console.WriteLine();
        }
Esempio n. 6
0
 // AddDeployedPlayer adds both players and will make sure that the AI
 // player has deployed all ships
 public void AddDeployedPlayer(Player p)
 {
     if (_players[0] == null)
     {
         _players[0] = p;
         Clone[0]    = DeepClone.Clone(p);
     }
     else if (_players[1] == null)
     {
         _players[1] = p;
         Clone[1]    = DeepClone.Clone(p);
         CompleteDeployment();
     }
     else
     {
         throw new ApplicationException("You cannot add another player, the game already has two players.");
     }
 }
Esempio n. 7
0
        public void NotClassArray()
        {
            FieldCloneArrayModel model = new FieldCloneArrayModel();

            model.Name = new string[10];
            for (int i = 0; i < 10; i++)
            {
                model.Name[i] = i.ToString();
            }

            CloneBuilder <FieldCloneArrayModel> .CreateCloneDelegate();

            var newModel = DeepClone <FieldCloneArrayModel> .Clone(model);


            for (int i = 0; i < 10; i++)
            {
                Assert.Equal(model.Name[i], newModel.Name[i]);
            }
        }
Esempio n. 8
0
        public void PropClassCollectionArray()
        {
            PropCloneClassCollectionModel model = new PropCloneClassCollectionModel();

            model.Nodes = new List <PropCloneNormalModel>();
            for (int i = 0; i < 10; i++)
            {
                model.Nodes.Add(new PropCloneNormalModel()
                {
                    Age = i, Name = i.ToString()
                });
            }

            CloneBuilder <PropCloneClassCollectionModel> .CreateCloneDelegate();

            var newModel = DeepClone <PropCloneClassCollectionModel> .Clone(model);

            for (int i = 0; i < 10; i++)
            {
                Assert.Equal(model.Nodes[i].Name, newModel.Nodes[i].Name);
                Assert.Equal(model.Nodes[i].Age, newModel.Nodes[i].Age);
            }
        }
Esempio n. 9
0
        public void ClassArray()
        {
            FieldCloneClassArrayModel model = new FieldCloneClassArrayModel();

            model.Models = new FieldCloneNormalModel[10];
            for (int i = 0; i < 10; i++)
            {
                model.Models[i] = new FieldCloneNormalModel()
                {
                    Age = i, Name = i.ToString()
                };
            }

            CloneBuilder <FieldCloneClassArrayModel> .CreateCloneDelegate();

            var newModel = DeepClone <FieldCloneClassArrayModel> .Clone(model);


            for (int i = 0; i < 10; i++)
            {
                Assert.Equal(model.Models[i].Name, newModel.Models[i].Name);
                Assert.Equal(model.Models[i].Age, newModel.Models[i].Age);
            }
        }
Esempio n. 10
0
        public void PropNormal()
        {
            PropCloneNormalModel model = new PropCloneNormalModel();

            model.Age   = 1000;
            model.Name  = "ababab";
            model.Timer = DateTime.Now;
            model.money = 100000;

            model.Title = false;
            model.Id    = 100000;


            CloneBuilder <PropCloneNormalModel> .CreateCloneDelegate();

            var newModel = DeepClone <PropCloneNormalModel> .Clone(model);

            Assert.Equal(model.Id, newModel.Id);
            Assert.Equal(model.Title, newModel.Title);
            Assert.Equal(model.money, newModel.money);
            Assert.Equal(model.Timer, newModel.Timer);
            Assert.Equal(model.Age, newModel.Age);
            Assert.Equal(model.Name, newModel.Name);
        }
Esempio n. 11
0
 object IDeepDefinitionClone.Clone()
 {
     return(DeepClone.Clone(this));
 }
Esempio n. 12
0
 object IDeepDefinitionClone.Clone()
 {
     //该方法有问题
     return(DeepClone.Clone(this));
 }
Esempio n. 13
0
        private void AddUnit(GameCommand cmdReceived, PlayerGame playerGame, Game game)
        {
            Unit newUnitType = game.AvailableUnits.Where(c => c.Id == cmdReceived.ObjectId).FirstOrDefault();

            if (newUnitType == null)
            {
                new CommandFeedback(cmdReceived, enCommandStatus.Rejected, newUnitType.Name + " not found in the game").Save(this.FAppPrivate);
            }
            else
            {
                if (playerGame == null)
                {
                    new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "PlayerGame not found").Save(this.FAppPrivate);
                }
                else
                {
                    if (this.flPlayerUnits.TypedItems <PlayerUnit>().Where(c => c.UserId == cmdReceived.UserId && c.Unit.UnitTypeId == newUnitType.UnitTypeId && c.Unit.UserId == playerGame.UserId).Count() >= newUnitType.MaxNumberOf)
                    {
                        new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Already too many " + newUnitType.Name + "s in the game").Save(this.FAppPrivate);
                    }
                    else
                    {
                        // Unit unitsOnPosition = game.UnitsInGame.Where(c => c.Position.Xpos == playerGame.Spawn.Xpos && c.Position.Ypos == playerGame.Spawn.Ypos).FirstOrDefault();
                        PlayerUnit unitsOnPosition = this.flPlayerUnits.TypedItems <PlayerUnit>().Where(c => c.Unit.Position.Xpos == playerGame.Spawn.Xpos && c.Unit.Position.Ypos == playerGame.Spawn.Ypos).FirstOrDefault();

                        if (unitsOnPosition != null)
                        {
                            new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Could not spawn, spawn is occupied").Save(this.FAppPrivate);
                        }
                        else
                        {
                            Unit newUnit = DeepClone.CloneJson <Unit>(newUnitType);
                            newUnit.Id            = Guid.NewGuid().ToString();
                            newUnit.CreatedAt     = DateTime.Now;
                            newUnit.UpdatedAt     = DateTime.Now;
                            newUnit.Position.Xpos = playerGame.Spawn.Xpos;
                            newUnit.Position.Ypos = playerGame.Spawn.Ypos;
                            newUnit.UserId        = cmdReceived.UserId;


                            game.UnitsInGame.Add(newUnit);
                            //TEST game.Save(this.FAppPublic);

                            PlayerUnit newPlayerUnit = new PlayerUnit(game.Id, playerGame.UserId, newUnit);
                            newPlayerUnit.Save(this.FAppPrivate);

                            UpdateRadarRange(playerGame, game, newUnit); //update map for player

                            //playerGame.Units.Add(newUnit);
                            //playerGame.Save(this.FAppPrivate);

                            //subscribe unit to game ticker
                            this.gameUpdateList.Add(new GameSubscriber()
                            {
                                FireObject = playerGame, GameObject = newUnit, Game = game, Unit = newUnit
                            });

                            new CommandFeedback(cmdReceived, enCommandStatus.Accepted, newUnitType.Name + " added to the game").Save(this.FAppPrivate);
                        }
                    }
                }
            }
        }
Esempio n. 14
0
 public DeepClone(DeepClone d)
 {
     telo        = new TELO();
     telo.Lenght = d.telo.Lenght;
     telo.Name   = d.telo.Name;
 }