Пример #1
0
        public Node AddNode()
        {
            Node v = new Node(this);

            NodeLayer.Add(v);
            return(v);
        }
Пример #2
0
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string    retStr    = "";
            Enums     enums     = new Enums(LanguageRequest);
            NodeLayer nodeLayer = validationContext.ObjectInstance as NodeLayer;

            nodeLayer.HasErrors = false;

            if (nodeLayer.Layer < 1 || nodeLayer.Layer > 100)
            {
                nodeLayer.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Layer", "1", "100"), new[] { "Layer" }));
            }

            //Z has no Range Attribute

            //CSSPError: Type not implemented [Node] of type [Node]

            //CSSPError: Type not implemented [Node] of type [Node]
            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                nodeLayer.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
Пример #3
0
        public void AddMemberTo(List <uint> nodeIds, Group to)
        {
            List <Node> nodes = NodeLayer.FindAll(delegate(Node v)
            {
                return(nodeIds.Exists(x => v.Id == x));
            });

            AddMemberTo(nodes, to);
        }
Пример #4
0
        public void MoveMember(List <uint> nodeIds, Group from, Group to)
        {
            List <Node> nodes = NodeLayer.FindAll(delegate(Node v)
            {
                return(nodeIds.Exists(x => v.Id == x));
            });

            MoveMember(nodes, from, to);
        }
Пример #5
0
    public Node(NodeLayer prev, int position, int depth)
    {
        this.prev     = prev;
        this.position = position;
        this.depth    = depth;

        this.active      = false;
        this.isConnected = false;
        this.edge        = new bool[] { false, false, false };
        this.weight      = 0;
    }
Пример #6
0
    public NodeLayer(NodeLayer prev, int width, int depth)
    {
        this.prev = prev;

        // Initialize nodes
        nodes = new Node[width];
        for (int i = 0; i < width; i++)
        {
            nodes[i] = new Node(prev, i, depth);
        }
    }
Пример #7
0
        private void TraverseNextLayer(NodeLayer nextLayer, Action <IResourceHookContainer, IResourceNode> action, ResourceHook target)
        {
            foreach (IResourceNode node in nextLayer)
            {
                var hookContainer = _executorHelper.GetResourceHookContainer(node.ResourceType, target);

                if (hookContainer != null)
                {
                    action(hookContainer, node);
                }
            }
        }
Пример #8
0
        private NodeLayer GetFilledRandomNodeLayer(string OmitPropName)
        {
            NodeLayer nodeLayer = new NodeLayer();

            if (OmitPropName != "Layer")
            {
                nodeLayer.Layer = GetRandomInt(1, 100);
            }
            // should implement a Range for the property Z and type NodeLayer
            //CSSPError: property [Node] and type [NodeLayer] is  not implemented

            return(nodeLayer);
        }
Пример #9
0
        /// <summary>
        /// Traverses the nodes in a <see cref="NodeLayer"/>.
        /// </summary>
        private void Traverse(NodeLayer currentLayer, ResourceHook target, Action <IResourceHookContainer, IResourceNode> action)
        {
            var nextLayer = currentLayer;

            while (true)
            {
                if (!nextLayer.AnyResources())
                {
                    return;
                }

                TraverseNextLayer(nextLayer, action, target);

                nextLayer = _traversalHelper.CreateNextLayer(nextLayer.ToList());
            }
        }
Пример #10
0
    private void GenerateGraph()
    {
        int       depth   = 0;
        NodeLayer current = null;

        while (depth < generationDepth)
        {
            current = new NodeLayer(current, width, depth);

            if (current.prev != null)
            {
                for (int target = 0; target < width; target++)
                {
                    List <int> legal = current.FindPossibleEdges(target);
                    if (legal.Count > 0)
                    {
                        current.ConnectNodes(target, legal[Random.Range(0, legal.Count)]);
                    }
                }

                //current.TrimOverlappingEdges();
                //current.TrimDoubleDiagonals();

                for (int i = 0; i < current.prev.nodes.Length; i++)
                {
                    Node node = current.prev.nodes[i];
                    node.Active = node.isConnected;
                }
            }
            else
            {
                current.SetNodeActive(start);
            }


            for (int i = 0; i < current.nodes.Length; i++)
            {
                current.nodes[i].Show();
            }

            current.Show();
            depth++;
        }
    }
        /// <summary>
        /// Traverses the nodes in a <see cref="NodeLayer"/>.
        /// </summary>
        private void Traverse(NodeLayer currentLayer, ResourceHook target, Action <IResourceHookContainer, IResourceNode> action)
        {
            if (!currentLayer.AnyResources())
            {
                return;
            }
            foreach (IResourceNode node in currentLayer)
            {
                var resourceType  = node.ResourceType;
                var hookContainer = _executorHelper.GetResourceHookContainer(resourceType, target);
                if (hookContainer == null)
                {
                    continue;
                }
                action(hookContainer, node);
            }

            Traverse(_traversalHelper.CreateNextLayer(currentLayer.ToList()), target, action);
        }
