private void Copy(IEntityNode from, IEntityNode to) { var source = from.Entity.Dereference(Registry); var duplicated = to.Entity.Dereference(Registry); foreach (var sourceComponent in source.Components) { sourceComponent.Refresh(); var typeRef = sourceComponent.Type; // There might be some automatic bindings that will add the component, so check if it is already present. var component = duplicated.GetOrAddComponent(typeRef); component.Refresh(); component.CopyFrom(sourceComponent); } var fromRecursive = from as EntityNode; if (fromRecursive != null) { var toRecursive = to as EntityNode; if (toRecursive != null) { for (var i = 0; i < fromRecursive.Children.Count; ++i) { Copy(fromRecursive.Children[i], toRecursive.Children[i]); } } } }
private static List <IEntityNode> GetSubNodes(IEntityNode node) { var result = new List <IEntityNode>(); GetSubNodes(node, result); return(result); }
public bool IsRoot(IEntityNode node) { if (node is EntityNode) { return(Roots.Contains(node)); } return(StaticEntities.Contains(node)); }
/// <summary> /// Fires the AfterUpdateRelationship hook /// </summary> void FireAfterUpdateRelationship(IResourceHookContainer container, IEntityNode node, ResourcePipeline pipeline) { Dictionary <RelationshipAttribute, IEnumerable> currenEntitiesGrouped = node.RelationshipsFromPreviousLayer.GetDependentEntities(); /// the relationships attributes in currenEntitiesGrouped will be pointing from a /// resource in the previouslayer to a resource in the current (nested) layer. /// For the nested hook we need to replace these attributes with their inverse. /// See the FireNestedBeforeUpdateHooks method for a more detailed example. var resourcesByRelationship = CreateRelationshipHelper(node.EntityType, ReplaceKeysWithInverseRelationships(currenEntitiesGrouped)); CallHook(container, ResourceHook.AfterUpdateRelationship, new object[] { resourcesByRelationship, pipeline }); }
private static void GetSubNodes(IEntityNode node, List <IEntityNode> result) { result.Add(node); if (node is EntityNode) { foreach (var child in (node as EntityNode).Children) { GetSubNodes(child, result); } } }
private IEntityNode Duplicate(IEntityNode node) { var duplicated = CreateNodes(node); Copy(node, duplicated); var sourceEntities = GetSubNodes(node).Select(n => n.Entity.Dereference(Registry)).ToList(); var duplicatedEntities = GetSubNodes(duplicated).Select(n => n.Entity.Dereference(Registry)).ToList(); foreach (var property in duplicatedEntities.SelectMany(e => e.Components)) { Rebind(property, sourceEntities, duplicatedEntities); } return(duplicated); }
public void Delete(IEntityNode node) { var entityNode = node as EntityNode; if (entityNode != null) { Delete(entityNode); } else { var staticEntityNode = node as StaticEntityNode; if (staticEntityNode != null) { Delete(staticEntityNode); } } }
public void Add(IEntityNode node) { var entityNode = node as EntityNode; if (entityNode != null) { Add(entityNode); } else { var staticEntityNode = node as StaticEntityNode; if (staticEntityNode != null) { Add(staticEntityNode); } } }
protected ObservableCollection<IEntityNode> GetChildrenNodes(IEnumerable<IEntityNode> allViewModels, IEntityNode parentNode) { var nodes = allViewModels.Where(x => parentNode == null ? x.ParentId == 0 : x.ParentId == parentNode.Id); foreach (var node in nodes) { if (parentNode == null) { Root.ChildNodes.Add(node); } else { parentNode.ChildNodes.Add(node); } GetChildrenNodes(allViewModels, node); } return parentNode == null? Root.ChildNodes : parentNode.ChildNodes; }
private IEntityNode CreateNodes(IEntityNode source) { var sourceNode = source as EntityNode; var sourceEntity = source.Entity.Dereference(Registry); if (sourceNode != null) { var node = CreateNodes(sourceNode, sourceNode.Parent); node.Entity.Dereference(Registry).Name = GetUniqueName((sourceNode.Parent?.Children.Select(n => n.Entity) ?? Roots.Select(n => n.Entity)), sourceEntity.Name); return(node); } else { var node = CreateStatic(); var entity = node.Entity.Dereference(Registry); entity.Name = GetUniqueName(StaticEntities.Select(n => n.Entity), sourceEntity.Name); entity.Layer = sourceEntity.Layer; entity.Enabled = sourceEntity.Enabled; return(node); } }
public IEntityNode FindNode(IEntityNode root, int id) { var queue = new Queue<IEntityNode>(); queue.Enqueue(root); while (queue.Count > 0) { var node = queue.Dequeue(); if (node.Id == id) return node; foreach (var child in node.ChildNodes) queue.Enqueue(child); } return null; }
public int GetInstanceId(IEntityNode node) { return(node.Entity.Dereference(Registry).View.gameObject.GetInstanceID()); }
private void FindRelationIdList(IEntityNode parentNode, List<Tuple<int,int>> relationIdList) { foreach (IEntityNode node in parentNode.ChildNodes) { if (node.ChildNodes.Count > 0) { FindRelationIdList(node, relationIdList); } else { relationIdList.Add(new Tuple<int, int>(CurrentOrganizationChart.Id, ((OrganizationChartPositionVM)node).PositionId)); } } }
private int[] AsInstanceIds(IEntityNode entity) { return(new int[] { entity.Entity.Dereference(Registry).View.gameObject.GetInstanceID() }); }
public void Update(int id, IEntityNode root, IEntityNode newValue) { foreach (var node in root.ChildNodes) { if (node.Id == id) { root.ChildNodes.Add(newValue); root.ChildNodes.Remove(node); return; } Update(id, node, newValue); } }
/// <summary> /// Create the first layer after the root layer (based on the root node) /// </summary> /// <returns>The next layer.</returns> /// <param name="rootNode">Root node.</param> public EntityChildLayer CreateNextLayer(IEntityNode rootNode) { return(CreateNextLayer(new IEntityNode[] { rootNode })); }
private void Unregister(IEntityNode node) { Registry.Unregister(node.Entity.Id); (node as EntityNode)?.Children.ForEach(Unregister); }
public static IEntityNode Find(int id, IEntityNode root) { if (root.Id == id) return root; return root.ChildNodes.Select(node => Find(id, node)).FirstOrDefault(result => result != null); }
private void FindRelationIdList(IEntityNode parentNode, List<Tuple<int, int>> relationIdList) { foreach (IEntityNode node in parentNode.ChildNodes) { if (node.ChildNodes.Count > 0) { relationIdList.Add(new Tuple<int, int>(CurrentUser.Id, node.Id)); FindRelationIdList(node, relationIdList); } else { relationIdList.Add(new Tuple<int, int>(CurrentUser.Id, node.Id)); } } }
public static void Remove(int id, IEntityNode root) { foreach (var node in root.ChildNodes) { if (node.Id == id) { root.ChildNodes.Remove(node); return; } Remove(id,node); } }