Ejemplo n.º 1
0
        //this is hideous but wanted to show an idea.
        public HtmlTag BuildLabel(BehaviorNode behaviorNode)
        {
            // TODO -- come back and policize this

            var span = new HtmlTag("span").AddClass("label");
            var pp   = behaviorNode.GetType().PrettyPrint();

            span.Text("behavior");

            if (pp.StartsWith("WebForm"))
            {
                span.Text("View");
                span.AddClass("notice");
            }
            else if (pp.StartsWith("Call"))
            {
                span.AddClass("warning");
                span.Text("continuation");
            }
            else if (!behaviorNode.GetType().Name.StartsWith("Fubu"))
            {
                span.Text("fubu");
            }

            return(span);
        }
Ejemplo n.º 2
0
        public static BehaviorNodeDef FromNode(BehaviorNode node)
        {
            var rep = new BehaviorNodeDef();

            rep.Name     = node.GetName();
            rep.TypeName = node.GetType().ToString();

            switch (node)
            {
            case CompositeBehaviorNode composite:
                rep.Children = new List <BehaviorNodeDef>();
                foreach (var child in composite.Children)
                {
                    rep.Children.Add(FromNode(child));
                }
                break;

            case DecoratorBehaviorNode decorator:
                rep.Children = new List <BehaviorNodeDef> {
                    FromNode(decorator.ChildNode)
                };
                break;

            default:
                rep.Children = null;
                break;
            }

            var extraParameterInfo = NodeUtil.GetConstructorExtraParameterInfo(node.GetType());

            if (extraParameterInfo == null || extraParameterInfo.Length == 0)
            {
                return(rep);
            }

            rep.ExtraParameters = new Dictionary <string, object>();
            foreach (var parameterInfo in extraParameterInfo)
            {
                var value = NodeUtil.GetParameterValueByType(node, parameterInfo.ParameterType);
                rep.ExtraParameters.Add(parameterInfo.Name, value);
            }

            return(rep);
        }
Ejemplo n.º 3
0
        public BehaviorNodeViewModel ToVisualizationSubject(BehaviorNode node)
        {
            var description = Description.For(node);


            return(new BehaviorNodeViewModel {
                Description = description,
                Node = node,
                VisualizationHtml = HasVisualizer(node.GetType())
                    ? _document.PartialFor(node).ToString()
                    : new DescriptionBodyTag(description).ToString()
            });
        }
Ejemplo n.º 4
0
        public void Verify(BehaviorSpecCheck check, BehaviorNode node)
        {
            check.Write(ToString());

            if (node == null)
            {
                check.RegisterError("was null");
                return;
            }

            var specific = node as T;

            if (specific == null)
            {
                check.RegisterError("was " + node.GetType().Name);
                return;
            }

            specificChecks(specific, check);
        }
Ejemplo n.º 5
0
        public static object GetParameterValueByType(BehaviorNode node, Type type)
        {
            var fields = AccessTools.GetDeclaredFields(node.GetType()).Except(AccessTools.GetDeclaredFields(typeof(BehaviorNode)));

            return(fields.FirstOrDefault(field => field.FieldType == type)?.GetValue(node));
        }