Пример #1
0
        private void CreateRBipartite()
        {
            double       x;
            double       y           = (SVGControl.Yaxis + SVGControl.Height / 2) + DefaultOptions.NodeRadius * 3;
            IList <Node> addedNodes1 = new List <Node>();
            IList <Node> addedNodes2 = new List <Node>();

            for (int i = 0; i < numNodes / 2; i++)
            {
                x = (SVGControl.Xaxis + SVGControl.Width / 2) + DefaultOptions.NodeRadius * 3 * (double)(numNodes / 2 - i);
                addedNodes1.Add(NodeService.AddNode(Graph.Nodes, DefaultOptions, x, y, (i + 1).ToString()));
            }
            y = (SVGControl.Yaxis + SVGControl.Height / 2) - DefaultOptions.NodeRadius * 3;
            for (int i = 0; i < numNodes / 2; i++)
            {
                x = (SVGControl.Xaxis + SVGControl.Width / 2) + DefaultOptions.NodeRadius * 3 * (double)(numNodes / 2 - i);
                addedNodes2.Add(NodeService.AddNode(Graph.Nodes, DefaultOptions, x, y, (i + 1).ToString()));
            }
            for (int i = 0; i < numNodes / 2; i++)
            {
                for (int k = 0; k < KValue; k++)
                {
                    var xx = (i + k) % addedNodes2.Count;
                    EdgeService.AddEdge(Graph.Edges, DefaultOptions, addedNodes1[i], addedNodes2[xx]);
                    if (Graph.Directed)
                    {
                        EdgeService.AddEdge(Graph.Edges, DefaultOptions, addedNodes2[i], addedNodes1[xx]);
                    }
                }
            }
        }
        public void AddNode_AddsToDAL()
        {
            // use helper methods to create specific test data or setups
            Node node = GetValidNode();

            _service.AddNode(node);

            _nodeDalMock.Verify(x => x.AddNode(node), Times.Once(), "Node was not saved to DAL.");
        }
Пример #3
0
        public void AddNode()
        {
            // Arrange
            var node = new TimerNode {
                Delay = 10000
            };

            // Act
            _target.AddNode(node);
            // Assert
            Check.That(_context.Nodes).ContainsExactly(node);
        }
Пример #4
0
        private void CreateCircle(IList <Node> addedNodes)
        {
            double x, y;
            double radius = DefaultOptions.NodeRadius / 1.5 * (double)numNodes;
            double theta  = (360.0 / (double)numNodes) * Math.PI / 180;

            for (int i = 0; i < numNodes; i++)
            {
                x = SVGControl.Xaxis + SVGControl.Width / 2 + radius * Math.Cos(theta * i);
                y = SVGControl.Yaxis + SVGControl.Height / 2 + radius * Math.Sin(theta * i);
                addedNodes.Add(NodeService.AddNode(Graph.Nodes, DefaultOptions, x, y, (i + 1).ToString()));
            }
        }
Пример #5
0
        private void CreateTree()
        {
            double       x;
            double       y          = (SVGControl.Yaxis + SVGControl.Height / 2);
            IList <Node> addedNodes = new List <Node>();

            for (int i = 0; i < numNodes; i++)
            {
                x = (SVGControl.Xaxis + SVGControl.Width / 2) + DefaultOptions.NodeRadius * 3 * (double)(numNodes / 2 - i);
                addedNodes.Add(NodeService.AddNode(Graph.Nodes, DefaultOptions, x, y, (i + 1).ToString()));
            }
            for (int i = 0; i < numNodes - 1; i++)
            {
                EdgeService.AddEdge(Graph.Edges, DefaultOptions, addedNodes[i], addedNodes[i + 1]);
            }
        }
Пример #6
0
 public void Copy()
 {
     CopiedGraph = new Graph();
     PasteOffset = 0;
     foreach (Node node in ActiveGraph.Nodes)
     {
         NodeService.AddNode(CopiedGraph.Nodes, node);
     }
     foreach (Edge edge in ActiveGraph.Edges)
     {
         if (ActiveGraph.Nodes.Where(n => n == edge.Head || n == edge.Tail).Count() == 2)
         {
             EdgeService.AddEdge(CopiedGraph.Edges, edge);
         }
     }
 }
