Esempio n. 1
0
        public void If_data_store_thorws_exception_facade_state_is_reloaded()
        {
            var changeSetId  = ChangeSetId.NewUniqueId();
            var objectId     = ObjectId.NewUniqueId();
            var objectTypeId = ObjectTypeId.NewUniqueId();
            var commands     = new List <AbstractCommand>
            {
                new CreateObjectCommand(objectTypeId, objectId)
            };

            dataStore.ChangeSets.Add(new ChangeSet(changeSetId, null, "Some comment", commands));
            dataStore.OnStored += (sender, args) => { throw new Exception("Some nasty exception happened AFTER storing value"); };
            var facade = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory());

            var newChangeSet = new UncommittedChangeSet(changeSetId, "Some comment");

            newChangeSet.Add(new ModifyAttributeCommand(objectId, "TextValue", "SomeText"));

            try
            {
                facade.Commit(newChangeSet);
            }
            catch (Exception)
            {
                //Intentionally swallowing exception
            }

            var o = facade.GetById(objectId, newChangeSet.Id); //Would throw if new change set was not loaded into memory.
        }
 private ObjectState(ObjectState objectStateToClone)
 {
     id = objectStateToClone.id;
     typeId = objectStateToClone.typeId;
     relations = objectStateToClone.relations.Clone();
     attributes = new Dictionary<string, object>(objectStateToClone.attributes);
 }
Esempio n. 3
0
        protected WowObject(ObjectTypeId typeid)
        {
            m_updateMask = new BitArray((int)UpdateFields.GetCount(typeid, uint.MaxValue));

            this.TypeId = typeid;
            this.TypeMask = (ObjectTypeMask)(1 << (int)typeid) | ObjectTypeMask.Object;
        }
 public ObjectTypeDescriptor(Type runtimeType, ObjectTypeId objectTypeId, IEnumerable<AttributeDescriptor> attributes, IEnumerable<RelationDescriptor> relations)
 {
     this.attributes = attributes.ToList();
     this.relations = relations.ToList();
     this.objectTypeId = objectTypeId;
     this.runtimeType = runtimeType;
 }
 public ObjectState(ObjectId id, ObjectTypeId typeId)
 {
     this.id = id;
     this.typeId = typeId;
     relations = new ObjectRelationCollection();
     attributes = new Dictionary<string, object>();
 }
Esempio n. 6
0
        /// <summary>
        /// Tries to get the first available entity ID.
        /// </summary>

        /// <returns>a non-zero ID if one was available; 0 otheriwse</returns>
        /// <remarks>If an available ID is found, it will be removed from the database.</remarks>
        public static uint GetLowEntityId(ObjectTypeId type)
        {
            // Lock so someone else doesn't grab the same row
            s_idLock.Enter();

            try
            {
                EntityIdStorage eid = GetFirstRecycledId(type);

                if (eid == null)
                {
                    return(0);
                }
                else
                {
                    RemoveRecycledId(eid);

                    return((uint)eid.EntityId);
                }
            }
            finally
            {
                s_idLock.Exit();
            }
        }
Esempio n. 7
0
 private static int GetMaxValues(ObjectTypeId typeId)
 {
     switch(typeId) {
     case ObjectTypeId.Object:
         return (int)UpdateFields.OBJECT_END;
     case ObjectTypeId.Item:
         return (int)UpdateFields.ITEM_END;
     case ObjectTypeId.Container:
         return (int)UpdateFields.CONTAINER_END;
     case ObjectTypeId.Unit:
         return (int)UpdateFields.UNIT_END;
     case ObjectTypeId.Player:
         return (int)UpdateFields.PLAYER_END;
     case ObjectTypeId.GameObject:
         return (int)UpdateFields.GAMEOBJECT_END;
     case ObjectTypeId.DynamicObject:
         return (int)UpdateFields.DYNAMICOBJECT_END;
     case ObjectTypeId.Corpse:
         return (int)UpdateFields.CORPSE_END;
     case ObjectTypeId.AIGroup:
         return (int)UpdateFields.OBJECT_END;
     case ObjectTypeId.AreaTrigger:
         return (int)UpdateFields.OBJECT_END;
     default:
         throw new ArgumentOutOfRangeException();
     }
 }
