private Tuple<IObjectSpecImmutable, string, string> FindContributee(IObjectSpecImmutable spec) {
     if (!IsContributedTo(spec)) {
         throw new Exception("Action is not contributed to " + spec.Type);
     }
     Tuple<IObjectSpecImmutable, string, string> tuple = objectContributees.First(t => spec.IsOfType(t.Item1));
     return tuple;
 }
        public bool IsContributedToLocalCollectionOf(IObjectSpecImmutable objectSpecImmutable, string id) {
            var memberOrderFacet = GetFacet<IMemberOrderFacet>();
            var directlyContributed = string.Equals(memberOrderFacet?.Name, id, StringComparison.CurrentCultureIgnoreCase);

            return directlyContributed || Parameters.Any(parm => {
                var facet = GetFacet<IContributedActionFacet>();
                return facet != null && facet.IsContributedToLocalCollectionOf(objectSpecImmutable, id);
            });
        }
        public ActionInvocationFacetViaMethod(MethodInfo method, ITypeSpecImmutable onType, IObjectSpecImmutable returnType, IObjectSpecImmutable elementType, ISpecification holder, bool isQueryOnly)
            : base(holder) {
            actionMethod = method;
            paramCount = method.GetParameters().Length;
            this.onType = onType;
            this.returnType = returnType;
            this.elementType = elementType;
            this.isQueryOnly = isQueryOnly;

            try {
                actionDelegate = DelegateUtils.CreateDelegate(actionMethod);
            }
            catch (Exception e) {
                Log.ErrorFormat("Failed to get Delegate for {0}:{1} reason {2}", onType, method, e.Message);
            }
        }
 private static void AddCollectionContributedAction(IReflector reflector, MethodInfo member, IObjectSpecImmutable type, ParameterInfo p, ContributedActionFacet facet, ContributedActionAttribute attribute) {
     if (!type.IsQueryable) {
         Log.WarnFormat("ContributedAction attribute added to a collection parameter type other than IQueryable: {0}", member.Name);
     }
     else {
         var returnType = reflector.LoadSpecification<IObjectSpecImmutable>(member.ReturnType);
         if (returnType.IsCollection) {
             Log.WarnFormat("ContributedAction attribute added to an action that returns a collection: {0}", member.Name);
         }
         else {
             Type elementType = p.ParameterType.GetGenericArguments()[0];
             type = reflector.LoadSpecification<IObjectSpecImmutable>(elementType);
             facet.AddCollectionContributee(type, attribute.SubMenu, attribute.Id);
         }
     }
 }
        public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder)
        {
            ParameterInfo parameter = method.GetParameters()[paramNum];
            var           facets    = new List <IFacet>();

            if (parameter.ParameterType.IsGenericType && (parameter.ParameterType.GetGenericTypeDefinition() == typeof(Nullable <>)))
            {
                facets.Add(new NullableFacetAlways(holder));
            }

            IObjectSpecBuilder returnSpec = reflector.LoadSpecification(parameter.ParameterType);

            if (returnSpec != null && returnSpec.IsCollection)
            {
                Type elementType = CollectionUtils.ElementType(parameter.ParameterType);
                IObjectSpecImmutable elementSpec = reflector.LoadSpecification(elementType);
                facets.Add(new ElementTypeFacet(holder, elementType, elementSpec));
            }

            FacetUtils.AddFacets(facets);
        }
 public IActionSpec GetAction(INakedObjectsFramework framework)
 {
     if (nakedObjectAction == null)
     {
         GetNakedObject(framework);
         IActionSpec[] actions;
         if (nakedObject.Spec.IsCollection)
         {
             var metamodel = framework.MetamodelManager.Metamodel;
             IObjectSpecImmutable elementSpecImmut = nakedObject.Spec.GetFacet <ITypeOfFacet>().GetValueSpec(nakedObject, metamodel);
             var elementSpec = framework.MetamodelManager.GetSpecification(elementSpecImmut) as IObjectSpec;
             Trace.Assert(elementSpec != null);
             actions = elementSpec.GetCollectionContributedActions();
         }
         else
         {
             actions = nakedObject.Spec.GetObjectActions();
         }
         nakedObjectAction = actions.Where(a => a.IsUsable(nakedObject).IsAllowed).Where(a => a.IsVisible(nakedObject)).SingleOrDefault(a => a.Id == ActionId);
     }
     return(nakedObjectAction);
 }
        public virtual void SetUp()
        {
            var cache = new ImmutableInMemorySpecCache();

            ReflectorConfiguration.NoValidate = true;
            var config = new ReflectorConfiguration(new[] { typeof(List <TestPoco>), typeof(ArrayList) }, new Type[] { }, new[] { typeof(TestPoco).Namespace });
            var functionalReflectorConfiguration = new FunctionalReflectorConfiguration(new Type[] { }, new Type[] { });

            var menuFactory   = new NullMenuFactory();
            var classStrategy = new DefaultClassStrategy(config);
            var mockLogger    = new Mock <ILogger <Metamodel> >().Object;

            var metamodel         = new Metamodel(classStrategy, cache, mockLogger);
            var mockLogger1       = new Mock <ILogger <ParallelReflector> >().Object;
            var mockLoggerFactory = new Mock <ILoggerFactory>().Object;

            var reflector = new ParallelReflector(classStrategy, metamodel, config, functionalReflectorConfiguration, menuFactory, new IFacetDecorator[] { }, facetFactories, mockLoggerFactory, mockLogger1);

            ITypeSpecBuilder spec;

            (spec, Metamodel) = LoadSpecification(reflector);
            Specification     = spec as IObjectSpecImmutable;
        }
