Пример #1
0
        public NodeModel CreateNodeFromXml(XmlElement nodeElement, SaveContext context)
        {
            string assembly = "";
            string function;
            var    nickname = nodeElement.Attributes["nickname"].Value;

            FunctionDescriptor descriptor;

            Trace.Assert(nodeElement.Attributes != null, "nodeElement.Attributes != null");

            if (nodeElement.Attributes["assembly"] == null)
            {
                assembly = DetermineAssemblyName(nodeElement);
                function = nickname.Replace(".get", ".");
            }
            else
            {
                string xmlSignature = nodeElement.Attributes["function"].Value;

                string hintedSigniture =
                    libraryServices.FunctionSignatureFromFunctionSignatureHint(xmlSignature);

                if (hintedSigniture != null)
                {
                    nodeElement.Attributes["nickname"].Value =
                        libraryServices.NicknameFromFunctionSignatureHint(xmlSignature);
                    function = hintedSigniture;

                    // if the node needs additional parameters, add them here
                    if (libraryServices.FunctionSignatureNeedsAdditionalAttributes(xmlSignature))
                    {
                        libraryServices.AddAdditionalAttributesToNode(xmlSignature, nodeElement);
                    }

                    if (libraryServices.FunctionSignatureNeedsAdditionalElements(xmlSignature))
                    {
                        libraryServices.AddAdditionalElementsToNode(xmlSignature, nodeElement);
                    }
                }
                else
                {
                    function = xmlSignature;
                }

                var xmlAttribute = nodeElement.Attributes["assembly"];
                if (xmlAttribute != null)
                {
                    assembly = Uri.UnescapeDataString(xmlAttribute.Value);
                }
            }

            if (context == SaveContext.File && !string.IsNullOrEmpty(assembly))
            {
                var document = nodeElement.OwnerDocument;
                var docPath  = Nodes.Utilities.GetDocumentXmlPath(document);
                assembly = Nodes.Utilities.MakeAbsolutePath(docPath, assembly);

                descriptor = libraryServices.IsLibraryLoaded(assembly) || libraryServices.ImportLibrary(assembly)
                    ? libraryServices.GetFunctionDescriptor(assembly, function)
                    : libraryServices.GetFunctionDescriptor(function);
            }
            else
            {
                descriptor = libraryServices.GetFunctionDescriptor(function);
            }

            if (null == descriptor)
            {
                var inputcount = DetermineFunctionInputCount(nodeElement);

                return(new DummyNode(
                           inputcount,
                           1,
                           nickname,
                           nodeElement,
                           assembly,
                           DummyNode.Nature.Unresolved));
            }

            DSFunctionBase result;

            if (descriptor.IsVarArg)
            {
                result = new DSVarArgFunction(descriptor);
                if (nodeElement.Name != typeof(DSVarArgFunction).FullName)
                {
                    VariableInputNodeController.SerializeInputCount(
                        nodeElement,
                        descriptor.Parameters.Count());
                }
            }
            else
            {
                result = new DSFunction(descriptor);
            }

            result.Deserialize(nodeElement, context);

            // In case of input parameters mismatch, use default arguments for parameters that have one
            if (!descriptor.MangledName.EndsWith(function))
            {
                string[] oldSignature = function.Split('@');
                string[] inputTypes = oldSignature.Length > 1 ? oldSignature[1].Split(',') : new string[] {};
                int      i = 0, j = 0;
                foreach (var param in descriptor.Parameters)
                {
                    if (i >= inputTypes.Length || param.Type.ToString() != inputTypes[i])
                    {
                        result.InPorts[j].UsingDefaultValue = result.InPortData[j].DefaultValue != null;
                    }
                    else
                    {
                        i++;
                    }
                    j++;
                }
            }

            return(result);
        }
Пример #2
0
        public NodeModel CreateNodeFromXml(XmlElement nodeElement, SaveContext context)
        {
            string assembly = "";
            string function;
            var    nickname = nodeElement.Attributes["nickname"].Value;

            FunctionDescriptor descriptor;

            Trace.Assert(nodeElement.Attributes != null, "nodeElement.Attributes != null");

            if (nodeElement.Attributes["assembly"] == null)
            {
                assembly = DetermineAssemblyName(nodeElement);
                function = nickname.Replace(".get", ".");
            }
            else
            {
                string xmlSignature = nodeElement.Attributes["function"].Value;

                string hintedSigniture =
                    libraryServices.FunctionSignatureFromFunctionSignatureHint(xmlSignature);

                if (hintedSigniture != null)
                {
                    nodeElement.Attributes["nickname"].Value =
                        libraryServices.NicknameFromFunctionSignatureHint(xmlSignature);
                    function = hintedSigniture;

                    // if the node needs additional parameters, add them here
                    if (libraryServices.FunctionSignatureNeedsAdditionalAttributes(xmlSignature))
                    {
                        libraryServices.AddAdditionalAttributesToNode(xmlSignature, nodeElement);
                    }

                    if (libraryServices.FunctionSignatureNeedsAdditionalElements(xmlSignature))
                    {
                        libraryServices.AddAdditionalElementsToNode(xmlSignature, nodeElement);
                    }
                }
                else
                {
                    function = xmlSignature;
                }

                var xmlAttribute = nodeElement.Attributes["assembly"];
                if (xmlAttribute != null)
                {
                    assembly = Uri.UnescapeDataString(xmlAttribute.Value);
                }
            }

            if (context == SaveContext.File && !string.IsNullOrEmpty(assembly))
            {
                var document = nodeElement.OwnerDocument;
                var docPath  = Nodes.Utilities.GetDocumentXmlPath(document);
                assembly = Nodes.Utilities.MakeAbsolutePath(docPath, assembly);

                descriptor = libraryServices.IsLibraryLoaded(assembly) || libraryServices.ImportLibrary(assembly)
                    ? libraryServices.GetFunctionDescriptor(assembly, function)
                    : libraryServices.GetFunctionDescriptor(function);
            }
            else
            {
                descriptor = libraryServices.GetFunctionDescriptor(function);
            }

            if (null == descriptor)
            {
                var inputcount = DetermineFunctionInputCount(nodeElement);

                return(new DummyNode(
                           inputcount,
                           1,
                           nickname,
                           nodeElement,
                           assembly,
                           DummyNode.Nature.Unresolved));
            }

            DSFunctionBase result;

            if (descriptor.IsVarArg)
            {
                result = new DSVarArgFunction(descriptor);
                if (nodeElement.Name != typeof(DSVarArgFunction).FullName)
                {
                    VariableInputNodeController.SerializeInputCount(
                        nodeElement,
                        descriptor.Parameters.Count());
                }
            }
            else
            {
                result = new DSFunction(descriptor);
            }

            result.Deserialize(nodeElement, context);
            return(result);
        }