Example #1
0
        public void TestLoadNoNamespaceClass()
        {
            LibraryLoaded = false;

            string libraryPath = "FFITarget.dll";

            // All we need to do here is to ensure that the target has been loaded
            // at some point, so if it's already thre, don't try and reload it
            if (!libraryServices.IsLibraryLoaded(libraryPath))
            {
                libraryServices.ImportLibrary(libraryPath);
                Assert.IsTrue(LibraryLoaded);
            }

            // Get function groups for global classes with no namespace
            var functions = libraryServices.GetFunctionGroups(libraryPath)
                            .Where(x => x.Functions
                                   .Where(y => string.IsNullOrEmpty(y.Namespace)).Any());

            if (functions.Any())
            {
                var ctorfg = functions.Where(x => x.Functions.Where(y => y.Type == FunctionType.Constructor).Any());
                Assert.IsTrue(ctorfg.Any());
                foreach (var fg in ctorfg)
                {
                    foreach (var ctor in fg.Functions)
                    {
                        Assert.IsTrue(ctor.ClassName == ctor.UnqualifedClassName);
                    }
                }
            }
        }
Example #2
0
        public void TestLoadDSFile()
        {
            LibraryLoaded = false;

            string libraryPath = Path.Combine(TestDirectory, @"core\library\Dummy.ds");

            libraryServices.ImportLibrary(libraryPath);
            Assert.IsTrue(LibraryLoaded);

            var functions = libraryServices.GetFunctionGroups(libraryPath);

            Assert.IsNotNull(functions);
            Assert.IsTrue(functions.Any());
        }
Example #3
0
        private IEnumerable <Dynamo.Engine.FunctionGroup> LoadLibraryIntoSearchViewModel(SearchViewModel searchViewModel, string libraryPath)
        {
            LibraryLoaded = false;

            // All we need to do here is to ensure that the target has been loaded
            // at some point, so if it's already here, don't try and reload it
            if (!libraryServices.IsLibraryLoaded(libraryPath))
            {
                libraryServices.ImportLibrary(libraryPath);
                Assert.IsTrue(LibraryLoaded);
            }

            var fgToCompare = libraryServices.GetFunctionGroups(libraryPath);

            foreach (var funcGroup in fgToCompare)
            {
                foreach (var functionDescriptor in funcGroup.Functions)
                {
                    if (functionDescriptor.IsVisibleInLibrary && !functionDescriptor.DisplayName.Contains("GetType"))
                    {
                        searchViewModel.Model.Add(new ZeroTouchSearchElement(functionDescriptor));
                    }
                }
            }

            return(fgToCompare);
        }
Example #4
0
        private void LoadAssembliesIntoDynamo(DynamoLoader loader, ILogger logger, LibraryServices libraryServices)
        {
            var assemblies = LoadAssembliesInBinDirectory(logger);

            // filter the assemblies
            var zeroTouchAssemblies = new List <Assembly>();
            var nodeModelAssemblies = new List <Assembly>();

            foreach (var assem in assemblies)
            {
                if (loader.ContainsNodeModelSubType(assem))
                {
                    nodeModelAssemblies.Add(assem);
                }
                else
                {
                    zeroTouchAssemblies.Add(assem);
                }
            }

            // load the zero touch assemblies
            foreach (var zeroTouchAssem in zeroTouchAssemblies)
            {
                libraryServices.ImportLibrary(zeroTouchAssem.Location, logger);
            }

            // load the node model assemblies
            foreach (var nodeModelAssem in nodeModelAssemblies)
            {
                var nodes = loader.LoadNodesFromAssembly(nodeModelAssem);
                nodes.ForEach(x => LoadedTypes.Add(x));
            }
        }
Example #5
0
        public void TestLoadNoNamespaceClass()
        {
            LibraryServices libraryServices = LibraryServices.GetInstance();
            bool            libraryLoaded   = false;

            libraryServices.LibraryLoaded     += (sender, e) => libraryLoaded = true;
            libraryServices.LibraryLoadFailed += (sender, e) => Assert.Fail("Failed to load library: " + e.LibraryPath);

            string libraryPath = "FFITarget.dll";

            libraryServices.ImportLibrary(libraryPath, ViewModel.Model.Logger);
            Assert.IsTrue(libraryLoaded);

            // Get function groups for global classes with no namespace
            var functions = libraryServices.GetFunctionGroups(libraryPath)
                            .Where(x => x.Functions
                                   .Where(y => string.IsNullOrEmpty(y.Namespace)).Any());

            if (functions.Any())
            {
                var ctorfg = functions.Where(x => x.Functions.Where(y => y.Type == FunctionType.Constructor).Any());
                Assert.IsTrue(ctorfg.Any());
                foreach (var fg in ctorfg)
                {
                    foreach (var ctor in fg.Functions)
                    {
                        Assert.IsTrue(ctor.ClassName == ctor.UnqualifedClassName);
                    }
                }
            }
        }
