예제 #1
0
 public override void UpdateServer(CustomEntity ent)
 {
     if (ent.SyncFromServer)
     {
         this.UpdateMe(ent);
     }
 }
예제 #2
0
        ////////////////

        public override void UpdateClient(CustomEntity ent)
        {
            if (ent.SyncFromClient)
            {
                this.UpdateMe(ent);
            }
        }
예제 #3
0
        public async Task ShouldSaveAndRetrieveCustomEntities()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            var customEntity1 = new CustomEntity()
            {
                PartitionKey = "ShouldSaveAndRetrieveCustomEntities",
                RowKey       = "ShouldSaveAndRetrieveCustomEntities_RowKey1",
                Id           = 6,
                Name         = "six"
            };

            var customEntity2 = new CustomEntity()
            {
                PartitionKey = "ShouldSaveAndRetrieveCustomEntities",
                RowKey       = "ShouldSaveAndRetrieveCustomEntities_RowKey2",
                Id           = 7,
                Name         = "seven"
            };

            var udfAzureTable = new UDFAzureTable(account, TableName);

            await udfAzureTable.SaveAsync(customEntity1);

            await udfAzureTable.SaveAsync(customEntity2);

            var storedEntities = await udfAzureTable.GetExtensionsByPartitionKeyAsync(typeof(CustomEntity), "ShouldSaveAndRetrieveCustomEntities");

            Assert.IsNotNull(storedEntities);
            Assert.AreEqual(customEntity1.ToString(), storedEntities.ToList()[0].ToString());
            Assert.AreEqual(customEntity2.ToString(), storedEntities.ToList()[1].ToString());
        }
예제 #4
0
        private CustomEntity MapEntity(AddCustomEntityCommand command, CustomEntityDefinitionSummary definition, IExecutionContext executionContext)
        {
            var entity = new CustomEntity();

            _entityAuditHelper.SetCreated(entity, executionContext);

            entity.Locale  = GetLocale(command.LocaleId);
            entity.UrlSlug = command.UrlSlug;
            entity.CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode;

            var version = new CustomEntityVersion();

            version.Title          = command.Title.Trim();
            version.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.Model);
            version.DisplayVersion = 1;

            if (command.Publish)
            {
                entity.PublishStatusCode = PublishStatusCode.Published;
                entity.PublishDate       = command.PublishDate ?? executionContext.ExecutionDate;
                version.WorkFlowStatusId = (int)WorkFlowStatus.Published;
            }
            else
            {
                entity.PublishStatusCode = PublishStatusCode.Unpublished;
                entity.PublishDate       = command.PublishDate;
                version.WorkFlowStatusId = (int)WorkFlowStatus.Draft;
            }

            _entityAuditHelper.SetCreated(version, executionContext);
            entity.CustomEntityVersions.Add(version);

            return(entity);
        }
        public static void DrawTexture(SpriteBatch sb, CustomEntity ent, Texture2D tex, int frameCount, Color color, float scale, float rotation = 0f, Vector2 origin = default(Vector2))
        {
            var core         = ent.Core;
            var worldScrRect = new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth, Main.screenHeight);

            if (!core.Hitbox.Intersects(worldScrRect))
            {
                return;
            }

            var scrScrPos = core.position - Main.screenPosition;
            var texRect   = new Rectangle(0, 0, tex.Width, tex.Height / frameCount);

            SpriteEffects dir = DrawsInGameEntityComponent.GetOrientation(core);

            sb.Draw(tex, scrScrPos, texRect, color, rotation, origin, scale, dir, 1f);

            if (ModHelpersMod.Instance.Config.DebugModeCustomEntityInfo)
            {
                var rect = new Rectangle(
                    (int)(core.position.X - Main.screenPosition.X - ((float)origin.X * scale)),
                    (int)(core.position.Y - Main.screenPosition.Y - ((float)origin.Y * scale)),
                    (int)((float)core.width * scale),
                    (int)((float)core.height * scale)
                    );
                HudHelpers.DrawBorderedRect(sb, null, Color.Red, rect, 1);
            }
        }
