Exemple #1
0
        public override void init()
        {
            // Static message to client
            EntityUtility.CreateMessage(Domain, "Players in server", 0, 0, 16);

            // Creates a list of all clients in server
            List <string> users = ClientProtocol.GetAllUsers();

            for (int i = 0; i < users.Count(); i++)
            {
                EntityUtility.CreateMessage(Domain, users[i], 0, 0, 18);
            }

            // Background
            Entity backGround = new Entity(Domain);

            backGround.AddComponent(new Transform());
            backGround.AddComponent(new Sprite(Assets.Textures.Background, 1280, 720));

            // Menu
            Entity Menu = new Entity(Domain);

            Menu.AddComponent(new Transform());
            Menu.AddComponent(new Sprite(Assets.Textures.Menu, 600, 600));

            // InputBox
            InputBox = EntityUtility.CreateInput(Domain, "Enter Name", -70, 100, 18);
        }
        public void Handle(IEnumerable <ITrackedEntry> changedEntries)
        {
            var versionId       = Guid.NewGuid();
            var _changedEntries = changedEntries.Where(i => (i.State == EntityState.Added || i.State == EntityState.Modified) &&
                                                       typeof(IVersionedEntity).IsAssignableFrom(i.Entity.GetType()))
                                  .ToArray();

            foreach (var entry in _changedEntries)
            {
                var versionedEntity = (IVersionedEntity)entry.Entity;
                if (entry.State == EntityState.Added)
                {
                    versionedEntity.VersionId = Guid.NewGuid();
                }
                else if (entry.State == EntityState.Modified)
                {
                    var entityType = versionedEntity.GetType();

                    /// Clone entity
                    var originalValues = entry.OriginalValues;
                    var originalEntity = (IVersionedEntity)originalValues.ToObject();

                    /// Assign new primary key
                    var property = entityType.GetProperty(EntityUtility.GetIdPropertyName(entityType));
                    property.SetValue(originalEntity, Guid.NewGuid());

                    /// Assign version
                    originalEntity.VersionId          = versionId;
                    versionedEntity.PreviousVersionId = originalEntity.VersionId;

                    context.Add(originalEntity);
                }
            }
        }
        private void InitializeEntities()
        {
            var gameData     = AppModel.GameData;
            var entityLookup = gameData.EntityManager.DisplayEntityLookup;
            var rng          = m_gameServices.RandomNumberGenerator;

            var entities    = SystemDataFileUtility.LoadEntities("Data\\SolSystem.txt", entityLookup, rng);
            var earthEntity = entities.FirstOrDefault(x => x.GetRequiredComponent <InformationComponent>().Name == "Earth");

            if (earthEntity != null)
            {
                EntityUtility.MakeHomeWorld(earthEntity, EntityUtility.GetHumanTemplate());
            }

            var planetViewModels = entities.Select(x => new PlanetViewModel(x));

            m_planets.AddRange(planetViewModels);

            foreach (var planet in m_planets)
            {
                planet.UpdateFromEntity(entityLookup);
            }

            Planet = m_planets.FirstOrDefault(x => x.Name == "Earth");
        }
        private static void CreateAsteroidBeltEntities(string[] parts, ref int asteroidCount, IEntityLookup entityLookup, Random rng, Dictionary <string, Entity> entities, Action <string> throwFormatException)
        {
            if (parts.Length != 7)
            {
                throwFormatException($"Asteroid belt data must have 7 fields, but found {parts.Length} fields.");
            }

            var count            = int.Parse(parts[1]);
            var parentId         = entities[parts[2]].Id;
            var minSemiMajorAxis = double.Parse(parts[3]);
            var maxSemiMajorAxis = double.Parse(parts[4]);
            var minEccentricity  = double.Parse(parts[5]);
            var maxEccentricity  = double.Parse(parts[6]);

            for (int i = 0; i < count; i++)
            {
                asteroidCount++;
                var name                 = $"Asteroid {asteroidCount}";
                var radius               = 100.0;
                var mass                 = 1e12 * (4.0 / 3.0) * PI * radius * radius * radius * 2600.0;
                var semiMajorAxis        = rng.NextDouble(minSemiMajorAxis, maxSemiMajorAxis);
                var eccentricity         = rng.NextDouble(minEccentricity, maxEccentricity);
                var longitudeOfPeriapsis = rng.NextDouble(0.0, 360.0);
                var meanAnomaly          = rng.NextDouble(0.0, 360.0);
                var isRetrograde         = rng.Next(0, 1000) == 0;
                var epoch                = 2000;

                var entity = EntityUtility.CreatePlanet(entityLookup, name, parentId, mass, radius, semiMajorAxis, eccentricity, longitudeOfPeriapsis, meanAnomaly, isRetrograde, epoch);
                entities.Add(name, entity);
            }
        }
