コード例 #1
0
        private void OnMenuClick(object sender, RoutedEventArgs args)
        {
            RobotMenuFlyoutItem robotMenu = sender as RobotMenuFlyoutItem;
            var controller = canvasController.CurrentController as RobotMindGraph;

            if (controller == null)
            {
                return;
            }

            var method   = controller.GetType().GetMethod("Create")?.MakeGenericMethod(robotMenu.ClassType);
            var instance = method?.Invoke(controller, new object[] {
                robotMenu.ClassTemplate,
                robotMenu.Method
            });

            if (instance is TemplateContainer)
            {
                (instance as TemplateContainer).Guid = robotMenu.Guid;
            }
        }
コード例 #2
0
        void GenerateMenu(object sender, RoutedEventArgs args)
        {
            var assembly = typeof(ILogicNode).Assembly;
            var nodes    = assembly.GetTypes()
                           .Where(x => typeof(IDevice).IsAssignableFrom(x))
                           .Where(x => x.IsClass)
                           .ToList();

            if (nodes.Count > 0)
            {
                MenuFlyout        menu = new MenuFlyout();
                MenuFlyoutSubItem item;
                foreach (var node in nodes)
                {
                    var guid = Guid.NewGuid();

                    item = new MenuFlyoutSubItem
                    {
                        Text = node.GetCustomAttribute <DisplayName>()?.Name ?? "Node"
                    };

                    // Если есть cобытия
                    var events = node.GetEvents();
                    if (events.Any())
                    {
                        var eventsItem = new RobotMenuFlyoutItem
                        {
                            Text          = "Events",
                            ClassTemplate = ClassTemplate.Event,
                            ClassType     = node,
                            Guid          = guid
                        };

                        eventsItem.Click += OnMenuClick;

                        item.Items.Add(eventsItem);
                    }

                    // Если есть cобытия
                    var props = node.GetProperties();
                    if (props.Any())
                    {
                        var propsItem = new RobotMenuFlyoutItem
                        {
                            Text          = "Properties",
                            ClassTemplate = ClassTemplate.Getter,
                            Guid          = guid,
                            ClassType     = node
                        };

                        propsItem.Click += OnMenuClick;
                        item.Items.Add(propsItem);
                    }

                    // Если есть cобытия
                    var setters = node.GetMethods().Where(x => x.IsPublic && x.GetCustomAttributes <rMind.Robot.Setter>().Any());
                    if (setters.Any())
                    {
                        var settersItem = new MenuFlyoutSubItem
                        {
                            Text = "Setters",
                        };

                        foreach (var setter in setters)
                        {
                            var setterItem = new RobotMenuFlyoutItem
                            {
                                ClassTemplate = ClassTemplate.Setter,
                                ClassType     = node,
                                Guid          = guid,
                                Text          = setter.GetCustomAttributes <DisplayName>().FirstOrDefault()?.Name ?? "None",
                                Method        = setter
                            };

                            setterItem.Click += OnMenuClick;
                            settersItem.Items.Add(setterItem);
                        }


                        item.Items.Add(settersItem);
                    }

                    menu.Items.Add(item);
                }

                canvas.ContextFlyout = menu;
            }
        }