public override void Save(SampleBlock block, IBlockEntity entity) { // By default 'BlockHandlerBase<TBlock>' stores block instance data as JSON in the 'Model' field of the 'PageStoryBlock' table. // You can, however, store data anywhere you like and override persistance behaviour in this method. base.Save(block, entity); }
public virtual void Save(T block, IBlockEntity entity) { Guard.NotNull(entity, nameof(entity)); if (block == null) { return; } var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, ObjectCreationHandling = ObjectCreationHandling.Replace, NullValueHandling = NullValueHandling.Ignore }; entity.Model = JsonConvert.SerializeObject(block, Formatting.None, settings); // save BindEntintyName & BindEntintyId if (block is IBindableBlock bindableBlock) { entity.BindEntityId = bindableBlock.BindEntityId; entity.BindEntityName = bindableBlock.BindEntityName; } }
public Task SetEntity(IBlockEntity furnaceEntity) { SlotAreas.Clear(); _properties.Clear(); SlotAreas.Add(new FurnaceSlotArea(furnaceEntity, this, GrainFactory)); SlotAreas.Add(new InventorySlotArea(this, GrainFactory)); SlotAreas.Add(new HotbarSlotArea(this, GrainFactory)); _furnaceEntity = furnaceEntity; return(Task.CompletedTask); }
private async Task <IBlockEntity> FindMasterEntity(IBlockEntity neighborEntity) { if (NeighborEntity == null) { return(AttachedObject.AsReference <IBlockEntity>()); } async Task <(IBlockEntity entity, BlockWorldPos position)> GetPosition(IBlockEntity entity) => (entity, await entity.GetPosition()); // 按 X, Z 排序取最小 return((from e in await Task.WhenAll(new[] { GetPosition(AttachedObject.AsReference <IBlockEntity>()), GetPosition(NeighborEntity) }) orderby e.position.X, e.position.Z select e.entity).First()); }
public virtual T Load(IBlockEntity entity, StoryViewMode viewMode) { Guard.NotNull(entity, nameof(entity)); var block = Create(entity); var json = entity.Model; if (json.IsEmpty()) { return(block); } JsonConvert.PopulateObject(json, block); if (block is IBindableBlock bindableBlock) { bindableBlock.BindEntityName = entity.BindEntityName; bindableBlock.BindEntityId = entity.BindEntityId; } return(block); }
internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, ref string fileName, string blockName) { string kMethodName = "DSBlock.ByCoordinateSystem "; if (null == contextCoordinateSystem) { throw new ArgumentNullException("contextCoordinateSystem"); } if (contextCoordinateSystem.IsSheared) { throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem"); } if (string.IsNullOrEmpty(blockName)) { throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName"); } fileName = DSGeometryExtension.LocateFile(fileName); if (!File.Exists(fileName)) { throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, fileName), "fileName"); } IBlockHelper helper = HostFactory.Factory.GetBlockHelper(); if (null == helper) { throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); } IBlockEntity entity = helper.InsertBlockFromFile(contextCoordinateSystem.CSEntity, fileName, blockName); if (null == entity) { throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName)); } return(entity); }
public override SampleBlock Load(IBlockEntity entity, StoryViewMode viewMode) { var block = base.Load(entity, viewMode); // By default 'BlockHandlerBase<TBlock>' stores block instance data as JSON in the 'Model' field of the 'PageStoryBlock' table. // You can, however, store data anywhere you like and override loading behaviour in this method. if (viewMode == StoryViewMode.Edit) { // You can prepare your model especially for the edit mode of the block, // e.g. add some SelectListItems for dropdownmenus which you will only need in the edit mode of the block block.MyProperties.Add(new SelectListItem { Text = "Item1", Value = "1" }); } else if (viewMode == StoryViewMode.GridEdit) { // Manipulate properties especially for the grid edit mode e.g. turn of any animation which could distract the user from editing the grid. //block.Autoplay = false; } return(block); }
internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, string blockName) { string kMethodName = "DSBlock.ByCoordinateSystem "; if (null == contextCoordinateSystem) { throw new ArgumentNullException("contextCoordinateSystem"); } if (contextCoordinateSystem.IsSheared) { throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem"); } if (string.IsNullOrEmpty(blockName)) { throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName"); } IBlockHelper helper = HostFactory.Factory.GetBlockHelper(); if (null == helper) { throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); } if (!helper.BlockExistsInCurrentDocument(blockName)) { throw new System.ArgumentException(string.Format(Properties.Resources.DoesNotExist, "DSBlock : " + blockName)); } IBlockEntity entity = helper.InsertBlockFromCurrentDocument(contextCoordinateSystem.CSEntity, blockName); if (null == entity) { throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName)); } return(entity); }
protected virtual void AppendBlock(T entity, IBlockEntity block) { }
private DSBlockInstance(IBlockEntity entity, bool persist = false) : base(entity, persist) { InitializeGuaranteedProperties(); }
public virtual void AfterSave(IBlockContainer container, IBlockEntity entity) { // Default impl does nothing. }
protected override void AppendBlock(Category entity, IBlockEntity block) { entity.Blocks.Add((CategoryBlock)block); base.AppendBlock(entity, block); }
protected override void RemoveBlock(Category entity, IBlockEntity block) { entity.Blocks.Remove((CategoryBlock)block); DataModelContext.Set <CategoryBlock>().Remove((CategoryBlock)block); base.RemoveBlock(entity, block); }
public FurnaceSlotArea(IBlockEntity furnaceEntity, WindowGrain window, IGrainFactory grainFactory) : base(FurnaceSlotsCount, window, grainFactory) { _furnaceEntity = furnaceEntity; }
public virtual string Clone(IBlockEntity sourceEntity, IBlockEntity clonedEntity) { return(sourceEntity.Model); }
protected override void AppendBlock(Location entity, IBlockEntity block) { entity.Blocks.Add((LocationBlock)block); base.AppendBlock(entity, block); }
public virtual T Create(IBlockEntity entity) { return(Activator.CreateInstance <T>()); }
protected virtual void RemoveBlock(T entity, IBlockEntity block) { }
private BlockInstance(IBlockEntity entity, bool persist = false) : base(entity, persist) { InitializeGuaranteedProperties(); }
protected override void RemoveBlock(Location entity, IBlockEntity block) { entity.Blocks.Remove((LocationBlock)block); DataModelContext.Set <LocationBlock>().Remove((LocationBlock)block); base.RemoveBlock(entity, block); }