Exemplo n.º 8
0
        public ITypedMenu <TObject> AddContributedActions()
        {
            IObjectSpecImmutable spec = GetObjectSpec <TObject>();

            foreach (IActionSpecImmutable ca in spec.ContributedActions)
            {
                var    facet       = ca.GetFacet <IContributedActionFacet>();
                string subMenuName = facet.SubMenuWhenContributedTo(spec);
                if (subMenuName != null)
                {
                    string   id      = facet.IdWhenContributedTo(spec);
                    MenuImpl subMenu = GetSubMenuIfExists(subMenuName) ?? CreateMenuImmutableAsSubMenu(subMenuName, id);
                    subMenu.AddOrderableElementsToMenu(new List <IActionSpecImmutable> {
                        ca
                    }, subMenu);
                }
                else
                {
                    //i.e. no sub-menu
                    AddMenuItem(new MenuAction(ca));
                }
            }
            return(this);
        }
Exemplo n.º 9
0
 public string IdWhenContributedTo(IObjectSpecImmutable spec)
 {
     return(FindContributee(spec).Item3);
 }
Exemplo n.º 10
0
 public bool IsContributedTo(IObjectSpecImmutable spec)
 {
     return(objectContributees.Select(t => t.Item1).Any(spec.IsOfType));
 }
Exemplo n.º 11
0
 public bool IsContributedToLocalCollectionOf(IObjectSpecImmutable spec, string id)
 {
     return(localCollectionContributees.Where(t => t.Item2 == id.ToLower()).Select(t => t.Item1).Any(spec.IsOfType));
 }
Exemplo n.º 12
0
 // The special constructor is used to deserialize values.
 public ActionSpecImmutable(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     ownerSpec  = info.GetValue <IObjectSpecImmutable>("specification");
     parameters = info.GetValue <IActionParameterSpecImmutable[]>("parameters");
 }
 public OneToOneAssociationSpecImmutable(IIdentifier identifier, IObjectSpecImmutable ownerSpec, IObjectSpecImmutable returnSpec)
     : base(identifier, returnSpec) {
     this.ownerSpec = ownerSpec;
 }
 // The special constructor is used to deserialize values. 
 public ActionParameterSpecImmutable(SerializationInfo info, StreamingContext context) : base(info, context) {
     specification = info.GetValue<IObjectSpecImmutable>("specification");
 }
 // The special constructor is used to deserialize values.
 protected AssociationSpecImmutable(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     returnSpec = info.GetValue <IObjectSpecImmutable>("returnSpec");
 }