Exemple #5
0
        /// <summary>
        /// 構造函數。
        /// </summary>
        /// <param name="surveys"></param>
        /// <param name="conclusion"></param>
        /// <param name="db"></param>
        public SaveConclusioModel(Surveys surveys, SurveysConclusion conclusion, DbContext db)
        {
            Conclusion = conclusion;
            var template = db.Set <SurveysTemplate>().Find(surveys.TemplateId);

            UserId            = surveys.UserId;
            SurveysTemplateId = surveys.TemplateId;
            var question = template.Questions.FirstOrDefault(c => c.QuestionTitle == "姓名");

            if (null != question)
            {
                Name = surveys.SurveysAnswers.FirstOrDefault(c => c.TemplateId == question.Id)?.Guts;
            }
            question = template.Questions.FirstOrDefault(c => c.QuestionTitle == "手机号");
            if (null != question)
            {
                Mobile = surveys.SurveysAnswers.FirstOrDefault(c => c.TemplateId == question.Id)?.Guts;
            }
            question = template.Questions.FirstOrDefault(c => c.QuestionTitle == "性别");
            if (null != question)
            {
                Sex = surveys.SurveysAnswers.FirstOrDefault(c => c.TemplateId == question.Id)?.Guts;
            }
            //写入方剂Id
            var idTp = surveys.ThingPropertyItems.FirstOrDefault(c => c.Name == "PrescriptionId");

            PrescriptionId = idTp?.Value;
            //写入方剂数据

            idTp = conclusion.ThingPropertyItems.FirstOrDefault(c => c.Name == CnMedicineAlgorithmBase.CnPrescriptionesName);
            if (null != idTp)
            {
                Prescriptiones = EntityUtility.FromJson <List <CnPrescription> >(idTp.Value);
            }
        }
        public override void init()
        {
            // Static message to client

            EntityUtility.CreateMessage(Domain, "Players in lobby", 0, -180, 16);
            if (Connection.Lobby.Owner == Connection.LocalPlayer)
            {
                clientInformation = EntityUtility.CreateMessage(Domain, "Press 'enter' to start game", 0, 100, 16);
            }
            else
            {
                clientInformation = EntityUtility.CreateMessage(Domain, "Waiting for host to start game", 0, 100, 16);
            }


            // Background
            Entity backGround = new Entity(Domain);

            backGround.AddComponent(new Transform());
            backGround.AddComponent(new Sprite(Assets.Textures.Background, 1280, 720));

            // Menu
            Entity Menu = new Entity(Domain);

            Menu.AddComponent(new Transform());
            Menu.AddComponent(new Sprite(Assets.Textures.Menu, 600, 600));
        }
        private static void CreatePlanetEntity(string[] parts, IEntityLookup entityLookup, Dictionary <string, Entity> entities, Action <string> throwFormatException)
        {
            if (parts.Length != 11)
            {
                throwFormatException($"Planet data must have 11 fields, but found {parts.Length} fields.");
            }

            var name   = parts[1];
            var radius = double.Parse(parts[2]);
            var mass   = double.Parse(parts[3]);

            if (mass < 0)
            {
                mass = 1e12 * (4.0 / 3.0) * PI * radius * radius * radius * mass;
            }
            var parentId             = entities[parts[4]].Id;
            var semiMajorAxis        = double.Parse(parts[5]);
            var eccentricity         = double.Parse(parts[6]);
            var longitudeOfPeriapsis = double.Parse(parts[7]);
            var meanAnomaly          = double.Parse(parts[8]);
            var isRetrograde         = int.Parse(parts[9]) != 0;
            var epoch = int.Parse(parts[10]);

            var entity = EntityUtility.CreatePlanet(entityLookup, name, parentId, mass, radius, semiMajorAxis, eccentricity, longitudeOfPeriapsis, meanAnomaly, isRetrograde, epoch);

            entities.Add(name, entity);
        }