Esempio n. 8
0
        protected WowObject(ObjectTypeId typeid)
        {
            m_updateMask = new BitArray((int)UpdateFields.GetCount(typeid, uint.MaxValue));

            this.TypeId   = typeid;
            this.TypeMask = (ObjectTypeMask)(1 << (int)typeid) | ObjectTypeMask.Object;
        }
        public void It_can_attach_one_object_to_another_event_if_it_was_created_as_part_of_previous_snapshot()
        {
            const string relationName    = "RelationName";
            var          refererObjectId = ObjectId.NewUniqueId();
            var          refereeObjectId = ObjectId.NewUniqueId();
            var          objectTypeId    = ObjectTypeId.NewUniqueId();

            var changeSet = new UncommittedChangeSet(null, "Some comment")
                            .Add(new CreateObjectCommand(objectTypeId, refererObjectId))
                            .Add(new CreateObjectCommand(objectTypeId, refereeObjectId));

            var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet);

            var nextChangeSet = new UncommittedChangeSet(changeSet.Id, "Some comment")
                                .Add(new AttachObjectCommand(refererObjectId, refereeObjectId, relationName));
            var nextSnapshot = new IncrementalCachingSnapshot(snapshot, commandExecutor, nextChangeSet);

            var currentObjectState = nextSnapshot.GetById(refererObjectId);

            Assert.IsTrue(currentObjectState.GetRelated(relationName).Any(x => x == refereeObjectId));

            var previousObjectState = snapshot.GetById(refererObjectId);

            Assert.IsFalse(previousObjectState.GetRelated(relationName).Any(x => x == refereeObjectId));
        }
Esempio n. 10
0
		/// <summary>
		/// Tries to get the first available entity ID.
		/// </summary>
		
		/// <returns>a non-zero ID if one was available; 0 otheriwse</returns>
		/// <remarks>If an available ID is found, it will be removed from the database.</remarks>
		public static uint GetLowEntityId(ObjectTypeId type)
		{
			// Lock so someone else doesn't grab the same row
			s_idLock.Enter();

			try
			{
				EntityIdStorage eid = GetFirstRecycledId(type);

				if (eid == null)
				{
					return 0;
				}
				else
				{
					RemoveRecycledId(eid);

					return (uint)eid.EntityId;
				}
			}
			finally
			{
				s_idLock.Exit();
			}
		}
Esempio n. 11
0
        public static string ToString(this ObjectTypeId type, uint id)
        {
            string str;

            switch (type)
            {
            case ObjectTypeId.Item:
                str = ((int)id) + " (" + id + ")";
                break;

            case ObjectTypeId.Unit:
                str = ((int)id) + " (" + id + ")";
                break;

            case ObjectTypeId.GameObject:
                str = ((int)id) + " (" + id + ")";
                break;

            default:
                str = ((int)id) + " (" + id + ")";
                break;
            }

            return(str);
        }
Esempio n. 12
0
		static void AddValues(ObjectTypeId objectType, ObjectTypeId includedEnumType)
		{
			object[] included;
			if (includedEnumType != ObjectTypeId.None)
			{
				included = FieldValues[includedEnumType];
			}
			else
			{
				included = null;
			}

			var arr = Enum.GetValues(EnumTypeMap[objectType]);
			var obj = new object[arr.Length + (included != null ? included.Length : 0)];
			int i = 0;

			if (included != null)
			{
				foreach (var val in included)
				{
					obj[i++] = val;
				}
			}
			foreach (var val in arr)
			{
				obj[i++] = val;
			}

			FieldValues[objectType] = obj;
		}
Esempio n. 13
0
        public MovementBlock(UpdateBlock update)
        {
            Update       = update;
            UpdateFlags  = (UpdateFlags)update.ReadUShort();
            ObjectTypeId = update.ObjectType;

            this.Parse();
        }
        public void SetUp()
        {
            var objectTypeId = new ObjectTypeId(new Guid(objectTypeIdValue));
            var repository   = new ObjectTypeDescriptorRepository();

            repository.RegisterUsingReflection(typeof(TestingObject));
            typeDescriptor = repository.GetByTypeId(objectTypeId);
        }
