private void GetMockedObject(HomeController controller)
        {
            AccountDTO[] accountDTO = new AccountDTO[] { new AccountDTO {
                                                             AccountID = "TestAccountID", AccountName = "Test Account Name"
                                                         } };
            ReportDTO[] reportDTO = new ReportDTO[] { new ReportDTO {
                                                          ReportID = 1, ReportName = "Test Report Name"
                                                      } };
            NodeDTO[] nodeDTO = new NodeDTO[] { new NodeDTO {
                                                    NodeID = "TestNodeID", DisplayValue = "Test Node Name"
                                                } };

            Mock <ICertonaService> applicationMock = new Mock <ICertonaService>();

            controller.ForesightService = applicationMock.Object;

            GetAccountsByUserResponse accountsByUserResponse = new GetAccountsByUserResponse {
                Success = true, Accounts = accountDTO
            };
            GetPanelBarWidthResponse panelBarWidthResponse = new GetPanelBarWidthResponse {
                Width = 100
            };
            GetReportsListResponse reportsListResponse = new GetReportsListResponse {
                Reports = reportDTO
            };
            GetAccountExplorerTreeResponse accountExplorerTreeResponse = new GetAccountExplorerTreeResponse {
                Nodes = nodeDTO
            };

            applicationMock.Setup(p => p.GetAccountsByUser(It.IsAny <GetAccountsByUserRequest>())).Returns(accountsByUserResponse);
            applicationMock.Setup(p => p.GetPanelBarWidth(It.IsAny <GetPanelBarWidthRequest>())).Returns(panelBarWidthResponse);
            applicationMock.Setup(p => p.GetReportsList(It.IsAny <GetReportsListRequest>())).Returns(reportsListResponse);
            applicationMock.Setup(p => p.GetAccountExplorerTree(It.IsAny <GetAccountExplorerTreeRequest>())).Returns(accountExplorerTreeResponse);
        }
Beispiel #2
0
 public SegmentDTO(NodeDTO firstNodeID, NodeDTO secondNodeID, int travelTimeBetweenNodes, double distanceBetweenNodes)
 {
     this.firstNodeID            = firstNodeID;
     this.secondNodeID           = secondNodeID;
     this.travelTimeBetweenNodes = travelTimeBetweenNodes;
     this.distanceBetweenNodes   = distanceBetweenNodes;
 }