Exemplo n.º 16
0
 public static bool IsCollectionOfBoundedSet(this IObjectSpecImmutable specification, IObjectSpecImmutable elementSpec)
 {
     return(specification.IsCollection && elementSpec.IsBoundedSet());
 }
Exemplo n.º 17
0
 public UIntValueSemanticsProvider(IObjectSpecImmutable spec, ISpecification holder)
     : base(Type, holder, AdaptedType, TypicalLengthConst, Immutable, EqualByContent, DefaultValueConst, spec)
 {
 }
Exemplo n.º 18
0
 public ObjectSpec(SpecFactory memberFactory, IMetamodelManager metamodelManager, INakedObjectManager nakedObjectManager, IObjectSpecImmutable innerSpec) :
     base(memberFactory, metamodelManager, nakedObjectManager, innerSpec) {}
 public OneToManyAssociationSpecImmutable(IIdentifier name, IObjectSpecImmutable ownerSpec, IObjectSpecImmutable returnSpec, IObjectSpecImmutable defaultElementSpec)
     : base(name, returnSpec) {
     defaultElementType = defaultElementSpec.Type;
     this.ownerSpec = ownerSpec;
     this.defaultElementSpec = defaultElementSpec;
 }
 public IObjectSpec GetSpecification(IObjectSpecImmutable spec) {
     return GetSpecification(spec as ITypeSpecImmutable) as IObjectSpec;
 }
Exemplo n.º 21
0
 private IObjectSpec CreateObjectSpec(IObjectSpecImmutable specImmutable) {
     Assert.AssertNotNull(framework);
     return new ObjectSpec(this, framework.MetamodelManager, framework.NakedObjectManager, specImmutable);
 }
 private bool IsContributedTo(IObjectSpecImmutable parmSpec, IObjectSpecImmutable contributeeSpec) {
     var facet = GetFacet<IContributedActionFacet>();
     return facet != null && (contributeeSpec.IsOfType(parmSpec) && facet.IsContributedTo(contributeeSpec));
 }
Exemplo n.º 23
0
 public void AddLocalCollectionContributee(IObjectSpecImmutable type, string id)
 {
     localCollectionContributees.Add(new Tuple <IObjectSpecImmutable, string>(type, id.ToLower()));
 }
 public bool IsContributedToCollectionOf(IObjectSpecImmutable objectSpecImmutable) {
     return Parameters.Any(parm => {
         var facet = GetFacet<IContributedActionFacet>();
         return facet != null && facet.IsContributedToCollectionOf(objectSpecImmutable);
     });
 }
 // The special constructor is used to deserialize values. 
 public OneToManyAssociationSpecImmutable(SerializationInfo info, StreamingContext context) : base(info, context) {
     defaultElementType = info.GetValue<Type>("defaultElementType");
     defaultElementSpec = info.GetValue<IObjectSpecImmutable>("defaultElementSpec");
 }
 public ActionParameterSpecImmutable(IObjectSpecImmutable specification, IIdentifier identifier) {
     this.specification = specification;
     this.identifier = identifier;
 }
