public ActionSpecImmutable(IIdentifier identifier, ITypeSpecImmutable ownerSpec,
                            IActionParameterSpecImmutable[] parameters)
     : base(identifier)
 {
     this.ownerSpec  = ownerSpec;
     this.parameters = parameters;
 }
示例#2
0
        public void IntrospectPropertiesAndCollections(ITypeSpecImmutable spec)
        {
            Log.InfoFormat("introspecting {0}: properties and collections", ClassName);
            var objectSpec = spec as IObjectSpecImmutable;

            orderedFields = objectSpec != null?CreateSortedListOfMembers(FindAndCreateFieldSpecs(objectSpec)) : new List <IAssociationSpecImmutable>();
        }
        public void IntrospectActions(ITypeSpecImmutable spec)
        {
            // find the actions ...
            var findObjectActionMethods = FindActionMethods(spec);

            orderedObjectActions = CreateSortedListOfMembers(findObjectActionMethods);
        }
        private ITypeSpec NewObjectSpec(ITypeSpecImmutable spec) {
            if (!localCache.ContainsKey(spec)) {
                localCache[spec] = specFactory.CreateTypeSpec(spec);
            }

            return localCache[spec];
        }
示例#5
0
 public IImmutableDictionary <string, ITypeSpecBuilder> IntrospectActions(ITypeSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel)
 {
     // find the actions ...
     IActionSpecImmutable[] findObjectActionMethods;
     (findObjectActionMethods, metamodel) = FindActionMethods(spec, metamodel);
     orderedObjectActions = CreateSortedListOfMembers(findObjectActionMethods);
     return(metamodel);
 }
示例#6
0
        public void IntrospectActions(ITypeSpecImmutable spec)
        {
            Log.InfoFormat("introspecting {0}: actions", ClassName);

            // find the actions ...
            IActionSpecImmutable[] findObjectActionMethods = FindActionMethods(spec);
            orderedObjectActions = CreateSortedListOfMembers(findObjectActionMethods);
        }
示例#7
0
 private void AddAsSubclass(ITypeSpecImmutable spec)
 {
     if (Superclass != null)
     {
         Log.DebugFormat("Superclass {0}", Superclass.FullName);
         Superclass.AddSubclass(spec);
     }
 }
 private string UniqueShortName(ITypeSpecImmutable spec) {
     string usn = spec.ShortName;
     Type type = spec.Type;
     if (type.IsGenericType) {
         usn += "-" + type.GetGenericArguments().First().Name;
     }
     return usn;
 }
示例#9
0
 protected static string GetMenuName(ITypeSpecImmutable spec)
 {
     if (spec is IServiceSpecImmutable)
     {
         return(spec.GetFacet <INamedFacet>().NaturalName);
     }
     return(Model.ActionsMenuName);
 }
示例#10
0
        private ITypeSpec NewObjectSpec(ITypeSpecImmutable spec)
        {
            if (!localCache.ContainsKey(spec))
            {
                localCache[spec] = specFactory.CreateTypeSpec(spec);
            }

            return(localCache[spec]);
        }
示例#11
0
        public ImmutableDictionary <string, ITypeSpecBuilder> IntrospectActions(ITypeSpecImmutable spec, ImmutableDictionary <string, ITypeSpecBuilder> metamodel)
        {
            // find the actions ...
            var result = FindActionMethods(spec, metamodel);

            IActionSpecImmutable[] findObjectActionMethods = result.Item1;
            metamodel            = result.Item2;
            orderedObjectActions = CreateSortedListOfMembers(findObjectActionMethods);
            return(metamodel);
        }
示例#12
0
        private string UniqueShortName(ITypeSpecImmutable spec)
        {
            string usn  = spec.ShortName;
            Type   type = spec.Type;

            if (type.IsGenericType)
            {
                usn += "-" + type.GetGenericArguments().First().Name;
            }
            return(usn);
        }
 public ActionInvocationFacetViaMethod(MethodInfo method, ITypeSpecImmutable onType, IObjectSpecImmutable returnType, IObjectSpecImmutable elementType, ISpecification holder, bool isQueryOnly, ILogger <ActionInvocationFacetViaMethod> logger)
     : base(holder)
 {
     this.logger    = logger;
     ActionMethod   = method;
     paramCount     = method.GetParameters().Length;
     OnType         = onType;
     ReturnType     = returnType;
     ElementType    = elementType;
     IsQueryOnly    = isQueryOnly;
     ActionDelegate = LogNull(DelegateUtils.CreateDelegate(ActionMethod), logger);
 }
