Пример #1
0
        public void MoveNodeMultipleParentsAndUndo()
        {
            string startStr = "Problem,Node 1,Node 1.1,Node 1.2,I have multiple parents!,Node 2,Node 2.1,Node 2.1.1,Node 2.2,I have multiple parents!";
            var    dict     = BuildTestTree();
            Node   node     = new AddNodeCommand(new NullDb(), dict["Node 1"], "I have multiple parents!", true).NewNode;

            new AddLinkCommand(new NullDb(), dict["Node 2"], node, true);
            Assert.AreEqual(startStr, StringifyTree(dict["Problem"]));
            Assert.AreEqual(2, node.CountParentNodes());
            Assert.AreEqual(3, dict["Node 1"].CountChildNodes());
            Assert.AreEqual(3, dict["Node 2"].CountChildNodes());

            IRootCauseCommand command = new MoveNodeCommand(new NullDb(), node, dict["Problem"], true);

            Assert.AreEqual("Problem,Node 1,Node 1.1,Node 1.2,Node 2,Node 2.1,Node 2.1.1,Node 2.2,I have multiple parents!", StringifyTree(dict["Problem"]));
            Assert.AreEqual(1, node.CountParentNodes());
            Assert.AreEqual(2, dict["Node 1"].CountChildNodes());
            Assert.AreEqual(2, dict["Node 2"].CountChildNodes());

            command.Undo();
            Assert.AreEqual(startStr, StringifyTree(dict["Problem"]));
            Assert.AreEqual(2, node.CountParentNodes());
            Assert.AreEqual(3, dict["Node 1"].CountChildNodes());
            Assert.AreEqual(3, dict["Node 2"].CountChildNodes());
        }
Пример #2
0
        /*This is the model that is created by CreateComplexModelForText
         *
         *                  Problem
         *                     |
         *               -------------
         *               |           |
         *            Node 1.1    Node 1.2
         *               |           |
         *               |      -------------------------
         *               |      |           |           |
         *               |---Node 2.1    Node 2.2    Node 2.3
         *                      |           |           |
         *                      |      -------------    |
         *                      |      |           |    |
         *                      |---Node 3.1    Node 3.2-
         */
        private Dictionary <string, Node> CreateComplexModelForTest()
        {
            var  db      = SqliteDb.GetInstance();
            Node problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId());

            db.InsertTopLevel(problem);

            Node node1_1 = new AddNodeCommand(db, problem, "Node 1.1", true).NewNode;
            Node node1_2 = new AddNodeCommand(db, problem, "Node 1.2", true).NewNode;
            Node node2_1 = new AddNodeCommand(db, node1_2, "Node 2.1", true).NewNode;
            Node node2_2 = new AddNodeCommand(db, node1_2, "Node 2.2", true).NewNode;
            Node node2_3 = new AddNodeCommand(db, node1_2, "Node 2.3", true).NewNode;
            Node node3_1 = new AddNodeCommand(db, node2_2, "Node 3.1", true).NewNode;
            Node node3_2 = new AddNodeCommand(db, node2_2, "Node 3.2", true).NewNode;

            new AddLinkCommand(db, node1_1, node2_1, true);
            new AddLinkCommand(db, node2_1, node3_1, true);
            new AddLinkCommand(db, node2_3, node3_2, true);

            return(new Dictionary <string, Node>()
            {
                { problem.Text, problem },
                { node1_1.Text, node1_1 },
                { node1_2.Text, node1_2 },
                { node2_1.Text, node2_1 },
                { node2_2.Text, node2_2 },
                { node2_3.Text, node2_3 },
                { node3_1.Text, node3_1 },
                { node3_2.Text, node3_2 }
            });
        }
Пример #3
0
        public void RemoveNodeWithParentChildLinks()
        {
            var db    = new NullDb();
            var node1 = new AddNodeCommand(db, problem, "Node 1", true).NewNode;
            var node2 = new AddNodeCommand(db, node1, "Node 2", true).NewNode;

            new AddLinkCommand(db, problem, node2, true);

            var command = new RemoveNodeCommand(db, node1, true);

            Assert.AreEqual(1, problem.CountChildNodes());
            Assert.ReferenceEquals(node2, Enumerable.First(problem.ChildNodes));
            Assert.AreEqual(1, node2.CountParentNodes());
            Assert.ReferenceEquals(problem, Enumerable.First(node2.ParentNodes));

            command.Undo();
            Assert.AreEqual(2, problem.CountChildNodes());
            Assert.ReferenceEquals(node1, Enumerable.First(problem.ChildNodes));
            Assert.ReferenceEquals(node2, Enumerable.Last(problem.ChildNodes));
            Assert.AreEqual(2, node2.CountParentNodes());
            Assert.ReferenceEquals(problem, Enumerable.First(node2.ParentNodes));
            Assert.ReferenceEquals(node1, Enumerable.Last(node2.ParentNodes));
            Assert.AreEqual(1, node1.CountParentNodes());
            Assert.AreEqual(1, node1.CountChildNodes());
            Assert.ReferenceEquals(problem, Enumerable.First(node1.ParentNodes));
            Assert.ReferenceEquals(node2, Enumerable.First(node1.ChildNodes));
        }