Пример #7
0
        protected void StoreDbNode(SqlServerDatabaseNode dbnode)
        {
            TypeService tsvc = new TypeService();

            if (dbnode.NodeIdentity == 0)
            {
                NodeService      nsvc   = new NodeService();
                AttributeService attsvc = new AttributeService();

                NodeType dbtype = tsvc.GetNodeType("Database", true);

                Node existing = nsvc.GetByName(dbnode.Name);
                if (existing == null)
                {
                    existing = new Node
                    {
                        name        = dbnode.Name,
                        description = "SQL Server Database",
                        type        = dbtype
                    };
                    int dbnodeid = nsvc.AddNode(existing);
                    dbnode.NodeIdentity = dbnodeid;
                    if (dbnode.Metadata != null)
                    {
                        foreach (NodeAttribute natt in dbnode.Metadata)
                        {
                            AttributeType atype = tsvc.GetAttributeType(natt.type.name, true);
                            natt.nodeId = dbnodeid;
                            natt.type   = atype;
                            attsvc.AddNodeAttribute(natt);
                        }
                    }
                }
                else
                {
                    dbnode.NodeIdentity = existing.id;
                }
            }
            //If the identities are set, add membership setting
            if (dbnode.NodeIdentity != 0 && serverStructure.ServerNode.NodeIdentity != 0)
            {
                MembershipType    mtype = tsvc.GetMembershipType("Database", true);
                MembershipService msvc  = new MembershipService();
                msvc.AddNodeMembership(serverStructure.ServerNode.NodeIdentity, dbnode.NodeIdentity, mtype.typeId);
            }
        }
Пример #8
0
        public async Task Paste()
        {
            int nextNodeId = NodeService.NextId(Graph.Nodes);

            PasteOffset += 5 * SVGControl.Scale;
            ActiveGraph  = new Graph();
            foreach (Node node in CopiedGraph.Nodes)
            {
                ActiveGraph.Nodes.Add(NodeService.AddNode(Graph.Nodes, node, nextNodeId, PasteOffset));
            }
            foreach (Edge edge in CopiedGraph.Edges)
            {
                ActiveGraph.Edges.Add(EdgeService.AddEdge(Graph, edge, nextNodeId));
            }
            await GraphChanged.InvokeAsync(Graph);

            await ActiveGraphChanged.InvokeAsync(ActiveGraph);
        }
