private void CheckAutoCompleteFacetIsNull(MethodInfo autoCompleteMethod, IActionParameterSpecImmutable parameter)
        {
            var facet = parameter.GetFacet(typeof(IAutoCompleteFacet));

            Assert.IsNull(facet);

            AssertMethodNotRemoved(autoCompleteMethod);
        }
        private void CheckChoicesFacet(MethodInfo choicesMethod, IActionParameterSpecImmutable parameter)
        {
            var facet = parameter.GetFacet(typeof(IActionChoicesFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is ActionChoicesFacetViaMethod);
            Assert.AreEqual(choicesMethod, ((ActionChoicesFacetViaMethod)facet).GetMethod());

            AssertMethodRemoved(choicesMethod);
        }
        private void CheckValidatePrameterFacet(MethodInfo method, IActionParameterSpecImmutable parameter)
        {
            var facet = parameter.GetFacet(typeof(IActionParameterValidationFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is ActionParameterValidation);
            Assert.AreEqual(method, ((ActionParameterValidation)facet).GetMethod());

            AssertMethodRemoved(method);
        }
        public IActionParameterSpec CreateParameter(IActionParameterSpecImmutable parameterSpecImmutable, IActionSpec actionSpec, int index)
        {
            CheckInitialised();
            var specification = parameterSpecImmutable.Specification;

            return(specification switch {
                _ when specification.IsParseable => new ActionParseableParameterSpec(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor),
                _ when specification.IsObject => new OneToOneActionParameter(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor),
                _ when specification.IsCollection => new OneToManyActionParameter(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor),
                _ => throw new UnknownTypeException(logger.LogAndReturn($"{specification}"))
            });
        private void CheckDefaultFacet(MethodInfo defaultMethod, IActionParameterSpecImmutable parameter)
        {
            var facet = parameter.GetFacet(typeof(IActionDefaultsFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is ActionDefaultsFacetViaMethod);
            Assert.AreEqual(defaultMethod, ((ActionDefaultsFacetViaMethod)facet).GetMethod());
            Assert.IsNotNull(((ActionDefaultsFacetViaMethod)facet).MethodDelegate);

            AssertMethodRemoved(defaultMethod);
        }
Пример #6
0
        public IActionParameterSpec CreateParameter(IActionParameterSpecImmutable parameterSpecImmutable, IActionSpec actionSpec, int index) {
            Assert.AssertNotNull(framework);
            IObjectSpecImmutable specification = parameterSpecImmutable.Specification;

            if (specification.IsParseable) {
                return new ActionParseableParameterSpec(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor);
            }
            if (specification.IsObject) {
                return new OneToOneActionParameter(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor);
            }
            if (specification.IsCollection) {
                return new OneToManyActionParameter(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor);
            }
            throw new UnknownTypeException(Log.LogAndReturn($"{specification}"));
        }
        private void CheckAutoCompleteFacet(MethodInfo autoCompleteMethod, IActionParameterSpecImmutable parameter, int pageSize, int minLength)
        {
            var facet = parameter.GetFacet(typeof(IAutoCompleteFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is AutoCompleteFacet);
            var acf = (AutoCompleteFacet)facet;

            Assert.AreEqual(autoCompleteMethod, acf.GetMethod());

            AssertMethodRemoved(autoCompleteMethod);

            Assert.AreEqual(pageSize, acf.PageSize);
            Assert.AreEqual(minLength, acf.MinLength);
        }
Пример #8
0
        public static void Compare(IActionParameterSpecImmutable actionParameter1, IActionParameterSpecImmutable actionParameter2)
        {
            var specName = actionParameter1.Identifier.ToIdString();

            Compare(actionParameter1.IsChoicesEnabled, actionParameter2.IsChoicesEnabled, specName);
            Compare(actionParameter1.IsMultipleChoicesEnabled, actionParameter2.IsMultipleChoicesEnabled, specName);

            // only carry on to compare facets if first time
            if (HasBeenCompared(actionParameter1, actionParameter2))
            {
                return;
            }
            Compare(actionParameter1.Specification, actionParameter2.Specification);
            Compare(actionParameter1, actionParameter2, specName);
        }
Пример #9
0
        protected internal ActionParameterSpec(IMetamodelManager metamodel, int number, IActionSpec actionSpec, IActionParameterSpecImmutable actionParameterSpecImmutable, INakedObjectManager manager, ISession session, IObjectPersistor persistor)
        {
            Assert.AssertNotNull(metamodel);
            Assert.AssertNotNull(actionSpec);
            Assert.AssertNotNull(actionParameterSpecImmutable);
            Assert.AssertNotNull(manager);
            Assert.AssertNotNull(session);
            Assert.AssertNotNull(persistor);

            this.metamodel = metamodel;
            this.number    = number;
            parentAction   = actionSpec;
            this.actionParameterSpecImmutable = actionParameterSpecImmutable;
            this.manager   = manager;
            this.session   = session;
            this.persistor = persistor;
        }
        public IActionParameterSpec CreateParameter(IActionParameterSpecImmutable parameterSpecImmutable, IActionSpec actionSpec, int index)
        {
            Assert.AssertNotNull(framework);
            IObjectSpecImmutable specification = parameterSpecImmutable.Specification;

            if (specification.IsParseable)
            {
                return(new ActionParseableParameterSpec(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor));
            }
            if (specification.IsObject)
            {
                return(new OneToOneActionParameter(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor));
            }
            if (specification.IsCollection)
            {
                return(new OneToManyActionParameter(framework.MetamodelManager, index, actionSpec, parameterSpecImmutable, framework.NakedObjectManager, framework.Session, framework.Persistor));
            }
            throw new UnknownTypeException(specification);
        }
 public static IActionSpecImmutable CreateActionSpecImmutable(IIdentifier identifier, ITypeSpecImmutable ownerSpec, IActionParameterSpecImmutable[] parameters) {
     return new ActionSpecImmutable(identifier, ownerSpec, parameters);
 }
Пример #12
0
 public ActionParseableParameterSpec(IMetamodelManager metamodel, int index, IActionSpec actionSpec, IActionParameterSpecImmutable actionParameterSpecImmutable, INakedObjectManager manager, ISession session, IObjectPersistor persistor)
     : base(metamodel, index, actionSpec, actionParameterSpecImmutable, manager, session, persistor) {}
        private void FindAndRemoveParametersValidateMethod(IReflector reflector, IMethodRemover methodRemover, Type type, string capitalizedName, Type[] paramTypes, string[] paramNames, IActionParameterSpecImmutable[] parameters) {
            for (int i = 0; i < paramTypes.Length; i++) {
                MethodInfo methodUsingIndex = FindMethod(reflector,
                    type,
                    MethodType.Object,
                    RecognisedMethodsAndPrefixes.ValidatePrefix + i + capitalizedName,
                    typeof (string),
                    new[] {paramTypes[i]});

                MethodInfo methodUsingName = FindMethod(reflector,
                    type,
                    MethodType.Object,
                    RecognisedMethodsAndPrefixes.ValidatePrefix + capitalizedName,
                    typeof (string),
                    new[] {paramTypes[i]},
                    new[] {paramNames[i]});

                if (methodUsingIndex != null && methodUsingName != null) {
                    Log.WarnFormat("Duplicate validate parameter methods {0} and {1} using {1}", methodUsingIndex.Name, methodUsingName.Name);
                }

                MethodInfo methodToUse = methodUsingName ?? methodUsingIndex;

                if (methodToUse != null) {
                    // deliberately not removing both if duplicate to show that method  is duplicate
                    RemoveMethod(methodRemover, methodToUse);

                    // add facets directly to parameters, not to actions 
                    FacetUtils.AddFacet(new ActionParameterValidation(methodToUse, parameters[i]));
                    AddOrAddToExecutedWhereFacet(methodToUse, parameters[i]);
                    AddAjaxFacet(methodToUse, parameters[i]);
                }
                else {
                    AddAjaxFacet(null, parameters[i]);
                }
            }
        }
        private void FindAndRemoveParametersAutoCompleteMethod(IReflector reflector, IMethodRemover methodRemover, Type type, string capitalizedName, Type[] paramTypes, IActionParameterSpecImmutable[] parameters) {
            for (int i = 0; i < paramTypes.Length; i++) {
                // only support on strings and reference types 
                Type paramType = paramTypes[i];
                if (paramType.IsClass || paramType.IsInterface) {

                    //returning an IQueryable ...
                    MethodInfo method = FindAutoCompleteMethod(reflector, type, capitalizedName, i,
                        typeof(IQueryable<>).MakeGenericType(paramType));

                    //.. or returning a single object
                    if (method == null ) {
                        method = FindAutoCompleteMethod(reflector, type, capitalizedName, i, paramType);
                    }

                    //... or returning an enumerable of string
                    if (method == null && (TypeUtils.IsString(paramType))) {                      
                        method = FindAutoCompleteMethod(reflector, type, capitalizedName, i, typeof(IEnumerable<string>));
                    }

                    if (method != null) {
                        var pageSizeAttr = method.GetCustomAttribute<PageSizeAttribute>();
                        var minLengthAttr = (MinLengthAttribute) Attribute.GetCustomAttribute(method.GetParameters().First(), typeof (MinLengthAttribute));

                        int pageSize = pageSizeAttr != null ? pageSizeAttr.Value : 0; // default to 0 ie system default
                        int minLength = minLengthAttr != null ? minLengthAttr.Length : 0;

                        // deliberately not removing both if duplicate to show that method  is duplicate
                        RemoveMethod(methodRemover, method);

                        // add facets directly to parameters, not to actions 
                        FacetUtils.AddFacet(new AutoCompleteFacet(method, pageSize, minLength, parameters[i]));
                        AddOrAddToExecutedWhereFacet(method, parameters[i]);
                    }
                }
            }
        }
        private void FindAndRemoveParametersChoicesMethod(IReflector reflector, IMethodRemover methodRemover, Type type, string capitalizedName, Type[] paramTypes, string[] paramNames, IActionParameterSpecImmutable[] parameters) {
            for (int i = 0; i < paramTypes.Length; i++) {
                Type paramType = paramTypes[i];
                string paramName = paramNames[i];
                bool isMultiple = false;

                if (CollectionUtils.IsGenericEnumerable(paramType)) {
                    paramType = paramType.GetGenericArguments().First();
                    isMultiple = true;
                }

                Type returnType = typeof (IEnumerable<>).MakeGenericType(paramType);
                string methodName = RecognisedMethodsAndPrefixes.ParameterChoicesPrefix + i + capitalizedName;

                MethodInfo[] methods = FindMethods(
                    reflector,
                    type,
                    MethodType.Object,
                    methodName,
                    returnType);

                if (methods.Length > 1) {
                    methods.Skip(1).ForEach(m => Log.WarnFormat("Found multiple action choices methods: {0} in type: {1} ignoring method(s) with params: {2}",
                        methodName,
                        type,
                        m.GetParameters().Select(p => p.Name).Aggregate("", (s, t) => s + " " + t)));
                }

                MethodInfo methodUsingIndex = methods.FirstOrDefault();

                MethodInfo methodUsingName = FindMethod(
                    reflector,
                    type,
                    MethodType.Object,
                    RecognisedMethodsAndPrefixes.ParameterChoicesPrefix + capitalizedName,
                    returnType,
                    new[] {paramType},
                    new[] {paramName});

                if (methodUsingIndex != null && methodUsingName != null) {
                    Log.WarnFormat("Duplicate choices parameter methods {0} and {1} using {1}", methodUsingIndex.Name, methodUsingName.Name);
                }

                MethodInfo methodToUse = methodUsingName ?? methodUsingIndex;

                if (methodToUse != null) {
                    // deliberately not removing both if duplicate to show that method  is duplicate
                    RemoveMethod(methodRemover, methodToUse);

                    // add facets directly to parameters, not to actions 
                    Tuple<string, IObjectSpecImmutable>[] parameterNamesAndTypes = methodToUse.GetParameters().Select(p => new Tuple<string, IObjectSpecImmutable>(p.Name.ToLower(), reflector.LoadSpecification<IObjectSpecImmutable>(p.ParameterType))).ToArray();
                    FacetUtils.AddFacet(new ActionChoicesFacetViaMethod(methodToUse, parameterNamesAndTypes, returnType, parameters[i], isMultiple));
                    AddOrAddToExecutedWhereFacet(methodToUse, parameters[i]);
                }
            }
        }
Пример #16
0
 protected override IImmutableDictionary <string, ITypeSpecBuilder> ProcessParameter(MethodInfo actionMethod, int i, IActionParameterSpecImmutable param, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) => ((SystemTypeFacetFactorySet)FacetFactorySet).ProcessParams(Reflector, actionMethod, i, param, metamodel);
Пример #17
0
 public ActionParseableParameterSpec(IMetamodelManager metamodel, int index, IActionSpec actionSpec, IActionParameterSpecImmutable actionParameterSpecImmutable, INakedObjectManager manager, ISession session, IObjectPersistor persistor)
     : base(metamodel, index, actionSpec, actionParameterSpecImmutable, manager, session, persistor)
 {
 }
 public ActionSpecImmutable(IIdentifier identifier, ITypeSpecImmutable ownerSpec,
                            IActionParameterSpecImmutable[] parameters)
     : base(identifier) {
     this.ownerSpec = ownerSpec;
     this.parameters = parameters;
 }