Пример #4
0
        public void AddNodeImmediately()
        {
            Assert.AreEqual(0, problem.CountChildNodes());
            Node node = new AddNodeCommand(new NullDb(), problem, "Child 1", true).NewNode;

            Assert.AreEqual("Child 1", node.Text);
            Assert.AreEqual(1, node.CountParentNodes());
            Assert.AreEqual(1, problem.CountChildNodes());
        }
Пример #5
0
        public void AddNodeAndUndo()
        {
            IRootCauseCommand command = new AddNodeCommand(new NullDb(), problem, "Child 1");

            command.Execute();
            Assert.AreEqual(1, problem.CountChildNodes());
            Assert.AreEqual(true, command.Executed);
            foreach (var node in problem.ChildNodes)
            {
                Assert.AreEqual("Child 1", node.Text);
                Assert.AreEqual(1, node.CountParentNodes());
            }
            command.Undo();
            Assert.AreEqual(0, problem.CountChildNodes());
            Assert.AreEqual(false, command.Executed);
        }
Пример #6
0
        public void NewProblemContainer()
        {
            IRootCauseDb db      = new NullDb();
            var          command = new CreateProblemContainer(db, "This is a problem");

            command.Execute();
            ProblemContainer container = command.Container;
            Node             problem   = container.InitialProblem;

            Assert.AreEqual("This is a problem", problem.Text);
            Assert.AreEqual(0, container.CountUndoActions());
            Assert.AreEqual(0, container.CountRedoActions());

            IRootCauseCommand add = new AddNodeCommand(db, problem, "Cause 1");

            container.AddAction(add);
            Assert.AreEqual(true, add.Executed);
            Assert.AreEqual(1, container.CountUndoActions());
            Assert.AreEqual(0, container.CountRedoActions());
            Assert.AreEqual(1, problem.CountChildNodes());

            add = new AddNodeCommand(db, problem, "Cause 2", true);
            container.AddAction(add);
            Assert.AreEqual(true, add.Executed);
            Assert.AreEqual(2, container.CountUndoActions());
            Assert.AreEqual(0, container.CountRedoActions());
            Assert.AreEqual(2, problem.CountChildNodes());

            container.Undo();
            Assert.AreEqual(1, container.CountUndoActions());
            Assert.AreEqual(1, container.CountRedoActions());
            Assert.AreEqual(1, problem.CountChildNodes());

            container.Redo();
            Assert.AreEqual(2, container.CountUndoActions());
            Assert.AreEqual(0, container.CountRedoActions());
            Assert.AreEqual(2, problem.CountChildNodes());

            container.Undo();
            add = new AddNodeCommand(db, problem, "Cause 3", true);
            container.AddAction(add);
            Assert.AreEqual(2, container.CountUndoActions());
            Assert.AreEqual(0, container.CountRedoActions());
            Assert.AreEqual(2, problem.CountChildNodes());
        }
Пример #7
0
        public void ChangeNodeTextAndUndo()
        {
            AddNodeCommand addCommand = new AddNodeCommand(new NullDb(), problem, "Child 1", true);

            addCommand = new AddNodeCommand(new NullDb(), problem, "Child 2");
            Node node = new AddNodeCommand(new NullDb(), problem, "Child 2", true).NewNode;

            ChangeNodeTextCommand txtCommand = new ChangeNodeTextCommand(new NullDb(), node, "Child 2");

            Assert.AreEqual("Child 2", node.Text);
            txtCommand.Execute();
            Assert.AreEqual("Child 2", node.Text);
            txtCommand = new ChangeNodeTextCommand(new NullDb(), node, "Child 3");
            Assert.AreEqual("Child 2", node.Text);
            txtCommand.Execute();
            Assert.AreEqual("Child 3", node.Text);
            Assert.AreEqual(true, txtCommand.Executed);
            txtCommand.Undo();
            Assert.AreEqual("Child 2", node.Text);
            Assert.AreEqual(false, txtCommand.Executed);
        }
        public static void Process(BaseChain chain, Node node, IncomingMessage message)
        {
            if (message.Message.Command != "addr")
            {
                return;
            }

            NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();
            AddrPayload payload = (AddrPayload)message.Message.Payload;

            foreach (NetworkAddress address in payload.Addresses)
            {
                AddNodeCommand command = new AddNodeCommand
                {
                    Chain   = chain.ChainName,
                    Address = address.Endpoint.Address.ToString(),
                    Port    = address.Endpoint.Port,
                };
                chain.SendCommand(command).GetAwaiter().GetResult();
            }
        }