Exemplo n.º 27
0
 public OneToOneAssociationSpecImmutable(IIdentifier identifier, IObjectSpecImmutable ownerSpec, IObjectSpecImmutable returnSpec)
     : base(identifier, returnSpec)
 {
     this.ownerSpec = ownerSpec;
 }
 public bool IsContributedTo(IObjectSpecImmutable spec) {
     return objectContributees.Select(t => t.Item1).Any(spec.IsOfType);
 }
 public bool IsContributedTo(IObjectSpecImmutable objectSpecImmutable) {
     return Parameters.Any(parm => IsContributedTo(parm.Specification, objectSpecImmutable));
 }
 public bool IsContributedToCollectionOf(IObjectSpecImmutable spec) {
     return collectionContributees.Select(t => t.Item1).Any(spec.IsOfType);
 }
 protected AssociationSpecImmutable(IIdentifier identifier, IObjectSpecImmutable returnSpec)
     : base(identifier)
 {
     this.returnSpec = returnSpec;
 }
 public string SubMenuWhenContributedTo(IObjectSpecImmutable spec) {
     return FindContributee(spec).Item2;
 }
Exemplo n.º 33
0
        private IEnumerable <IAssociationSpecImmutable> CreateCollectionSpecs(IEnumerable <PropertyInfo> collectionProperties, IObjectSpecImmutable spec)
        {
            var specs = new List <IAssociationSpecImmutable>();

            foreach (PropertyInfo property in collectionProperties)
            {
                IIdentifier identifier = new IdentifierImpl(FullName, property.Name);

                // create a collection property spec
                Type returnType  = property.PropertyType;
                var  returnSpec  = reflector.LoadSpecification <IObjectSpecImmutable>(returnType);
                Type defaultType = typeof(object);
                var  defaultSpec = reflector.LoadSpecification <IObjectSpecImmutable>(defaultType);

                var collection = ImmutableSpecFactory.CreateOneToManyAssociationSpecImmutable(identifier, spec, returnSpec, defaultSpec);

                FacetFactorySet.Process(reflector, property, new IntrospectorMethodRemover(methods), collection, FeatureType.Collections);
                specs.Add(collection);
            }
            return(specs);
        }
 public string IdWhenContributedTo(IObjectSpecImmutable spec) {
     return FindContributee(spec).Item3;
 }
Exemplo n.º 35
0
 public bool IsContributedTo(IObjectSpecImmutable objectSpecImmutable)
 {
     return(Parameters.Any(parm => IsContributedTo(parm.Specification, objectSpecImmutable)));
 }
 //Here the type is the ElementType of the collection, not the type of collection.
 public void AddCollectionContributee(IObjectSpecImmutable type, string subMenu, string id) {
     collectionContributees.Add(new Tuple<IObjectSpecImmutable, string, string>(type, subMenu, id));
 }
Exemplo n.º 37
0
 public virtual void Cache(string key, IObjectSpecImmutable spec)
 {
     specs = specs.Add(key, spec);
 }
 public static IActionParameterSpecImmutable CreateActionParameterSpecImmutable(IObjectSpecImmutable spec, IIdentifier identifier) {
     return new ActionParameterSpecImmutable(spec, identifier);
 }
Exemplo n.º 39
0
 public bool IsContributedToCollectionOf(IObjectSpecImmutable spec)
 {
     return(collectionContributees.Select(t => t.Item1).Any(spec.IsOfType));
 }
 public static IOneToManyAssociationSpecImmutable CreateOneToManyAssociationSpecImmutable(IIdentifier identifier, IObjectSpecImmutable ownerSpec, IObjectSpecImmutable returnSpec, IObjectSpecImmutable defaultElementSpec) {
     return new OneToManyAssociationSpecImmutable(identifier, ownerSpec, returnSpec, defaultElementSpec);
 }
Exemplo n.º 41
0
 public string SubMenuWhenContributedTo(IObjectSpecImmutable spec)
 {
     return(FindContributee(spec).Item2);
 }
 public static IOneToOneAssociationSpecImmutable CreateOneToOneAssociationSpecImmutable(IIdentifier identifier, IObjectSpecImmutable ownerSpec, IObjectSpecImmutable returnSpec) {
     return new OneToOneAssociationSpecImmutable(identifier, ownerSpec, returnSpec);
 }