Esempio n. 15
0
 public static UpdateFieldCollection Get(ObjectTypeId type)
 {
     if (Collections[0] == null)
     {
         Init();
     }
     return(Collections[(int)type]);
 }
Esempio n. 16
0
		public MovementBlock(UpdateBlock update)
		{
			Update = update;
			UpdateFlags = (UpdateFlags)update.ReadUShort();
			ObjectTypeId = update.ObjectType;

			this.Parse();
		}
 public void ExecuteCommands(ObjectTypeId objectTypeId, ICommandExecutor commandExecutor, CompositeCommandExecutionContext compositeContext)
 {
     foreach (var command in commands)
     {
         var context = compositeContext.GetFor(command.TargetObjectId);
         commandExecutor.Execute(command, context);
     }
 }
        public void SetUp()
        {
            var objectTypeId = new ObjectTypeId(new Guid(objectTypeIdValue));
            var repository = new ObjectTypeDescriptorRepository();

            repository.RegisterUsingReflection(typeof(TestingObject));
            typeDescriptor = repository.GetByTypeId(objectTypeId);
        }
        public void It_returns_null_for_not_registered_type_id()
        {
            var objectTypeId = ObjectTypeId.NewUniqueId();
            var repository   = new ObjectTypeDescriptorRepository();

            var notRegistered = repository.GetByTypeId(objectTypeId);

            Assert.IsNull(notRegistered);
        }
 protected override IEnumerable<ObjectState> RetrieveData(ObjectTypeId objectTypeId)
 {
     var data = base.RetrieveData(objectTypeId);
     foreach (var loadedState in data)
     {
         loadedStates[loadedState.Id] = loadedState;
     }
     return data;
 }
 public void SetUp()
 {
     objectId       = ObjectId.NewUniqueId();
     objectTypeId   = new ObjectTypeId(new Guid(objectTypeIdValue));
     changeSetId    = ChangeSetId.NewUniqueId();
     typeRepository = new ObjectTypeDescriptorRepository().RegisterUsingReflection <TestingObject>();
     dataFacadeMock = new Mock <IDataFacade>();
     objectFacade   = new ObjectFacade(dataFacadeMock.Object, typeRepository, new Mock <ICommandExecutor>().Object);
 }
Esempio n. 22
0
        public void It_can_create_new_instance()
        {
            var contextMock = new Mock <ICommandExecutionContext>();
            var handler     = new CreateTestingCommandHandler();

            handler.Handle(new TestingCommand(ObjectId.NewUniqueId()), contextMock.Object);

            contextMock.Verify(x => x.Create(ObjectTypeId.Parse("4FBF64D4-96A5-4693-87ED-670E88DDD705")), Times.Once());
        }
Esempio n. 23
0
        public bool CustomFieldCreatingHasNoInitData_PreTransitionCRUD(string transition)
        {
            switch (transition.ToUpper())
            {
            case "ACCEPT":
                if (ASPxEdit.ValidateEditorsInContainer(formlayoutGeneralInfo))
                {
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        Guid selectedCustomFieldTypeId =
                            Guid.Parse(cbbCustomFieldType.SelectedItem.Value.ToString());
                        CustomFieldType customFieldType =
                            uow.GetObjectByKey <CustomFieldType>(selectedCustomFieldTypeId);
                        //Create new CustomField
                        NAS.DAL.CMS.ObjectDocument.CustomField customField =
                            new NAS.DAL.CMS.ObjectDocument.CustomField(uow)
                        {
                            CustomFieldId     = Guid.NewGuid(),
                            Name              = txtCustomFieldName.Text,
                            CustomFieldTypeId = customFieldType
                        };
                        //Attach CustomField to ObjectTypeId
                        if (ObjectTypeId != null && !ObjectTypeId.Equals(Guid.Empty))
                        {
                            /*2013-12-12 Khoa.Truong DEL START
                             * Decoupling with the client using this form
                             * //Guid objectTypeId = ((ObjectTypeCustomFieldListing)Parent).ObjectTypeId;
                             * 2013-12-12 Khoa.Truong DEL END*/
                            ObjectType            objectType            = uow.GetObjectByKey <ObjectType>(ObjectTypeId);
                            ObjectTypeCustomField objectTypeCustomField = new ObjectTypeCustomField(uow)
                            {
                                ObjectTypeCustomFieldId = Guid.NewGuid(),
                                CustomFieldId           = customField,
                                ObjectTypeId            = objectType
                            };
                        }
                        //Attach new custom fields for all object of the object type

                        /*These code is replace with lazy updating for custom fields of each object
                         * //ObjectBO objectBO = new ObjectBO();
                         * //objectBO.UpdateCMSObjects(uow, objectTypeId);
                         */

                        uow.CommitChanges();
                    }
                }
                else
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }
        private void FillGroupList()
        {
            var sizes = SetupGroups();

            for (ObjectTypeId group = ObjectTypeId.Object; group < (ObjectTypeId)UpdateField.ObjectTypeCount; group++)
            {
                var size = sizes[(int)group];
                Array.Resize(ref m_updateFieldsByGroup[(int)group], (int)size);
            }
        }
        public void It_return_all_unempty_contexts()
        {
            var composite = new CompositeCommandExecutionContext();

            composite.GetFor(ObjectId.NewUniqueId()).Create(ObjectTypeId.NewUniqueId());
            composite.GetFor(ObjectId.NewUniqueId()).Create(ObjectTypeId.NewUniqueId());
            composite.GetFor(ObjectId.NewUniqueId());

            Assert.AreEqual(2, composite.GetAll().Count());
        }
