Beispiel #1
0
        public async Task <string> CreateNodeAsync([FromBody] NodeViewModel request)
        {
            // HttpRequest res = null;
            var response         = new ListModelResponse <NodeViewModel>();
            var objectsDataModel = false;

            try
            {
                objectsDataModel = await _nodeRepository.CreateNode(request.ToEntity());

                if (objectsDataModel)
                {
                    response.Message = Messages.SuccessMsg;
                }
                //response.Message = String.Format("Created Project Successfully");

                else
                {
                    //  response.Message = String.Format("Create Project failed");
                    response.Message = Messages.FailMsg;
                }
            }

            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.Message);
        }
        public bool ContainsNodeAfterAddition(string body)
        {
            if (string.IsNullOrEmpty(body))
            {
                body = "1";                             // TODO
            }
            var entityId = _nodeRepository.CreateNode(body);
            var allNodes = _nodeRepository.GetAll();

            return(allNodes.Any(n => n.Id == entityId));
        }
        public async Task <Node> CreateNodeAsync(Node node)
        {
            logger.LogInformation($"Adding node {node}");

            await ValidateNode(node);

            var createdNode = nodeRepository.CreateNode(node);

            eventBus.Publish(new NodeAddedEvent()
            {
                CreationDate = clock.UtcNow(), CreatedNode = createdNode
            });

            return(createdNode);
        }
Beispiel #4
0
        public async Task <Node> CreateNodeAsync(Node node)
        {
            logger.LogInformation($"Adding node {node}");
            // Try to connect to node
            var bitcoind = bitcoindFactory.Create(node.Host, node.Port, node.Username, node.Password);

            try
            {
                // try to call some method to test if connectivity parameters are correct
                _ = await bitcoind.GetBlockCountAsync();
            }
            catch (Exception ex)
            {
                throw new BadRequestException($"The node was not added. Unable to connect to node {node.Host}:{node.Port}.", ex);
            }

            RpcActiveZmqNotification[] notifications;
            try
            {
                notifications = await bitcoind.ActiveZmqNotificationsAsync();
            }
            catch (Exception ex)
            {
                throw new BadRequestException($"Node at address '{node.Host}:{node.Port}' did not return a valid response to call 'activeZmqNotifications'", ex);
            }


            if (!notifications.Any() || notifications.Select(x => x.Notification).Intersect(ZMQTopic.RequiredZmqTopics).Count() != ZMQTopic.RequiredZmqTopics.Length)
            {
                var missingNotifications = ZMQTopic.RequiredZmqTopics.Except(notifications.Select(x => x.Notification));
                throw new BadRequestException($"Node '{node.Host}:{node.Port}', does not have all required zmq notifications enabled. Missing notifications ({string.Join(",", missingNotifications)})");
            }

            var createdNode = nodeRepository.CreateNode(node);

            eventBus.Publish(new NodeAddedEvent()
            {
                CreationDate = clock.UtcNow(), CreatedNode = createdNode
            });

            return(createdNode);
        }
Beispiel #5
0
 public bool CreateNode(Node node)
 {
     _nodeRepository.CreateNode(node);
     return(true);
 }
        public BluePrint CreateBluePrint(BluePrintDesign design)
        {
            var lifeTimeId = Guid.NewGuid().ToString();
            var scope      = _parentScope.BeginLifetimeScope(lifeTimeId);
            var nodeOrder  = new List <NodeInstance>();
            var nodes      = new List <NodeInstance>();

            foreach (var designNode in design.Nodes)
            {
                var nodeCreateResult = _nodeRepository.CreateNode(scope, designNode.NodeTypeKey);
                var nodeLifeTimeId   = Guid.NewGuid().ToString();
                var nodeInstance     = new NodeInstance(nodeLifeTimeId, designNode, nodeCreateResult.Node, nodeCreateResult.Descriptor);

                if (nodeInstance.IsValueNode)
                {
                    nodeInstance.SetValue(designNode.Value);
                }

                var portDescriptor = _nodeRepository.CreatePortDescriptor(nodeInstance.Descriptor.Id);
                foreach (var definition in portDescriptor.PortDefinitions)
                {
                    nodeInstance.Ports.Add(new PortInstance(definition));
                }

                nodes.Add(nodeInstance);
            }

            var toConnectNodes  = nodes.ToList();
            var openConnections = design.Connections.ToList();
            var lastCount       = -1;

            while (toConnectNodes.Count > 0 && lastCount != toConnectNodes.Count)
            {
                lastCount = toConnectNodes.Count;
                var nodesReady = toConnectNodes.Where(x => x.AllRequiredInputsConnected).ToList();

                foreach (var node in nodesReady)
                {
                    toConnectNodes.Remove(node);
                    nodeOrder.Add(node);

                    var outputPorts = node.Ports.Where(x => x.Definition.InputOutputType == InputOutputType.Output);
                    foreach (var outputPort in outputPorts)
                    {
                        outputPort.InitializeAsOutput();

                        var portConnections = openConnections.Where(x => x.NodeFrom == node.Design.NodeInstanceId && x.NodePortFrom == outputPort.Definition.Key).ToList();

                        foreach (var connection in portConnections)
                        {
                            openConnections.Remove(connection);
                            var toNode = nodes.FirstOrDefault(x => x.Design.NodeInstanceId == connection.NodeTo);
                            var toPort = toNode?.Ports.FirstOrDefault(x => x.Definition.Key == connection.NodePortTo);
                            toPort?.InitializeAsInput(outputPort.InputOutput);
                        }
                    }
                }
            }

            return(new BluePrint(scope, nodeOrder));
        }