Exemple #8
0
        /// <summary>
        /// 获取一个这是第几次诊断。
        /// </summary>
        /// <param name="surveys"></param>
        /// <returns>0初诊,1复诊。</returns>
        public static int GetDiagnosisCount(this Surveys surveys)
        {
            var ary  = EntityUtility.GetTuples(surveys.UserState);
            var flag = ary.FirstOrDefault(c => c.Item1 == "诊次")?.Item2 ?? 0;

            return((int)flag);
        }
Exemple #9
0
        internal static List <PostPair> GetPostPair(object entity, Control parentControl)
        {
            Type            entityType = entity.GetType();
            string          key        = parentControl.Page.Request.Path + entityType.Name;
            List <PostPair> list       = (List <PostPair>)HttpRuntime.Cache[key];

            if (list == null)
            {
                lock (GetLocker(parentControl.Page.Request.Path))
                {
                    list = (List <PostPair>)HttpRuntime.Cache[key];
                    if (list == null)
                    {
                        HttpRuntime.Cache[key] = list = new List <PostPair>();
                        foreach (PropertyAccess property in EntityUtility.GetEnumerable(entityType))
                        {
                            Control control = FindControl(parentControl, string.Concat(ControlPrefix, property.MappedName))
                                              ?? FindControl(parentControl, string.Concat("auto", property.MappedName));
                            if (control != null)
                            {
                                list.Add(new PostPair(control.UniqueID, property));
                            }
                        }
                    }
                }
            }
            return(list);
        }
        public LobbyList(Game game, State state)
        {
            ParentState = state;
            Game        = game;
            Camera      = new Camera(Domain);

            clientInformation = EntityUtility.CreateMessage(Domain, "", 0, 150, 16);

            EntityUtility.CreateMessage(Domain, "Select lobby", 0, -180, 16);

            // Background
            Entity backGround = new Entity(Domain);

            backGround.AddComponent(new Transform());
            backGround.AddComponent(new Sprite(Assets.Textures.Background, 1280, 720));

            // Menu
            Entity Menu = new Entity(Domain);

            Menu.AddComponent(new Transform());
            Menu.AddComponent(new Sprite(Assets.Textures.Menu, 600, 600));

            // pointer
            left_pointer  = EntityUtility.MenuArrow(Domain, false);
            right_pointer = EntityUtility.MenuArrow(Domain, true);

            UpdateLobbies();
        }
        public TEntity GetById(TKey id)
        {
            var expression = EntityUtility.BuildEqualityExpressionForId <TEntity, TKey>(id);
            var entity     = DbSet.FirstOrDefault(expression);

            return(entity);
        }
Exemple #12
0
        public void FillSystemTypeTest()
        {
            var obj  = new TestCustomObject();
            var prop = typeof(TestCustomObject).GetProperties().FirstOrDefault(z => z.Name == "Id");

            EntityUtility.FillSystemType(obj, prop, "666");
            Assert.AreEqual(666, obj.Id);

            obj.Markers = 100;
            prop        = typeof(TestCustomObject).GetProperties().FirstOrDefault(z => z.Name == "Markers");
            EntityUtility.FillSystemType(obj, prop, "");
            Assert.AreEqual(null, obj.Markers);


            obj.ArrInt = new[] { 987, 543 };
            prop       = typeof(TestCustomObject).GetProperties().FirstOrDefault(z => z.Name == "ArrInt");
            EntityUtility.FillSystemType(obj, prop, "123,456,789");
            Assert.AreEqual(3, obj.ArrInt.Length);
            Assert.AreEqual(123, obj.ArrInt[0]);
            Assert.AreEqual(456, obj.ArrInt[1]);
            Assert.AreEqual(789, obj.ArrInt[2]);


            obj.ArrLong = new[] { (long)987, (long)543 };
            prop        = typeof(TestCustomObject).GetProperties().FirstOrDefault(z => z.Name == "ArrLong");
            EntityUtility.FillSystemType(obj, prop, "123,456,789");
            Assert.AreEqual(3, obj.ArrLong.Length);
            Assert.AreEqual(123, obj.ArrLong[0]);
            Assert.AreEqual(456, obj.ArrLong[1]);
            Assert.AreEqual(789, obj.ArrLong[2]);
        }