예제 #6
0
        ////////////////

        private void AttemptShoot(CustomEntity ent, Player targetPlayer)
        {
            if (!this.IgnoresSolidCover)
            {
                bool isBlocked = false;

                Utils.PlotTileLine(ent.Core.Center, targetPlayer.Center, 1f, (x, y) => {
                    if (TileHelpers.IsSolid(Main.tile[x, y]))
                    {
                        isBlocked = true;
                        return(false);
                    }
                    return(true);
                });

                if (isBlocked)
                {
                    return;
                }
            }

            if (this.Cooldown <= 0)
            {
                this.Cooldown = this.MaxCooldown;

                this.Shoot(ent, targetPlayer);
            }
        }
        ////////////////

        private void UpdateMe(CustomEntity ent)
        {
            var     core = ent.Core;
            bool    respectsGravity = ent.GetComponentByType <RespectsGravityEntityComponent>() != null;
            Vector2 wetVelocity = core.velocity * 0.5f;
            bool    lavaWet, honeyWet;

            if (!respectsGravity)
            {
                this.ApplyZeroGravityMovement(ent);
            }
            this.RefreshLiquidContactStates(ent, out lavaWet, out honeyWet);
            this.ApplyLiquidMovement(ent, lavaWet, honeyWet);
            this.ApplyCollisionMovement(ent, ref wetVelocity);
            this.ApplySlopeDodgeAndConveyorMovement(ent);

            if (core.wet)
            {
                core.position += wetVelocity;
            }
            else
            {
                core.position += core.velocity;
            }
        }
예제 #8
0
        public bool SetTrainEntityStanding_NoSync(CustomEntity ent, Player owner)
        {
            var mymod      = OnARailMod.Instance;
            var encumb_mod = ModLoader.GetMod("Encumbrance");

            this.IsMountedBy = -1;

            owner.position.Y -= 12;

            ent.Core.Center      = owner.Center;
            ent.Core.position.Y -= 16;
            ent.Core.direction   = owner.direction;

            if (encumb_mod != null)
            {
                encumb_mod.Call("EnableEncumbrance");
            }

            if (owner.whoAmI == Main.myPlayer && Main.netMode == 1)                  // needed because player mounts aren't synced to server...?
            {
                ent.SyncToAll();
            }

            return(true);
        }
예제 #9
0
        public void BuildDataRow(DataTable dt, DataRow dr, CustomEntity customEntity)
        {
            int nLength = this._SelectedFields.Count;

            for (int i = 0; i < nLength; i++)
            {
                FieldInfo field   = this._SelectedFields[i];
                Type      colType = dt.Columns[_SelectedFields[i].Name].DataType;
                string    sValue  = customEntity.Properties[i] != null ? customEntity.Properties[i].ToString().Trim() : string.Empty;
                if (FieldInfo.HasFunctionField(field))
                {
                    sValue = customEntity.FuncValues[i] != null ? customEntity.FuncValues[i].ToString().Trim() : string.Empty;
                }

                object value = null;
                TypeHelper.GetValue(sValue, colType, field, out value);
                if (value == null)
                {
                    if (!string.IsNullOrEmpty(field.DBDefaulValueOrBinding))
                    {
                        value = field.GetDBDefaulValueOrBinding();
                    }

                    if (value == null)
                    {
                        value = DBNull.Value;
                    }
                }

                dr[this._SelectedFields[i].Name] = value;
            }
        }
예제 #10
0
        public static void WarpPlayerToTrain(Player player)
        {
            if (!SaveableEntityComponent.HaveAllEntitiesLoaded)
            {
                throw new HamstarException("OnARail.TrainEntityHandler.WarpPlayerToTrain - Entities not loaded.");
            }

            var myplayer = player.GetModPlayer <OnARailPlayer>();

            if (myplayer.MyTrainWho == -1)
            {
                throw new HamstarException("OnARail.TrainEntityHandler.WarpPlayerToTrain - Player " + player.name + " (" + player.whoAmI + ") has no train.");
            }

            CustomEntity train_ent = CustomEntityManager.GetEntityByWho(myplayer.MyTrainWho);

            if (train_ent == null)
            {
                throw new HamstarException("OnARail.TrainEntityHandler.WarpPlayerToTrain - Player " + player.name + " (" + player.whoAmI + ") has no train entity.");
            }

            PlayerHelpers.Teleport(player, train_ent.Core.Center - new Vector2(player.width / 2, (player.height / 2) + 16));

            int train_buff_id = OnARailMod.Instance.BuffType <TrainMountBuff>();

            player.AddBuff(train_buff_id, 30);
        }
 private void UpdateMe(CustomEntity ent)
 {
     if (this.CheckMouseHover(ent))
     {
         this.OnMouseHover(ent);
     }
 }
