Example #1
0
        /// <summary>
        /// Equalses the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>A <see cref="System.Boolean"/></returns>
        public virtual bool Equals( Entity entity )
        {
            if ( ReferenceEquals ( null, entity ) )
            {
                return false;
            }
            if ( ReferenceEquals ( this, entity ) )
            {
                return true;
            }
            if ( GetType () != entity.GetType () )
            {
                return false;
            }

            var otherIsTransient = Equals ( entity.Key, ( long )0 );
            var thisIsTransient = Equals ( Key, ( long )0 );

            if ( otherIsTransient && thisIsTransient )
            {
                return ReferenceEquals ( entity, this );
            }

            return entity.Key.Equals ( Key );
        }
Example #2
0
        /// <summary>
        /// Constructor referencing an <see cref="Entity"/>
        /// </summary>
        /// <param name="entity"><see cref="Entity"/> reference to be offlined</param>
        /// <param name="addedEntity">Conditional <see cref="Boolean"/> to specify whether or not the <see cref="Entity"/> is Added</param>
        public OfflinableEntity(Entity entity, bool addedEntity = false)
        {
            this.OriginalEntity = entity.GetOriginal();
            this.CurrentEntity = entity;

            if (addedEntity)
            {
                foreach (var collection in entity.GetType().GetProperties().Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(EntityCollection<>)))
                {
                    List<Entity> entities = new List<Entity>();
                    foreach (var entityRef in collection.GetValue(entity, null) as IEnumerable<Entity>)
                    {
                       entities.Add(entityRef);
                    }
                    if (entities.Any())
                    {
                        if (EntityRefs == null)
                        {
                            EntityRefs = new Dictionary<string, List<Entity>>();
                        }
                        this.EntityRefs.Add(collection.Name, entities);
                    }
                }
            }
            this.EntityState = entity.EntityState;
            this.EntityActions = ConvertToOfflinableEntityActions(entity.EntityActions);
        }
Example #3
0
 private void NewBuildOrder(ActionType actionType, Entity target)
 {
     if (actionType == ActionType.Build)
     {
         if (target != null)
             if (target.GetType() == typeof(Building))
                 _buildingToBuild = target as Building;
     }
 }
    // returns callable methods, for triggers etc
    public static string[] GetMethodList(Entity ent)
    {
        string [] tempMethods =
            ent.GetType()
            .GetMethods(BindingFlags.Instance| BindingFlags.Public | BindingFlags.NonPublic |  BindingFlags.FlattenHierarchy)
            .Where(m => m.GetCustomAttributes(typeof(Callable), false).Length > 0)
            .Where(x => !ignoreMethods.Any(n => n == x.Name)) // Don't list methods in the ignoreMethods array (so we can exclude Unity specific methods, etc.)
            .Select(x => x.Name)
            .ToArray();

        if (tempMethods.Length > 0) {
            // sort the list
            Array.Sort<string> (tempMethods);
        }

        return tempMethods;
    }
        public void TestLinqCount()
        {
            var collection = Configuration.GetTestCollection<Entity>();
            if (collection.Exists()) { collection.Drop(); }

            for (int i = 0; i < 100; ++i)
            {
                var e = new Entity() { Name = "Name_" + i };
                collection.Insert(e.GetType(), e, WriteConcern.Acknowledged);
            }

            var query = (from e in collection.AsQueryable<Entity>()
                         where true || e.Name == "Name_22"
                         select e);
            var count = query.Count();

            Assert.AreEqual(100, count);
        }
    private void SetEntity(Entity entity)
    {
        this.entity = entity;

        switch (type)
        {
            case StatBarType.Health:
                entity.OnSelect += ShowStatBar;
                entity.OnDeselect += HideStatBar;
                entity.OnDamageReceive += UpdateStatBar;
                break;
            case StatBarType.BuildProgress:
                entity.OnConstructionProgress += UpdateStatBar;
                if (entity.GetType() == typeof(Building))
                    ((Building)entity).OnPlace += ShowStatBar;
                break;
        }
    }
