/*
     *	Create a new speech bubble and add to list
     */
    public void SendMessage(string[] messages, Entity sendingEntity, int messageType)
    {
        // choose what message to use
        int    randomMessageIndex = Random.Range(0, messages.Length);
        string message            = messages[randomMessageIndex];

        // create speech bubble, set parameters
        SpeechBubble speechBubble = new SpeechBubble(message, messageType, sendingEntity);

        speechBubbles.Add(sendingEntity.GetID(), speechBubble);

        // THIS IS TEMPORARY - this should be managed by looking at the list
        // for now, send to panel to create new speech bubble panel
        if (ShouldCreateSpeechBubble(messageType, sendingEntity.transform.position) &&
            !speechBubbles[sendingEntity.GetID()].bubbleCreated)
        {
            //print("creating speech bubble! size = " + speechBubbles.Count + " entity ID = " + sendingEntity.GetID());

            speechBubbles[sendingEntity.GetID()].panel = speechBubblePanel.CreateNewSpeechBubblePanel(sendingEntity.transform,
                                                                                                      message,
                                                                                                      sendingEntity,
                                                                                                      this);
        }
        else
        {
            RemoveMessageDelayed(sendingEntity);
        }
    }
 public void AddEntity(Entity e)
 {
     if (!this.m_Entities.ContainsKey(e.GetID()))
     {
         this.m_Entities.Add(e.GetID(), e);
     }
 }
    /*
     *	A person (or entity) can remove speech after moving onto another state
     *
     */
    public void RemoveMessageImmediate(Entity entity)
    {
        if (speechBubbles.ContainsKey(entity.GetID())) {
            SpeechBubble speechBubble = speechBubbles[entity.GetID()];

            if (speechBubble.panel != null)
                speechBubble.panel.RemoveSpeechBubble();

            speechBubbles.Remove(entity.GetID());

        }
    }
    /*
     *	A person (or entity) can remove speech after moving onto another state
     *
     */
    public void RemoveMessageImmediate(Entity entity)
    {
        if (speechBubbles.ContainsKey(entity.GetID()))
        {
            SpeechBubble speechBubble = speechBubbles[entity.GetID()];

            if (speechBubble.panel != null)
            {
                speechBubble.panel.RemoveSpeechBubble();
            }

            speechBubbles.Remove(entity.GetID());
        }
    }
    Dictionary<int, SpeechBubble> speechBubbles = new Dictionary<int, SpeechBubble>(); // first int is entity id

    #endregion Fields

    #region Methods

    /*
     *	A person (or entity) can remove speech after completing showing speech bubble
     *	(called from speech bubble panel)
     *
     *	Delay removal (therefore introducing timeout to next continuous speech bubble)
     */
    public void RemoveMessageDelayed(Entity entity)
    {
        if (speechBubbles.ContainsKey(entity.GetID())) {
            // make sure we're not already waiting for removal
            if (!speechBubbles[entity.GetID()].waitingForRemoval) {
                // setup delayed removal
                speechBubbles[entity.GetID()].waitingForRemoval = true;

                int removalTimeInSeconds = TimeController.TimeInSeconds + speechRemovalTimeDelayInSeconds;
                speechBubbles[entity.GetID()].removalTimeInSeconds = removalTimeInSeconds;

                removeQueue.Enqueue(speechBubbles[entity.GetID()]);

            }
        }
    }
Example #6
0
    }                                      // time of next cost account

    public CostNode(Cost cost, Entity entity, int time)
    {
        Entity   = entity;
        EntityID = Entity.GetID();

        CostPerHour   = cost.costPerHour;
        TimeInMinutes = time;
    }
    /*
     *	A person (or entity) can remove speech after completing showing speech bubble
     *	(called from speech bubble panel)
     *
     *	Delay removal (therefore introducing timeout to next continuous speech bubble)
     */
    public void RemoveMessageDelayed(Entity entity)
    {
        if (speechBubbles.ContainsKey(entity.GetID()))
        {
            // make sure we're not already waiting for removal
            if (!speechBubbles[entity.GetID()].waitingForRemoval)
            {
                // setup delayed removal
                speechBubbles[entity.GetID()].waitingForRemoval = true;

                int removalTimeInSeconds = TimeController.TimeInSeconds + speechRemovalTimeDelayInSeconds;
                speechBubbles[entity.GetID()].removalTimeInSeconds = removalTimeInSeconds;

                removeQueue.Enqueue(speechBubbles[entity.GetID()]);
            }
        }
    }