Esempio n. 26
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (DisplayInfo != null ? DisplayInfo.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Image != null ? Image.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ObjectTypeId?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
Esempio n. 27
0
        public static UpdateField GetUpdateField(uint index, ObjectTypeId type)
        {
            if (index < (uint)ObjectUpdateFields.End)
            {
                return(GetUpdateField((ObjectUpdateFields)index));
            }

            switch (type)
            {
            // Complicated cases
            case ObjectTypeId.Player:
                if (index < (uint)UnitUpdateFields.End)
                {
                    return(GetUpdateField((UnitUpdateFields)index));
                }
                else
                {
                    return(GetUpdateField((PlayerUpdateFields)index));
                }

            case ObjectTypeId.Container:
                if (index < (uint)ItemUpdateFields.End)
                {
                    return(GetUpdateField((ItemUpdateFields)index));
                }
                else
                {
                    return(GetUpdateField((ContainerUpdateFields)index));
                }

            // Simple cases
            case ObjectTypeId.Unit:
                return(GetUpdateField((UnitUpdateFields)index));

            case ObjectTypeId.GameObject:
                return(GetUpdateField((GameObjectUpdateFields)index));

            case ObjectTypeId.DynamicObject:
                return(GetUpdateField((DynamicObjectUpdateFields)index));

            case ObjectTypeId.Corpse:
                return(GetUpdateField((CorpseUpdateFields)index));

            case ObjectTypeId.Item:
                return(GetUpdateField((ItemUpdateFields)index));

            case ObjectTypeId.AreaTrigger:
                return(GetUpdateField((AreaTriggerUpdateFields)index));

            // Must never happen
            default:
                Console.WriteLine("Error: Called GetUpdateField(index={0}, type={1})", index, type);
                return(GetUpdateField((ObjectUpdateFields)index));
            }
        }
        public void It_throws_exception_when_trying_to_register_two_types_with_same_id()
        {
            var objectTypeId         = ObjectTypeId.NewUniqueId();
            var repository           = new ObjectTypeDescriptorRepository();
            var firstTypeDescriptor  = new ObjectTypeDescriptor(typeof(object), objectTypeId, new AttributeDescriptor[] { }, new RelationDescriptor[] { });
            var secondTypeDescriptor = new ObjectTypeDescriptor(typeof(int), objectTypeId, new AttributeDescriptor[] { }, new RelationDescriptor[] { });

            repository.RegisterTypeDescriptor(firstTypeDescriptor);

            Assert.Throws <InvalidOperationException>(() => repository.RegisterTypeDescriptor(secondTypeDescriptor));
        }
Esempio n. 29
0
        public UpdateBlock(ParsedUpdatePacket parser, int index)
        {
            this.index = index;
            packet     = parser;
            //Offset = parser.index;

            Type = (UpdateType)ReadByte();

            if (!Enum.IsDefined(typeof(UpdateType), (byte)Type))
            {
                throw new Exception("Invalid UpdateType '" + Type + "' in Block " + this);
            }

            // Console.WriteLine("Reading {0}-Block...", Type);

            if (Type == UpdateType.OutOfRange ||
                Type == UpdateType.Near)
            {
                var count = ReadUInt();
                EntityIds = new EntityId[count];
                for (var i = 0; i < count; i++)
                {
                    EntityIds[i] = ReadPackedEntityId();
                }
            }
            else
            {
                EntityId = ReadPackedEntityId();

                if (Type == UpdateType.Create ||
                    Type == UpdateType.CreateSelf)
                {
                    ObjectType = (ObjectTypeId)ReadByte();
                }

                if (Type == UpdateType.Create ||
                    Type == UpdateType.CreateSelf ||
                    Type == UpdateType.Movement)
                {
                    m_movement = ReadMovementBlock();
                }

                if (Type != UpdateType.Movement)
                {
                    Values = ReadValues();
                }
            }

            if (Type != UpdateType.Create && Type != UpdateType.CreateSelf)
            {
                ObjectType = EntityId.ObjectType;
            }
        }
Esempio n. 30
0
        public UpdateBlock(ParsedUpdatePacket parser, int index)
        {
            this.index = index;
            packet = parser;
            //Offset = parser.index;

            Type = (UpdateType)ReadByte();

            if (!Enum.IsDefined(typeof(UpdateType), (byte)Type))
            {
                throw new Exception("Invalid UpdateType '" + Type + "' in Block " + this);
            }

            // Console.WriteLine("Reading {0}-Block...", Type);

            if (Type == UpdateType.OutOfRange ||
                Type == UpdateType.Near)
            {
                var count = ReadUInt();
                EntityIds = new EntityId[count];
                for (var i = 0; i < count; i++)
                {
                    EntityIds[i] = ReadPackedEntityId();
                }
            }
            else
            {
                EntityId = ReadPackedEntityId();

                if (Type == UpdateType.Create ||
                    Type == UpdateType.CreateSelf)
                {
                    ObjectType = (ObjectTypeId)ReadByte();
                }

                if (Type == UpdateType.Create ||
                    Type == UpdateType.CreateSelf ||
                    Type == UpdateType.Movement)
                {
                    m_movement = ReadMovementBlock();
                }

                if (Type != UpdateType.Movement)
                {
                    Values = ReadValues();
                }
            }

            if (Type != UpdateType.Create && Type != UpdateType.CreateSelf)
            {
                ObjectType = EntityId.ObjectType;
            }
        }
Esempio n. 31
0
 protected WowUnit(ObjectTypeId type)
     : base(type)
 {
     this.CombatReach     = 1.0f;
     this.BoundingRadius  = 1.0f;
     this.CastHaste       = 1.0f;
     this.CastSpeed       = 1.0f;
     this.HoverHeight     = 1.0f;
     this.BaseAttackTime  = 2000;
     this.BaseAttackTime2 = 2000;
     this.Sheath          = SheathType.Melee;
 }
        public void It_returns_object_type_by_its_id()
        {
            var objectTypeId   = ObjectTypeId.NewUniqueId();
            var repository     = new ObjectTypeDescriptorRepository();
            var typeDescriptor = new ObjectTypeDescriptor(typeof(object), objectTypeId, new AttributeDescriptor[] {},
                                                          new RelationDescriptor[] {});

            repository.RegisterTypeDescriptor(typeDescriptor);
            var registered = repository.GetByTypeId(objectTypeId);

            Assert.IsNotNull(registered);
        }
Esempio n. 33
0
        public static void Init()
        {
            InitInheritance();
            FixFields();
            for (ObjectTypeId id = ObjectTypeId.Object; id < ObjectTypeId.Count; ++id)
            {
                UpdateField[] fields           = (UpdateField[])UpdateFields.AllFields[(int)id].Clone();
                int           offset           = int.MaxValue;
                bool          hasPrivateFields = false;
                UpdateField   updateField1     = null;
                for (int index = 0; index < fields.Length; ++index)
                {
                    UpdateField updateField2 = fields[index];
                    if (updateField2 != null)
                    {
                        if (offset == int.MaxValue)
                        {
                            offset = (int)updateField2.Offset;
                        }
                        updateField1     = updateField2;
                        hasPrivateFields = hasPrivateFields ||
                                           (updateField2.Flags & UpdateFieldFlags.Private) != UpdateFieldFlags.None;
                    }
                    else if (updateField1 != null)
                    {
                        fields[index] = updateField1;
                    }
                }

                ObjectTypeId          inheritedTypeId = InheritedTypeIds[(int)id];
                UpdateFieldCollection baseCollection;
                if (inheritedTypeId != ObjectTypeId.None)
                {
                    baseCollection = Collections[(int)inheritedTypeId];
                    if (baseCollection.Fields.Length >= fields.Length)
                    {
                        throw new Exception("BaseCollection of UpdateFields equal or bigger than inherited collection");
                    }
                    for (int index = 0; index < baseCollection.Fields.Length; ++index)
                    {
                        UpdateField field = baseCollection.Fields[index];
                        fields[index] = field;
                    }
                }
                else
                {
                    baseCollection = null;
                }

                Collections[(int)id] =
                    new UpdateFieldCollection(id, fields, baseCollection, offset, hasPrivateFields);
            }
        }
        public void It_can_create_object_and_get_by_id()
        {
            var objectId     = ObjectId.NewUniqueId();
            var objectTypeId = ObjectTypeId.NewUniqueId();

            var changeSet = new UncommittedChangeSet(null, "Some comment")
                            .Add(new CreateObjectCommand(objectTypeId, objectId));

            var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet);
            var o        = snapshot.GetById(objectId);

            Assert.IsNotNull(o);
        }