Example #7
0
        public void TestLinqCount()
        {
            var collection = LegacyTestConfiguration.GetCollection<Entity>();
            if (collection.Exists()) { collection.Drop(); }

            for (int i = 0; i < 100; ++i)
            {
                var e = new Entity() { Name = "Name_" + i };
                collection.Insert(e.GetType(), e, WriteConcern.Acknowledged);
            }

#pragma warning disable 429 // unreachable code
            var query = (from e in collection.AsQueryable<Entity>()
                         where true || e.Name == "Name_22"
                         select e);
#pragma warning restore
            var count = query.Count();

            Assert.Equal(100, count);
        }
Example #8
0
 public override bool CanShootEntity(Entity e)
 {
     System.Type entityType = e.GetType();
     if (entityType == typeof(PlayerControl))
     {
         // return reactions[PlayerControl] == HOSTILE
         return false;
     }
     else if (entityType == typeof(Enemy))
     {
         // return reactions[PlayerControl] == HOSTILE
         return true;
     }
     else if (entityType == typeof(NPC))
     {
         // return reactions[PlayerControl] == HOSTILE
         return false;
     }
     return false;
 }
Example #9
0
 public void Delete(Entity entity)
 {
     log.DebugFormat("{0} #{1} deleted.", entity.GetType(), entity.Id);
 }
Example #10
0
	public void setInitialEntity(Entity entity) {
        removeEntity();
        entity.transform.parent = this.transform.parent;
        entity.transform.position = transform.position;
		this.entityPresent = entity;
		entity.setCurrentTile (this);
        if (entity.GetType() != typeof(Obstacle))
        {
            int type = (entity.getIsPlayer() ? 0 : 1);
            graphicTile = GetComponent<GraphicTile>();
            graphicTile.setAnim();
            setTileType(type);
        }
    }
Example #11
0
        public virtual void Populate(FieldMap fieldMap, Entity entity)
        {
            var fieldsWithNoValueOnEntity = new List<string>();

            var @class = new Class(GetType());
            @class.EachField(delegate(FieldInfo fieldInfo)
                                 {
                                     var uiItem = fieldInfo.GetValue(this) as UIItem;
                                     if (uiItem == null || !ControlDictionary.Instance.IsEditable(uiItem)) return;

                                     string fieldName = fieldMap.GetFieldNameFor(fieldInfo.Name, fieldInfo.FieldType);
                                     if (string.IsNullOrEmpty(fieldName)) return;

                                     try
                                     {
                                         EntityField entityField = entity.Field(fieldName);
                                         if (entityField == null)
                                             fieldsWithNoValueOnEntity.Add(fieldName);
                                         else
                                             entityField.SetValueOn(uiItem);
                                     }
                                     catch (TargetInvocationException e)
                                     {
                                         throw new AppScreenException(
                                             string.Format("Error assigning {0}.{1} to {2}.{3} ", entity.GetType(), fieldName, GetType(), fieldInfo.Name),
                                             e.InnerException);
                                     }
                                 });

            if (fieldsWithNoValueOnEntity.Count == 0) return;

            string message = string.Join(",", fieldsWithNoValueOnEntity.ToArray());
            WhiteLogger.Instance.WarnFormat("Mapping to screen: {0} with {1}, No value specified for fields {2}", this, entity.GetType(), message);
        }
Example #12
0
        protected override void MarkEntityAsDeleted(Entity entity)
        {
            AttachIfNeeded(entity);

            _dbContext.Set(entity.GetType()).Remove(entity);
        }
Example #13
0
 private void UpdateEntityDetails(Entity entity)
 {
     this.updateMethods[entity.GetType()](entity);
 }
Example #14
0
 public static void SetIdOf(Entity entity, int id)
 {
     PropertyInfo idProperty = entity.GetType().GetProperty("Id",
       BindingFlags.Public | BindingFlags.Instance);
       idProperty.SetValue(entity, id, null);
 }
Example #15
0
 public void Insert(Entity entity)
 {
     log.DebugFormat("{0} #{1} inserted.", entity.GetType(), entity.Id);
 }
Example #16
0
 public void Update(Entity entity)
 {
     log.DebugFormat("{0} #{1} updated.", entity.GetType(), entity.Id);
 }
Example #17
0
 private void AttachIfNeeded(Entity entity)
 {
     if (_dbContext.Entry(entity).State == EntityState.Detached)
         _dbContext.Set(entity.GetType()).Attach(entity);
 }