예제 #12
0
 public void DisplayMembers(Identifier modelId, CustomVersion versionId, CustomEntity entity, string searchTerm)
 {
     try
     {
         if (modelId == null || versionId == null || entity == null)
         {
             return;
         }
         List <Member> members = MDSWrapper.GetMembers(modelId, versionId.Identifier, entity, searchTerm);
         this.lstMembers.Items.Clear();
         (this.FindForm() as Form1).ProgressBar.Maximum = members.Count;
         foreach (Member m in members)
         {
             ((ListBox.ObjectCollection) this.lstMembers.Items).Add((object)new CustomMember(m));
             (this.FindForm() as Form1).ProgressBar.PerformStep();
         }
         this.lstMembers.DisplayMember = this.rbNameCode.Checked ? "NameCode" : "CodeName";
         (this.FindForm() as Form1).ProgressBar.Value = 0;
         //this.lblCntMembers.Text = this.lstMembers.Items.Count.ToString();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #13
0
        ////////////////

        private void UpdateMe(CustomEntity myent, Player owner)
        {
            if (owner.mount.Active && owner.mount.Type == OnARailMod.Instance.MountType <TrainMount>())
            {
                if (this.IsMountedBy == -1)
                {
                    this.SetTrainEntityFollowing_NoSync(myent, owner);
                }
            }
            else
            {
                if (this.IsMountedBy != -1)
                {
                    this.SetTrainEntityStanding_NoSync(myent, owner);
                }
            }

            if (this.IsMountedBy != -1)
            {
                if (this.IsMountedBy == owner.whoAmI)
                {
                    if (!owner.active || owner.dead)
                    {
                        this.SetTrainEntityStanding_NoSync(myent, owner);                            // failsafe
                    }
                    else
                    {
                        myent.Core.Center = owner.MountedCenter + new Vector2(0, 22);                           // Follows dumbly while inactive
                    }
                }
            }
        }
예제 #14
0
        ////////////////

        protected override void OnMouseHover(CustomEntity ent)
        {
            Player player = Main.LocalPlayer;

            this.IsMouseHovering = player.Distance(ent.Core.Center) <= TrainMouseInteractionEntityComponent.BoardingDistance;

            if (this.IsMouseHovering)
            {
                if (Main.mouseRight)
                {
                    var draw_comp = ent.GetComponentByType <TrainDrawInGameEntityComponent>();

                    if (!player.dead && !draw_comp.IsMinecartIconHovering)
                    {
                        var myplayer = player.GetModPlayer <OnARailPlayer>();

                        if (!myplayer.IsInInitLockdown)
                        {
                            if (ent.MyOwnerPlayerWho == player.whoAmI)
                            {
                                int train_buff_id = OnARailMod.Instance.BuffType <TrainMountBuff>();

                                if (player.FindBuffIndex(train_buff_id) == -1)
                                {
                                    player.AddBuff(train_buff_id, 30);                                          // Board train
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #15
0
        public static CustomEntitiesDefinition GetEntitiesDefinition(
            int maximumFuziness  = 0,
            bool caseSensitive   = false,
            bool accentSensitive = false,
            params string[] words)
        {
            var targetCustomEntities = new List <CustomEntity>();

            foreach (var word in words)
            {
                var entity = new CustomEntity(
                    name: word,
                    description: $"description of {word}",
                    type: $"type of {word}",
                    subtype: $"subtype of {word}",
                    id: $"id of {word}",
                    caseSensitive: caseSensitive,
                    accentSensitive: accentSensitive,
                    fuzzyEditDistance: maximumFuziness,
                    defaultCaseSensitive: false,
                    defaultAccentSensitive: false,
                    defaultFuzzyEditDistance: 0,
                    aliases: null);
                targetCustomEntities.Add(entity);
            }

            var entitiesDefinition = new CustomEntitiesDefinition(targetCustomEntities);

            return(entitiesDefinition);
        }
예제 #16
0
        private void GenerateColumns(DataGrid dataGrid, SheetInfo sheetInfo)
        {
            dataGrid.Columns.Clear();
            int i = 0;

            #region Dynamic Columns

            foreach (var m_Column in sheetInfo.Columns)
            {
                if (m_Column.Index > 0)
                {
                    string m_FieldName           = CustomEntity.GetPropertyName(i);
                    string m_BackgroundFieldName = CustomEntity.GetBackgroundFieldName(i);

                    //Use FColumn -> CellTemplate
                    DataGridTemplateColumn m_TemplateColumn = new DataGridTemplateColumn()
                    {
                        Header     = m_Column.Header,
                        IsReadOnly = false,
                    };
                    m_TemplateColumn.CellTemplate = GetDataTemplate(m_FieldName, m_BackgroundFieldName);

                    dataGrid.Columns.Add(m_TemplateColumn);
                    i++;
                }
            }

            #endregion
        }
예제 #17
0
        ////////////////

        public override void UpdateSingle(CustomEntity myent)
        {
            if (myent.MyOwnerPlayerWho == Main.myPlayer)
            {
                this.UpdateMe(myent, Main.LocalPlayer);
            }
        }
        ////////////////

        public void SnapToTrack(CustomEntity ent, int tileX, int tileY)
        {
            Entity core = ent.Core;

            core.position.Y = ((tileY * 16) - core.height) + 8;
            core.velocity.X = 0;
            core.velocity.Y = 0;
        }
		public void properties_and_events_exposed_by_the_class_are_successfully_resolved_and_bound(BindingManager bindingManager, CustomEntity targetObject, CustomEntity sourceObject)
		{
			SetName(sourceObject, "A new name");
			Assert.Equal("A new name", GetName(targetObject));

			SetName(targetObject, "Another name");
			Assert.Equal("Another name", GetName(sourceObject));
		}
예제 #20
0
        public List <CustomEntity> RetrieveActivitySummary(int userId, DateTime activityFromDate, DateTime activityToDate)
        {
            SqlCommand     command = null;
            SqlDataAdapter adapter = null;

            try
            {
                //Define The Command.
                command             = mDbConnection.CreateCommand();
                command.CommandText = "[RetrieveActivitySummaryForReset]";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@UserId", SqlDbType.VarChar).Value            = userId;
                command.Parameters.Add("@ActivityFromDate", SqlDbType.DateTime).Value = activityFromDate;
                command.Parameters.Add("@ActivityToDate", SqlDbType.DateTime).Value   = activityToDate;
                //Execute The Command
                adapter = new SqlDataAdapter(command);
                DataTable dtResetActivity = new DataTable("ActivitySummary");
                adapter.Fill(dtResetActivity);

                // Create List
                List <CustomEntity> summaryList = null;
                if (dtResetActivity.Rows.Count > 0)
                {
                    summaryList = new List <CustomEntity>();
                }

                // Iterate each row.
                foreach (DataRow row in dtResetActivity.Rows)
                {
                    // Create an instance.
                    CustomEntity entity = new CustomEntity();
                    entity.CustomData.Add("ActivityDate", row["ActivityDate"]);
                    entity.CustomData.Add("UserId", row["UserId"]);
                    entity.CustomData.Add("UserName", row["UserName"]);
                    entity.CustomData.Add("ActivityCount", row["ActivityCount"]);

                    // Add to list.
                    summaryList.Add(entity);
                }

                // Return the list.
                return(summaryList);
            }

            catch { throw; }
            finally
            {
                // Dispose.
                if (adapter != null)
                {
                    adapter.Dispose();
                }
                if (command != null)
                {
                    command.Dispose();
                }
            }
        }
예제 #21
0
        ////

        public void Shoot(CustomEntity ent, Player targetPlayer)
        {
            var aim = targetPlayer.Center - ent.Core.Center;

            aim.Normalize();
            aim = this.GetShotVelocity(aim);

            Projectile.NewProjectile(ent.Core.Center, aim, this.ProjectileType, this.GetShotDamage(), this.GetShotKnockback());
        }
 public void DrawFullscreenMap(SpriteBatch sb, CustomEntity ent)
 {
     if (!this.PreDrawFullscreenMap(sb, ent))
     {
         return;
     }
     DrawsOnMapEntityComponent.DrawToFullMap(sb, this.Texture, this.GetColor(ent), ent.Core.Center, this.Zooms, this.Scale);
     this.PostDrawFullscreenMap(sb, ent);
 }
예제 #23
0
        public override void UpdateServer(CustomEntity ent)
        {
            var train_comp = ent.GetComponentByType <TrainBehaviorEntityComponent>();

            if (train_comp.IsMountedBy == -1)
            {
                base.UpdateServer(ent);
            }
        }
예제 #24
0
        ////////////////

        private void OnLoad(CustomEntity ent)
        {
            var behav_comp = ent.GetComponentByType <TrainBehaviorEntityComponent>();

            if (behav_comp == null)
            {
                throw new HamstarException("Train entity " + ent.ToString() + " is missing TrainBehaviorEntityComponent.");
            }
        }
예제 #25
0
 public static CustomEntity CreateCustomEntityWithCylinder()
 {
     var entity = new CustomEntity
     {
         Name = Helper.GetUniqueName(),
         Geometry = new Cylinder {TopRadius = 10.2, BaseRadius = 10.2, Height = 11.3}
     };
     SetTransformation(((IHasObjectSpace) entity.Geometry), 2, 3, 4);
     return entity;
 }
        public void TestCustomObject()
        {
            var original = new CustomEntity {
                Id = 10
            };
            var data = DefaultSerializer.Serialize(original);
            var copy = (CustomEntity)DefaultSerializer.Deserialize(data);

            Assert.That(copy.Id, Is.EqualTo(original.Id));
        }
        private Task OnTransactionComplete(CustomEntity entity)
        {
            _customEntityCache.Clear(entity.CustomEntityDefinitionCode, entity.CustomEntityId);

            return(_messageAggregator.PublishAsync(new CustomEntityUnPublishedMessage()
            {
                CustomEntityId = entity.CustomEntityId,
                CustomEntityDefinitionCode = entity.CustomEntityDefinitionCode
            }));
        }
        private Task OnTransactionComplete(DeleteCustomEntityCommand command, CustomEntity customEntity)
        {
            _customEntityCache.Clear(customEntity.CustomEntityDefinitionCode, command.CustomEntityId);

            return(_messageAggregator.PublishAsync(new CustomEntityDeletedMessage()
            {
                CustomEntityId = command.CustomEntityId,
                CustomEntityDefinitionCode = customEntity.CustomEntityDefinitionCode
            }));
        }
예제 #29
0
        private IList <CustomEntity> ReadData(string fileName, SheetInfo sheetInfo)
        {
            IList <CustomEntity> m_CustomEntities    = new List <CustomEntity>();
            ExcelReaderWriter    m_ExcelReaderWriter = new ExcelReaderWriter(fileName, sheetInfo.Index);

            try
            {
                m_ExcelReaderWriter.OpenWorkbook();
                object[,] m_Values = (object[, ])m_ExcelReaderWriter.ActiveWorksheet.UsedRange.Value2;
                if (m_Values != null)
                {
                    if (sheetInfo.BeginRowIndex == 0)
                    {
                        sheetInfo.BeginRowIndex = 0;
                    }
                    if (sheetInfo.EndRowIndex == 0)
                    {
                        sheetInfo.EndRowIndex = (int)m_Values.GetLongLength(0);
                    }

                    if (m_Values != null)
                    {
                        for (int m_RowIndex = sheetInfo.BeginRowIndex; m_RowIndex <= sheetInfo.EndRowIndex; m_RowIndex++)
                        {
                            CustomEntity m_CustomEntity = new CustomEntity();

                            //Dynamic value excel
                            foreach (var m_ColumnInfo in sheetInfo.Columns)
                            {
                                if (m_ColumnInfo.Index != 0)
                                {
                                    //Range a = (Range)m_ExcelReaderWriter.ActiveWorksheet.UsedRange[m_RowIndex, m_ColumnInfo.Index];
                                    //var x = a.Text;
                                    var    x             = m_Values[m_RowIndex, m_ColumnInfo.Index];
                                    string m_ValueString = string.Format("{0}", x);// m_Values[m_RowIndex, m_ColumnInfo.Index]);
                                    m_CustomEntity.Properties.Add(m_ValueString);
                                }
                            }

                            m_CustomEntities.Add(m_CustomEntity);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                m_ExcelReaderWriter.CloseWorkbook();
            }

            return(m_CustomEntities);
        }
예제 #30
0
        public CustomEntityRoute Map(
            CustomEntity dbCustomEntity,
            ActiveLocale locale
            )
        {
            if (dbCustomEntity == null)
            {
                throw new ArgumentNullException(nameof(dbCustomEntity));
            }
            if (dbCustomEntity.CustomEntityVersions == null)
            {
                throw new ArgumentNullException(nameof(dbCustomEntity.CustomEntityVersions));
            }

            var route = new CustomEntityRoute()
            {
                CustomEntityDefinitionCode = dbCustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbCustomEntity.CustomEntityId,
                UrlSlug         = dbCustomEntity.UrlSlug,
                Locale          = locale,
                PublishDate     = dbCustomEntity.PublishDate,
                LastPublishDate = dbCustomEntity.LastPublishDate,
                PublishStatus   = dbCustomEntity.PublishStatusCode == PublishStatusCode.Published ? PublishStatus.Published : PublishStatus.Unpublished,
                Ordering        = dbCustomEntity.Ordering
            };

            bool hasLatestPublishVersion = false;

            route.Versions = new List <CustomEntityVersionRoute>();

            foreach (var dbVersion in dbCustomEntity
                     .CustomEntityVersions
                     .OrderByLatest())
            {
                var version = new CustomEntityVersionRoute()
                {
                    CreateDate     = dbVersion.CreateDate,
                    Title          = dbVersion.Title,
                    VersionId      = dbVersion.CustomEntityVersionId,
                    WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId
                };

                if (!hasLatestPublishVersion && version.WorkFlowStatus == WorkFlowStatus.Published)
                {
                    version.IsLatestPublishedVersion = true;
                    hasLatestPublishVersion          = true;
                }
                route.Versions.Add(version);
            }

            route.HasDraftVersion     = route.Versions.Any(v => v.WorkFlowStatus == WorkFlowStatus.Draft);
            route.HasPublishedVersion = route.Versions.Any(v => v.WorkFlowStatus == WorkFlowStatus.Published);

            return(route);
        }
예제 #31
0
        ////

        protected virtual bool UpdateMe(CustomEntity ent)
        {
            if (this.NextSync-- <= 0)
            {
                this.NextSync = PeriodicSyncEntityComponent.GetRandomSyncDuration();

                ent.SyncToAll();
                return(true);
            }
            return(false);
        }
예제 #32
0
        private Task OnTransactionComplete(CustomEntity entity)
        {
            _customEntityCache.Clear(entity.CustomEntityDefinitionCode, entity.CustomEntityId);

            return(_messageAggregator.PublishAsync(new CustomEntityUrlChangedMessage()
            {
                CustomEntityId = entity.CustomEntityId,
                CustomEntityDefinitionCode = entity.CustomEntityDefinitionCode,
                HasPublishedVersionChanged = entity.PublishStatusCode == PublishStatusCode.Published
            }));
        }
		private string GetName(CustomEntity customEntity)
		{
			return TypeDescriptor.GetProperties(customEntity).Find("Name", false).GetValue(customEntity) as string;
		}
		private void SetName(CustomEntity customEntity, string name)
		{
			TypeDescriptor.GetProperties(customEntity).Find("Name", false).SetValue(customEntity, name);
		}