Exemplo n.º 43
0
 //Here the type is the ElementType of the collection, not the type of collection.
 public void AddCollectionContributee(IObjectSpecImmutable type, string subMenu, string id)
 {
     collectionContributees.Add(new Tuple <IObjectSpecImmutable, string, string>(type, subMenu, id));
 }
 public TypeOfFacetDefaultToType(ISpecification holder, Type type, IObjectSpecImmutable spec)
     : base(Type, holder) {
     this.type = type;
     this.spec = spec;
 }
 private IObjectSpec CreateObjectSpec(IObjectSpecImmutable specImmutable)
 {
     Assert.AssertNotNull(framework);
     return(new ObjectSpec(this, framework.MetamodelManager, framework.NakedObjectManager, specImmutable));
 }
 public ElementTypeFacet(ISpecification holder, Type type, IObjectSpecImmutable spec) : base(Type, holder) {
     this.type = type;
     this.spec = spec;
 }
Exemplo n.º 47
0
 public static bool IsBoundedSet(this IObjectSpecImmutable specification)
 {
     return(specification.ContainsFacet <IBoundedFacet>() || specification.ContainsFacet <IEnumValueFacet>());
 }
Exemplo n.º 48
0
 public ObjectSpec(SpecFactory memberFactory, IMetamodelManager metamodelManager, INakedObjectManager nakedObjectManager, IObjectSpecImmutable innerSpec) :
     base(memberFactory, metamodelManager, nakedObjectManager, innerSpec)
 {
 }
Exemplo n.º 49
0
 public static bool IsCollectionOfEnum(this IObjectSpecImmutable specification, IObjectSpecImmutable elementSpec)
 {
     return(specification.IsCollection && elementSpec.ContainsFacet <IEnumFacet>());
 }
Exemplo n.º 50
0
        private Tuple <IAssociationSpecImmutable[], IImmutableDictionary <string, ITypeSpecBuilder> > FindAndCreateFieldSpecs(IObjectSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel)
        {
            // now create fieldSpecs for value properties, for collections and for reference properties
            IList <PropertyInfo> collectionProperties = FacetFactorySet.FindCollectionProperties(properties, ClassStrategy).Where(pi => !FacetFactorySet.Filters(pi, ClassStrategy)).ToArray();
            var result1 = CreateCollectionSpecs(collectionProperties, spec, metamodel);

            IEnumerable <IAssociationSpecImmutable> collectionSpecs = result1.Item1;

            metamodel = result1.Item2;

            // every other accessor is assumed to be a reference property.
            IList <PropertyInfo>       allProperties = FacetFactorySet.FindProperties(properties, ClassStrategy).Where(pi => !FacetFactorySet.Filters(pi, ClassStrategy)).ToArray();
            IEnumerable <PropertyInfo> refProperties = allProperties.Except(collectionProperties);

            var result   = CreateRefPropertySpecs(refProperties, spec, metamodel);
            var refSpecs = result.Item1;

            metamodel = result.Item2;

            return(new Tuple <IAssociationSpecImmutable[], IImmutableDictionary <string, ITypeSpecBuilder> >(collectionSpecs.Union(refSpecs).ToArray(), metamodel));
        }
 public ITypeSpec GetSpecification(IObjectSpecImmutable spec)
 {
     return(spec == null ? null : NewObjectSpec(spec));
 }