Example #6
0
        public void TestLoadDSFile()
        {
            bool libraryLoaded = false;

            libraryServices.LibraryLoaded     += (sender, e) => libraryLoaded = true;
            libraryServices.LibraryLoadFailed += (sender, e) => Assert.Fail("Failed to load library: " + e.LibraryPath);

            string libraryPath = Path.Combine(GetTestDirectory(), @"core\library\Dummy.ds");

            libraryServices.ImportLibrary(libraryPath);
            Assert.IsTrue(libraryLoaded);

            var functions = libraryServices.GetFunctionGroups(libraryPath);

            Assert.IsNotNull(functions);
            Assert.IsTrue(functions.Any());
        }
Example #7
0
        public void TestLoadLibrary()
        {
            LibraryServices libraryServices = LibraryServices.GetInstance();
            bool            libraryLoaded   = false;

            libraryServices.LibraryLoaded     += (sender, e) => libraryLoaded = true;
            libraryServices.LibraryLoadFailed += (sender, e) => Assert.Fail("Failed to load library: " + e.LibraryPath);

            string libraryPath = Path.Combine(GetTestDirectory(), @"core\library\MultiReturnTest.dll");

            libraryServices.ImportLibrary(libraryPath);
            Assert.IsTrue(libraryLoaded);

            var functions = libraryServices.GetFunctionGroups(libraryPath);

            Assert.IsNotNull(functions);
            Assert.IsTrue(functions.Any());
        }
Example #8
0
        private void LoadAssembliesIntoDynamo(DynamoLoader loader, LibraryServices libraryServices, string context)
        {
            var assemblies = LoadAssembliesInBinDirectory();

            // filter the assemblies
            var zeroTouchAssemblies = new List <Assembly>();
            var nodeModelAssemblies = new List <Assembly>();

            // categorize the assemblies to load, skipping the ones that are not identified as node libraries
            foreach (var assem in assemblies.Where(x => x.IsNodeLibrary).Select(x => x.Assembly))
            {
                if (loader.ContainsNodeModelSubType(assem))
                {
                    nodeModelAssemblies.Add(assem);
                }
                else
                {
                    zeroTouchAssemblies.Add(assem);
                }
            }

            // load the zero touch assemblies
            foreach (var zeroTouchAssem in zeroTouchAssemblies)
            {
                libraryServices.ImportLibrary(zeroTouchAssem.Location);
            }

            // load the node model assemblies
            var nodes = nodeModelAssemblies.SelectMany(
                assem =>
            {
                var assemblyNodes = new List <TypeLoadData>();
                loader.LoadNodesFromAssembly(assem, context, assemblyNodes, new List <TypeLoadData>());
                return(assemblyNodes);
            });

            foreach (var node in nodes)
            {
                LoadedTypes.Add(node.Type);
            }
        }
Example #9
0
        public void TestLibraryAcrossSessions()
        {
            LibraryServices libraryServices = LibraryServices.GetInstance();

            bool libraryLoaded = false;

            libraryServices.LibraryLoaded += (sender, e) => libraryLoaded = true;

            // library should be able to load
            string libraryPath = Path.Combine(GetTestDirectory(), @"core\library\Test.ds");

            libraryServices.ImportLibrary(libraryPath);
            Assert.IsTrue(libraryLoaded);

            // open dyn file which uses node in that library
            RunModel(@"core\library\t1.dyn");
            AssertValue("a", 1025);

            // open the other dyn file which uses node in that library, and
            // library should still be available
            RunModel(@"core\library\t2.dyn");
            AssertValue("a", 43);
        }
Example #10
0
        public void TestLibraryAcrossSessions()
        {
            LibraryServices libraryServices = LibraryServices.GetInstance();

            bool libraryLoaded = false;

            libraryServices.LibraryLoaded += (sender, e) => libraryLoaded = true;

            // library should be able to load
            string libraryPath = Path.Combine(GetTestDirectory(), @"core\library\Test.ds");

            libraryServices.ImportLibrary(libraryPath, ViewModel.Model.Logger);
            Assert.IsTrue(libraryLoaded);

            // open dyn file which uses node in that library
            RunModel(@"core\library\t1.dyn");
            AssertPreviewValue("2cacc70a-23a8-4fe0-92d1-9b72ae3db10b", 1025);

            // open the other dyn file which uses node in that library, and
            // library should still be available
            RunModel(@"core\library\t2.dyn");
            AssertPreviewValue("880ea294-7a01-4a78-8602-54d73f4b681b", 43);
        }
