public TargetTypeDirective CreateTargetType(PropertyTreeNavigator nav)
        {
            if (nav.IsProperty)
            {
                Exception error;

                try {
                    var tr = TypeReference.Parse(Convert.ToString(nav.Value), parent.GetBasicServices(nav));
                    return(new TargetTypeDirective(tr, null));
                } catch (Exception ex) {
                    if (Failure.IsCriticalException(ex))
                    {
                        throw;
                    }

                    error = ex;
                    Errors.BadTargetTypeDirective(error, nav.FileLocation);
                    return(null);
                }
            }
            else
            {
                try {
                    return(nav.Bind <TargetTypeDirective>());
                } catch (Exception ex) {
                    if (Failure.IsCriticalException(ex))
                    {
                        throw;
                    }

                    Errors.BadTargetTypeDirective(ex, nav.FileLocation);
                    return(null);
                }
            }
        }
            public override PropertyTreeMetaObject Process(PropertyTreeBinderImpl parent,
                                                           PropertyTreeMetaObject target,
                                                           PropertyTreeNavigator self,
                                                           NodeList children)
            {
                Type type = target.ComponentType ?? typeof(object);

                // Select providers
                if (type.IsProviderType())
                {
                    var node = children.FindAndRemove(ImplicitDirective(target, "provider")).FirstOrDefault();

                    if (node != null)
                    {
                        var serviceProvider = parent.GetBasicServices(node);
                        var pro             = parent.DirectiveFactory.CreateTargetProvider(type, node);
                        if (pro != null)
                        {
                            target = target.BindTargetProvider(pro, serviceProvider);
                            return(target);
                        }
                    }
                }

                return(target);
            }
            public override PropertyTreeMetaObject Process(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator self, NodeList children)
            {
                Predicate <PropertyTreeNavigator> predicate = ImplicitDirective(target, "source");

                var node = children.FindAndRemove(predicate).FirstOrDefault();

                if (node != null)
                {
                    IServiceProvider serviceProvider = parent.GetBasicServices(node);
                    var uriContext = node as IUriContext;
                    TargetSourceDirective ss;
                    ss = parent.DirectiveFactory.CreateTargetSource(node, uriContext);

                    if (ss != null)
                    {
                        try {
                            target = target.BindStreamingSource(ss, serviceProvider);
                        } catch (PropertyTreeException) {
                            throw;
                        } catch (Exception ex) {
                            if (ex.IsCriticalException())
                            {
                                throw;
                            }

                            parent._errors.FailedToLoadFromSource(ss.Uri, ex, node.FileLocation);
                        }
                    }
                }

                return(target);
            }
            public override PropertyTreeMetaObject Process(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator self, NodeList children)
            {
                IServiceProvider serviceProvider = parent.GetBasicServices(self);
                int lineNumber   = self.LineNumber;
                int linePosition = self.LinePosition;

                return(target.BindFileLocation(lineNumber, linePosition, serviceProvider));
            }
