internal IEnumerable <TemplateUiInfo> GetCompatibleViews(IApp app, BlockConfiguration blockConfiguration) { IEnumerable <IView> availableTemplates; var items = blockConfiguration.Content; // if any items were already initialized... if (items.Any(e => e != null)) { availableTemplates = GetFullyCompatibleViews(blockConfiguration); } // if it's only nulls, and only one (no list yet) else if (items.Count <= 1) { availableTemplates = GetAll(); } // if it's a list of nulls, only allow lists else { availableTemplates = GetAll().Where(p => p.UseForList); } return(availableTemplates.Select(t => new TemplateUiInfo { TemplateId = t.Id, Name = t.Name, ContentTypeStaticName = t.ContentType, IsHidden = t.IsHidden, Thumbnail = Parent.ServiceProvider.Build <TemplateHelpers>().Init(app, Log).IconPathOrNull(t, PathTypes.Link) })); }
protected new BlockConfiguration GetBlockConfiguration(string alias, string tag) { BlockConfiguration back = new BlockConfiguration(); string[] optionList = null; string blockOptionStr = ""; if (!string.IsNullOrWhiteSpace(alias)) { optionList = alias.Replace(@"\r\n", string.Empty).Split(';'); blockOptionStr = !string.IsNullOrWhiteSpace(tag) ? tag.Replace(@"\r\n", string.Empty) : string.Empty; } else if (!string.IsNullOrWhiteSpace(tag)) { optionList = tag.Replace(@"\r\n", string.Empty).Split(';'); if (optionList.Length >= 3) { blockOptionStr = optionList[2]; } } if (null == optionList || optionList.Length < 2) { return(back); } back.Type = optionList[0]; back.Name = optionList[1]; if (optionList.Length > 2 && string.IsNullOrWhiteSpace(blockOptionStr)) { blockOptionStr += $",{optionList.Skip(2).Aggregate((current, next) => $"{current},{next}")}"; } back.Options = string.IsNullOrWhiteSpace(blockOptionStr) ? new Dictionary <string, string>() : ParseOptions(blockOptionStr); return(back); }
private static void ConvertListIndexToEntityIds(ItemIdentifier identifier, BlockConfiguration blockConfiguration) { var part = blockConfiguration[identifier.Group.Part]; if (!identifier.ListAdd()) // not in add-mode { var idx = identifier.ListIndex(); if (part.Count > idx && // has as many items as desired part[idx] != null) // and the slot has something { identifier.EntityId = part[idx].EntityId; } } // tell the UI that it should not actually use this data yet, keep it locked if (!identifier.Group.Part.ToLower().Contains(ViewParts.PresentationLower)) { return; } // the following steps are only for presentation items identifier.Group.SlotCanBeEmpty = true; // all presentations can always be locked if (identifier.EntityId != 0) { return; } identifier.Group.SlotIsEmpty = true; // if it is blank, then lock this one to begin with identifier.DuplicateEntity = identifier.Group.Part.ToLower() == ViewParts.PresentationLower ? blockConfiguration.View.PresentationItem?.EntityId : blockConfiguration.View.HeaderPresentationItem?.EntityId; }
/// <summary> /// Parse the document in order to proceed to the alimentation of all blocks into the given container. /// </summary> /// <param name="container">Container to build.</param> public virtual void ParseDocument(OpenXmlPartContainer container) { IList <BlockItem> blocks = GetBlocks(container); foreach (BlockItem block in blocks) { BlockConfiguration config = GetBlockConfiguration(block); try { if (TextBlock.IsMatching(config.Type)) { TextBlock.BuildContent(ReportData, container, block, config.Name, config.Options); } else if (TableBlock.IsMatching(config.Type)) { TableBlock.BuildContent(ReportData, container, block, config.Name, config.Options); } else if (GraphBlock.IsMatching(config.Type)) { GraphBlock.BuildContent(ReportData, Package, block, config.Name, config.Options); } else { LogHelper.Instance.LogWarnFormat("Block type '{0}' not found.", config.Type); } } catch (Exception exception) { string logMessage = $"Exception thrown during document parsing (BlockType : {(null != config ? config.Type : string.Empty)}, BlockName : {(null != config ? config.Name : string.Empty)})"; LogHelper.Instance.LogError(logMessage, exception); } } }
/// <summary> /// Get templates which match the signature of possible content-items, presentation etc. of the current template /// </summary> /// <param name="blockConfiguration"></param> /// <returns></returns> private IEnumerable <IView> GetFullyCompatibleViews(BlockConfiguration blockConfiguration) { var isList = blockConfiguration.Content.Count > 1; var compatibleTemplates = GetAll().Where(t => t.UseForList || !isList); compatibleTemplates = compatibleTemplates .Where(t => blockConfiguration.Content.All(c => c == null) || blockConfiguration.Content.First(e => e != null).Type.StaticName == t.ContentType) .Where(t => blockConfiguration.Presentation.All(c => c == null) || blockConfiguration.Presentation.First(e => e != null).Type.StaticName == t.PresentationType) .Where(t => blockConfiguration.Header.All(c => c == null) || blockConfiguration.Header.First(e => e != null).Type.StaticName == t.HeaderType) .Where(t => blockConfiguration.HeaderPresentation.All(c => c == null) || blockConfiguration.HeaderPresentation.First(e => e != null).Type.StaticName == t.HeaderPresentationType); return(compatibleTemplates); }
/// <summary> /// Updates a single voxel at a position in the world /// </summary> /// <param name="point">A global position in the voxel world</param> /// <param name="voxel">The block index that will be added</param> /// <param name="refresh">Flags if listeners should be notifed</param> public void Write(Vector3Int point, byte voxel, bool refresh = true) { if (!Contains(point)) { return; } // point is out of bounds Vector3Int chunkIndex = chunkManager.IndexFrom(point); Chunk chunk = chunkManager.Get(chunkIndex); if (chunk == null) { return; } // the chunk is missing Vector3Int localPos = point - chunk.offset; byte original = chunk.Read(localPos); if (voxel == original) { return; } // skip duplicate voxels BlockConfiguration originalBlock = blockManager.blocks[original]; if (!originalBlock.editable) { return; } // block can not be changed chunk.Write(localPos, voxel, refresh); if (refresh) { chunkManager.UpdateFrom(point); } if (refresh && modified != null) { modified.Invoke(default);
private void BuildReportTemplateEFPFlexi(string strTargetFile) { string fileName = strTargetFile; const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string[] alph = new string[676]; // 676 = 26*26 for (int i = 0; i < 26; i++) { alph[i] = alphabet.Substring(i, 1); } for (int i = 0; i < 26; i++) { for (int j = 0; j < 26; j++) { alph[26 + i + j] = alphabet.Substring(i, 1) + alphabet.Substring(j, 1); } } var tableTargets = new List <TableInfo>(); using (SpreadsheetDocument workbook = SpreadsheetDocument.Open(fileName, true)) { var workbookPart = workbook.WorkbookPart; var sharedStringPart = workbookPart.SharedStringTablePart; var values = sharedStringPart.SharedStringTable.Elements <SharedStringItem>().ToArray(); foreach (WorksheetPart worksheetpart in workbookPart.WorksheetParts) { foreach (var sheetData in worksheetpart.Worksheet.Elements <SheetData>()) { // reset accross sheets tableTargets.Clear(); #region TextPopulate foreach (var cell in sheetData.Descendants <Cell>()) { if (cell.CellValue != null) { if (cell.CellFormula != null) { // force recompute cell.CellValue.Remove(); } else if (cell.DataType != null && cell.DataType.Value == CellValues.SharedString) { var index = int.Parse(cell.CellValue.Text); if (values[index].InnerText.StartsWith(FLEXI_PREFIX)) { string strBlockTypeAndName = values[index].InnerText.Substring(FLEXI_PREFIX.Length); BlockConfiguration config = GetBlockConfiguration(strBlockTypeAndName); if (TextBlock.IsMatching(config.Type)) { TextBlock instance = BlockHelper.GetAssociatedBlockInstance <TextBlock>(config.Name); if (instance != null) { SetCellValue(cell, instance.GetContent(reportData, config.Options)); } } else if (TableBlock.IsMatching(config.Type)) { TableBlock instance = BlockHelper.GetAssociatedBlockInstance <TableBlock>(config.Name); if (instance != null) { tableTargets.Add(new TableInfo { cell = cell, table = instance.GetContent(reportData, config.Options) }); } } } } } } #endregion TextPopulate #region TablePopulate foreach (var tableInfo in tableTargets) { var _finaleCell = tableInfo.cell; var _finaleTable = tableInfo.table; int intColumns = _finaleTable.NbColumns; // TODO: handle cell references after 'ZZ' (AA1, AB1...) // TODO: current limitation: the generated cells must be in the range "A-ZZ" string firstLetter = _finaleCell.CellReference.InnerText[0].ToString(); int firstColIdx = alph.ToList().IndexOf(firstLetter) + 1; int lastColIdx = firstColIdx + intColumns - 1; int curColIdx = firstColIdx; uint firstRowIdx = uint.Parse(_finaleCell.CellReference.InnerText.Substring(1)); uint curRowIdx = firstRowIdx; // create first row Row curRow = new Row(); foreach (var result in _finaleTable.Data) { // append cell to current row Cell c = new Cell(); SetCellValue(c, result); // to avoid crash when too many columns generated if (curColIdx > 676) { continue; } c.CellReference = alph[curColIdx - 1] + curRowIdx.ToString(); c.StyleIndex = 0; // ReSharper disable once PossiblyMistakenUseOfParamsMethod curRow.Append(c); if (curColIdx == lastColIdx) { // add row to current worksheet InsertRow(curRowIdx, worksheetpart, curRow); // create new row for next data curRow = new Row(); // first cell on next row curRowIdx++; curColIdx = firstColIdx; } else { // next cell curColIdx++; } } _finaleCell.Parent.RemoveChild(_finaleCell); } workbookPart.Workbook.Save(); #endregion TablePopulate } } } }
public void AddEmptyItem(BlockConfiguration block, int?sortOrder, bool forceDraft) => Parent.Entities.FieldListUpdate(block.Entity, ViewParts.ContentPair, forceDraft, lists => lists.Add(sortOrder, new int?[] { null, null }));
private void BuildReportTemplateEFPFlexi(string strTargetFile) { string fileName = strTargetFile; const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var tableTargets = new List <TableInfo>(); using (SpreadsheetDocument workbook = SpreadsheetDocument.Open(fileName, true)) { var workbookPart = workbook.WorkbookPart; var sharedStringPart = workbookPart.SharedStringTablePart; var values = sharedStringPart.SharedStringTable.Elements <SharedStringItem>().ToArray(); foreach (WorksheetPart worksheetpart in workbookPart.WorksheetParts) { foreach (var sheetData in worksheetpart.Worksheet.Elements <SheetData>()) { // reset accross sheets //Cell FinaleCell = null; //TableDefinition FinaleTable = null; tableTargets.Clear(); #region TextPopulate foreach (var cell in sheetData.Descendants <Cell>()) { if (cell.CellValue != null) { if (cell.CellFormula != null) { // force recompute cell.CellValue.Remove(); } else if (cell.DataType != null && cell.DataType.Value == CellValues.SharedString) { var index = int.Parse(cell.CellValue.Text); if (values[index].InnerText.StartsWith(FLEXI_PREFIX)) { string strBlockTypeAndName = values[index].InnerText.Substring(FLEXI_PREFIX.Length); BlockConfiguration config = GetBlockConfiguration(strBlockTypeAndName); if (TextBlock.IsMatching(config.Type)) { TextBlock instance = BlockHelper.GetAssociatedBlockInstance <TextBlock>(config.Name); if (instance != null) { SetCellValue(cell, instance.GetContent(reportData, config.Options)); } } else if (TableBlock.IsMatching(config.Type)) { TableBlock instance = BlockHelper.GetAssociatedBlockInstance <TableBlock>(config.Name); if (instance != null) { tableTargets.Add(new TableInfo { cell = cell, table = instance.GetContent(reportData, config.Options) }); //FinaleCell = cell; //FinaleTable = instance.GetContent(reportData, config.Options); } } } } } } #endregion TextPopulate #region TablePopulate foreach (var tableInfo in tableTargets) { var FinaleCell = tableInfo.cell; var FinaleTable = tableInfo.table; int intColumns = FinaleTable.NbColumns; int intRows = FinaleTable.NbRows; // TODO: handle cell references after 'Znn' (AA1, AB1...) // TODO: current limitation: the generated cells must be in the range "A-Z" char firstLetter = FinaleCell.CellReference.InnerText[0]; int firstColIdx = alphabet.IndexOf(firstLetter) + 1; int lastColIdx = firstColIdx + intColumns - 1; int curColIdx = firstColIdx; uint firstRowIdx = uint.Parse(FinaleCell.CellReference.InnerText.Substring(1)); uint curRowIdx = firstRowIdx; // create first row Row curRow = new Row(); foreach (var result in FinaleTable.Data) { // append cell to current row Cell c = new Cell(); SetCellValue(c, result.ToString()); c.CellReference = alphabet[curColIdx - 1] + curRowIdx.ToString(); c.StyleIndex = 0; curRow.Append(c); if (curColIdx == lastColIdx) { // add row to current worksheet InsertRow(curRowIdx, worksheetpart, curRow, false); // create new row for next data curRow = new Row(); // first cell on next row curRowIdx++; curColIdx = firstColIdx; } else { // next cell curColIdx++; } } FinaleCell.Parent.RemoveChild(FinaleCell); } workbookPart.Workbook.Save(); #endregion TablePopulate } } } }
protected BlockConfiguration GetBlockConfiguration(string alias, string tag) { BlockConfiguration back = new BlockConfiguration(); string[] optionList = null; string blockOptionStr = ""; if (!string.IsNullOrWhiteSpace(alias)) { optionList = alias.Replace(@"\r\n", string.Empty).Split(';'); blockOptionStr = !string.IsNullOrWhiteSpace(tag) ? tag.Replace(@"\r\n", string.Empty) : string.Empty; } else if (!string.IsNullOrWhiteSpace(tag)) { optionList = tag.Replace(@"\r\n", string.Empty).Split(';'); if (optionList.Length >= 3) { blockOptionStr = optionList[2]; } } if (null != optionList && optionList.Length >= 2) { back.Type = optionList[0]; back.Name = optionList[1]; if (optionList.Length > 2 && string.IsNullOrWhiteSpace(blockOptionStr)) { blockOptionStr += string.Format(",{0}", optionList.Skip(2).Aggregate((current, next) => string.Format("{0},{1}", current, next))); } back.Options = string.IsNullOrWhiteSpace(blockOptionStr) ? new Dictionary<string, string>() : ParseOptions(blockOptionStr); } return back; }
public void AddEmptyItem(BlockConfiguration block, int?sortOrder) => AppManager.Entities.FieldListUpdate(block.Entity, ViewParts.ContentPair, block.VersioningEnabled, lists => lists.Add(sortOrder, new int?[] { null, null }));
//public void ChangeOrder(BlockConfiguration block, int sourceIndex, int targetIndex) //{ // var wrapLog = Log.Call($"change order orig:{sourceIndex}, dest:{targetIndex}"); // /* // * Known Issue 2017-08-28: // * Should case DRAFT copy of the BlockConfiguration if versioning is enabled. // */ // FieldListUpdate(block, ViewParts.ContentPair, lists => lists.Move(sourceIndex, targetIndex)); // wrapLog(null); //} //public void UpdateEntityIfChanged(BlockConfiguration block, string[] fields, int sortOrder, Tuple<bool, int?>[] values) // => FieldListUpdate(block, fields, lists => lists.Replace(sortOrder, values)); //public void ResetBlockEntity(BlockConfiguration block) // => block.Entity = CmsManager.Read.Blocks.GetBlockConfig(block.Entity.EntityGuid).Entity; /// <summary> /// If SortOrder is not specified, adds at the end /// </summary> private /*public*/ void AddContentAndPresentationEntity(BlockConfiguration block, string[] fields, int?sortOrder, int?contentId, int?presentationId) => FieldListUpdate(block, fields, lists => lists.Add(sortOrder, new[] { contentId, presentationId }));
// TODO replace with direct call to Entities.FieldListReplaceIfModified public void AddEmptyItem(BlockConfiguration block, int?sortOrder = null) => AddContentAndPresentationEntity(block, ViewParts.ContentPair, sortOrder, null, null);
//------------------------------------------------- #region Public API /// <summary> /// Initializes the agent manager with an array of agent transforms /// </summary> public virtual void Initialize(Dictionary <NavAgentArchetype, List <Transform> > agents) { Dispose(); // clear any existing memory int configCount = configurations.Count; int archetypeCount = archetypes.Count; // initialize agent movement configurations m_movementTypes = new NativeArray <AgentMovement>(configCount, Allocator.Persistent); for (int i = 0; i < configCount; i++) { m_movementTypes[i] = configurations[i].movement; } // initialize job handle arrays m_updatingHandles = new NativeArray <JobHandle>(archetypeCount, Allocator.Persistent); m_movingByArchetype = new NativeArray <JobHandle>(archetypeCount, Allocator.Persistent); // initialize the agent properties m_agentMovementTypes = new List <NativeArray <int> >(archetypeCount); m_agentBehaviors = new List <NativeArray <AgentBehaviors> >(archetypeCount); m_agentKinematics = new List <NativeArray <AgentKinematics> >(archetypeCount); m_transformAccess = new List <TransformAccessArray>(archetypeCount); m_agentSteering = new List <NativeArray <float3> >(archetypeCount); m_totalAgents = new List <int>(archetypeCount); // initialize the flow field data structures int length = world.size.x * world.size.y * world.size.z; m_flowFields = new List <NativeArray <byte> >(archetypeCount); m_costFields = new List <NativeArray <byte> >(archetypeCount); m_intFields = new List <NativeArray <ushort> >(archetypeCount); m_openNodes = new List <NativeQueue <int3> >(archetypeCount); // cached data to build the flow fields m_targetPositions = new NativeList <int3>(Allocator.Persistent); // initialize each archetype for (int i = 0; i < archetypeCount; i++) { // initialize flow field data for each archetype m_openNodes.Add(new NativeQueue <int3>(Allocator.Persistent)); m_flowFields.Add(new NativeArray <byte>(length, Allocator.Persistent)); m_costFields.Add(new NativeArray <byte>(length, Allocator.Persistent)); m_intFields.Add(new NativeArray <ushort>(length, Allocator.Persistent)); // initialize agent data for each archetype Transform[] transforms = agents[archetypes[i]].ToArray(); int count = transforms.Length; TransformAccessArray transformAccess = new TransformAccessArray(transforms); NativeArray <int> movementTypes = new NativeArray <int>(count, Allocator.Persistent); NativeArray <float3> steering = new NativeArray <float3>(count, Allocator.Persistent); NativeArray <AgentKinematics> kinematics = new NativeArray <AgentKinematics>(count, Allocator.Persistent); NativeArray <AgentBehaviors> behaviors = new NativeArray <AgentBehaviors>(count, Allocator.Persistent); // read agent configuration for (int a = 0; a < count; a++) { NavAgent agent = transforms[a].GetComponent <NavAgent>(); int movementType = configurations.IndexOf(agent.configuration); AgentKinematics agentKinematics = new AgentKinematics(); agentKinematics.maxSpeed = agent.configuration.movement.topSpeed; movementTypes[a] = movementType; kinematics[a] = agentKinematics; } m_agentMovementTypes.Add(movementTypes); m_transformAccess.Add(transformAccess); m_agentKinematics.Add(kinematics); m_agentBehaviors.Add(behaviors); m_agentSteering.Add(steering); m_totalAgents.Add(count); } // initialize the agent spatial map m_spatialMap = new NativeMultiHashMap <int3, SpatialMapData>(m_totalAgents.Sum(), Allocator.Persistent); m_spatialMapWriter = m_spatialMap.AsParallelWriter(); // cache all directions m_directions = new NativeArray <int3>(27, Allocator.Persistent); for (int i = 0; i < 27; i++) { Vector3Int dir = Core.Direction3Int.Directions[i]; m_directions[i] = new int3(dir.x, dir.y, dir.z); } // cache directions for climbable check m_directionsNESW = new NativeArray <int>(4, Allocator.Persistent); m_directionsNESW[0] = 3; m_directionsNESW[1] = 5; m_directionsNESW[2] = 7; m_directionsNESW[3] = 9; // convert blocks to a struct and cache the data byte defaultCost = 1; int blockCount = blockManager.blocks.Count; m_blockTypes = new List <NativeArray <Block> >(); for (int a = 0; a < archetypeCount; a++) { NativeArray <Block> blocks = new NativeArray <Block>( blockCount, Allocator.Persistent); for (int i = 0; i < blockCount; i++) { BlockConfiguration block = blockManager.blocks[i]; int index = archetypes[a].movementCosts .FindIndex(x => x.block == block); Block navBlock = new Block(); if (index == -1) { navBlock.cost = defaultCost; } else { navBlock.cost = archetypes[a] .movementCosts[index].cost; } navBlock.solid = block.collidable; blocks[i] = navBlock; } m_blockTypes.Add(blocks); } }
public ContentBlockDto(BlockConfiguration block, IEnumerable <ModuleWithContent> blockModules) { Id = block.Id; Guid = block.Guid; Modules = blockModules.Select(m => new ModuleDto(m.Module, m.Page)); }