Esempio n. 35
0
		public static string GetFriendlyName(ObjectTypeId type, uint field)
		{
			var infos = FieldRenderers[type];
			if (infos == null) {
				throw new Exception("Invalid ObjectTypeId: " + type);
			}
			
			var info = infos.GetFieldInfo(field);
			if (info == null) {
				throw new Exception(string.Format("Invalid Field " + field + " for Type " + type));
			}
			return info.Name.ToFriendlyName();
		}
Esempio n. 36
0
        /// <summary>
        /// Tries to retrieve an entity ID from the database.
        /// </summary>
        /// <param name="lowerId">the ID to check for</param>
        /// <param name="type">the entity ID type to check for</param>
        /// <returns>true if the ID has already been recycled; false if not</returns>
        public static EntityIdStorage GetEntityId(uint lowerId, ObjectTypeId type)
        {
            s_idLock.Enter();

            try
            {
                return(FindFirst(new EqExpression("EntityId", (long)lowerId), new EqExpression("EntityType", type)));
            }
            finally
            {
                s_idLock.Exit();
            }
        }
        public void It_can_get_object_by_id_even_if_it_was_creates_as_part_of_previous_snapshot()
        {
            var objectId     = ObjectId.NewUniqueId();
            var objectTypeId = ObjectTypeId.NewUniqueId();

            var changeSet = new UncommittedChangeSet(null, "Some comment")
                            .Add(new CreateObjectCommand(objectTypeId, objectId));

            var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet);

            var nextSnapshot = new IncrementalCachingSnapshot(snapshot, commandExecutor, new UncommittedChangeSet(changeSet.Id, "Some comment"));
            var o            = nextSnapshot.GetById(objectId);

            Assert.IsNotNull(o);
        }
        public void It_stores_and_returns_object_attributes()
        {
            const string attributeName = "Attribute";
            var          objectId      = ObjectId.NewUniqueId();
            var          objectTypeId  = ObjectTypeId.NewUniqueId();

            var changeSet = new UncommittedChangeSet(null, "Some comment")
                            .Add(new CreateObjectCommand(objectTypeId, objectId))
                            .Add(new ModifyAttributeCommand(objectId, attributeName, "SomeValue"));

            var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet);
            var o        = snapshot.GetById(objectId);

            Assert.AreEqual("SomeValue", o.GetAttributeValue(attributeName));
        }
