Exemple #1
0
        public void OnModuleClientLeave()
        {
            NWPlayer oPC = (_.GetExitingObject());

            if (!oPC.IsPlayer)
            {
                return;
            }

            foreach (var pin in _data.Where <PCMapPin>(x => x.PlayerID == oPC.GlobalID))
            {
                _data.SubmitDataChange(pin, DatabaseActionType.Delete);
            }

            for (int x = 0; x < GetNumberOfMapPins(oPC); x++)
            {
                MapPin mapPin = GetMapPin(oPC, x);

                if (string.IsNullOrWhiteSpace(mapPin.Text))
                {
                    continue;
                }

                PCMapPin entity = new PCMapPin
                {
                    AreaTag   = mapPin.Area.Tag,
                    NoteText  = mapPin.Text,
                    PlayerID  = oPC.GlobalID,
                    PositionX = mapPin.PositionX,
                    PositionY = mapPin.PositionY
                };

                _data.SubmitDataChange(entity, DatabaseActionType.Insert);
            }
        }
Exemple #2
0
        public void GetByID_OneItem_ReturnsPCMapPin()
        {
            // Arrange
            var      id     = Guid.NewGuid();
            PCMapPin entity = new PCMapPin {
                ID = id
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCMapPin>(entity));

            // Assert
            Assert.AreNotSame(entity, _cache.GetByID(id));
        }
Exemple #3
0
        public void GetByID_TwoItems_ReturnsCorrectObject()
        {
            // Arrange
            var      id1     = Guid.NewGuid();
            var      id2     = Guid.NewGuid();
            PCMapPin entity1 = new PCMapPin {
                ID = id1
            };
            PCMapPin entity2 = new PCMapPin {
                ID = id2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCMapPin>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCMapPin>(entity2));

            // Assert
            Assert.AreNotSame(entity1, _cache.GetByID(id1));
            Assert.AreNotSame(entity2, _cache.GetByID(id2));
        }
Exemple #4
0
        public void GetByID_RemovedItem_ReturnsCorrectObject()
        {
            // Arrange
            var      id1     = Guid.NewGuid();
            var      id2     = Guid.NewGuid();
            PCMapPin entity1 = new PCMapPin {
                ID = id1
            };
            PCMapPin entity2 = new PCMapPin {
                ID = id2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCMapPin>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCMapPin>(entity2));
            MessageHub.Instance.Publish(new OnCacheObjectDeleted <PCMapPin>(entity1));

            // Assert
            Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(id1); });
            Assert.AreNotSame(entity2, _cache.GetByID(id2));
        }
Exemple #5
0
        private static void OnModuleLeave()
        {
            NWPlayer oPC = (_.GetExitingObject());

            if (!oPC.IsPlayer)
            {
                return;
            }

            var mapPins = DataService.Where <PCMapPin>(x => x.PlayerID == oPC.GlobalID).ToList();

            for (int x = mapPins.Count - 1; x >= 0; x--)
            {
                var pin = mapPins.ElementAt(x);
                DataService.SubmitDataChange(pin, DatabaseActionType.Delete);
            }

            for (int x = 0; x < GetNumberOfMapPins(oPC); x++)
            {
                MapPin mapPin = GetMapPin(oPC, x);

                if (string.IsNullOrWhiteSpace(mapPin.Text))
                {
                    continue;
                }

                PCMapPin entity = new PCMapPin
                {
                    AreaTag   = mapPin.Area.Tag,
                    NoteText  = mapPin.Text,
                    PlayerID  = oPC.GlobalID,
                    PositionX = mapPin.PositionX,
                    PositionY = mapPin.PositionY
                };

                DataService.SubmitDataChange(entity, DatabaseActionType.Insert);
            }
        }
        public void OnModuleClientLeave()
        {
            NWPlayer oPC = NWPlayer.Wrap(_.GetExitingObject());

            if (!oPC.IsPlayer)
            {
                return;
            }

            foreach (var pin in _db.PCMapPins.Where(x => x.PlayerID == oPC.GlobalID))
            {
                _db.PCMapPins.Remove(pin);
            }

            for (int x = 0; x < GetNumberOfMapPins(oPC); x++)
            {
                MapPin mapPin = GetMapPin(oPC, x);

                if (string.IsNullOrWhiteSpace(mapPin.Text))
                {
                    continue;
                }

                PCMapPin entity = new PCMapPin
                {
                    AreaTag   = mapPin.Area.Tag,
                    NoteText  = mapPin.Text,
                    PlayerID  = oPC.GlobalID,
                    PositionX = mapPin.PositionX,
                    PositionY = mapPin.PositionY
                };

                _db.PCMapPins.Add(entity);
            }

            _db.SaveChanges();
        }