示例#14
0
        protected TypeSpec(SpecFactory memberFactory, IMetamodelManager metamodelManager, INakedObjectManager nakedObjectManager, ITypeSpecImmutable innerSpec)
        {
            Assert.AssertNotNull(memberFactory);
            Assert.AssertNotNull(metamodelManager);
            Assert.AssertNotNull(nakedObjectManager);
            Assert.AssertNotNull(innerSpec);

            this.memberFactory      = memberFactory;
            this.metamodelManager   = metamodelManager;
            this.nakedObjectManager = nakedObjectManager;
            this.innerSpec          = innerSpec;
        }
示例#15
0
        private string UniqueShortName(ITypeSpecImmutable spec)
        {
            var usn  = spec.ShortName;
            var type = spec.Type;

            if (type.IsGenericType)
            {
                usn += $"-{type.GetGenericArguments().First().Name}";
            }

            return(usn);
        }
示例#16
0
        public ITypeSpec CreateTypeSpec(ITypeSpecImmutable specImmutable) {
            var osi = specImmutable as IObjectSpecImmutable;
            if (osi != null) {
                return CreateObjectSpec(osi);
            }

            var ssi = specImmutable as IServiceSpecImmutable;
            if (ssi != null) {
                return CreateServiceSpec(ssi);
            }

            throw new InitialisationException(string.Format("Unexpected Spec Type {0}", specImmutable.Type));
        }
示例#17
0
        public ITypeSpec CreateTypeSpec(ITypeSpecImmutable specImmutable) {
            var osi = specImmutable as IObjectSpecImmutable;
            if (osi != null) {
                return CreateObjectSpec(osi);
            }

            var ssi = specImmutable as IServiceSpecImmutable;
            if (ssi != null) {
                return CreateServiceSpec(ssi);
            }

            throw new InitialisationException(Log.LogAndReturn($"Unexpected Spec Type {specImmutable.Type}"));
        }
        public ITestAction CreateTestActionOnService(IActionSpecImmutable actionSpecImm)
        {
            ITypeSpecImmutable objectIm = actionSpecImm.OwnerSpec; //This is the spec for the service

            if (!(objectIm is IServiceSpecImmutable))
            {
                throw new Exception("Action is not on a known service");
            }
            var serviceSpec                 = (IServiceSpec)metamodelManager.GetSpecification(objectIm);
            INakedObjectAdapter service     = servicesManager.GetService(serviceSpec);
            ITestService        testService = CreateTestService(service);

            return(CreateTestAction(actionSpecImm, testService));
        }
        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);
            }
        }
示例#20
0
        public static void Compare(ITypeSpecImmutable spec1, ITypeSpecImmutable spec2, string name = "")
        {
            if (spec1 == null && spec2 == null)
            {
                return;
            }

            if (spec1 == null)
            {
                Assert.Fail("Missing spec1 " + name + " : " + spec2.FullName);
            }

            if (spec2 == null)
            {
                Assert.Fail("Missing spec2 " + name + " : " + spec1.FullName);
            }

            var specName = name + " : " + spec1.FullName;

            // make sure same spec
            Compare(spec1.FullName, spec2.FullName, specName);
            Compare(spec1.GetType(), spec2.GetType(), specName);
            Compare(spec1.Type, spec2.Type, specName);
            Compare(spec1.Identifier, spec2.Identifier, specName);

            // only carry on to compare facets if first time
            if (HasBeenCompared(spec1, spec2))
            {
                return;
            }

            Compare(spec1.ShortName, spec2.ShortName, specName);
            Compare(spec1.ObjectMenu, spec2.ObjectMenu);
            Compare(spec1.ObjectActions, spec2.ObjectActions, true);
            Compare(spec1.ContributedActions, spec2.ContributedActions, true);
            Compare(spec1.CollectionContributedActions, spec2.CollectionContributedActions, true);
            Compare(spec1.FinderActions, spec2.FinderActions);
            Compare(spec1.Fields, spec2.Fields, specName);
            Compare(spec1.Interfaces, spec2.Interfaces);
            Compare(spec1.Subclasses, spec2.Subclasses); // todo possible bug here with populating subclasses
            Compare(spec1.Superclass, spec2.Superclass);
            Compare(spec1.IsObject, spec2.IsObject, specName);
            Compare(spec1.IsCollection, spec2.IsCollection, specName);
            Compare(spec1.IsQueryable, spec2.IsQueryable, specName);
            Compare(spec1.IsParseable, spec2.IsParseable, specName);
            Compare(spec1 as ISpecification, spec2, specName);
        }