Beispiel #3
0
        public void InsertNode([FromBody] NodeDTO node)
        {
            var parentNode = new ParentNodeDTO();

            try
            {
                //Fetch the subtree of the Sponsor
                //A sponsor cannot be the direct parent of the new user when max number of children has been reached
                var subTreeList = _hierarchyBL.GetSubTreeDepth(node.SponsorId, HierarchyType.BinaryTree);

                if (subTreeList.Count > 1)
                {
                    //Traverse the tree and search for the appropriate parent node
                    parentNode = _binaryTreeBl.GetLogicalParentNode(subTreeList);
                }
                else if (subTreeList.Count == 1)
                {
                    parentNode.NodeId = subTreeList.First().UserID;
                }
                else
                {
                    //Master Parent Node Insert
                    _binaryTreeBl.InsertMasterParentNode(node);
                    return;
                }

                //Insert Node
                _binaryTreeBl.InsertNode(node, parentNode);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        public async Task <IActionResult> PutNode([FromRoute] string id, [FromBody] NodeDTO node)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != node.id)
            {
                return(BadRequest());
            }
            var editedNode = await db.Nodes.SingleOrDefaultAsync(n => n.Id == node.id);

            editedNode.Topic           = node.topic;
            db.Entry(editedNode).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NodeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #5
0
        public async Task <IActionResult> PostNode([FromBody] NodeDTO node)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newNode = new Node()
            {
                Id       = node.id,
                ParentId = node.parentid,
                TreeId   = node.treeid,
                Topic    = node.topic
            };

            db.Nodes.Add(newNode);
            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (NodeExists(newNode.Id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
        private void ForceConfiguration(object sender, EventArgs e)
        {
            if (this.listBoxNodes.SelectedItem != null)
            {
                NodeDTO node = (NodeDTO)listBoxNodes.SelectedItem;

                Services.NodeService.ForceUpdateNodeConfiguration(node.Id);
            }
        }
        public Node Create(NodeDTO nodeDto)
        {
            if (!ModelState.IsValid && nodeDto == null)
                return null;

            var node = _repo.Create(nodeDto);

            return node;
        }
Beispiel #8
0
        public NodeDTO AddNode(int value)
        {
            if (root == null)
            {
                root       = new NodeDTO();
                root.Value = value;
            }

            return(AddNodeToTree(root, value));
        }
Beispiel #9
0
        public async Task <DriverDutyDTO> AddDriverDuty(CreatingDriverDutyDTO driverDutyDTO)
        {
            List <WorkBlock> workBlocks    = new List <WorkBlock>();
            List <WorkBlock> workBlocksAux = new List <WorkBlock>();

            foreach (var workBlockId in driverDutyDTO.listWorkBlocks)
            {
                var workBlock = await _workBlockRepository.GetByIdAsync(new WorkBlockID(workBlockId));

                workBlocks.Add(workBlock);
                workBlocksAux.Add(workBlock);
            }

            for (int i = 1; i < workBlocks.Count; i++)
            {
                var firstVehicleDutyId = await this._repoVehicleDutyRepository.getVehicleDutyByWorkblock(workBlocks[i]);

                var secondVehicleDutyId = await this._repoVehicleDutyRepository.getVehicleDutyByWorkblock(workBlocks[i - 1]);

                if (!firstVehicleDutyId.Id.Equals(secondVehicleDutyId.Id))
                {
                    if (workBlocks[i - 1].tripList.Count > 0 && workBlocks[i].tripList.Count > 0)
                    {
                        var lastNodeOfLastWorkblok = workBlocks[i - 1].tripList.Last().nodePassageList.Last().nodeID.id;

                        var firstNodeOfActualWorkblock = workBlocks[i].tripList.First().nodePassageList.First().nodeID.id;
                        // if (lastNodeOfLastWorkblok.Equals(firstNodeOfActualWorkblock))
                        // {
                        NodeDTO firstNode = await HttpRequest <NodeDTO> .GetByID("http://localhost:8080/api/node/" + firstNodeOfActualWorkblock);

                        if (!firstNode.isReliefPoint)
                        {
                            throw new BusinessRuleValidationException(firstNode.code + " invalid: this node is not a relief point.");
                        }
                        // }
                        // else
                        // {
                        //     throw new BusinessRuleValidationException("When two workblocks have a diferent vehicleDuty the last node of the last workblock must be the same as the first of actual workblock");
                        // }
                    }
                }
            }

            var driverDuty = new DriverDuty(
                driverDutyDTO.driverDutyCode,
                workBlocks
                );

            var savedDriverDuty = await this._driverDutyRepository.AddAsync(driverDuty);

            await this._unitOfWork.CommitAsync();

            return(this._driverDutyMapper.DomainToDTO(savedDriverDuty));
        }
Beispiel #10
0
 public void InsertNode(NodeDTO node, ParentNodeDTO parentNode)
 {
     if (parentNode.HasNoLeafNode)
     {
         _ctx.InsertLeafNode(node.NodeId, parentNode.NodeId, node.SponsorId, HierarchyType.BinaryTree.ToString());
     }
     else
     {
         _ctx.InsertNode(node.NodeId, parentNode.NodeId, node.SponsorId, HierarchyType.BinaryTree.ToString());
     }
 }
        public PartialViewResult ViewReport(NodeDTO node)
        {
            string cultureName = null;

            if (HttpContext != null && HttpContext.Request != null && HttpContext.Request.UserLanguages != null && HttpContext.Request.UserLanguages.Length > 0)
            {
                cultureName = HttpContext.Request.UserLanguages[0];
            }

            var model = ReportingModel.GetReportViewModel();

            return(PartialView(model));
        }
Beispiel #12
0
        private void UpdateCapableFreeConnector(object sender, EventArgs e)
        {
            if (listBoxFreeHomeDevices.SelectedItem != null && comboBoxNode.SelectedItem != null)
            {
                HomeDeviceDTO homeDev = (HomeDeviceDTO)listBoxFreeHomeDevices.SelectedItem;

                NodeDTO node = (NodeDTO)this.comboBoxNode.SelectedItem;

                listBoxCapableFreeConnector.Items.Clear();
                listBoxCapableFreeConnector.Items.AddRange(Services.NodeService.GetConnectorsCapable(homeDev.Id, node.Id).ToArray());

                buttonLinkHomeDevice.Enabled = true;
            }
        }
Beispiel #13
0
        private void ConnectorProductAvailable(object sender, EventArgs e)
        {
            if (comboBoxNodeProduct.SelectedItem != null && comboBoxListProduct.SelectedItem != null)
            {
                string product = (string)comboBoxListProduct.SelectedItem;

                NodeDTO node = (NodeDTO)comboBoxNodeProduct.SelectedItem;

                listBoxConnectorsAvailable.Items.Clear();
                listBoxConnectorsAvailable.Items.AddRange(Services.HomeDeviceService.GetConnectorsCapableProduct(node.Id, product).ToArray());

                buttonLinkProduct.Enabled = true;
            }
        }
Beispiel #14
0
        public void InsertMasterParentNode(NodeDTO node)
        {
            var binaryTreeItem = new BINARYTREE();

            binaryTreeItem.USERID         = node.NodeId;
            binaryTreeItem.LFT            = 1;
            binaryTreeItem.RGT            = 2;
            binaryTreeItem.PARENTID       = node.ParentId;
            binaryTreeItem.SPONSORID      = node.SponsorId;
            binaryTreeItem.ISMASTERPARENT = true;

            _ctx.BINARYTREE.Add(binaryTreeItem);
            _ctx.SaveChanges();
        }
        public PartialViewResult GetContentPanel(NodeDTO node)
        {
            IViewModel vm = new ContentViewModel
            {
                NodeID        = node.NodeID,
                NodeType      = node.NodeType.ToString().Replace("_", ""),
                ApplicationID = node.ApplicationID,
                CatalogID     = node.CatalogID
            };

            var panel = ContentModel.GetContentPanel((int)node.NodeType);

            vm.ContentPanelSections = panel.ContentPanelSections;

            return(PartialView(panel.PartialViewName, vm));
        }
        private void SelectNode(object sender, EventArgs e)
        {
            if (this.listBoxNodes.SelectedItem != null)
            {
                //update textboxs
                NodeDTO node = (NodeDTO)listBoxNodes.SelectedItem;
                textBoxNameNode.Text    = node.Name;
                textBoxBaseNode.Text    = node.Base;
                textBoxAddressNode.Text = node.Address.ToString();
                textBoxShieldNode.Text  = node.Shield;

                //update connectors
                listBoxConnectors.Items.Clear();
                listBoxConnectors.Items.AddRange(Services.NodeService.GetConnectors(node.Id).ToArray());
            }
        }
Beispiel #17
0
        public async void PostNodeActionSuccess()
        {
            var controller = new NodesController(fixture.Context);
            var node       = new NodeDTO()
            {
                id       = "node4",
                parentid = null,
                treeid   = 4,
                topic    = "Node 4"
            };
            var result = await controller.PostNode(node);

            var receivedNode = await fixture.Context.Nodes.SingleOrDefaultAsync(n => n.Id == node.id);

            Assert.NotNull(receivedNode);
            Assert.IsType <OkResult>(result);
        }
        private void ChangeNodeConfiguration(object sender, EventArgs e)
        {
            if (this.listBoxNodes.SelectedItem != null)
            {
                NodeDTO node = (NodeDTO)listBoxNodes.SelectedItem;

                Services.NodeService.SetNameNode(node.Id, textBoxNameNode.Text);

                ushort newAddress = 0;
                if (ushort.TryParse(textBoxAddressNode.Text, out newAddress))
                {
                    Services.NodeService.SetAddressNode(node.Id, newAddress);
                }

                UpdateNodes();
            }
        }
Beispiel #19
0
        public async void PutNodeActionSuccess()
        {
            var controller = new NodesController(fixture.Context);
            var node       = new NodeDTO()
            {
                id       = "node3",
                parentid = null,
                treeid   = 3,
                topic    = "Bingo"
            };
            var result = await controller.PutNode(node.id, node);

            var receivedNode = await fixture.Context.Nodes.SingleOrDefaultAsync(n => n.Id == node.id);

            Assert.NotNull(receivedNode);
            Assert.Equal(node.topic, receivedNode.Topic);
            Assert.IsType <NoContentResult>(result);
        }
Beispiel #20
0
        private int GetMaxTreeHeight(NodeDTO node)
        {
            if (node == null)
            {
                return(0);
            }
            int leftHeight  = GetMaxTreeHeight(node.LeftNode);
            int rightHeight = GetMaxTreeHeight(node.RightNode);

            if (leftHeight > rightHeight)
            {
                return(leftHeight + 1);
            }
            else
            {
                return(rightHeight + 1);
            }
        }
Beispiel #21
0
        public static void SetAccountExplorerNodeState(string nodeID, string nodeType, string nodeName, int?classificationID, bool expand)
        {
            try
            {
                using (_certonaService = new CertonaServiceClient())
                {
                    try
                    {
                        UserDTO user    = FormsAuthenticationWrapper.User;
                        var     nodeDTO = new NodeDTO
                        {
                            NodeID           = nodeID,
                            DisplayValue     = nodeName,
                            NodeType         = (NodeType)Enum.Parse(typeof(NodeType), nodeType),
                            ClassificationID = classificationID,
                            Expanded         = expand
                        };

                        var accountExplorerNodeStateRequest = new SetAccountExplorerNodeStateRequest
                        {
                            User = user,
                            Node = nodeDTO
                        };

                        _certonaService.SetAccountExplorerNodeState(accountExplorerNodeStateRequest);
                    }
                    catch (TimeoutException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                    catch (CommunicationException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #22
0
        private NodeDTO GetSelectedNode(List <NodeDTO> nodes)
        {
            NodeDTO selected = null;

            foreach (NodeDTO node in nodes)
            {
                if (node.Selected)
                {
                    return(node);
                }

                selected = GetSelectedNode(node.ChildNodes);

                if (selected != null)
                {
                    break;
                }
            }

            return(selected);
        }
Beispiel #23
0
        private NodeDTO AddNodeToTree(NodeDTO node, int value)
        {
            if (value < node.Value)
            {
                if (node.LeftNode == null)
                {
                    NodeDTO newNode = new NodeDTO();
                    newNode.Value = value;
                    node.LeftNode = newNode;

                    return(newNode);
                }
                else
                {
                    return(AddNodeToTree(node.LeftNode, value));
                }
            }
            else
            {
                if (value > node.Value)
                {
                    if (node.RightNode == null)
                    {
                        NodeDTO newNode = new NodeDTO();
                        newNode.Value  = value;
                        node.RightNode = newNode;

                        return(newNode);
                    }
                    else
                    {
                        return(AddNodeToTree(node.RightNode, value));
                    }
                }
                else
                {
                    throw new Exception(String.Format("Can't add nodes with the same value {0}", value));
                }
            }
        }
Beispiel #24
0
 public BinaryTree(int rootValue)
 {
     root       = new NodeDTO();
     root.Value = rootValue;
 }