Example #11
0
        public void DumpLibraryToXmlZeroTouchTest()
        {
            var searchViewModel = new SearchViewModel(new NodeSearchModel());

            LibraryLoaded = false;

            string libraryPath = "DSOffice.dll";

            // All we need to do here is to ensure that the target has been loaded
            // at some point, so if it's already here, don't try and reload it
            if (!libraryServices.IsLibraryLoaded(libraryPath))
            {
                libraryServices.ImportLibrary(libraryPath);
                Assert.IsTrue(LibraryLoaded);
            }

            var fgToCompare = libraryServices.GetFunctionGroups(libraryPath);

            foreach (var funcGroup in fgToCompare)
            {
                foreach (var functionDescriptor in funcGroup.Functions)
                {
                    if (functionDescriptor.IsVisibleInLibrary && !functionDescriptor.DisplayName.Contains("GetType"))
                    {
                        searchViewModel.Model.Add(new ZeroTouchSearchElement(functionDescriptor));
                    }
                }
            }

            var document = searchViewModel.Model.ComposeXmlForLibrary(ExecutingDirectory);

            Assert.AreEqual("LibraryTree", document.DocumentElement.Name);

            XmlNode node, subNode;

            foreach (var functionGroup in fgToCompare)
            {
                foreach (var function in functionGroup.Functions)
                {
                    // Obsolete, not visible and "GetType" functions are not presented in UI tree.
                    // So they are should not be presented in dump.
                    if (function.IsObsolete || !function.IsVisibleInLibrary || function.FunctionName.Contains("GetType"))
                    {
                        continue;
                    }

                    var category = function.Category;
                    var group    = SearchElementGroup.Action;
                    category = searchViewModel.Model.ProcessNodeCategory(category, ref group);

                    node = document.SelectSingleNode(string.Format(
                                                         "//{0}[FullCategoryName='{1}' and Name='{2}']",
                                                         typeof(ZeroTouchSearchElement).FullName, category, function.FunctionName));
                    Assert.IsNotNull(node);

                    subNode = node.SelectSingleNode("Group");
                    Assert.IsNotNull(subNode.FirstChild);
                    Assert.AreEqual(group.ToString(), subNode.FirstChild.Value);

                    // 'FullCategoryName' is already checked.
                    // 'Name' is already checked.

                    subNode = node.SelectSingleNode("Description");
                    Assert.IsNotNull(subNode.FirstChild);

                    // No check Description on text equality because for some reason
                    // function.Descriptions are different in real executing Dynamo and
                    // Dynamo started from tests.
                    //
                    // For example:
                    // tests  function.Description: Excel.ReadFromFile (file: FileInfo, sheetName: string): var[][]
                    // normal function.Description: Excel.ReadFromFile (file: var, sheetName: string): var[][]
                }
            }
        }
Example #12
0
        public NodeModel CreateNodeFromXml(XmlElement nodeElement, SaveContext context, ElementResolver resolver)
        {
            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
                    libraryServices.AddAdditionalAttributesToNode(xmlSignature, nodeElement);
                    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);

                if (libraryServices.IsLibraryLoaded(assembly))
                {
                    descriptor = libraryServices.GetFunctionDescriptor(assembly, function);
                }
                else
                {
                    // If the desired assembly is not loaded already. Check if it belongs to BuiltInFunctionGroup.
                    if (libraryServices.IsFunctionBuiltIn(assembly, nickname))
                    {
                        descriptor = libraryServices.GetFunctionDescriptor(function);
                    }
                    else
                    {
                        // If neither of these, Dynamo need to import the library.
                        try
                        {
                            libraryServices.ImportLibrary(assembly);
                            descriptor = libraryServices.GetFunctionDescriptor(assembly, function);
                        }
                        catch (LibraryLoadFailedException)
                        {
                            descriptor = 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);

                var akas = typeof(DSVarArgFunction).GetCustomAttribute <AlsoKnownAsAttribute>().Values;
                if (nodeElement.Name != typeof(DSVarArgFunction).FullName &&
                    akas.All(aka => aka != nodeElement.Name))
                {
                    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.InputParameters)
                {
                    if (i >= inputTypes.Length || param.Item2 != inputTypes[i])
                    {
                        result.InPorts[j].UsingDefaultValue = result.InPorts[j].DefaultValue != null;
                    }
                    else
                    {
                        i++;
                    }
                    j++;
                }
            }

            return(result);
        }
Example #13
0
        private void LoadAssembliesIntoDynamo( DynamoLoader loader, ILogger logger, LibraryServices libraryServices)
        {
            var assemblies = LoadAssembliesInBinDirectory(logger);

            // filter the assemblies
            var zeroTouchAssemblies = new List<Assembly>();
            var nodeModelAssemblies = new List<Assembly>();

            foreach (var assem in assemblies)
            {
                if (loader.ContainsNodeModelSubType(assem))
                {
                    nodeModelAssemblies.Add(assem);
                }
                else
                {
                    zeroTouchAssemblies.Add(assem);
                }
            }

            // load the zero touch assemblies
            foreach (var zeroTouchAssem in zeroTouchAssemblies)
            {
                libraryServices.ImportLibrary(zeroTouchAssem.Location, logger);
            }

            // load the node model assemblies
            foreach (var nodeModelAssem in nodeModelAssemblies)
            {
                var nodes = loader.LoadNodesFromAssembly(nodeModelAssem);
                nodes.ForEach(x => LoadedTypes.Add(x));
            }
        }
Example #14
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);
        }