Example #8
0
    public CostNode(Cost cost, Entity entity, int time)
    {
        Entity = entity;
        EntityID = Entity.GetID();

        CostPerHour = cost.costPerHour;
        TimeInMinutes = time;
    }
 public void SendMessageContinuous(string[] messages, Entity sendingEntity, int messageType)
 {
     if (speechBubbles.ContainsKey(sendingEntity.GetID()))
     {
         return;
     }
     else
     {
         SendMessage(messages, sendingEntity, messageType);
     }
 }
Example #10
0
        /// <summary>
        /// 物理删除,对于普通的TopBasePoco和Delete操作相同,对于PersistPoco则进行真正的删除。子类如有自定义操作应重载本函数
        /// </summary>
        public virtual void DoRealDelete()
        {
            try
            {
                List <Guid> fileids = new List <Guid>();
                var         pros    = typeof(TModel).GetProperties();
                //如果包含附件,则先删除附件
                var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBasePoco).IsAssignableFrom(x.PropertyType)).ToList();
                foreach (var f in fa)
                {
                    if (f.GetValue(Entity) is FileAttachment file)
                    {
                        fileids.Add(file.ID);
                    }
                    f.SetValue(Entity, null);
                }

                var fas = pros.Where(x => typeof(IEnumerable <ISubFile>).IsAssignableFrom(x.PropertyType)).ToList();
                foreach (var f in fas)
                {
                    var subs = f.GetValue(Entity) as IEnumerable <ISubFile>;
                    foreach (var sub in subs)
                    {
                        fileids.Add(sub.FileId);
                    }
                    f.SetValue(Entity, null);
                }
                using (var newdc = DC.ReCreate())
                {
                    TModel m = new TModel();
                    m.SetPropertyValue("ID", Entity.GetID());
                    newdc.Set <TModel>().Attach(m);
                    newdc.DeleteEntity(m);
                    newdc.SaveChanges();
                }
                foreach (var item in fileids)
                {
                    FileAttachmentVM ofa = new FileAttachmentVM();
                    ofa.CopyContext(this);
                    ofa.SetEntityById(item);
                    ofa.DoDelete();
                }
            }
            catch (Exception e)
            {
                MSD.AddModelError("", "数据使用中,无法删除");
            }
        }
        public void CreateNewEntity(Entity entity)
        {
            Actor newEntity;
            int   ID = entity.GetID();

            if (Entities.TryGetValue(ID, out newEntity))
            {
                Debug.Log("[GVisualise]: Что-то пошло не так. Я пытаюсь создать объект, который уже есть на сцене!");
            }
            else
            {
                newEntity = new Actor("Сущность " + ID, EntitiesParent, entity);
                Entities.Add(ID, newEntity);
                Debug.Log("[GVisualise]: Создал актера. ID = " + ID);
            }
        }
Example #12
0
 public override void HandleCollisionEnd( Entity collider )
 {
     if( null == collider )
     {
         //-- Ignore null targets
         return;
     }
     
     if( IsAffectedTarget( collider ) )
     {
         //-- Check if this entity is one of our targets
         int targetSlotIndex = -1;
         if( m_TargetLookup.TryGetValue( collider.GetID(), out targetSlotIndex ) )
         {
             //-- If so, deactivate it
             
         }
     }
 }