Пример #9
0
 public bool AddNode(RPCConnection rpc, string ipAddress, int port, AddNodeCommand command)
 {
     return(GetRPCTypedResult <bool>(rpc, ZendRPCCommand.AddNode, new object[] { $"{ipAddress}", port, command }));
 }
Пример #10
0
 public Task <JsonRpcResponse <string> > AddNodeAsync(string address, AddNodeCommand command)
 {
     return(this.ExecuteAsync <string>("addnode", 0, address, command.ToString().ToLower()));
 }
Пример #11
0
        public void AddNodeTwice()
        {
            IRootCauseCommand command = new AddNodeCommand(new NullDb(), problem, "Child 1", true);

            command.Execute();
        }
Пример #12
0
        public void AddNodeUndoBeforeExecute()
        {
            IRootCauseCommand command = new AddNodeCommand(new NullDb(), problem, "Child 1");

            command.Undo();
        }
        static void ImportRouteNodes(IMediator CommandBus, Wgs84GraphBuilder graphBuilder)
        {
            // Import node objects to database
            var nodesJsonText = File.ReadAllText(_builderDataPath + "RouteNodes.geojson");

            var nodesJson = JsonConvert.DeserializeObject(nodesJsonText) as JObject;

            var features = nodesJson["features"];

            foreach (var feature in features)
            {
                var properties = feature["properties"] as JObject;

                var geometry = feature["geometry"];

                var geometryType = geometry["type"].ToString();
                var geometryCoordinates = geometry["coordinates"].ToString().Replace("\r\n", "").Replace(" ", "");

                var nodeId = _nodeIdPrefix + properties["Id"].ToString().PadLeft(6, '0');
                var nodeType = properties["NodeType"].ToString();
                var nodeName = properties["NodeName"].ToString();
                var assetStatus = properties["Status"].ToString();

                if (properties["BuildTestData"].ToString() != "")
                {
                    var buildCodes = properties["BuildTestData"].ToString().Split(';');
                    _nodeBuildCodes.Add(nodeId, buildCodes);
                }

                // Add node to graph
                var x = ((JArray)geometry["coordinates"])[0];
                var y = ((JArray)geometry["coordinates"])[1];
                graphBuilder.AddNodeToGraph(nodeId, (double)x, (double)y);

                // Derive node and function kind
                var nodeKind = RouteNodeKindEnum.Unknown;
                var nodeFunctionKind =RouteNodeFunctionKindEnum.Unknown;

                if (nodeType == "CO")
                {
                    nodeKind = RouteNodeKindEnum.CentralOfficeSmall;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.SecondaryNode;
                }
                else if (nodeType == "HH")
                {
                    nodeKind = RouteNodeKindEnum.HandHole;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.OpenConduitPoint;
                }
                else if (nodeType == "CC")
                {
                    nodeKind = RouteNodeKindEnum.ConduitClosure;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.BurriedConduitPont;
                }
                else if (nodeType == "CE")
                {
                    nodeKind = RouteNodeKindEnum.ConduitEnd;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.BurriedConduitPont;
                }
                else if (nodeType == "SJ")
                {
                    nodeKind = RouteNodeKindEnum.ConduitSimpleJunction;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.BurriedConduitPont;
                }
                else if (nodeType == "FP")
                {
                    nodeKind = RouteNodeKindEnum.CabinetBig;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.FlexPoint;
                }
                else if (nodeType == "SP")
                {
                    nodeKind = RouteNodeKindEnum.CabinetSmall;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.SplicePoint;
                }
                else if (nodeType == "A")
                {
                    nodeKind = RouteNodeKindEnum.BuildingAccessPoint;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.SplicePoint;
                }
                else if (nodeType == "MDU")
                {
                    nodeKind = RouteNodeKindEnum.MultiDwellingUnit;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.ServiceDeliveryPoint;
                }
                else if (nodeType == "SDU")
                {
                    nodeKind = RouteNodeKindEnum.SingleDwellingUnit;
                    nodeFunctionKind = RouteNodeFunctionKindEnum.ServiceDeliveryPoint;
                }

                // location info
                var locationInfo = new LocationInfo();
                locationInfo.Id = Guid.NewGuid();
                locationInfo.AccessAddress = new AccessAddressInfo()
                {
                    MunicipalCode = "0630",
                    MunicipalRoadCode = "1521",
                    StreetName = properties["StreetName"].ToString(),
                    HouseNumber = properties["HouseNumber"].ToString(),
                    PostalCode = "7120",
                    PostalName = "Vejle Ø"
                };

                var addNodeCmd = new AddNodeCommand()
                {
                    Id = Guid.Parse(nodeId),
                    Name = nodeName,
                    NodeKind = nodeKind,
                    NodeFunctionKind = nodeFunctionKind,
                    LocationInfo = locationInfo,
                    Geometry = new Geometry(geometryType, geometryCoordinates)
                };

                CommandBus.Send(addNodeCmd).Wait();
            }
        }