Esempio n. 39
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Type != 0)
            {
                hash ^= Type.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.IntValue)
            {
                hash ^= IntValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.LongIntValue)
            {
                hash ^= LongIntValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.BoolValue)
            {
                hash ^= BoolValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.StringValue)
            {
                hash ^= StringValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.BytesValue)
            {
                hash ^= BytesValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.FloatValue)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(FloatValue);
            }
            if (valueCase_ == ValueOneofCase.DoubleValue)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleValue);
            }
            if (ObjectTypeId != 0)
            {
                hash ^= ObjectTypeId.GetHashCode();
            }
            hash ^= (int)valueCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 40
0
        public void It_creates_object_and_returns_it_by_id()
        {
            var changeSetId  = ChangeSetId.NewUniqueId();
            var objectId     = ObjectId.NewUniqueId();
            var objectTypeId = ObjectTypeId.NewUniqueId();
            var commands     = new List <AbstractCommand>
            {
                new CreateObjectCommand(objectTypeId, objectId)
            };

            dataStore.ChangeSets.Add(new ChangeSet(changeSetId, null, "Some comment", commands));
            var facade = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory());

            var o = facade.GetById(objectId, changeSetId);

            Assert.IsNotNull(o);
        }
Esempio n. 41
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Categories?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (DisplayInfo != null ? DisplayInfo.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (EffectivenessAgainstAir?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (EffectivenessAgainstInfantry?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (EffectivenessAgainstVehicles?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Image != null ? Image.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ObjectTypeId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (StandardEnergyCost != null ? StandardEnergyCost.GetHashCode() : 0);;
         hashCode = (hashCode * 397) ^ (StandardPopulationCost != null ? StandardPopulationCost.GetHashCode() : 0);;
         hashCode = (hashCode * 397) ^ (StandardSupplyCost != null ? StandardSupplyCost.GetHashCode() : 0);
         return(hashCode);
     }
 }
Esempio n. 42
0
        public FieldRenderer(ObjectTypeId enumType)
        {
            EnumType = enumType;

            var fields = FieldRenderUtil.GetValues(enumType);

            Fields = new FieldRenderInfo[fields.Length];

            uint i = 0;

            var fieldDefs = UpdateFieldMgr.Get(enumType);
            foreach (var e in fields)
            {
                var fieldDef = fieldDefs.Fields.Get((uint)((int)e));

                UpdateFieldType type = fieldDef == null ? UpdateFieldType.UInt32 : fieldDef.Type;
                Fields[i] = new FieldRenderInfo(e, type);
                i++;
            }
        }
Esempio n. 43
0
		internal UpdateFieldCollection(ObjectTypeId id, UpdateField[] fields,
			UpdateFieldCollection baseCollection, int offset, bool hasPrivateFields)
		{
			TypeId = id;
			Fields = fields;
			FieldFlags = new UpdateFieldFlags[fields.Length];
			var ownerIndices = new List<int>(25);
			var groupIndices = new List<int>(25);
			var dynamicIndices = new List<int>(25);
			for (var i = 0; i < Fields.Length; i++)
			{
				var field = Fields[i];
				FieldFlags[i] = field.Flags;
				if ((field.Flags & UpdateFieldFlags.Dynamic) != 0)
				{
					dynamicIndices.Add(i);
				}
				else
				{
					if ((field.Flags & UpdateFieldFlags.OwnerOnly) != 0)
					{
						ownerIndices.Add(i);
					}
					if ((field.Flags & UpdateFieldFlags.GroupOnly) != 0)
					{
						groupIndices.Add(i);
					}
				}
			}
			OwnerIndices = ownerIndices.ToArray();
			GroupIndices = groupIndices.ToArray();
			DynamicIndices = dynamicIndices.ToArray();
			BaseCollection = baseCollection;
			Offset = offset;
			HasPrivateFields = hasPrivateFields;
		}
Esempio n. 44
0
 protected WowItem(ObjectTypeId type)
     : base(type)
 {
 }
Esempio n. 45
0
		public ExtendedUpdateFieldId(CorpseFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Corpse;
		}
Esempio n. 46
0
		public ExtendedUpdateFieldId(ItemFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Item;
		}
Esempio n. 47
0
		public ExtendedUpdateFieldId(ContainerFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Container;
		}
Esempio n. 48
0
		public ExtendedUpdateFieldId(DynamicObjectFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.DynamicObject;
		}
Esempio n. 49
0
		public ExtendedUpdateFieldId(int rawId, ObjectTypeId objectType)
		{
			RawId = rawId;
			ObjectType = objectType;
		}
Esempio n. 50
0
		/// <summary>
		/// Checks if the recycled ID already exists in the database.
		/// </summary>
		/// <param name="lowerId">the ID to check for</param>
		/// <param name="type">the entity ID type to check for</param>
		/// <returns>true if the ID has already been recycled; false if not</returns>
		public static bool DoesIdExist(uint lowerId, ObjectTypeId type)
		{
			return Exists(new EqExpression("EntityId", (long)lowerId), new EqExpression("EntityType", type));
		}
Esempio n. 51
0
		/// <summary>
		/// Gets the first available ID of the given type.
		/// </summary>
		/// <param name="type">the type of entity ID to get</param>
		/// <returns>a <see cref="EntityIdStorage" /> object representing the ID; null if no ID was available</returns>
		private static EntityIdStorage GetFirstRecycledId(ObjectTypeId type)
		{
			return FindFirst(new Order("EntityId", true), new EqExpression("EntityType", type));
		}
Esempio n. 52
0
		/// <summary>
		/// Recycles an entity ID of the given type.
		/// </summary>
		/// <param name="lowerEntityId">the lower entity id</param>
		
		public static bool RecycleLowerEntityId(uint lowerEntityId, ObjectTypeId idType)
		{
			if (DoesIdExist(lowerEntityId, idType))
			{
				// TODO: What should we do if it already exists? This is are a serious bug.
				s_log.Debug(Resources.AlreadyRecycledEntityId, lowerEntityId.ToString(), idType.ToString());

				return false;
			}

			EntityIdStorage eid = new EntityIdStorage();
			eid.EntityId = lowerEntityId;
			eid.EntityType = idType;

			AddRecycledId(eid);

			return true;
		}
Esempio n. 53
0
		public ExtendedUpdateFieldId(GameObjectFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.GameObject;
		}
Esempio n. 54
0
		public static UpdateFieldCollection Get(ObjectTypeId type)
		{
			if (Collections[0] == null)
			{
				Init();
			}
			return Collections[(int)type];
		}
Esempio n. 55
0
		/// <summary>
		/// Tries to retrieve an entity ID from the database.
		/// </summary>
		/// <param name="lowerId">the ID to check for</param>
		/// <param name="type">the entity ID type to check for</param>
		/// <returns>true if the ID has already been recycled; false if not</returns>
		public static EntityIdStorage GetEntityId(uint lowerId, ObjectTypeId type)
		{
			s_idLock.Enter();

			try
			{
				return FindFirst(new EqExpression("EntityId", (long)lowerId), new EqExpression("EntityType", type));
			}
			finally
			{
				s_idLock.Exit();
			}
		}
Esempio n. 56
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="id"></param>
 /// <param name="fields"></param>
 /// <param name="baseCollection"></param>
 /// <param name="offset"></param>
 /// <param name="hasPrivateFields"></param>
 internal UpdateFieldCollection( ObjectTypeId typeId, UpdateField[] updateFields,
     UpdateFieldCollection baseCollection, uint iOffset, bool hasPrivateFields )
 {
     TypeId = typeId;
     Fields = updateFields;
     BaseCollection = baseCollection;
     Offset = iOffset;
     HasPrivateFields = hasPrivateFields;
 }
Esempio n. 57
0
		public ExtendedUpdateFieldId(UnitFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Unit;
		}
 public ObjectTypeDescriptor GetByTypeId(ObjectTypeId objectTypeId)
 {
     ObjectTypeDescriptor existing;
     return map.TryGetValue(objectTypeId, out existing) ? existing : null;
 }
Esempio n. 59
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static UpdateFieldCollection GetCollection( ObjectTypeId typeId )
        {
            //////////////////////////////////////////////////////////////////////////
            // 初始化物体全部的基础字段信息

            if ( UpdateFieldManager.Collections[0] == null )
                UpdateFieldManager.Init();

            return UpdateFieldManager.Collections[(int)typeId];
        }
Esempio n. 60
0
		public ExtendedUpdateFieldId(PlayerFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Player;
		}