示例#21
0
        private IActionSpecImmutable[] FindActionMethods(ITypeSpecImmutable spec)
        {
            Log.Debug("Looking for action methods");

            var actionSpecs = new List <IActionSpecImmutable>();
            var actions     = FacetFactorySet.FindActions(methods.Where(m => m != null).ToArray(), reflector.ClassStrategy).Where(a => !FacetFactorySet.Filters(a, reflector.ClassStrategy)).ToArray();

            methods = methods.Except(actions).ToArray();

            // ReSharper disable once ForCanBeConvertedToForeach
            // kepp for look as actions are nulled out within loop
            for (int i = 0; i < actions.Length; i++)
            {
                MethodInfo actionMethod = actions[i];

                // actions are potentially being nulled within this loop
                if (actionMethod != null)
                {
                    string fullMethodName = actionMethod.Name;

                    Type[] parameterTypes = actionMethod.GetParameters().Select(parameterInfo => parameterInfo.ParameterType).ToArray();

                    // build action & its parameters

                    if (actionMethod.ReturnType != typeof(void))
                    {
                        reflector.LoadSpecification(actionMethod.ReturnType);
                    }

                    IIdentifier identifier = new IdentifierImpl(FullName, fullMethodName, actionMethod.GetParameters().ToArray());
                    IActionParameterSpecImmutable[] actionParams = parameterTypes.Select(pt => ImmutableSpecFactory.CreateActionParameterSpecImmutable(reflector.LoadSpecification <IObjectSpecImmutable>(pt), identifier)).ToArray();

                    var action = ImmutableSpecFactory.CreateActionSpecImmutable(identifier, spec, actionParams);

                    // Process facets on the action & parameters
                    FacetFactorySet.Process(reflector, actionMethod, new IntrospectorMethodRemover(actions), action, FeatureType.Actions);
                    for (int l = 0; l < actionParams.Length; l++)
                    {
                        FacetFactorySet.ProcessParams(reflector, actionMethod, l, actionParams[l]);
                    }

                    actionSpecs.Add(action);
                }
            }

            return(actionSpecs.ToArray());
        }
        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.WarnFormat("Failed to get Delegate for {0}:{1} reason {2}", onType, method, e.Message);
            }
        }
 public ActionInvocationFacetViaStaticMethod(MethodInfo method,
                                             ITypeSpecImmutable onType,
                                             IObjectSpecImmutable returnType,
                                             IObjectSpecImmutable elementType,
                                             ISpecification holder,
                                             bool isQueryOnly,
                                             ILogger <ActionInvocationFacetViaStaticMethod> logger)
     : base(holder)
 {
     ActionMethod = method;
     this.logger  = logger;
     paramCount   = method.GetParameters().Length;
     OnType       = onType;
     ReturnType   = returnType;
     ElementType  = elementType;
     IsQueryOnly  = isQueryOnly;
 }
        public ITypeSpec CreateTypeSpec(ITypeSpecImmutable specImmutable)
        {
            var osi = specImmutable as IObjectSpecImmutable;

            if (osi != null)
            {
                return(CreateObjectSpec(osi));
            }

            var ssi = specImmutable as IServiceSpecImmutable;

            if (ssi != null)
            {
                return(CreateServiceSpec(ssi));
            }

            throw new InitialisationException(string.Format("Unexpected Spec Type {0}", specImmutable.Type));
        }
        public ITypeSpec CreateTypeSpec(ITypeSpecImmutable specImmutable)
        {
            var osi = specImmutable as IObjectSpecImmutable;

            if (osi != null)
            {
                return(CreateObjectSpec(osi));
            }

            var ssi = specImmutable as IServiceSpecImmutable;

            if (ssi != null)
            {
                return(CreateServiceSpec(ssi));
            }

            throw new InitialisationException(Log.LogAndReturn($"Unexpected Spec Type {specImmutable.Type}"));
        }
        public void IntrospectType(Type typeToIntrospect, ITypeSpecImmutable spec)
        {
            if (!TypeUtils.IsPublic(typeToIntrospect))
            {
                throw new ReflectionException(logger.LogAndReturn(string.Format(Resources.NakedObjects.DomainClassReflectionError, typeToIntrospect)));
            }

            IntrospectedType  = typeToIntrospect;
            SpecificationType = GetSpecificationType(typeToIntrospect);

            properties = typeToIntrospect.GetProperties();
            methods    = GetNonPropertyMethods();
            Identifier = new IdentifierImpl(FullName);

            // Process facets at object level
            // this will also remove some methods, such as the superclass methods.
            var methodRemover = new IntrospectorMethodRemover(methods);

            FacetFactorySet.Process(reflector, IntrospectedType, methodRemover, spec);

            if (SuperclassType != null && ClassStrategy.IsTypeToBeIntrospected(SuperclassType))
            {
                Superclass = reflector.LoadSpecification(SuperclassType);
            }

            AddAsSubclass(spec);

            var interfaces = new List <ITypeSpecBuilder>();

            foreach (var interfaceType in InterfacesTypes)
            {
                if (interfaceType != null && ClassStrategy.IsTypeToBeIntrospected(interfaceType))
                {
                    var interfaceSpec = reflector.LoadSpecification(interfaceType);
                    interfaceSpec.AddSubclass(spec);
                    interfaces.Add(interfaceSpec);
                }
            }

            Interfaces = interfaces.ToArray();
            IntrospectPropertiesAndCollections(spec);
            IntrospectActions(spec);
        }
        public bool IsOfType(ITypeSpecImmutable otherSpecification)
        {
            if (otherSpecification == this)
            {
                return(true);
            }

            Type otherType = otherSpecification.Type;

            if (otherType.IsAssignableFrom(Type))
            {
                return(true);
            }

            // match  generic types
            if (Type.IsGenericType && IsCollection && otherType.IsGenericType && otherSpecification.IsCollection)
            {
                var thisGenericType  = Type.GetGenericTypeDefinition();
                var otherGenericType = Type.GetGenericTypeDefinition();
                return(thisGenericType == otherGenericType || IsAssignableToGenericType(otherType, thisGenericType));
            }

            return(false);
        }