Пример #9
0
        protected void StoreServerNode()
        {
            DataSourceNodeBase srvrNode = serverStructure.ServerNode;
            NodeService        nsvc     = new NodeService();
            TypeService        tsvc     = new TypeService();
            AttributeService   attsvc   = new AttributeService();
            Node existing = nsvc.GetByName(srvrNode.Name);

            if (existing == null)
            {
                //doesn't exist--add it
                existing = new Node {
                    name = srvrNode.Name
                };
                NodeType srvrType = tsvc.GetNodeType("SQL Server", true);
                existing.type = srvrType;
                int srvrId = nsvc.AddNode(existing);
                existing.id = srvrId;
            }
            else
            {
                srvrNode.NodeIdentity = existing.id;
            }
            if (srvrNode.Metadata != null)
            {
                foreach (NodeAttribute natt in srvrNode.Metadata)
                {
                    try
                    {
                        AttributeType atype = tsvc.GetAttributeType(natt.type.name, true);
                        natt.nodeId = existing.id;
                        natt.type   = atype;
                        attsvc.AddNodeAttribute(natt);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }
Пример #10
0
        private void CreateStar()
        {
            double       x, y;
            double       midX       = SVGControl.Xaxis + SVGControl.Width / 2;
            double       midY       = SVGControl.Yaxis + SVGControl.Height / 2;
            double       radius     = DefaultOptions.NodeRadius / 2 * (double)numNodes;
            double       theta      = (360.0 / (double)numNodes) * Math.PI / 180;
            IList <Node> addedNodes = new List <Node>();
            Node         root       = NodeService.AddNode(Graph.Nodes, DefaultOptions, midX, midY, "1");

            for (int i = 1; i < numNodes; i++)
            {
                x = midX + radius * Math.Cos(theta * i);
                y = midY + radius * Math.Sin(theta * i);
                addedNodes.Add(NodeService.AddNode(Graph.Nodes, DefaultOptions, x, y, (i + 1).ToString()));
            }
            foreach (Node node in addedNodes)
            {
                EdgeService.AddEdge(Graph.Edges, DefaultOptions, node, root);
            }
        }
Пример #11
0
        private void CreateCBipartite()
        {
            double       x;
            double       y           = (SVGControl.Yaxis + SVGControl.Height / 2) + DefaultOptions.NodeRadius * 3;
            IList <Node> addedNodes1 = new List <Node>();
            IList <Node> addedNodes2 = new List <Node>();

            for (int i = 0; i < numNodes; i++)
            {
                x = (SVGControl.Xaxis + SVGControl.Width / 2) + DefaultOptions.NodeRadius * 3 * (double)(numNodes / 2 - i);
                addedNodes1.Add(NodeService.AddNode(Graph.Nodes, DefaultOptions, x, y, (i + 1).ToString()));
            }
            y = (SVGControl.Yaxis + SVGControl.Height / 2) - DefaultOptions.NodeRadius * 3;
            for (int i = 0; i < KValue; i++)
            {
                x = (SVGControl.Xaxis + SVGControl.Width / 2) + DefaultOptions.NodeRadius * 3 * (double)(numNodes / 2 - i);
                addedNodes2.Add(NodeService.AddNode(Graph.Nodes, DefaultOptions, x, y, (i + 1).ToString()));
            }
            if (Graph.Directed)
            {
                foreach (Node node1 in addedNodes1)
                {
                    foreach (Node node2 in addedNodes2)
                    {
                        EdgeService.AddEdge(Graph.Edges, DefaultOptions, node1, node2);
                        EdgeService.AddEdge(Graph.Edges, DefaultOptions, node2, node1);
                    }
                }
            }
            else
            {
                foreach (Node node1 in addedNodes1)
                {
                    foreach (Node node2 in addedNodes2)
                    {
                        EdgeService.AddEdge(Graph.Edges, DefaultOptions, node1, node2);
                    }
                }
            }
        }
Пример #12
0
        public IActionResult Create([FromBody] Node node)
        {
            if (!ModelState.IsValid)
            {
                return(View(node));
            }
            try
            {
                var categoryToAdd = new Node
                {
                    Name     = node.Name,
                    ParentID = node.ParentID,
                };

                _service.AddNode(node);
                return(new JsonResult(node));
            }
            catch (Exception ex)
            {
                return(new JsonResult(ex));
            }
        }
Пример #13
0
        public async Task OnChangeText(ChangeEventArgs e)
        {
            string input = e.Value.ToString();

            double[,] weights = ParseInput(input);
            if (ValidInput)
            {
                int difference = weights.GetLength(0) - Graph.Nodes.Count;
                if (difference > 0)
                {
                    for (int i = 1; i <= difference; i++)
                    {
                        NodeService.AddNode(Graph.Nodes, DefaultOptions, GetRandom(true), GetRandom(false));
                    }
                }
                else if (difference < 0)
                {
                    for (int i = difference; i < 0; i++)
                    {
                        Graph.Nodes.RemoveAt(Graph.Nodes.Count + i);
                    }
                }
                Graph.Edges.Clear();
                for (int i = 0; i < weights.GetLength(0); i++)
                {
                    for (int j = 0; j < weights.GetLength(1); j++)
                    {
                        if (weights[i, j] != 0)
                        {
                            EdgeService.AddEdge(Graph.Edges, DefaultOptions, Graph.Nodes[j], Graph.Nodes[i], weights[i, j]);
                        }
                    }
                }
                await GraphChanged.InvokeAsync(Graph);

                ShowText = GetText();
            }
        }
Пример #14
0
        protected void StoreNodes(List <DataSourceNodeBase> nlist, SqlServerDatabaseNode databaseNode)
        {
            NodeService       nsvc   = new NodeService();
            TypeService       tsvc   = new TypeService();
            AttributeService  attsvc = new AttributeService();
            MembershipService msvc   = new MembershipService();

            foreach (DataSourceNodeBase dbnode in nlist)
            {
                string memtypename = null;

                //if there is a non-zero id value, it's already been stored/pulled.
                if (dbnode.NodeIdentity == 0)
                {
                    Node existnode = nsvc.GetByName(dbnode.Name);
                    if (existnode == null)
                    {
                        //hasn't been added yet--create one
                        Type   nclasstype = dbnode.GetType();
                        string ntypename  = null;
                        switch (nclasstype.FullName)
                        {
                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerInstanceNode":
                            ntypename   = "SQL Server";
                            memtypename = null;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerDatabaseNode":
                            ntypename   = EnumParser.GetValueName(DbClasses.Database);
                            memtypename = null;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerTableNode":
                            ntypename   = EnumParser.GetValueName(DbClasses.Table);
                            memtypename = ntypename;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerViewNode":
                            ntypename   = EnumParser.GetValueName(DbClasses.View);
                            memtypename = ntypename;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerProcedureNode":
                            ntypename   = EnumParser.GetValueName(DbProcesses.StoredProcedue);
                            memtypename = ntypename;
                            break;

                        case "SystemMap.Models.Transform.db.sqlserver.SqlServerFunctionNode":
                            ntypename   = EnumParser.GetValueName(DbProcesses.Function);
                            memtypename = ntypename;
                            break;

                        case "SystemMap.Models.Transform.db.GenericDataSourceNode":
                            ntypename   = "External Reference";
                            memtypename = null;
                            break;

                        default:
                            ntypename   = "General";
                            memtypename = null;
                            break;
                        }
                        NodeType ntype = tsvc.GetNodeType(ntypename, true);
                        existnode = new Node
                        {
                            name        = dbnode.Name,
                            description = ntypename,
                            type        = ntype
                        };
                        try
                        {
                            int nid = nsvc.AddNode(existnode);
                            dbnode.NodeIdentity = nid;
                            if (dbnode.Metadata != null)
                            {
                                foreach (NodeAttribute natt in dbnode.Metadata)
                                {
                                    try
                                    {
                                        AttributeType atype = tsvc.GetAttributeType(natt.type.name, true);
                                        natt.nodeId = dbnode.NodeIdentity;
                                        natt.type   = atype;
                                        attsvc.AddNodeAttribute(natt);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.StackTrace);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    else
                    {
                        dbnode.NodeIdentity = existnode.id;
                    }
                }
                if (memtypename != null)
                {
                    MembershipType mtype = tsvc.GetMembershipType(memtypename, true);
                    if (mtype != null && databaseNode.NodeIdentity != 0 && dbnode.NodeIdentity != 0)
                    {
                        try
                        {
                            msvc.AddNodeMembership(databaseNode.NodeIdentity, dbnode.NodeIdentity, mtype.typeId);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
        }
Пример #15
0
 public async Task OnMouseUp(MouseEventArgs e)
 {
     MouseDown = false;
     if (e.Button == 2)
     {
         RectSelection.Create = false;
         if (!e.CtrlKey && RectSelection.Width <= 0 && RectSelection.Height <= 0)
         {
             if (ObjectClicked.Right)
             {
                 ObjectClicked.Right = false;
                 ObjectContextMenu.Open(e.ClientX, e.ClientY);
             }
             else
             {
                 if (GraphMode == GraphMode.Algorithm)
                 {
                     AlgorithmContextMenu.Open(e.ClientX, e.ClientY);
                 }
                 else
                 {
                     CanvasContextMenu.Open(e.ClientX, e.ClientY);
                     origin[0] = e.ClientX;
                     origin[1] = e.ClientY;
                     if (ActiveGraph.Nodes.Any() || ActiveGraph.Edges.Any())
                     {
                         await ActiveGraphChanged.InvokeAsync(new Graph());
                     }
                 }
             }
         }
         else
         {
             bool aNodesChanged = false;
             bool aEdgesChanged = false;
             foreach (Node node in Graph.Nodes)
             {
                 if (node.Xaxis <= RectSelection.X + RectSelection.Width &&
                     node.Xaxis >= RectSelection.X &&
                     node.Yaxis <= RectSelection.Y + RectSelection.Height &&
                     node.Yaxis >= RectSelection.Y)
                 {
                     if (!ActiveGraph.Nodes.Contains(node))
                     {
                         ActiveGraph.Nodes.Add(node);
                         aNodesChanged = true;
                     }
                 }
                 else if (ActiveGraph.Nodes.Remove(node))
                 {
                     aNodesChanged = true;
                 }
             }
             foreach (Edge edge in Graph.Edges)
             {
                 ShowEdge showEdge = new ShowEdge(edge);
                 var      x        = 0.25 * edge.Head.Xaxis + 0.5 * showEdge.CurvePoint[0] + 0.25 * edge.Tail.Xaxis;
                 var      y        = 0.25 * edge.Head.Yaxis + 0.5 * showEdge.CurvePoint[1] + 0.25 * edge.Tail.Yaxis;
                 if (x <= RectSelection.X + RectSelection.Width &&
                     x >= RectSelection.X &&
                     y <= RectSelection.Y + RectSelection.Height &&
                     y >= RectSelection.Y)
                 {
                     if (!ActiveGraph.Edges.Contains(edge))
                     {
                         ActiveGraph.Edges.Add(edge);
                         aEdgesChanged = true;
                     }
                 }
                 else if (ActiveGraph.Edges.Remove(edge))
                 {
                     aEdgesChanged = true;
                 }
             }
             if (aNodesChanged || aEdgesChanged)
             {
                 await ActiveGraphChanged.InvokeAsync(ActiveGraph);
             }
         }
         RectSelection = new RectSelection();
         return;
     }
     if (ObjectClicked.Left)
     {
         ObjectClicked.Left = false;
         if (GraphMode == GraphMode.InsertNode)
         {
             SvgClass = "pointer";
         }
         else
         {
             SvgClass = "grab";
         }
     }
     else if (!e.CtrlKey && !ActiveGraph.Nodes.Any() && !ActiveGraph.Nodes.Any() && GraphMode == GraphMode.InsertNode)
     {
         NodeService.AddNode(Graph.Nodes, Options.Default, e.ClientX * SVGControl.Scale + SVGControl.Xaxis, e.ClientY * SVGControl.Scale + SVGControl.Yaxis);
     }
     else if (ActiveGraph.Nodes.Any() || ActiveGraph.Edges.Any())
     {
         await ActiveGraphChanged.InvokeAsync(new Graph());
     }
     if (SVGControl.Pan)
     {
         SVGControl.Pan      = false;
         SvgClass            = "grab";
         SVGControl.OldXaxis = SVGControl.Xaxis;
         SVGControl.OldYaxis = SVGControl.Yaxis;
     }
 }
Пример #16
0
        public async Task Select(MenuEventArgs <MenuItem> e)
        {
            switch (e.Item.Text)
            {
            case "Copy":
                Copy();
                break;

            case "Paste":
                await Paste();

                break;

            case "Left":
            case "Center":
            case "Right":
            case "Top":
            case "Middle":
            case "Bottom":
                NodeService.Align(ActiveGraph.Nodes, e.Item.Text);
                break;

            case "Delete":
                await DeleteActive.InvokeAsync("all");

                break;

            case "Edit":
            case "Nodes":
            case "Edges":
                await ChangeMenu.InvokeAsync(NavChoice.Design);

                break;

            case "All Nodes":
                await Activate("nodes");

                break;

            case "All Edges":
                await Activate("edges");

                break;

            case "Everything":
                await Activate("all");

                break;

            case "Insert Edge":
                await InsertEdge();

                break;

            case "Insert Node":
                NodeService.AddNode(Graph.Nodes, Options.Default, origin[0] * SVGControl.Scale + SVGControl.Xaxis, origin[1] * SVGControl.Scale + SVGControl.Yaxis);
                await GraphChanged.InvokeAsync(Graph);

                break;

            case "Stop Algorithm":
                if (StartAlgorithm.Done)
                {
                    StartAlgorithm.Clear = true;
                }
                else
                {
                    await Reset();
                }
                break;

            case "Zoom In":
                if (ZoomService.ZoomIn(SVGControl))
                {
                    await SVGControlChanged.InvokeAsync(SVGControl);
                }
                break;

            case "Zoom Out":
                if (ZoomService.ZoomOut(SVGControl))
                {
                    await SVGControlChanged.InvokeAsync(SVGControl);
                }
                break;
            }
        }
Пример #17
0
 public virtual void AddNode(INodeTypeProxy nodeType, string originalId, Point location)
 {
     NodeService.AddNode(DomainId, nodeType, originalId, location);
 }
Пример #18
0
 public void AddNode(float latitude, float longitude, string type, bool fill, Action <bool> callback)
 {
     nodeService.AddNode(latitude, longitude, type, fill, callback);
 }