Example #13
0
    /// <summary>
    /// Returns an active collision involving two specified entities or null if
    /// no such collision exists.
    /// </summary>
    private static Tuple<InstanceID, InstanceID> GetCollision( Entity entity1, Entity entity2 )
    {
        foreach( Tuple<InstanceID, InstanceID> collision in s_Collisions )
        {
            bool colliding = false;
            colliding = colliding || ((collision.Item1 == entity1.GetID()) && (collision.Item2 == entity2.GetID()));
            colliding = colliding || ((collision.Item2 == entity1.GetID()) && (collision.Item1 == entity2.GetID()));

            if( colliding )
            {
                //-- Both members of the collision match the specified entities
                return collision;
            }
        }

        return null;
    }
Example #14
0
 public void CreateEntity(Entity entity)
 {
     Debug.Log("[GLogic]: сообщаю, что Сущность[" + entity.GetID() + "] создана. Тип: " + entity.GetType());
     CreateEntityEvent(entity);
 }
Example #15
0
    /// <summary>
    /// The implementation of this method code assumes that this function does
    /// not get called twice for the same entity unless there is a 'HandleCollisionEnd'
    /// call for that entity in between.
    /// </summary>
    public override void HandleCollision( Entity collider )
    {
        if( (null == collider) || (collider.GetID() == InstanceID.Invalid_IID) )
        {
            //-- Don't accept null or invalid targets
            return;
        }

        if( !m_Active )
        {
            //-- Don't accept targets when inactive
            return;
        }
        
        if( IsAffectedTarget( collider ) )
        {
            int newTargetSlotIndex = -1;
            if( 0 < m_FreeSlots.Count )
            {
                //-- There's an expired target we can use
                int slotIndex = m_FreeSlots.Dequeue();

                //-- Re-initilize expired target with new data
                HotSpotTarget target = m_TargetPool[slotIndex];
                {
                    target.TargetEntityID = collider.GetID();
                    target.AffectationCount = 0;
                    target.Active = true;
                }

                newTargetSlotIndex = slotIndex;
            }
            else
            {
                //-- There was no more room in the pool, so grow it. Create a new
                //   target and append it to the target pool
                HotSpotTarget newTarget = new HotSpotTarget();
                newTarget.TargetEntityID = collider.GetID();
                newTarget.AffectationCount = 0;
                newTarget.Active = true;

                //-- Add new slot to target pool
                m_TargetPool.Add( newTarget );

                newTargetSlotIndex = m_TargetPool.Count - 1;
            }

            //-- Register the new target to our lookup dictionary
            m_TargetLookup[collider.GetID()] = newTargetSlotIndex;

            //-- Immediately schedule the target to be affected
            ScheduleTarget( newTargetSlotIndex, GameSystem.GetTime() + m_InitialDelay );
        }
    }
Example #16
0
 /// <summary>
 /// Prints the description for an individual entity on its own line.
 /// </summary>
 /// <param name="entity"></param>
 private static void PrintEntity( Entity entity )
 {
     Console.Out.WriteLine( entity.GetID() + " - " + entity.ToString() + " [" + entity.m_Type.ToString() + "]" );
 }
    /*
     *	Create a new speech bubble and add to list
     */
    public void SendMessage(string[] messages, Entity sendingEntity, int messageType)
    {
        // choose what message to use
        int randomMessageIndex = Random.Range(0, messages.Length);
        string message = messages[randomMessageIndex];

        // create speech bubble, set parameters
        SpeechBubble speechBubble = new SpeechBubble(message, messageType, sendingEntity);
        speechBubbles.Add(sendingEntity.GetID(), speechBubble);

        // THIS IS TEMPORARY - this should be managed by looking at the list
        // for now, send to panel to create new speech bubble panel
        if (ShouldCreateSpeechBubble(messageType, sendingEntity.transform.position) &&
                                     !speechBubbles[sendingEntity.GetID()].bubbleCreated) {
            //print("creating speech bubble! size = " + speechBubbles.Count + " entity ID = " + sendingEntity.GetID());

            speechBubbles[sendingEntity.GetID()].panel = speechBubblePanel.CreateNewSpeechBubblePanel(sendingEntity.transform,
                                                                              message,
                                                                              sendingEntity,
                                                                              this);
        } else
            RemoveMessageDelayed(sendingEntity);
    }
