static void RandomGenPositions(Vector2 xRange, PuzzleData puzzle, ref List <NodeBlock> currentBlocks, int num) { int cap = 1000; while (num > 0 && --cap > 0) { Vector2 randPos = new Vector2(Random.Range(Mathf.RoundToInt(xRange.x), Mathf.RoundToInt(xRange.y)), Random.Range(0, puzzle.gridSize[1])); bool skip = false; foreach (NodeBlock block in currentBlocks) { if ((block.pos - randPos).magnitude < 1.0f) { skip = true; } } if (skip) { continue; } NodeBlock newBlock = new NodeBlock(); newBlock.pos = randPos; currentBlocks.Add(newBlock); --num; } }
protected void InsertBlock(BlockWithTransactionHashes block) { try { var isblock = blockRepository.Get(x => x.BlockNumber == (int)block.Number.Value).FirstOrDefault(); if (isblock != null) //block has already in DB { return; } var _nodeBlock = new NodeBlock() { BlockNumber = (int)block.Number.Value, BlockTime = new Helpers().UnixTimeStampToDateTime((double)block.Timestamp.Value), BlockHash = block.BlockHash, ParentHash = block.ParentHash, TransactionCount = block.TransactionHashes.Length, Nonce = block.Nonce, }; blockRepository.Add(_nodeBlock); repositoryBase.Commit(); } catch (Exception e) { new Helpers().AddLog(LogType.Failure, $"Block-{block.Number.Value} DB Write Error => " + e.InnerException); } }
public void Reset() { gCost = int.MaxValue; hCost = 0; CalculateFCost(); cameFromNodeBlock = null; }
public void LoadProcGenScene(int level) { //currentLevel = level; currentLevel = 14; lineMan.ResetLines(); lineMan.currentLineBeingDrawn = null; // Hand crafted levels //gridMan.ConstructLevel(LevelData.puzzleData[currentLevel]); // Full random level gen //PuzzleData puzzle = ProcGenManager.RandomGenLevel(); // Proc. queued level gen // Remove used start blocks here for (int i = 0; i < currentPuzzle.startBlocks.Count; ++i) { NodeBlock startB = currentPuzzle.startBlocks[i]; StartBlockScript sbs = grid[(int)startB.pos.x][(int)startB.pos.y].GetComponent <StartBlockScript>(); if (sbs.isInUse) { currentPuzzle.startBlocks.Remove(startB); --i; } } currentPuzzle = ProcGenManager.RandomGenQueuedLevel(currentPuzzle); gridMan.ConstructLevel(currentPuzzle); uiMan.UpdateLevelUI(); // Reset number of objects intersection objsIntersect = 0; levelCompleted = false; }
public Node(NodeBlock nodeBlock, DbEngine db, EntityState state = EntityState.Unchanged) { NodeId = nodeBlock.NodeId; LabelId = nodeBlock.LabelId; Label = IO.DbReader.ReadGenericStringBlock(DbControl.LabelPath, LabelId).Data; Db = db; Properties = new Dictionary <string, NodeProperty>(); var propertyBlock = DbReader.ReadPropertyBlock(DbControl.NodePropertyPath, nodeBlock.FirstPropertyId); while (propertyBlock.PropertyId != 0) { if (!propertyBlock.Used) { propertyBlock = DbReader.ReadPropertyBlock(DbControl.NodePropertyPath, propertyBlock.NextPropertyId); continue; } var property = new NodeProperty(this, propertyBlock); Properties.Add(property.Key, property); propertyBlock = DbReader.ReadPropertyBlock(DbControl.NodePropertyPath, propertyBlock.NextPropertyId); } OutRelations = null; InRelations = null; this.nodeBlock = nodeBlock; }
public void UpdateCosts(NodeBlock relative, int distanceToRelative, int distanceToEndNode) { cameFromNodeBlock = relative; gCost = relative.gCost + distanceToRelative; hCost = distanceToEndNode; CalculateFCost(); }
static void DragFromTo(int fromX, int fromY, int toX, int toY) { if (!FieldMatrix.Get(fromX, fromY, out var fromBlock)) { return; } if (FieldMatrix.Get(toX, toY, out var toBlock)) { var bind = BindMatrix.GetBind(fromBlock, toBlock); var newBlockOffset = new Vector2(toX - fromX, toY - fromY); if (bind == null) { BindMatrix.AddBind(fromBlock, toBlock, newBlockOffset, Bind.BlockBindStrength); return; } if (bind.First != fromBlock) { if (!(fromBlock is RootBlock) && BindMatrix.GetOutBindsCount(fromBlock) == 0) { fromBlock.Destroy(); return; } bind.Break(); BindMatrix.AddBind(fromBlock, toBlock, newBlockOffset, Bind.BlockBindStrength); return; } return; } NodeBlock.Create(toX, toY, fromBlock); }
public static bool Create(NodeBlock b, out NodeBlockSerialized result) { result = null; result = new NodeBlockSerialized { X = b.logic.X, Y = b.logic.Y, RootId = b.rootId }; return(true); }
public static IEnumerable <NodeBlock> TraverseParents(this NodeBlock nodeBlock, IEnumerable <NodeBlock> nodeBlocks) { var currentBlock = nodeBlock; while ((currentBlock = nodeBlocks.FirstOrDefault(x => x.Name == currentBlock.ParentName)) != null) { yield return(currentBlock); } }
private List <NodeBlock> GetFinalPath(NodeBlock node) { var result = new List <NodeBlock>(); var currentNode = node; while (currentNode != null) { result.Add(currentNode); currentNode = currentNode.cameFromNodeBlock; } result.Reverse(); return(result); }
private int CalculateDistanceCost(NodeBlock start, NodeBlock end) { var xDistance = Mathf.Abs(start.X - end.X); var zDistance = Mathf.Abs(start.Z - end.Z); int remaining = Mathf.Abs(xDistance - zDistance); return(MOVE_DIAGONAL_COST * Mathf.Min(xDistance, zDistance) + MOVE_STRAIGHT_COST * remaining); // var diagonalDistance = xDistance == 1 && zDistance == 1; // if(diagonalDistance) // { // return MOVE_DIAGONAL_COST * // } }
protected override void OnEnable() { logic.onTap += e => { if (BindMatrix.GetOutBindsCount(this) == 0) { var v = logic.Position + Utils.CoordsFromDir(rootId % 4); NodeBlock.Create(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y), this); } else { logic.ReceivePulse(); } }; view.onRefresh += () => view.SecondaryPainter.NumInPalette = logic.HasPulse ? 3 : 2; logic.stepNumber = 0; }
public List <NodeBlock> GetClosestNodes(NodeBlock node) { var closest = new List <NodeBlock>(); var newX = node.X - 1; if (newX >= 0) { closest.Add(GetNode(newX, node.Z)); if (node.Z - 1 >= 0) { closest.Add(GetNode(newX, node.Z - 1)); } if (node.Z + 1 < sizeZ) { closest.Add(GetNode(newX, node.Z + 1)); } } newX = node.X + 1; if (newX < sizeX) { closest.Add(GetNode(newX, node.Z)); if (node.Z - 1 >= 0) { closest.Add(GetNode(newX, node.Z - 1)); } if (node.Z + 1 < sizeZ) { closest.Add(GetNode(newX, node.Z + 1)); } } newX = node.X; if (node.Z + 1 < sizeZ) { closest.Add(GetNode(newX, node.Z + 1)); } if (node.Z - 1 >= 0) { closest.Add(GetNode(newX, node.Z - 1)); } return(closest); }
public Node(string label, DbEngine db, EntityState state) { NodeId = 0; LabelId = 0; Label = label; Db = db; Properties = new Dictionary <string, NodeProperty>(); OutRelations = new List <Relation>(); InRelations = new List <Relation>(); State = state; if (state != EntityState.Unchanged) { Db.ChangedEntities.Add(this); } nodeBlock = null; }
protected IRenderingEngine ResolveRenderingEngine(NodeBlock block) { try { var blockDoc = new Document(block.Id); //resolve with partial view IRenderingEngine engine = new PartialViewRenderingEngine { Macro = new MacroModel(new Macro { ScriptingFile = blockDoc.ContentType.Alias }) }; return(engine); } catch (Exception) { return(null); } }
public virtual async Task ProcessTransactionAsync(BlockWithTransactionHashes block) { nodeBlock = blockRepository.Get(x => x.BlockNumber == block.Number.Value).FirstOrDefault(); if (nodeBlock?.NodeTransactions != null) { return; } nodeBlock.NodeTransactions = new List <NodeTransaction>(); foreach (var _hash in block.TransactionHashes) { await CheckandFillTransactionAsync(_hash, block.Timestamp.Value); } try { repositoryBase.Commit(); } catch (Exception e) { new Helpers().AddLog(LogType.Failure, $"Block-{block.Number.Value} Transactions DB Write Error => " + e.InnerException); } }
private Node PrimaryExpression(bool allowPostfixInvocation = true) { if (!TokensRemain) return null; var loc = Location; Node node; switch (Current.type) { case WILDCARD: // If we aren't in a truly anon function, we ignore this if (CurrentFunction != null && CurrentFunction.fullAnon && CurrentFunction.paramNames.Count == 0) CurrentFunction.paramNames.Add(null); node = new NodeWildcard(loc); Advance(); break; case PARAM_INDEX: var index = (uint)Current.intValue; // If we aren't in a truly anon function, we ignore this if (CurrentFunction != null && CurrentFunction.fullAnon) while (CurrentFunction.paramNames.Count <= index) CurrentFunction.paramNames.Add(null); node = new NodeParamIndex(loc, index); Advance(); break; case IDENTIFIER: node = new NodeIdentifier(loc, Current.image); Advance(); break; case SYMBOL: node = new NodeSymbol(loc, Current.image); Advance(); break; case NULL: node = new NodeNull(loc); Advance(); break; case TRUE: case FALSE: node = new NodeBool(loc, Check(TRUE)); Advance(); break; case ENDL: node = new NodeEndL(loc); Advance(); break; case THIS: node = new NodeThis(loc); Advance(); break; case SELF: node = new NodeSelf(loc); Advance(); break; case INT: node = new NodeInt(loc, Current.intValue); Advance(); break; case FLOAT: node = new NodeFloat(loc, Current.floatValue); Advance(); break; case STRING: node = new NodeString(loc, Current.image); Advance(); break; case OPEN_BRACE: Advance(); if (Check(CLOSE_BRACE)) { // 0-length tuple: node = new NodeTuple(loc, new List<Node>()); node.EndLine = Current.location.line; Advance(); } else { var values = CommaExpressions(); if (values.Count != 1) { // This is a tuple :D node = new NodeTuple(loc, values); Expect(CLOSE_BRACE, "Closing brace (')') expected to end tuple expression."); node.EndLine = tokens[-1].location.line; } else { Expect(CLOSE_BRACE, "Closing brace (')') expected to surround expression."); // Just an expression, carry on: node = values[0]; } } break; case OPEN_SQUARE_BRACE: // This is a list :D Advance(); node = new NodeList(loc, (TokensRemain && Current.type != CLOSE_SQUARE_BRACE) ? CommaExpressions() : new List<Node>()); Expect(CLOSE_SQUARE_BRACE, "Closing square brace (']') expected to end list expression."); node.EndLine = tokens[-1].location.line; break; case OPEN_CURLY_BRACE: // This is a code block :D Advance(); var exprs = new List<Node>(); while (!Check(CLOSE_CURLY_BRACE)) { if (!TokensRemain) { log.Error(tokens[-1].location, "Unfinished block. A closing curly brace ('}') should be used to end blocks."); break; } var expr = Expression(); if (expr != null) exprs.Add(expr); } Expect(CLOSE_CURLY_BRACE, "Closing curly brace ('}') expected to end block."); node = new NodeBlock(loc, exprs); node.EndLine = tokens[-1].location.line; break; case TAILREC: Advance(); Expect(OPEN_BRACE, "Expected an open brace ('(') to begin the tailrec argument list."); List<Node> args; if (!Check(CLOSE_BRACE)) args = CommaExpressions(); else args = new List<Node>(); Expect(CLOSE_BRACE, "Expected a close brace (')') to end the tailrec argument list."); node = new NodeTailRec(loc, args); break; // These can't be postfix'd, so we don't allow it. case OPERATOR: var prefix = Current.image; Advance(); if (!TokensRemain) log.Error(loc, "An expression is expected after prefix operator, but the end of the file was reached."); var prefixValue = PrimaryExpression(); return new NodePrefix(loc, prefix, prefixValue); case NOT: Advance(); if (!TokensRemain) log.Error(loc, "An expression is expected after the 'not' keyword, but the end of the file was reached."); return new NodeNot(loc, Expression()); case THROW: Advance(); if (!TokensRemain) log.Error(loc, "An expression is expected after the 'throw' keyword, but the end of the file was reached."); return new NodeThrow(loc, Expression()); case YIELD: Advance(); if (!TokensRemain) log.Error(loc, "An expression is expected after the 'yield' keyword, but the end of the file was reached."); return new NodeYield(loc, Expression()); case RES: Advance(); if (!TokensRemain) log.Error(loc, "An expression is expected after the 'res' keyword, but the end of the file was reached."); return new NodeRes(loc, Expression()); case BREAK: Advance(); string bLabel = null; if (Check(IDENTIFIER) && Current.location.line == loc.line) { bLabel = Current.image; Advance(); } return new NodeBreak(loc, bLabel); case CONT: Advance(); string cLabel = null; if (Check(IDENTIFIER) && Current.location.line == loc.line) { cLabel = Current.image; Advance(); } return new NodeCont(loc, cLabel); case FN: return ParseFn(); case GEN: return ParseFn(true); case VAR: return ParseVar(); case IF: return ParseIf(); case WHILE: return ParseWhile(); case TRY: return ParseTry(); case ITER: return ParseIter(); case EACH: return ParseEach(); // And here, we don't know what they want... oops. default: log.Error(Location, "Unexpected token '{0}', skipping...", Current.ToString()); // We don't know what to do with this, let's skip and try to recover. Advance(); // Error saying we couldn't understand the token: // return a new primary expression. return PrimaryExpression(); } // TODO postfix return Postfix(node, allowPostfixInvocation); }
public void Deserialize() { NodeBlock.Create(X, Y, RootId, 0.1f); }
void ASTVisitor.Accept(NodeBlock value) { Accept(value); }
internal void Accept(NodeBlock block) { if (block.createScope) builder.StartScope(); for (int i = 0; i < block.body.Count; i++) { var expr = block.body[i]; expr.isResultRequired = i == block.body.Count - 1 ? block.isResultRequired : false; expr.inTailPosition = block.inTailPosition && i == block.body.Count - 1; expr.Visit(this); } if (block.createScope) builder.EndScope(); }
public void SaveChanges() { foreach (var entity in ChangedEntities.Distinct()) { var entityType = entity.GetType(); if ((entity.State & EntityState.Added) == EntityState.Added) { if (entityType == typeof(Node)) { ((Node)entity).NodeId = DbControl.AllocateId(DbControl.NodePath); } else if (entityType == typeof(Relation)) { ((Relation)entity).RelationId = DbControl.AllocateId(DbControl.RelationPath); } else if (entityType == typeof(NodeProperty)) { ((NodeProperty)entity).PropertyId = DbControl.AllocateId(DbControl.NodePropertyPath); } else if (entityType == typeof(RelationProperty)) { ((RelationProperty)entity).PropertyId = DbControl.AllocateId(DbControl.RelationPropertyPath); } } if (((entity.State & EntityState.Deleted) == EntityState.Deleted) & ((entity.State & EntityState.Added) == EntityState.Added)) continue; if ((entity.State & EntityState.Deleted) == EntityState.Deleted) { if (entityType == typeof(Node)) { var node = ((Node)entity); DbWriter.InvalidateBlock(DbControl.NodePath, node.NodeId); var nodeBlock = DbReader.ReadNodeBlock(node.NodeId); var nextNodePropertyId = nodeBlock.FirstPropertyId; while (nextNodePropertyId != 0) { var nextPropertyBlock = DbReader.ReadPropertyBlock(DbControl.NodePropertyPath, nextNodePropertyId); DbWriter.InvalidateBlock(DbControl.NodePropertyPath, nextNodePropertyId); if (nextPropertyBlock.PropertyType is PropertyType.String) { DbWriter.InvalidateBlock(DbControl.StringPath, BitConverter.ToInt32(nextPropertyBlock.Value, 0)); } nextNodePropertyId = nextPropertyBlock.NextPropertyId; } var nextOutRelationId = nodeBlock.FirstOutRelationId; while (nextOutRelationId != 0) { var nextOutRelationBLock = DbReader.ReadRelationBlock(nextOutRelationId); DbWriter.InvalidateBlock(DbControl.RelationPath, nextOutRelationId); var nextRelationPropertyId = nextOutRelationBLock.FirstPropertyId; while (nextRelationPropertyId != 0) { var nextPropertyBlock = DbReader.ReadPropertyBlock(DbControl.RelationPropertyPath, nextRelationPropertyId); DbWriter.InvalidateBlock(DbControl.RelationPropertyPath, nextRelationPropertyId); if (nextPropertyBlock.PropertyType is PropertyType.String) { DbWriter.InvalidateBlock(DbControl.StringPath, BitConverter.ToInt32(nextPropertyBlock.Value, 0)); } nextRelationPropertyId = nextPropertyBlock.NextPropertyId; } nextOutRelationId = nextOutRelationBLock.FirstNodeNextRelation; } var nextInRelationId = nodeBlock.FirstInRelationId; while (nextInRelationId != 0) { var nextInRelationBlock = DbReader.ReadRelationBlock(nextInRelationId); DbWriter.InvalidateBlock(DbControl.RelationPath, nextInRelationId); var nextRelationPropertyId = nextInRelationBlock.FirstPropertyId; while (nextRelationPropertyId != 0) { var nextPropertyBlock = DbReader.ReadPropertyBlock(DbControl.RelationPropertyPath, nextRelationPropertyId); DbWriter.InvalidateBlock(DbControl.RelationPropertyPath, nextRelationPropertyId); if (nextPropertyBlock.PropertyType is PropertyType.String) { DbWriter.InvalidateBlock(DbControl.StringPath, BitConverter.ToInt32(nextPropertyBlock.Value, 0)); } nextRelationPropertyId = nextPropertyBlock.NextPropertyId; } nextInRelationId = nextInRelationBlock.SecondNodeNextRelation; } } else if (entityType == typeof(Relation)) { var relation = ((Relation)entity); DbWriter.InvalidateBlock(DbControl.RelationPath, relation.RelationId); var relationBlock = DbReader.ReadRelationBlock(relation.RelationId); var nextPropertyId = relationBlock.FirstPropertyId; while (nextPropertyId != 0) { var nextPropertyBlock = DbReader.ReadPropertyBlock(DbControl.RelationPropertyPath, nextPropertyId); DbWriter.InvalidateBlock(DbControl.NodePropertyPath, nextPropertyId); if (nextPropertyBlock.PropertyType is PropertyType.String) { DbWriter.InvalidateBlock(DbControl.StringPath, BitConverter.ToInt32(nextPropertyBlock.Value, 0)); } nextPropertyId = nextPropertyBlock.NextPropertyId; } } else if (entityType == typeof(NodeProperty)) { var nodeProperty = ((NodeProperty)entity); if (nodeProperty.PropertyType is PropertyType.String) { var nodePropertyBlock = DbReader.ReadPropertyBlock(DbControl.NodePropertyPath, nodeProperty.PropertyId); DbWriter.InvalidateBlock(DbControl.StringPath, BitConverter.ToInt32(nodePropertyBlock.Value, 0)); } DbWriter.InvalidateBlock(DbControl.NodePropertyPath, nodeProperty.PropertyId); } else if (entityType == typeof(RelationProperty)) { var relationProperty = ((RelationProperty)entity); if (relationProperty.PropertyType is PropertyType.String) { var relationPropertyBlock = DbReader.ReadPropertyBlock(DbControl.RelationPropertyPath, relationProperty.PropertyId); DbWriter.InvalidateBlock(DbControl.StringPath, BitConverter.ToInt32(relationPropertyBlock.Value, 0)); } DbWriter.InvalidateBlock(DbControl.RelationPropertyPath, relationProperty.PropertyId); } else { throw new NotSupportedException("Not supported Entity Type"); } continue; } if ((entity.State & EntityState.Added) == EntityState.Added) { NodeBlock nodeBlock; RelationBlock relationBlock; switch (entity) { case Node node: nodeBlock = new NodeBlock(true, node.NodeId, 0, 0, 0, DbControl.FetchLabelId(node.Label)); DbWriter.WriteNodeBlock(nodeBlock); break; case Relation relation: //Cast, Create with given information relationBlock = new RelationBlock { Used = true, FirstNodeId = relation.From.NodeId, SecondNodeId = relation.To.NodeId, FirstNodePreviousRelationId = 0, SecondNodePreviousRelationId = 0, LabelId = DbControl.FetchLabelId(relation.Label), FirstPropertyId = 0, RelationId = relation.RelationId }; // Read Source, Target nodes to change the links in them and get their current links var fromNodeBlock = DbReader.ReadNodeBlock(relationBlock.FirstNodeId); var toNodeBlock = DbReader.ReadNodeBlock(relationBlock.SecondNodeId); // Point to the current relations relationBlock.FirstNodeNextRelation = fromNodeBlock.FirstOutRelationId; relationBlock.SecondNodeNextRelation = toNodeBlock.FirstInRelationId; // Read Relations to which nodes point to update them if (fromNodeBlock.FirstOutRelationId != 0) { var fromNodeFirstOutRelationBlock = DbReader.ReadRelationBlock(fromNodeBlock.FirstOutRelationId); fromNodeFirstOutRelationBlock.FirstNodePreviousRelationId = relation.RelationId; DbWriter.WriteRelationBlock(fromNodeFirstOutRelationBlock); } if (toNodeBlock.FirstInRelationId != 0) { var toNodeFirstInRelationBlock = DbReader.ReadRelationBlock(toNodeBlock.FirstInRelationId); toNodeFirstInRelationBlock.SecondNodePreviousRelationId = relation.RelationId; DbWriter.WriteRelationBlock(toNodeFirstInRelationBlock); } toNodeBlock.FirstInRelationId = relation.RelationId; fromNodeBlock.FirstOutRelationId = relation.RelationId; DbWriter.WriteNodeBlock(toNodeBlock); DbWriter.WriteNodeBlock(fromNodeBlock); DbWriter.WriteRelationBlock(relationBlock); break; case NodeProperty _: case RelationProperty _: var property = (Property)entity; byte[] byteValue = new byte[4]; switch (property.PropertyType) { case PropertyType.Int: byteValue = BitConverter.GetBytes((int)property.Value); break; case PropertyType.Bool: byteValue[3] = (byte)((bool)property.Value ? 1 : 0); break; case PropertyType.Float: byteValue = BitConverter.GetBytes((float)property.Value); break; case PropertyType.String: // Add to String Storage, get returned pointer to the string storage, write it as the byteValue var newStringId = DbControl.AllocateId(DbControl.StringPath); DbWriter.WriteStringBlock(new StringBlock(true, (string)property.Value, newStringId)); byteValue = BitConverter.GetBytes(newStringId); break; default: throw new NotSupportedException(); } int parentId; PropertyBlock propertyBlock; switch (property) { case NodeProperty _: parentId = ((Node)property.Parent).NodeId; propertyBlock = new NodePropertyBlock(property.PropertyId, true, property.PropertyType, DbControl.FetchPropertyNameId(property.Key), byteValue, 0, parentId); nodeBlock = DbReader.ReadNodeBlock(parentId); propertyBlock.NextPropertyId = nodeBlock.FirstPropertyId; nodeBlock.FirstPropertyId = propertyBlock.PropertyId; DbWriter.WritePropertyBlock(propertyBlock); DbWriter.WriteNodeBlock(nodeBlock); break; case RelationProperty _: parentId = ((Relation)property.Parent).RelationId; propertyBlock = new RelationPropertyBlock(property.PropertyId, true, property.PropertyType, DbControl.FetchPropertyNameId(property.Key), byteValue, 0, parentId); relationBlock = DbReader.ReadRelationBlock(parentId); propertyBlock.NextPropertyId = relationBlock.FirstPropertyId; relationBlock.FirstPropertyId = propertyBlock.PropertyId; DbWriter.WritePropertyBlock(propertyBlock); DbWriter.WriteRelationBlock(relationBlock); break; default: throw new NotSupportedException(); } break; } continue; } if ((entity.State & EntityState.Modified) == EntityState.Modified) { switch (entity) { case Node _: throw new NotSupportedException( "Node modification is not supported. Update it's properties instead."); case Relation _: throw new NotSupportedException( "Relation modification is not supported. Update it's properties instead."); case NodeProperty _: // case RelationProperty _: var property = (Property)entity; var propertyPath = (property is NodeProperty) ? DbControl.NodePropertyPath : DbControl.RelationPropertyPath; var oldPropertyBlock = DbReader.ReadPropertyBlock(propertyPath, property.PropertyId); byte[] byteValue = new byte[4]; switch (property.PropertyType) { case PropertyType.Int: byteValue = BitConverter.GetBytes((int)property.Value); break; case PropertyType.Bool: byteValue[3] = (byte)((bool)property.Value ? 1 : 0); break; case PropertyType.Float: byteValue = BitConverter.GetBytes((float)property.Value); break; case PropertyType.String: DbWriter.InvalidateBlock(DbControl.StringPath, BitConverter.ToInt32(oldPropertyBlock.Value, 0)); var newStringId = DbControl.AllocateId(DbControl.StringPath); DbWriter.WriteStringBlock(new StringBlock(true, (string)property.Value, newStringId)); byteValue = BitConverter.GetBytes(newStringId); break; default: throw new NotSupportedException("Such Property dtye is not supported"); } oldPropertyBlock.Value = byteValue; DbWriter.WritePropertyBlock(oldPropertyBlock); break; } } } ChangedEntities.Clear(); }
private void renameBlock(NodeBlock block) { for (var iter = block.nodes.begin(); iter.more();) { var node = iter.node; switch (node.type) { case NodeType.TempName: case NodeType.Jump: case NodeType.JumpCondition: case NodeType.Store: case NodeType.Return: case NodeType.IncDec: case NodeType.DeclareStatic: case NodeType.Switch: { iter.next(); continue; } case NodeType.DeclareLocal: { var decl = (DDeclareLocal)node; if (decl.var == null) { if (decl.uses.Count <= 1) { // This was probably just a stack temporary. if (decl.uses.Count == 1) { var use = decl.uses.First.Value; use.node.replaceOperand(use.index, decl.value); } block.nodes.remove(iter); continue; } var name = new DTempName(graph_.tempName()); node.replaceAllUsesWith(name); name.init(decl.value); block.nodes.replace(iter, name); } iter.next(); continue; } case NodeType.SysReq: case NodeType.Call: { // Calls are statements or expressions, so we can't // remove them if they have no uses. if (node.uses.Count <= 1) { if (node.uses.Count == 1) { block.nodes.remove(iter); } else { iter.next(); } continue; } break; } case NodeType.Constant: { // Constants can be deeply copied. block.nodes.remove(iter); continue; } default: { if (node.uses.Count <= 1) { // This node has one or zero uses, so instead of // renaming it, we remove it from the instruction // stream. This way the source printer will deep- // print it instead of using its 'SSA' name. block.nodes.remove(iter); continue; } break; } } // If we've reached here, the expression has more than one use // and we have to wrap it in some kind of name, lest we // duplicate it in the expression tree which may be illegal. var replacement = new DTempName(graph_.tempName()); node.replaceAllUsesWith(replacement); replacement.init(node); block.nodes.replace(iter, replacement); iter.next(); } }
protected string RenderNodeBlock(NodeBlock block, HtmlHelper html) { //check if the node exists if (block.Content == null) { return(null); } //set the block model for the view to access WebBlocksUtility.CurrentBlockContent = block.Content; //initialise WebBlocksAPI for the view WebBlocksAPI blockInstanceAPI = new WebBlocksAPI(); blockInstanceAPI.CssClasses = new List <string>(); blockInstanceAPI.BlockElement = ""; blockInstanceAPI.BlockAttributes = new Dictionary <string, string>(); //set up the rendering engine for the view IRenderingEngine renderingEngine = ResolveRenderingEngine(block); //if rendering engine is null then the document doesn't exist anymore if (renderingEngine == null || block.Content == null) { return(""); } string blockIdAttribute = WebBlocksUtility.IsInBuilder ? string.Format(" wbid='{0}'", block.Id) : ""; string blockTemplateAttribute = WebBlocksUtility.IsInBuilder ? string.Format(" templateblock='{0}'", block.IsTemplateBlock.ToString().ToLower()) : ""; string blockDeletedAttribute = WebBlocksUtility.IsInBuilder && block.IsDeleted ? " deletedBlock='deleted' style='display:none;visibilty:hidden;'" : ""; string renderedContent = ""; //render renderedContent = renderingEngine.Render(html); List <string> CssClasses = blockInstanceAPI.CssClasses; string blockElement = blockInstanceAPI.BlockElement ?? "div"; blockElement = blockElement != "" ? blockElement : "div"; Dictionary <string, string> blockAttributeDictionary = blockInstanceAPI.BlockAttributes; string blockAttributes = string.Join(" ", blockAttributeDictionary.Keys.Select(c => c + "='" + blockAttributeDictionary[c] + "'")); string blockClass = string.Format("{0}{1}{0}{2}{3}{4}", block.Class.Length > 0 ? " " : "", block.Class, WebBlocksUtility.CurrentBlockContent.GetPropertyValue("cssClasses"), CssClasses.Any() ? " " : "", String.Join(" ", CssClasses)); blockClass = WebBlocksUtility.IsInBuilder ? "block " + blockClass : blockClass; renderedContent = string.Format("<{0} class='{1}'{2}{3}{4}{5}>{6}</{0}>", blockElement, blockClass, blockIdAttribute, blockTemplateAttribute, blockDeletedAttribute, blockAttributes, renderedContent); return(renderedContent); }