Пример #12
0
        public Diagram(DiagramOptions?options = null)
        {
            _behaviors = new Dictionary <Type, Behavior>();
            _componentByModelMapping = new Dictionary <Type, Type>();
            _groups = new List <GroupModel>();

            Options = options ?? new DiagramOptions();
            Nodes   = new NodeLayer(this);
            Links   = new LinkLayer(this);

            RegisterBehavior(new SelectionBehavior(this));
            RegisterBehavior(new DragMovablesBehavior(this));
            RegisterBehavior(new DragNewLinkBehavior(this));
            RegisterBehavior(new DeleteSelectionBehavior(this));
            RegisterBehavior(new PanBehavior(this));
            RegisterBehavior(new ZoomBehavior(this));
            RegisterBehavior(new GroupingBehavior(this));
            RegisterBehavior(new EventsBehavior(this));
        }
        /// <summary>
        /// Fires the nested before hooks for resources in the current <paramref name="layer"/>
        /// </summary>
        /// <remarks>
        /// For example: consider the case when the owner of article1 (one-to-one)
        /// is being updated from owner_old to owner_new, where owner_new is currently already
        /// related to article2. Then, the following nested hooks need to be fired in the following order.
        /// First the BeforeUpdateRelationship should be for owner1, then the
        /// BeforeImplicitUpdateRelationship hook should be fired for
        /// owner2, and lastly the BeforeImplicitUpdateRelationship for article2.</remarks>
        private void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, NodeLayer layer)
        {
            foreach (IResourceNode node in layer)
            {
                var         nestedHookContainer = _executorHelper.GetResourceHookContainer(node.ResourceType, ResourceHook.BeforeUpdateRelationship);
                IEnumerable uniqueResources     = node.UniqueResources;
                RightType   resourceType        = node.ResourceType;
                Dictionary <RelationshipAttribute, IEnumerable> currentResourcesGrouped;
                Dictionary <RelationshipAttribute, IEnumerable> currentResourcesGroupedInverse;

                // fire the BeforeUpdateRelationship hook for owner_new
                if (nestedHookContainer != null)
                {
                    if (uniqueResources.Cast <IIdentifiable>().Any())
                    {
                        var relationships = node.RelationshipsToNextLayer.Select(p => p.Attribute).ToArray();
                        var dbValues      = LoadDbValues(resourceType, uniqueResources, ResourceHook.BeforeUpdateRelationship, relationships);

                        // these are the resources of the current node grouped by
                        // RelationshipAttributes that occurred in the previous layer
                        // so it looks like { HasOneAttribute:owner  =>  owner_new }.
                        // Note that in the BeforeUpdateRelationship hook of Person,
                        // we want want inverse relationship attribute:
                        // we now have the one pointing from article -> person, ]
                        // but we require the the one that points from person -> article
                        currentResourcesGrouped        = node.RelationshipsFromPreviousLayer.GetRightResources();
                        currentResourcesGroupedInverse = ReplaceKeysWithInverseRelationships(currentResourcesGrouped);

                        var resourcesByRelationship = CreateRelationshipHelper(resourceType, currentResourcesGroupedInverse, dbValues);
                        var allowedIds = CallHook(nestedHookContainer, ResourceHook.BeforeUpdateRelationship, new object[] { GetIds(uniqueResources), resourcesByRelationship, pipeline }).Cast <string>();
                        var updated    = GetAllowedResources(uniqueResources, allowedIds);
                        node.UpdateUnique(updated);
                        node.Reassign(_resourceFactory);
                    }
                }

                // Fire the BeforeImplicitUpdateRelationship hook for owner_old.
                // Note: if the pipeline is Post it means we just created article1,
                // which means we are sure that it isn't related to any other resources yet.
                if (pipeline != ResourcePipeline.Post)
                {
                    // To fire a hook for owner_old, we need to first get a reference to it.
                    // For this, we need to query the database for the  HasOneAttribute:owner
                    // relationship of article1, which is referred to as the
                    // left side of the HasOneAttribute:owner relationship.
                    var leftResources = node.RelationshipsFromPreviousLayer.GetLeftResources();
                    if (leftResources.Any())
                    {
                        // owner_old is loaded, which is an "implicitly affected resource"
                        FireForAffectedImplicits(resourceType, leftResources, pipeline, uniqueResources);
                    }
                }

                // Fire the BeforeImplicitUpdateRelationship hook for article2
                // For this, we need to query the database for the current owner
                // relationship value of owner_new.
                currentResourcesGrouped = node.RelationshipsFromPreviousLayer.GetRightResources();
                if (currentResourcesGrouped.Any())
                {
                    // rightResources is grouped by relationships from previous
                    // layer, ie { HasOneAttribute:owner  =>  owner_new }. But
                    // to load article2 onto owner_new, we need to have the
                    // RelationshipAttribute from owner to article, which is the
                    // inverse of HasOneAttribute:owner
                    currentResourcesGroupedInverse = ReplaceKeysWithInverseRelationships(currentResourcesGrouped);
                    // Note that currently in the JADNC implementation of hooks,
                    // the root layer is ALWAYS homogenous, so we safely assume
                    // that for every relationship to the previous layer, the
                    // left type is the same.
                    LeftType leftType = currentResourcesGrouped.First().Key.LeftType;
                    FireForAffectedImplicits(leftType, currentResourcesGroupedInverse, pipeline);
                }
            }
        }
Пример #14
0
 public NodeLayerTest()
 {
     nodeLayer = new NodeLayer();
 }
Пример #15
0
 /// <summary>
 /// Called after a <paramref name="node"/> is removed from the diagram.
 /// </summary>
 /// <param name="node">a <see cref="Node"/></param>
 /// <param name="layer">the <see cref="NodeLayer"/> that the <paramref name="node"/> was removed from</param>
 /// <remarks>
 /// <para>
 /// By default this method does nothing.
 /// </para>
 /// <para>
 /// The implementation of this method should not modify the model.
 /// This method cannot and should not prevent or alter the removal of the node from the diagram.
 /// </para>
 /// </remarks>
 protected virtual void OnNodeRemoved(Node node, NodeLayer layer) {
 }
Пример #16
0
 public bool HasNode(uint id)
 {
     return(NodeLayer.Exists(x => x.Id == id));
 }
Пример #17
0
 public examML()
 {
     layer1 = new FlatLayer(2);
     layer2 = new NodeLayer(2);
 }