Esempio n. 5
0
            private void ApplyType(PropertyTreeBinderImpl parent,
                                   PropertyTreeMetaObject target,
                                   PropertyTreeNavigator node)
            {
                if (node == null)
                {
                    return;
                }

                var serviceProvider = parent.GetBasicServices(node);

                target.BindTargetType(parent.DirectiveFactory.CreateTargetType(node), serviceProvider);
            }
            public override PropertyTreeMetaObject Process(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator self, NodeList children)
            {
                QualifiedName name = self.QualifiedName;
                var           ctor = PropertyTreeDefinition.FromType(target.ComponentType).Constructor;

                if (target.ShouldConstruct && ctor != null)
                {
                    OperatorDefinition op = ctor;
                    var args = parent.ExtractParameterDictionary(op, target, parent.GetBasicServices(self), children);

                    target = target.BindConstructor(ctor, args);
                }

                return(target);
            }
            public override PropertyTreeMetaObject Process(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator self, NodeList children)
            {
                Predicate <PropertyTreeNavigator> predicate = ImplicitDirective(target, "base");

                var node = children.FindAndRemove(predicate).FirstOrDefault();

                Uri baseUri;
                IServiceProvider serviceProvider;

                if (node == null)
                {
                    baseUri         = self.BaseUri;
                    serviceProvider = parent;
                }
                else
                {
                    baseUri         = Utility.NewUri(Convert.ToString(node.Value));
                    serviceProvider = parent.GetBasicServices(node);
                }
                return(target.BindBaseUri(baseUri, serviceProvider));
            }
            private PropertyTreeMetaObject DoOperatorBind(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator navigator, OperatorDefinition op)
            {
                OperatorDefinition addon = op;

                if (addon.DefaultParameter != null)
                {
                    Type itemType = addon.OutputType;
                    // TODO Use service activation (we have the output type)

                    var item  = target.CreateChild(itemType);
                    var model = parent.Bind(item, navigator, null);
                    var args  = new Dictionary <string, PropertyTreeMetaObject>
                    {
                        { addon.DefaultParameter.Name, model }
                    };

                    try {
                        target.BindAddChild(op, args);
                    } catch (PropertyTreeException) {
                        throw;
                    } catch (Exception ex) {
                        if (ex.IsCriticalException())
                        {
                            throw;
                        }

                        parent._errors.BadAddChild(target.ComponentType, ex, navigator.FileLocation);
                    }
                }
                else
                {
                    // TODO The number and kinds of arguments are constrained.  This should probably
                    // be enforced within schema operator reflection (spec)

                    Action <IReadOnlyDictionary <string, PropertyTreeMetaObject> > func;
                    var children = NodeList.Create(SelectChildren(navigator));

                    switch (addon.OperatorType)
                    {
                    case OperatorType.Add:
                        func = args => {
                            var child = target.BindAddChild(addon, args);

                            if (child.ShouldBindChildren)
                            {
                                parent.BindChildNodes(child, navigator, children);
                            }
                        };
                        break;

                    case OperatorType.Remove:
                        func = args => target.BindRemoveChild(addon, args);
                        break;

                    case OperatorType.Clear:
                    default:
                        func = args => target.BindClearChildren(addon, args);
                        break;
                    }

                    var services = parent.GetBasicServices(navigator);
                    var args2    = parent.ExtractParameterDictionary(op, target, services, children);
                    func(args2);
                }

                return(target);
            }
            private PropertyTreeMetaObject DoOperatorBind(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator navigator, OperatorDefinition op)
            {
                OperatorDefinition addon = op;

                if (addon.DefaultParameter != null) {
                    Type itemType = ((PropertyTreeFactoryDefinition) addon).OutputType;
                    // TODO Use service activation (we have the output type)

                    var item = target.CreateChild(itemType);
                    var model = parent.Bind(item, navigator, null);
                    var args = new Dictionary<string, PropertyTreeMetaObject>
                    {
                        { addon.DefaultParameter.Name, model }
                    };

                    try {
                        target.BindAddChild(op, args);

                    } catch (Exception ex) {
                        if (ex.IsCriticalException())
                            throw;

                        parent.errors.BadAddChild(target.ComponentType, ex, navigator.FileLocation);
                    }

                } else {
                    // TODO The number and kinds of arguments are constrained.  This should probably
                    // be enforced within schema operator reflection (spec)

                    Action<IReadOnlyDictionary<string, PropertyTreeMetaObject>> func;
                    var children = NodeList.Create(SelectChildren(navigator));

                    switch (addon.OperatorType) {
                        case OperatorType.Add:
                            func = args => {
                                var child = target.BindAddChild(addon, args);

                                if (child.ShouldBindChildren) {
                                    parent.BindChildNodes(child, navigator, children);
                                }
                            };
                            break;

                        case OperatorType.Remove:
                            func = args => target.BindRemoveChild(addon, args);
                            break;

                        case OperatorType.Clear:
                        default:
                            func = args => target.BindClearChildren(addon, args);
                            break;
                    }

                    var services = parent.GetBasicServices(navigator);
                    var args2 = parent.ExtractParameterDictionary(op, target, services, children);
                    func(args2);
                }

                return target;
            }