Exemple #13
0
        public void CreateSelectionCircle()
        {
            var circle   = gameObject.GetComponentInChildren <LineRenderer>();
            var collider = gameObject.GetComponent <Collider2D>();

            EntityUtility.GetSelectionCircle(collider, circle);
            circle.enabled = false;
        }
Exemple #14
0
        public T Update(T updated, long id)
        {
            T t = Session.Load <T>(EntityUtility.GetRecordId <T>(id));

            t.CopyPropertiesFrom(updated);
            //t.Properties = updated.Properties;
            t.Id = id;
            return(t);
        }
Exemple #15
0
        public async System.Threading.Tasks.Task <T> UpdateAsync(T updated, long id)
        {
            T t = await AsyncSession.LoadAsync <T>(EntityUtility.GetRecordId <T>(id));

            t.CopyPropertiesFrom(updated);
            //t.Properties = updated.Properties;
            t.Id = id;
            return(t);
        }
        public override void init()
        {
            // Input box
            InputBox = EntityUtility.CreateInput(domain, "", 360, 200, 14);

            // Chat layout
            ChatBox = new Entity(domain);
            ChatBox.AddComponent(new Transform());
            ChatBox.AddComponent(new Sprite(Assets.Textures.Chat, 200, 200));
        }
        internal static Expression <Func <TEntity, bool> > GetIdExpression(Guid id)
        {
            var parameterExpression = Expression.Parameter(typeof(TEntity));

            return(Expression.Lambda <Func <TEntity, bool> >(
                       Expression.Equal(
                           Expression.PropertyOrField(parameterExpression, EntityUtility.GetIdPropertyName(typeof(TEntity))),
                           Expression.Constant(id, typeof(Guid)))
                       , parameterExpression
                       ));
        }
        public virtual TEntity GetById <TId, TProperty>(TId id, params Expression <Func <TEntity, TProperty> >[] includes)
        {
            var query      = GetQuery(includes);
            var entityType = typeof(TEntity);
            var parameter  = Expression.Parameter(entityType);
            var left       = Expression.Property(parameter, EntityUtility.GetIdPropertyName(entityType));
            var right      = Expression.Constant(id);
            var body       = Expression.Equal(left, right);
            var predicate  = Expression.Lambda <Func <TEntity, bool> >(body, parameter);

            return(query.SingleOrDefault(predicate));
        }
Exemple #19
0
        public async System.Threading.Tasks.Task <int> DeleteAsync(long id)
        {
            int count    = 0;
            var existing = await AsyncSession.LoadAsync <T>(EntityUtility.GetRecordId <T>(id));

            if (existing != null)
            {
                count = 1;
                AsyncSession.Delete(existing);
            }
            return(count);
        }
Exemple #20
0
        public int Delete(long id)
        {
            int count    = 0;
            var existing = Session.Load <T>(EntityUtility.GetRecordId <T>(id));

            if (existing != null)
            {
                count = 1;
                Session.Delete(existing);
            }
            return(count);
        }
Exemple #21
0
        /// <summary>
        /// 设置诊断次数。
        /// </summary>
        /// <param name="surveys"></param>
        /// <param name="count">0初诊,1复诊。</param>
        public static void SetDiagnosisCount(this Surveys surveys, int count)
        {
            var ary  = EntityUtility.GetTuples(surveys.UserState);
            var flag = ary.FirstOrDefault(c => c.Item1 == "诊次");

            if (null != flag)
            {
                ary.Remove(flag);
            }
            flag = Tuple.Create("诊次", (decimal)count);
            ary.Add(flag);
            surveys.UserState = string.Join(",", ary.Select(c => $"{c.Item1}{c.Item2.ToString()}"));
        }
