/// <summary>
        /// Get the complete node parameter.
        /// </summary>
        /// <param name="node">Concerned node.</param>
        /// <param name="parameter">Parameter from configuration request.</param>
        /// <returns>Complete parameter.</returns>
        internal static NodeParameterDto Get(NodeDto node, NodeParameterDto parameter)
        {
            // find parameter from database
            var result = node?.Parameters?.FirstOrDefault(x => x.Identifier == parameter.Identifier);

            // if not exists, create new
            if (result == null)
            {
                var definitionParameter = node?.Product?.Parameters?.FirstOrDefault(x => x.Identifier == parameter.DefinitionIdentifier);
                if (definitionParameter != null)
                {
                    result = new NodeParameterDto
                    {
                        Definition = definitionParameter,
                        DefinitionIdentifier = definitionParameter.Identifier,
                        Node = node,
                        NodeIdentifier = node.Identifier,
                        Update = DateTime.Now,
                        Value = parameter.Value
                    };
                }
            }

            return result;
        }
Exemplo n.º 2
0
        public void Get_NonExistent()
        {
            // initialize
            var node = new NodeDto
            {
                ConstructorIdentifier = "ZZZZ",
                ProductIdentifier = "ZZZZ"
            };

            // execute
            var test = ProductBusiness.Get(node);

            // test
            Assert.IsTrue(string.IsNullOrEmpty(test.Name));

            // clean
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get product linked to the device.
        /// </summary>
        /// <param name="node">Node.</param>
        /// <returns>Product result.</returns>
        internal static ProductDto Get(NodeDto node)
        {
            ProductDto result;
            using (var ctx = new ProductDtoFactory())
            {
                result = ctx.Get(node) ?? new ProductDto {Constructor = new ConstructorDto()};
            }
            if (result.Parameters == null) result.Parameters = new List<ProductParameterDto>();

            // complete labels
            var labelIds = new List<int> {result.NameIdentifier};
            labelIds.AddRange(result.Parameters.Select(x => x.DescriptionIdentifier));
            labelIds.AddRange(result.Parameters.Select(x => x.NameLabelIdentifier));
            var labels = LabelBusiness.Get(labelIds.ToArray());

            result.Name = labels[result.NameIdentifier];
            foreach (var p in result.Parameters)
            {
                p.Description = labels[p.DescriptionIdentifier];
                p.Name = labels[p.NameLabelIdentifier];
            }

            return result;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Set the value of a node.
 /// </summary>
 /// <param name="node">Node to set.</param>
 /// <returns>True if value is setted, else false.</returns>
 public bool Set(NodeDto node)
 {
     return NodeBusiness.Set(node);
 }