Example #18
0
    /// <summary>
    /// Adds a specified entity to the game world.
    /// </summary>
    private static void AddEntity( Entity entity )
    {
        //-- Print new entity
        Console.Out.Write( "Created entity: " );
        PrintEntity( entity );

        //-- Add the entity to the world
        s_GameEntities.Add( entity.GetID(), entity );
        entity.EnterWorld();

        //-- Print list
        Console.Out.WriteLine();
        PrintEntities();
    }
Example #19
0
    /// <summary>
    /// Removes a specified entity from the game. This private function assumes that its parameter
    /// is a valid entity currently present in the game world.
    /// </summary>
    /// <param name="entity"></param>
    private static void RemoveEntity( Entity entity )
    {
        //-- Remove any collision that this entity may be involved with
        RemoveCollision( entity );
        
        //-- Remove the entity from the world
        entity.ExitWorld();
        s_GameEntities.Remove( entity.GetID() );

        //-- Print
        Console.Out.Write( "Removed entity: " );
        PrintEntity( entity );

        Console.Out.WriteLine();
        PrintEntities();
    }
Example #20
0
    /// <summary>
    /// The implementation of this method code assumes that this function does
    /// not get called twice for the same entity unless there is a 'HandleCollisionEnd'
    /// call for that entity in between.
    /// </summary>
    public override void HandleCollision( Entity collider )
    {
        if( (null == collider) || (collider.GetID() == InstanceID.Invalid_IID) )
        {
            //-- Don't accept null or invalid targets
            return;
        }

        if( !m_Active )
        {
            //-- Don't accept targets when inactive
            return;
        }

        //-- Track the colliding entity
        m_CollidingEntities.Add( collider.GetID() );

        if( IsAffectedTarget( collider ) )
        {
            //-- Create a new target to schedule to be affected
            HotSpotTarget newTarget = new HotSpotTarget();
            newTarget.TargetEntityID = collider.GetID();
            newTarget.AffectationCount = 0;

            //-- Schedule the new target
            ScheduleTarget( newTarget, GameSystem.GetTime() + m_InitialDelay );
        }
    }
 public void SendMessageContinuous(string[] messages, Entity sendingEntity, int messageType)
 {
     if (speechBubbles.ContainsKey(sendingEntity.GetID()))
         return;
     else
         SendMessage(messages, sendingEntity, messageType);
 }
