Beispiel #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);
 }
Beispiel #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>();
 }
Beispiel #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();
            }
        }
Beispiel #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();
     }
 }
Beispiel #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));
        }
Beispiel #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();
			}
		}
Beispiel #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);
        }
Beispiel #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;
		}
Beispiel #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);
        }
Beispiel #15
0
 public static UpdateFieldCollection Get(ObjectTypeId type)
 {
     if (Collections[0] == null)
     {
         Init();
     }
     return(Collections[(int)type]);
 }
Beispiel #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);
 }
Beispiel #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());
        }
        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());
        }
Beispiel #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);
     }
 }
Beispiel #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));
        }
Beispiel #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;
            }
        }
Beispiel #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;
            }
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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();
		}
Beispiel #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));
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
     }
 }
Beispiel #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++;
            }
        }
		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;
		}
Beispiel #44
0
 protected WowItem(ObjectTypeId type)
     : base(type)
 {
 }
Beispiel #45
0
		public ExtendedUpdateFieldId(CorpseFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Corpse;
		}
Beispiel #46
0
		public ExtendedUpdateFieldId(ItemFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Item;
		}
Beispiel #47
0
		public ExtendedUpdateFieldId(ContainerFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Container;
		}
Beispiel #48
0
		public ExtendedUpdateFieldId(DynamicObjectFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.DynamicObject;
		}
Beispiel #49
0
		public ExtendedUpdateFieldId(int rawId, ObjectTypeId objectType)
		{
			RawId = rawId;
			ObjectType = objectType;
		}
Beispiel #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));
		}
Beispiel #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));
		}
Beispiel #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;
		}
Beispiel #53
0
		public ExtendedUpdateFieldId(GameObjectFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.GameObject;
		}
Beispiel #54
0
		public static UpdateFieldCollection Get(ObjectTypeId type)
		{
			if (Collections[0] == null)
			{
				Init();
			}
			return Collections[(int)type];
		}
Beispiel #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();
			}
		}
 /// <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;
 }
Beispiel #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;
 }
        /// <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];
        }
Beispiel #60
0
		public ExtendedUpdateFieldId(PlayerFields val)
		{
			RawId = (int)val;
			ObjectType = ObjectTypeId.Player;
		}