示例#28
0
 private void AddAsSubclass(ITypeSpecImmutable spec)
 {
     Superclass?.AddSubclass(spec);
 }
示例#29
0
 public void IntrospectType(Type typeToIntrospect, ITypeSpecImmutable specification)
 {
     throw new NotImplementedException();
 }
 public ActionSpecImmutable(IIdentifier identifier, ITypeSpecImmutable ownerSpec,
                            IActionParameterSpecImmutable[] parameters)
     : base(identifier) {
     this.ownerSpec = ownerSpec;
     this.parameters = parameters;
 }
示例#31
0
 protected override IImmutableDictionary <string, ITypeSpecBuilder> ProcessType(ITypeSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) =>
 ((SystemTypeFacetFactorySet)FacetFactorySet).Process(Reflector, IntrospectedType, new IntrospectorMethodRemover(Methods), spec, metamodel);
 public void Cache(string key, ITypeSpecImmutable spec)
 {
     specs = specs.Add(key, spec);
 }
示例#33
0
 public static bool IsCollectionOfBoundedSet(this ITypeSpecImmutable spec, IObjectSpecImmutable elementSpec)
 {
     return(spec.IsCollection && elementSpec.IsBoundedSet());
 }
 // 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 bool IsOfType(ITypeSpecImmutable otherSpecification) {
            if (otherSpecification == this) {
                return true;
            }

            Type otherType = otherSpecification.Type;

            if (otherType.IsAssignableFrom(Type)) {
                return true;
            }

            // match  generic types 
            if (Type.IsGenericType && IsCollection  && otherType.IsGenericType && otherSpecification.IsCollection) {
                var thisGenericType = Type.GetGenericTypeDefinition();
                var otherGenericType = Type.GetGenericTypeDefinition();
                return thisGenericType == otherGenericType || IsAssignableToGenericType(otherType, thisGenericType);
            }

            return false;
        }
 public void AddSubclass(ITypeSpecImmutable subclass) {
     subclasses = subclasses.Add(subclass);
 }
 public ITypeSpec GetSpecification(ITypeSpecImmutable spec) {
     return spec == null ? null : NewObjectSpec(spec);
 }