Exemplo n.º 52
0
        /// <summary>
        ///     Creates a list of Association fields for all the properties that use NakedObjects.
        /// </summary>


        private Tuple <IEnumerable <IAssociationSpecImmutable>, IImmutableDictionary <string, ITypeSpecBuilder> > CreateRefPropertySpecs(IEnumerable <PropertyInfo> foundProperties, IObjectSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel)
        {
            var specs = new List <IAssociationSpecImmutable>();

            foreach (PropertyInfo property in foundProperties)
            {
                // create a reference property spec
                var  identifier   = new IdentifierImpl(FullName, property.Name);
                Type propertyType = property.PropertyType;
                var  result       = reflector.LoadSpecification(propertyType, metamodel);
                metamodel = result.Item2;
                var propertySpec = result.Item1;
                if (propertySpec is IServiceSpecImmutable)
                {
                    throw new ReflectionException(Log.LogAndReturn($"Type {propertyType.Name} is a service and cannot be used in public property {property.Name} on type {property.DeclaringType?.Name}. If the property is intended to be an injected service it should have a protected get."));
                }
                var referenceProperty = ImmutableSpecFactory.CreateOneToOneAssociationSpecImmutable(identifier, spec, propertySpec as IObjectSpecImmutable);

                // Process facets for the property
                metamodel = FacetFactorySet.Process(reflector, property, new IntrospectorMethodRemover(methods), referenceProperty, FeatureType.Properties, metamodel);
                specs.Add(referenceProperty);
            }

            return(new Tuple <IEnumerable <IAssociationSpecImmutable>, IImmutableDictionary <string, ITypeSpecBuilder> >(specs, metamodel));
        }
 protected AssociationSpecImmutable(IIdentifier identifier, IObjectSpecImmutable returnSpec)
     : base(identifier) {
     this.returnSpec = returnSpec;
 }
 public bool IsFinderMethodFor(IObjectSpecImmutable spec) {
     return IsFinderMethod && (ReturnSpec.IsOfType(spec) || (ReturnSpec.IsCollection && ElementSpec.IsOfType(spec)));
 }
Exemplo n.º 55
0
 public ElementTypeFacet(ISpecification holder, Type type, IObjectSpecImmutable spec) : base(Type, holder)
 {
     this.type = type;
     this.spec = spec;
 }
 // The special constructor is used to deserialize values. 
 protected AssociationSpecImmutable(SerializationInfo info, StreamingContext context) : base(info, context) {
     returnSpec = info.GetValue<IObjectSpecImmutable>("returnSpec");
 }
Exemplo n.º 57
0
        private Tuple <IEnumerable <IAssociationSpecImmutable>, IImmutableDictionary <string, ITypeSpecBuilder> > CreateCollectionSpecs(IEnumerable <PropertyInfo> collectionProperties, IObjectSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel)
        {
            var specs = new List <IAssociationSpecImmutable>();

            foreach (PropertyInfo property in collectionProperties)
            {
                IIdentifier identifier = new IdentifierImpl(FullName, property.Name);

                // create a collection property spec
                Type returnType  = property.PropertyType;
                Type defaultType = typeof(object);
                var  result      = reflector.LoadSpecification(returnType, metamodel);

                metamodel = result.Item2;
                var returnSpec = result.Item1 as IObjectSpecImmutable;
                result    = reflector.LoadSpecification(defaultType, metamodel);
                metamodel = result.Item2;
                var defaultSpec = result.Item1 as IObjectSpecImmutable;

                var collection = ImmutableSpecFactory.CreateOneToManyAssociationSpecImmutable(identifier, spec, returnSpec, defaultSpec);

                metamodel = FacetFactorySet.Process(reflector, property, new IntrospectorMethodRemover(methods), collection, FeatureType.Collections, metamodel);
                specs.Add(collection);
            }
            return(new Tuple <IEnumerable <IAssociationSpecImmutable>, IImmutableDictionary <string, ITypeSpecBuilder> >(specs, metamodel));
        }
Exemplo n.º 58
0
 public static bool IsCollectionOfBoundedSet(this IObjectSpecImmutable specification, IObjectSpecImmutable elementSpec) {
     return specification.IsCollection && elementSpec.IsBoundedSet();
 }
Exemplo n.º 59
0
 public TypeOfFacetDefaultToType(ISpecification holder, Type type, IObjectSpecImmutable spec)
     : base(Type, holder)
 {
     this.type = type;
     this.spec = spec;
 }
Exemplo n.º 60
0
 public static bool IsCollectionOfEnum(this IObjectSpecImmutable specification, IObjectSpecImmutable elementSpec) {
     return specification.IsCollection && elementSpec.ContainsFacet<IEnumFacet>();
 }