Example #22
0
        private void DoEditPrepare(bool updateAllFields)
        {
            if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(BasePoco)))
            {
                BasePoco ent = Entity as BasePoco;
                if (ent.UpdateTime == null)
                {
                    ent.UpdateTime = DateTime.Now;
                }
                if (string.IsNullOrEmpty(ent.UpdateBy))
                {
                    ent.UpdateBy = LoginUserInfo?.ITCode;
                }
            }
            var pros = typeof(TModel).GetProperties();

            #region 更新子表
            foreach (var pro in pros)
            {
                //找到类型为List<xxx>的字段
                if (pro.PropertyType.GenericTypeArguments.Count() > 0)
                {
                    //获取xxx的类型
                    var ftype = pro.PropertyType.GenericTypeArguments.First();
                    //如果xxx继承自TopBasePoco
                    if (ftype.IsSubclassOf(typeof(TopBasePoco)))
                    {
                        //界面传过来的子表数据

                        if (pro.GetValue(Entity) is IEnumerable <TopBasePoco> list && list.Count() > 0)
                        {
                            //获取外键字段名称
                            string         fkname   = DC.GetFKName <TModel>(pro.Name);
                            PropertyInfo[] itemPros = ftype.GetProperties();

                            bool found = false;
                            foreach (var newitem in list)
                            {
                                var subtype = newitem.GetType();
                                if (subtype.IsSubclassOf(typeof(BasePoco)))
                                {
                                    BasePoco ent = newitem as BasePoco;
                                    if (ent.UpdateTime == null)
                                    {
                                        ent.UpdateTime = DateTime.Now;
                                    }
                                    if (string.IsNullOrEmpty(ent.UpdateBy))
                                    {
                                        ent.UpdateBy = LoginUserInfo?.ITCode;
                                    }
                                }
                                //循环页面传过来的子表数据,将关联到TopBasePoco的字段设为null,并且把外键字段的值设定为主表ID
                                foreach (var itempro in itemPros)
                                {
                                    if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)))
                                    {
                                        itempro.SetValue(newitem, null);
                                    }
                                    if (!string.IsNullOrEmpty(fkname))
                                    {
                                        if (itempro.Name.ToLower() == fkname.ToLower())
                                        {
                                            itempro.SetValue(newitem, Entity.GetID());
                                            found = true;
                                        }
                                    }
                                }
                            }
                            //如果没有找到相应的外建字段,则可能是多对多的关系,或者做了特殊的设定,这种情况框架无法支持,直接退出本次循环
                            if (found == false)
                            {
                                continue;
                            }


                            TModel _entity = null;
                            //打开新的数据库联接,获取数据库中的主表和子表数据
                            using (var ndc = DC.CreateNew())
                            {
                                _entity = ndc.Set <TModel>().Include(pro.Name).AsNoTracking().CheckID(Entity.GetID()).FirstOrDefault();
                            }
                            //比较子表原数据和新数据的区别
                            IEnumerable <TopBasePoco> toadd    = null;
                            IEnumerable <TopBasePoco> toremove = null;
                            IEnumerable <TopBasePoco> data     = _entity.GetType().GetProperty(pro.Name).GetValue(_entity) as IEnumerable <TopBasePoco>;
                            Utils.CheckDifference(data, list, out toremove, out toadd);
                            //设定子表应该更新的字段
                            List <string> setnames = new List <string>();
                            foreach (var field in FC.Keys)
                            {
                                if (field.StartsWith("Entity." + pro.Name + "[0]."))
                                {
                                    string name = field.Replace("Entity." + pro.Name + "[0].", "");
                                    setnames.Add(name);
                                }
                            }

                            //前台传过来的数据
                            foreach (var newitem in list)
                            {
                                //数据库中的数据
                                foreach (var item in data)
                                {
                                    //需要更新的数据
                                    if (newitem.GetID().ToString() == item.GetID().ToString())
                                    {
                                        dynamic i           = newitem;
                                        var     newitemType = item.GetType();
                                        foreach (var itempro in itemPros)
                                        {
                                            if (!itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)) && (updateAllFields == true || setnames.Contains(itempro.Name)))
                                            {
                                                var notmapped = itempro.GetCustomAttribute <NotMappedAttribute>();
                                                if (itempro.Name != "ID" && notmapped == null && itempro.PropertyType.IsList() == false)
                                                {
                                                    DC.UpdateProperty(i, itempro.Name);
                                                }
                                            }
                                        }
                                        if (item.GetType().IsSubclassOf(typeof(BasePoco)))
                                        {
                                            DC.UpdateProperty(i, "UpdateTime");
                                            DC.UpdateProperty(i, "UpdateBy");
                                        }
                                    }
                                }
                            }
                            //需要删除的数据
                            foreach (var item in toremove)
                            {
                                //如果是PersistPoco,则把IsValid设为false,并不进行物理删除
                                if (ftype.IsSubclassOf(typeof(PersistPoco)))
                                {
                                    (item as PersistPoco).IsValid    = false;
                                    (item as PersistPoco).UpdateTime = DateTime.Now;
                                    (item as PersistPoco).UpdateBy   = LoginUserInfo?.ITCode;
                                    dynamic i = item;
                                    DC.UpdateEntity(i);
                                }
                                else
                                {
                                    foreach (var itempro in itemPros)
                                    {
                                        if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)))
                                        {
                                            itempro.SetValue(item, null);
                                        }
                                    }
                                    dynamic i = item;
                                    DC.DeleteEntity(i);
                                }
                            }
                            //需要添加的数据
                            foreach (var item in toadd)
                            {
                                if (item.GetType().IsSubclassOf(typeof(BasePoco)))
                                {
                                    BasePoco ent = item as BasePoco;
                                    if (ent.CreateTime == null)
                                    {
                                        ent.CreateTime = DateTime.Now;
                                    }
                                    if (string.IsNullOrEmpty(ent.CreateBy))
                                    {
                                        ent.CreateBy = LoginUserInfo?.ITCode;
                                    }
                                }
                                DC.AddEntity(item);
                            }
                        }
                        else if (FC.Keys.Contains("Entity." + pro.Name + ".DONOTUSECLEAR") || (FC.ContainsKey("Entity." + pro.Name) && pro.GetValue(Entity) is IEnumerable <TopBasePoco> list2 && list2?.Count() == 0))
                        {
                            PropertyInfo[] itemPros = ftype.GetProperties();
                            var            _entity  = DC.Set <TModel>().Include(pro.Name).AsNoTracking().CheckID(Entity.GetID()).FirstOrDefault();
                            if (_entity != null)
                            {
                                IEnumerable <TopBasePoco> removeData = _entity.GetType().GetProperty(pro.Name).GetValue(_entity) as IEnumerable <TopBasePoco>;
                                //如果是PersistPoco,则把IsValid设为false,并不进行物理删除
                                if (removeData is IEnumerable <PersistPoco> removePersistPocoData)
                                {
                                    foreach (var item in removePersistPocoData)
                                    {
                                        (item as PersistPoco).IsValid    = false;
                                        (item as PersistPoco).UpdateTime = DateTime.Now;
                                        (item as PersistPoco).UpdateBy   = LoginUserInfo?.ITCode;
                                        dynamic i = item;
                                        DC.UpdateEntity(i);
                                    }
                                }
                                else
                                {
                                    foreach (var item in removeData)
                                    {
                                        foreach (var itempro in itemPros)
                                        {
                                            if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)))
                                            {
                                                itempro.SetValue(item, null);
                                            }
                                        }
                                        dynamic i = item;
                                        DC.DeleteEntity(i);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion


            if (updateAllFields == false)
            {
                foreach (var field in FC.Keys)
                {
                    if (field.StartsWith("Entity.") && !field.Contains("["))
                    {
                        string name = field.Replace("Entity.", "");
                        try
                        {
                            DC.UpdateProperty(Entity, name);
                        }
                        catch (Exception ea)
                        {
                        }
                    }
                }
                if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(BasePoco)))
                {
                    try
                    {
                        DC.UpdateProperty(Entity, "UpdateTime");
                        DC.UpdateProperty(Entity, "UpdateBy");
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            else
            {
                DC.UpdateEntity(Entity);
            }
        }
Example #23
0
 public void AddEntity(Entity e)
 {
     this.m_Entities.Add(e.GetID(), e);
 }
Example #24
0
    public override void HandleCollisionEnd( Entity collider )
    {
        if( null == collider )
        {
            //-- Ignore null targets
            return;
        }

        //-- Track colliding entity
        m_CollidingEntities.Remove( collider.GetID() );
        
        if( IsAffectedTarget( collider ) )
        {
            //-- Remove the target from any jobs it might be in
            RemoveTargetFromJobs( collider.GetID() );
        }
    }
Example #25
0
        private void DoAddPrepare()
        {
            var pros = typeof(TModel).GetProperties();

            //将所有TopBasePoco的属性赋空值,防止添加关联的重复内容
            if (typeof(TModel) != typeof(FileAttachment))
            {
                foreach (var pro in pros)
                {
                    if (pro.PropertyType.GetTypeInfo().IsSubclassOf(typeof(TopBasePoco)))
                    {
                        pro.SetValue(Entity, null);
                    }
                }
            }
            //自动设定添加日期和添加人
            if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(BasePoco)))
            {
                BasePoco ent = Entity as BasePoco;
                if (ent.CreateTime == null)
                {
                    ent.CreateTime = DateTime.Now;
                }
                if (string.IsNullOrEmpty(ent.CreateBy))
                {
                    ent.CreateBy = LoginUserInfo?.ITCode;
                }
            }

            if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(PersistPoco)))
            {
                (Entity as PersistPoco).IsValid = true;
            }

            #region 更新子表
            foreach (var pro in pros)
            {
                //找到类型为List<xxx>的字段
                if (pro.PropertyType.GenericTypeArguments.Count() > 0)
                {
                    //获取xxx的类型
                    var ftype = pro.PropertyType.GenericTypeArguments.First();
                    //如果xxx继承自TopBasePoco
                    if (ftype.IsSubclassOf(typeof(TopBasePoco)))
                    {
                        //界面传过来的子表数据
                        IEnumerable <TopBasePoco> list = pro.GetValue(Entity) as IEnumerable <BasePoco>;
                        if (list != null && list.Count() > 0)
                        {
                            string         fkname   = DC.GetFKName <TModel>(pro.Name);
                            PropertyInfo[] itemPros = ftype.GetProperties();

                            bool found = false;
                            foreach (var newitem in list)
                            {
                                foreach (var itempro in itemPros)
                                {
                                    if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)))
                                    {
                                        itempro.SetValue(newitem, null);
                                    }
                                    if (!string.IsNullOrEmpty(fkname))
                                    {
                                        if (itempro.Name.ToLower() == fkname.ToLower())
                                        {
                                            itempro.SetValue(newitem, Entity.GetID());
                                            found = true;
                                        }
                                    }
                                }
                            }
                            //如果没有找到相应的外建字段,则可能是多对多的关系,或者做了特殊的设定,这种情况框架无法支持,直接退出本次循环
                            if (found == false)
                            {
                                continue;
                            }
                            //循环页面传过来的子表数据,自动设定添加日期和添加人
                            foreach (var newitem in list)
                            {
                                var      subtype = newitem.GetType();
                                BasePoco ent     = newitem as BasePoco;
                                if (ent.CreateTime == null)
                                {
                                    ent.CreateTime = DateTime.Now;
                                }
                                if (string.IsNullOrEmpty(ent.CreateBy))
                                {
                                    ent.CreateBy = LoginUserInfo?.ITCode;
                                }
                            }
                        }
                    }
                }
            }
            #endregion


            //添加数据
            DC.Set <TModel>().Add(Entity);
        }
