Beispiel #1
0
        // Test checks png images. If at least one icon is not presented, test fails.
        public void SearchForPNGFiles()
        {
            var model = DynamoModel.Start();

            IEnumerable   searchEntries            = model.SearchModel.SearchEntries.OfType <NodeSearchElement>();
            IconServices  iconServices             = new IconServices(model.PathManager);
            IconWarehouse currentWarehouse         = null;
            var           currentWarehouseAssembly = string.Empty;

            List <String> missingIcons = new List <string>();

            foreach (var entry in searchEntries)
            {
                var searchEle = entry as NodeSearchElement;
                if (String.IsNullOrEmpty(searchEle.IconName))
                {
                    continue;
                }

                var smallIconName = searchEle.IconName + Configurations.SmallIconPostfix;
                var largeIconName = searchEle.IconName + Configurations.LargeIconPostfix;


                // Only retrieve the icon warehouse for different assembly.
                if (currentWarehouseAssembly != searchEle.Assembly)
                {
                    currentWarehouseAssembly = searchEle.Assembly;
                    currentWarehouse         = iconServices.GetForAssembly(searchEle.Assembly);
                }

                ImageSource smallIcon = null;
                ImageSource largeIcon = null;
                if (currentWarehouse != null)
                {
                    smallIcon = currentWarehouse.LoadIconInternal(smallIconName);
                    largeIcon = currentWarehouse.LoadIconInternal(largeIconName);
                }

                if (smallIcon == null)
                {
                    missingIcons.Add(smallIconName);
                }
                if (largeIcon == null)
                {
                    missingIcons.Add(largeIconName);
                }
            }

            Assert.IsTrue(missingIcons.Count == 0, String.Join(Environment.NewLine, missingIcons));
            model.ShutDown(false);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to find the node's icon, which is the same as its type name plus a Postfix, such as '.Small'.
        /// </summary>
        /// <returns>An ImageSource object pointing to the icon image for the NodeViewModel</returns>
        internal bool TryGetNodeIcon(NodeViewModel nodeViewModel, out ImageSource iconSource)
        {
            string nodeTypeName;
            string assemblyLocation;

            switch (nodeViewModel.NodeModel)
            {
            // For ZeroTouch nodes
            case DSFunction dsFunction:
                FunctionDescriptor functionDescriptor = dsFunction.Controller.Definition;
                assemblyLocation = functionDescriptor.Assembly;
                nodeTypeName     = Graph.Nodes.Utilities.GetFunctionDescriptorIconName(functionDescriptor);
                break;

            // For DSVarArgFunctions like String.Concat
            case DSVarArgFunction dsVarArgFunction:
                nodeTypeName     = dsVarArgFunction.Controller.Definition.QualifiedName;
                assemblyLocation = dsVarArgFunction.Controller.Definition.Assembly;
                break;

            // For NodeModel nodes
            case NodeModel nodeModel:
                nodeTypeName     = nodeModel.GetType().FullName;
                assemblyLocation = nodeModel.GetType().Assembly.Location;
                break;

            default:
                nodeTypeName     = "";
                assemblyLocation = "";
                break;
            }

            iconSource = null;

            IconWarehouse currentWarehouse = iconServices.GetForAssembly(assemblyLocation);

            if (currentWarehouse is null)
            {
                return(false);
            }

            iconSource = currentWarehouse.LoadIconInternal(nodeTypeName + Configurations.SmallIconPostfix);
            return(!(iconSource is null));
        }