Exemple #22
0
        public static void Update()
        {
            using (EntityUtility db = new EntityUtility())
            {
                db.DeleteAll("delete from tb_type");

                //AddDatas(db, typeof(PageEnum), EnumType.Type_01.GetValue());
                AddDatas(db, typeof(EnumLevel), EnumType.Type_02.GetValue());
                AddDatas(db, typeof(EnumDevType), EnumType.Type_03.GetValue());
                AddDatas(db, typeof(EnumLanguage), EnumType.Type_04.GetValue());
                AddDatas(db, typeof(EnumMessage), EnumType.Type_05.GetValue());
            }
        }
        public override void ProcessTick(IEntityLookup entityLookup, NotificationLog notificationLog, TimePoint newTime)
        {
            var entities = entityLookup.GetEntitiesMatchingKey(entityLookup.CreateComponentKey <ShipyardComponent>());

            foreach (var entity in entities)
            {
                if (((newTime.Tick - 1) % (int)Math.Round(Constants.TicksPerDay * 365.25 * 5)) == 0)
                {
                    var position = entity.GetRequiredComponent <EllipticalOrbitalPositionComponent>().GetCurrentAbsolutePosition(entityLookup);
                    EntityUtility.CreateShip(entityLookup, $"Discovery {Interlocked.Increment(ref m_shipId)}", position);
                }
            }
        }
        private static void CreateStarEntity(string[] parts, IEntityLookup entityLookup, Dictionary <string, Entity> entities, Action <string> throwFormatException)
        {
            if (parts.Length != 4)
            {
                throwFormatException($"Star data must have 4 fields, but found {parts.Length} fields.");
            }

            var name   = parts[1];
            var radius = double.Parse(parts[2]);
            var mass   = double.Parse(parts[3]);

            var entity = EntityUtility.CreatePlanet(entityLookup, name, mass, radius);

            entities.Add(name, entity);
        }
Exemple #25
0
        public override void update(GameTime gameTime)
        {
            if (!started)
            {
                return;
            }

            Domain.Clean();

            // Updates player names and icons if player is added to remote space on server
            int clientInDomain = 0;

            Domain.ForMatchingEntities <Sprite, Transform>((entity) => {
                clientInDomain++;
            });

            var currentLives = lifeController.Lives;

            foreach (Entity icon in playerIcons)
            {
                icon.Delete();
            }
            foreach (Entity playerName in playerNames)
            {
                playerName.Delete();
            }
            foreach (Entity score in playerScores)
            {
                score.Delete();
            }

            playerScores.Clear();
            playerIcons.Clear();
            playerNames.Clear();

            var players = Connection.Lobby.Players;

            foreach (var player in players)
            {
                var lives = lifeController.GetClientLives(player.Id);

                playerIcons.Add(EntityUtility.CreateIcon(Domain, (int)player.Id));
                playerNames.Add(EntityUtility.CreateMessage(Domain, player.Name, 0, 0, 16, origin: TextOrigin.Left));
                playerScores.Add(EntityUtility.CreateMessage(Domain, lives.ToString(), 0, 0, 16, origin: TextOrigin.Left));
            }

            Display();
        }
Exemple #26
0
        public static void FillEntityWithXml <T>(this T entity, XDocument doc) where T : class, new()
        {
            entity = entity ?? new T();
            var root = doc.Root;

            var props = entity.GetType().GetProperties();

            foreach (var prop in props)
            {
                var propName = prop.Name;
                if (root.Element(propName) != null)
                {
                    switch (prop.PropertyType.Name)
                    {
                    //case "String":
                    //    goto default;
                    case "DateTime":
                    case "Int32":
                    case "Int64":
                    case "Double":
                    case "Nullable`1":     //可为空对象
                        EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value);
                        break;

                    case "Boolean":
                        if (propName == "FuncFlag")
                        {
                            EntityUtility.FillSystemType(entity, prop, root.Element(propName).Value == "1");
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    //以下为枚举类型
                    case "RequestInfoType":
                        //已设为只读
                        break;

                    default:
                        prop.SetValue(entity, root.Element(propName).Value, null);
                        break;
                    }
                }
            }
        }
