Ejemplo n.º 1
0
        private Adapter AddAdapter(AdapterConfigurationModel adpaterModel)
        {
            try
            {
                if (_nodeSynchroniztaionService.IsRunning)
                {
                    _nodeSynchroniztaionService.StopAsync(new System.Threading.CancellationToken());
                }

                return(_adapterManager.AddAdapter(adpaterModel));
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                if (!_nodeSynchroniztaionService.IsRunning)
                {
                    _nodeSynchroniztaionService.StartAsync(new System.Threading.CancellationToken());
                }
            }
        }
Ejemplo n.º 2
0
        public IActionResult AddNode(Guid adapterGuid, NodeConfigurationModel configModel)
        {
            try
            {
                if (_nodeSynchroniztaionService.IsRunning)
                {
                    _nodeSynchroniztaionService.StopAsync(new System.Threading.CancellationToken());
                }

                var adapter = _adapterManager.Adapters.Where(x => x.Guid == adapterGuid).FirstOrDefault();

                if (adapter == null)
                {
                    return(BadRequest($"Adapter with guid: '{adapterGuid}' not found."));
                }

                var node = _nodeFactory.Create(configModel.TypeFullName, configModel.JsonConfiguration);
                node.Name       = configModel.Name;
                node.Guid       = Guid.NewGuid();
                node.DataType   = NodeDataType.Int;
                node.ParentGuid = configModel.ParentGuid;

                adapter.AddNode(node);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            finally
            {
                if (!_nodeSynchroniztaionService.IsRunning)
                {
                    _nodeSynchroniztaionService.StartAsync(new System.Threading.CancellationToken());
                }
            }
            return(CreatedAtAction());
        }