示例#38
0
        public IImmutableDictionary <string, ITypeSpecBuilder> IntrospectPropertiesAndCollections(ITypeSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel)
        {
            var objectSpec = spec as IObjectSpecImmutable;

            if (objectSpec != null)
            {
                var result = FindAndCreateFieldSpecs(objectSpec, metamodel);
                metamodel     = result.Item2;
                orderedFields = CreateSortedListOfMembers(result.Item1);
            }
            else
            {
                orderedFields = new List <IAssociationSpecImmutable>();
            }

            return(metamodel);
        }
示例#39
0
        private Tuple <IActionSpecImmutable[], IImmutableDictionary <string, ITypeSpecBuilder> > FindActionMethods(ITypeSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel)
        {
            var actionSpecs = new List <IActionSpecImmutable>();
            var actions     = FacetFactorySet.FindActions(methods.Where(m => m != null).ToArray(), reflector.ClassStrategy).Where(a => !FacetFactorySet.Filters(a, reflector.ClassStrategy)).ToArray();

            methods = methods.Except(actions).ToArray();

            // ReSharper disable once ForCanBeConvertedToForeach
            // kepp for look as actions are nulled out within loop
            for (int i = 0; i < actions.Length; i++)
            {
                MethodInfo actionMethod = actions[i];

                // actions are potentially being nulled within this loop
                if (actionMethod != null)
                {
                    string fullMethodName = actionMethod.Name;

                    Type[] parameterTypes = actionMethod.GetParameters().Select(parameterInfo => parameterInfo.ParameterType).ToArray();

                    // build action & its parameters

                    if (actionMethod.ReturnType != typeof(void))
                    {
                        metamodel = reflector.LoadSpecification(actionMethod.ReturnType, metamodel).Item2;
                    }

                    IIdentifier identifier = new IdentifierImpl(FullName, fullMethodName, actionMethod.GetParameters().ToArray());
                    //IActionParameterSpecImmutable[] actionParams = parameterTypes.
                    //    Select(pt => ImmutableSpecFactory.CreateActionParameterSpecImmutable(reflector.LoadSpecification<IObjectSpecImmutable>(pt, metamodel), identifier)).ToArray();

                    var actionParams = new List <IActionParameterSpecImmutable>();

                    foreach (var pt in parameterTypes)
                    {
                        var result = reflector.LoadSpecification(pt, metamodel);
                        metamodel = result.Item2;
                        var ospec      = result.Item1 as IObjectSpecImmutable;
                        var actionSpec = ImmutableSpecFactory.CreateActionParameterSpecImmutable(ospec, identifier);
                        actionParams.Add(actionSpec);
                    }

                    var action = ImmutableSpecFactory.CreateActionSpecImmutable(identifier, spec, actionParams.ToArray());

                    // Process facets on the action & parameters
                    metamodel = FacetFactorySet.Process(reflector, actionMethod, new IntrospectorMethodRemover(actions), action, FeatureType.Actions, metamodel);
                    for (int l = 0; l < actionParams.Count; l++)
                    {
                        metamodel = FacetFactorySet.ProcessParams(reflector, actionMethod, l, actionParams[l], metamodel);
                    }

                    actionSpecs.Add(action);
                }
            }

            return(new Tuple <IActionSpecImmutable[], IImmutableDictionary <string, ITypeSpecBuilder> >(actionSpecs.ToArray(), metamodel));
        }
 public static IActionSpecImmutable CreateActionSpecImmutable(IIdentifier identifier, ITypeSpecImmutable ownerSpec, IActionParameterSpecImmutable[] parameters) {
     return new ActionSpecImmutable(identifier, ownerSpec, parameters);
 }
 public void AddSubclass(ITypeSpecImmutable subclass)
 {
     subclasses = subclasses.Add(subclass);
 }
 protected static string GetMenuName(ITypeSpecImmutable spec) {
     if (spec is IServiceSpecImmutable) {
         return spec.GetFacet<INamedFacet>().NaturalName;
     }
     return Model.ActionsMenuName;
 }