Example #26
0
    /// <summary>
    /// Adds a collision between two specified entities
    /// </summary>
    private static void AddCollision( Entity entity1, Entity entity2 )
    {
        //-- Only add a collision if the pair aren't already colliding
        if( GetCollision( entity1, entity2 ) == null )
        {
            //-- Send collision events
            entity1.HandleCollision( entity2 );
            entity2.HandleCollision( entity1 );

            //-- Add new collision
            s_Collisions.AddLast( new Tuple<InstanceID, InstanceID>( entity1.GetID(), entity2.GetID() ) );
        }
    }
Example #27
0
        /// <summary>
        /// 验证重复数据
        /// </summary>
        protected void ValidateDuplicateData()
        {
            //获取设定的重复字段信息
            var checkCondition = SetDuplicatedCheck();

            if (checkCondition != null && checkCondition.Groups.Count > 0)
            {
                //生成基础Query
                var baseExp              = DC.Set <TModel>().AsQueryable();
                var modelType            = typeof(TModel);
                ParameterExpression para = Expression.Parameter(modelType, "tm");
                //循环所有重复字段组
                foreach (var group in checkCondition.Groups)
                {
                    List <Expression> conditions = new List <Expression>();
                    //生成一个表达式,类似于 x=>x.Id != id,这是为了当修改数据时验证重复性的时候,排除当前正在修改的数据
                    var idproperty                = typeof(TModel).GetProperties().Where(x => x.Name.ToLower() == "id").FirstOrDefault();
                    MemberExpression   idLeft     = Expression.Property(para, idproperty);
                    ConstantExpression idRight    = Expression.Constant(Entity.GetID());
                    BinaryExpression   idNotEqual = Expression.NotEqual(idLeft, idRight);
                    conditions.Add(idNotEqual);
                    List <PropertyInfo> props = new List <PropertyInfo>();
                    //在每个组中循环所有字段
                    foreach (var field in group.Fields)
                    {
                        Expression exp = field.GetExpression(Entity, para);
                        if (exp != null)
                        {
                            conditions.Add(exp);
                        }
                        //将字段名保存,为后面生成错误信息作准备
                        props.AddRange(field.GetProperties());
                    }
                    //如果要求判断id不重复,则去掉id不相等的判断,加入id相等的判断
                    if (props.Any(x => x.Name.ToLower() == "id"))
                    {
                        conditions.RemoveAt(0);
                        BinaryExpression idEqual = Expression.Equal(idLeft, idRight);
                        conditions.Insert(0, idEqual);
                    }
                    int count = 0;
                    if (conditions.Count > 1)
                    {
                        //循环添加条件并生成Where语句
                        Expression conExp = conditions[0];
                        for (int i = 1; i < conditions.Count; i++)
                        {
                            conExp = Expression.And(conExp, conditions[i]);
                        }

                        MethodCallExpression whereCallExpression = Expression.Call(
                            typeof(Queryable),
                            "Where",
                            new Type[] { modelType },
                            baseExp.Expression,
                            Expression.Lambda <Func <TModel, bool> >(conExp, new ParameterExpression[] { para }));
                        var result = baseExp.Provider.CreateQuery(whereCallExpression);

                        foreach (var res in result)
                        {
                            count++;
                        }
                    }
                    if (count > 0)
                    {
                        //循环拼接所有字段名
                        string AllName = "";
                        foreach (var prop in props)
                        {
                            string name = PropertyHelper.GetPropertyDisplayName(prop);
                            AllName += name + ",";
                        }
                        if (AllName.EndsWith(","))
                        {
                            AllName = AllName.Remove(AllName.Length - 1);
                        }
                        //如果只有一个字段重复,则拼接形成 xxx字段重复 这种提示
                        if (props.Count == 1)
                        {
                            MSD.AddModelError(GetValidationFieldName(props[0])[0], Program._localizer["DuplicateError", AllName]);
                        }
                        //如果多个字段重复,则拼接形成 xx,yy,zz组合字段重复 这种提示
                        else if (props.Count > 1)
                        {
                            MSD.AddModelError(GetValidationFieldName(props.First())[0], Program._localizer["DuplicateGroupError", AllName]);
                        }
                    }
                }
            }
        }
Example #28
0
    /// <summary>
    /// Removes all active collisions involving a specified entity or does nothing
    /// if no such collisions exist.
    /// </summary>
    private static void RemoveCollision( Entity entity )
    {
        LinkedListNode<Tuple<InstanceID, InstanceID>> collisionIter = s_Collisions.First;
        while( null != collisionIter )
        {
            //-- Cache next collision
            LinkedListNode<Tuple<InstanceID, InstanceID>> nextCollisionIter = collisionIter.Next;

            //-- Remove this collision if one of its colliders is the entity
            Tuple<InstanceID, InstanceID> collision = collisionIter.Value;
            if( (collision.Item1 == entity.GetID()) || (collision.Item2 == entity.GetID()) )
            {
                //-- Send collision end events
                Entity collider1 = GetEntity( collision.Item1 );
                Entity collider2 = GetEntity( collision.Item2 );

                if( null != collider1 )
                {
                    collider1.HandleCollisionEnd( collider2 );
                }

                if( null != collider2 )
                {
                    collider2.HandleCollisionEnd( collider1 );
                }

                //-- Remove the collision
                s_Collisions.Remove( collisionIter );
            }

            //-- Next collision
            collisionIter = nextCollisionIter;
        }
    }