Exemple #27
0
        public async Task <int> InsertAsync(params T[] entities)
        {
            int insertCount = 0;

            #region PreExecute
            var watch = StartMonitor();
            if (entities == null || entities.Length == 0)
            {
                return(0);
            }
            if (entities != null && entities.Length > 0 && (tableInfo.IsICreateRecord || tableInfo.IsIModifyRecord))
            {
                foreach (T entity in entities)
                {
                    DateTime now = DateTime.Now;
                    if (tableInfo.IsICreateRecord)
                    {
                        var insertEntity = (ICreateRecord)entity;
                        insertEntity.CreateTime     = now;
                        insertEntity.CreateUserId   = AccessUser.UserId;
                        insertEntity.CreateUserName = AccessUser.UserName;
                    }
                    if (tableInfo.IsIModifyRecord)
                    {
                        var modifyEntity = (IModifyRecord)entity;
                        modifyEntity.ModifyTime     = now;
                        modifyEntity.ModifyUserId   = AccessUser.UserId;
                        modifyEntity.ModifyUserName = AccessUser.UserName;
                        modifyEntity.RecordHash     = EntityUtility.GetEntityHash <T>(entity);
                    }
                }
            }
            #endregion

            #region Executing
            insertCount = await OnInsertAsync(entities);

            #endregion

            #region Executed
            Monitoring("Insert", "插入一条或多条数据", entities.ToJson(), watch);
            #endregion

            return(insertCount);
        }
Exemple #28
0
        public async Task <int> UpdateAsync(T entity, string where, params Expression <Func <T, object> >[] fields)
        {
            int updateCount = 0;

            #region PreExecute
            var watch = StartMonitor();
            //重新构建where
            where = BuildWhere(where);

            //处理IModifyRecord
            if (fields != null && fields.Length > 0 && tableInfo.IsIModifyRecord)
            {
                var fieldList = fields.ToList();
                Expression <Func <T, object> > expression = a => (a as IModifyRecord).ModifyTime;
                fieldList.Add(expression as Expression <Func <T, object> >);
                expression = a => (a as IModifyRecord).ModifyUserId;
                fieldList.Add(expression as Expression <Func <T, object> >);
                expression = a => (a as IModifyRecord).ModifyUserName;
                fieldList.Add(expression as Expression <Func <T, object> >);
                expression = a => (a as IModifyRecord).RecordHash;
                fieldList.Add(expression as Expression <Func <T, object> >);

                var baseEntity = entity as IModifyRecord;
                baseEntity.ModifyTime = DateTime.Now;
                if (this.AccessUser != null)
                {
                    baseEntity.ModifyUserId   = this.AccessUser.UserId;
                    baseEntity.ModifyUserName = this.AccessUser.UserName;
                }
                baseEntity.RecordHash = EntityUtility.GetEntityHash <T>(entity, true);
                fields = fieldList.Distinct(new FieldExpressionComparer <T>()).ToArray();
            }
            #endregion

            #region Executing
            updateCount = await OnUpdateAsync(entity, where, fields);

            #endregion

            #region Executed
            Monitoring("Update", "数据更新", string.Format("要更新的数据为[{0}],过滤条件为[{1}],要更新的字段为[{2}]", entity.ToJson(), where, fields.ToJson()), watch);
            #endregion

            return(updateCount);
        }
Exemple #29
0
 private void InterceptPrimaryKey(DbEntityEntry entityEntry)
 {
     if (entityEntry.State == EntityState.Added)
     {
         var entity     = entityEntry.Entity;
         var entityType = entity.GetType();
         var property   = entityType.GetProperty(EntityUtility.GetIdPropertyName(entityType));
         var value      = property.GetValue(entity);
         if (value.GetType() == typeof(Guid))
         {
             var guid = (Guid)value;
             if (guid == Guid.Empty)
             {
                 property.SetValue(entity, Guid.NewGuid());
             }
         }
     }
 }
 public void Handle(IEnumerable <ITrackedEntry> changedEntities)
 {
     foreach (var entityEntry in changedEntities.Where(i => i.State == EntityState.Added))
     {
         var entity     = entityEntry.Entity;
         var entityType = entity.GetType();
         var property   = EntityUtility.GetIdProperty(entityType);
         var value      = property.GetValue(entity);
         if (value.GetType() == typeof(Guid))
         {
             var guid = (Guid)value;
             if (guid == Guid.Empty)
             {
                 property.SetValue(entity, Guid.NewGuid());
             }
         }
     }
 }