Exemple #1
0
        public ActionSpec(SpecFactory memberFactory,
                          IMetamodelManager metamodel,
                          ILifecycleManager lifecycleManager,
                          ISession session,
                          IServicesManager servicesManager,
                          INakedObjectManager nakedObjectManager,
                          IActionSpecImmutable actionSpecImmutable,
                          IMessageBroker messageBroker,
                          ITransactionManager transactionManager,
                          IObjectPersistor persistor,
                          ILoggerFactory loggerFactory,
                          ILogger <ActionSpec> logger)
            : base(actionSpecImmutable?.Identifier?.MemberName, actionSpecImmutable, session, lifecycleManager, metamodel, persistor)
        {
            this.servicesManager     = servicesManager ?? throw new InitialisationException($"{nameof(servicesManager)} is null");
            this.nakedObjectManager  = nakedObjectManager ?? throw new InitialisationException($"{nameof(nakedObjectManager)} is null");
            this.actionSpecImmutable = actionSpecImmutable ?? throw new InitialisationException($"{nameof(actionSpecImmutable)} is null");
            this.messageBroker       = messageBroker ?? throw new InitialisationException($"{nameof(messageBroker)} is null");
            this.transactionManager  = transactionManager ?? throw new InitialisationException($"{nameof(transactionManager)} is null");
            this.loggerFactory       = loggerFactory ?? throw new InitialisationException($"{nameof(loggerFactory)} is null");
            this.logger = logger ?? throw new InitialisationException($"{nameof(logger)} is null");
            var index = 0;

            Parameters = this.actionSpecImmutable.Parameters.Select(pp => memberFactory.CreateParameter(pp, this, index++)).ToArray();
        }
        protected bool HasAction(IActionSpecImmutable action)
        {
            bool nativeAction = MenuItems.OfType <MenuAction>().Any(mi => mi.Action == action);

            if (nativeAction)
            {
                return(true);
            }
            return(MenuItems.OfType <MenuImpl>().Any(m => m.HasAction(action)));
        }
        public bool HasActionOrSuperMenuHasAction(IActionSpecImmutable action)
        {
            if (HasAction(action))
            {
                return(true);
            }
            var superMenu = SuperMenu as MenuImpl;

            return(superMenu != null && superMenu.HasActionOrSuperMenuHasAction(action));
        }
Exemple #4
0
        public ITestAction AsAction()
        {
            AssertIsAction();
            IActionSpecImmutable actionSpecIm = ((IMenuActionImmutable)item).Action;

            if (owningObject == null)
            {
                return(factory.CreateTestActionOnService(actionSpecIm));
            }
            return(factory.CreateTestAction(actionSpecIm, owningObject));
        }
        public IMenu AddAction(string actionName)
        {
            IActionSpecImmutable actionSpec = ActionsForObject.FirstOrDefault(a => a.Identifier.MemberName == actionName);

            if (actionSpec == null)
            {
                throw new ReflectionException(Log.LogAndReturn($"No such action: {actionName} on {Type}"));
            }
            AddMenuItem(new MenuAction(actionSpec));
            return(this);
        }
        public IMenu AddActionFrom <TObject>(string actionName, string renamedTo = null)
        {
            Type serviceType = typeof(TObject);

            IActionSpecImmutable actionSpec = GetActionsForObject <TObject>().FirstOrDefault(a => a.Identifier.MemberName == actionName);

            if (actionSpec == null)
            {
                throw new ReflectionException("No such action: " + actionName + " on " + serviceType);
            }
            AddMenuItem(new MenuAction(actionSpec, renamedTo));
            return(this);
        }
        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));
        }
        private static ElementDescriptor MenuActionAsElementDescriptor(this HtmlHelper html, IMenuActionImmutable menuAction, INakedObject nakedObject, bool isEdit)
        {
            IActionSpecImmutable actionIm   = menuAction.Action;
            IActionSpec          actionSpec = html.Framework().MetamodelManager.GetActionSpec(actionIm);

            if (nakedObject == null)
            {
                IObjectSpecImmutable objectIm = actionIm.OwnerSpec; //This is the spec for the service

                if (!objectIm.Service)
                {
                    throw new Exception("Action is not on a known object or service");
                }
                //TODO: Add method to IServicesManager to get a service by its IObjectSpec (or IObjectSpecImmutable)
                ITypeSpec objectSpec = html.Framework().MetamodelManager.GetSpecification(objectIm);
                nakedObject = html.Framework().ServicesManager.GetServices().Single(s => s.Spec == objectSpec);
            }

            var actionContext = new ActionContext(false, nakedObject, actionSpec);

            RouteValueDictionary attributes;
            string tagType;
            string value;

            if (!actionContext.Action.IsVisible(actionContext.Target))
            {
                return(null);
            }
            IConsent consent = actionContext.Action.IsUsable(actionContext.Target);

            if (consent.IsVetoed)
            {
                tagType = html.GetVetoedAction(actionContext, consent, out value, out attributes);
            }
            else if (isEdit)
            {
                tagType = html.GetActionAsButton(actionContext, out value, out attributes);
            }
            else
            {
                tagType = html.GetActionAsForm(actionContext, html.Framework().GetObjectTypeName(actionContext.Target.Object), new { id = html.Framework().GetObjectId(actionContext.Target) }, out value, out attributes);
            }

            return(new ElementDescriptor {
                TagType = tagType,
                Value = value,
                Attributes = attributes
            });
        }
        public ITestAction CreateTestActionOnService(IActionSpecImmutable actionSpecImm)
        {
            var 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)framework.MetamodelManager.GetSpecification(objectIm);
            var service     = framework.ServicesManager.GetService(serviceSpec);
            var testService = CreateTestService(service);

            return(CreateTestAction(actionSpecImm, testService));
        }
Exemple #10
0
        public ActionSpec(SpecFactory memberFactory, IMetamodelManager metamodel, ILifecycleManager lifecycleManager, ISession session, IServicesManager servicesManager, INakedObjectManager nakedObjectManager, IActionSpecImmutable actionSpecImmutable, IMessageBroker messageBroker, ITransactionManager transactionManager)
            : base(actionSpecImmutable.Identifier.MemberName, actionSpecImmutable, session, lifecycleManager, metamodel) {
            Assert.AssertNotNull(memberFactory);
            Assert.AssertNotNull(servicesManager);
            Assert.AssertNotNull(nakedObjectManager);
            Assert.AssertNotNull(actionSpecImmutable);

            this.memberFactory = memberFactory;
            this.servicesManager = servicesManager;
            this.nakedObjectManager = nakedObjectManager;
            this.actionSpecImmutable = actionSpecImmutable;
            this.messageBroker = messageBroker;
            this.transactionManager = transactionManager;
            int index = 0;
            parametersSpec = this.actionSpecImmutable.Parameters.Select(pp => this.memberFactory.CreateParameter(pp, this, index++)).ToArray();
        }
Exemple #11
0
        public ActionSpec(SpecFactory memberFactory, IMetamodelManager metamodel, ILifecycleManager lifecycleManager, ISession session, IServicesManager servicesManager, INakedObjectManager nakedObjectManager, IActionSpecImmutable actionSpecImmutable)
            : base(actionSpecImmutable.Identifier.MemberName, actionSpecImmutable, session, lifecycleManager, metamodel)
        {
            Assert.AssertNotNull(memberFactory);
            Assert.AssertNotNull(servicesManager);
            Assert.AssertNotNull(nakedObjectManager);
            Assert.AssertNotNull(actionSpecImmutable);

            this.memberFactory       = memberFactory;
            this.servicesManager     = servicesManager;
            this.nakedObjectManager  = nakedObjectManager;
            this.actionSpecImmutable = actionSpecImmutable;
            int index = 0;

            parametersSpec = this.actionSpecImmutable.Parameters.Select(pp => this.memberFactory.CreateParameter(pp, this, index++)).ToArray();
        }
        public ActionSpec(INakedObjectsFramework framework,
                          SpecFactory memberFactory,

                          IActionSpecImmutable actionSpecImmutable,

                          ILoggerFactory loggerFactory,
                          ILogger <ActionSpec> logger)
            : base(actionSpecImmutable?.Identifier?.MemberName, actionSpecImmutable, framework)
        {
            this.framework           = framework ?? throw new InitialisationException($"{nameof(framework)} is null");
            this.actionSpecImmutable = actionSpecImmutable ?? throw new InitialisationException($"{nameof(actionSpecImmutable)} is null");
            this.loggerFactory       = loggerFactory ?? throw new InitialisationException($"{nameof(loggerFactory)} is null");
            this.logger = logger ?? throw new InitialisationException($"{nameof(logger)} is null");
            var index = 0;

            Parameters = this.actionSpecImmutable.Parameters.Select(pp => memberFactory.CreateParameter(pp, this, index++)).ToArray();
        }
        public static string ToOrderString(this IActionSpecImmutable spec)
        {
            if (spec == null)
            {
                return("");
            }

            var facet  = spec.GetFacet <IActionInvocationFacet>();
            var suffix = "";

            if (facet != null)
            {
                suffix = facet.OrderString();
            }

            return($"{spec.ToIdString()}/{suffix}");
        }
        private void AddContributedAction(IActionSpecImmutable ca, IObjectSpecImmutable spec)
        {
            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));
            }
        }
Exemple #15
0
        public static void Compare(IActionSpecImmutable action1, IActionSpecImmutable action2)
        {
            var specName = action1.Name;

            // make sure same spec
            Compare(action1.OwnerSpec, action2.OwnerSpec);
            Compare(action1.ElementSpec, action2.ElementSpec);
            Compare(action1.Parameters, action2.Parameters);
            Compare(action1.ReturnSpec, action2.ReturnSpec);
            Compare(action1.Description, action2.Description, specName);
            Compare(action1.Name, action2.Name, specName);

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

            Compare(action1, action2, specName);
        }
Exemple #16
0
 public ITestAction CreateTestAction(IActionSpecImmutable actionSpec, ITestHasActions owningObject)
 {
     throw new NotImplementedException();
 }
 private bool HasAction(IActionSpecImmutable action) {
     bool nativeAction = MenuItems.OfType<MenuAction>().Any(mi => mi.Action == action);
     return nativeAction || MenuItems.OfType<MenuImpl>().Any(m => m.HasAction(action));
 }
Exemple #18
0
        private bool IsContributedFunction(IActionSpecImmutable sa, ITypeSpecImmutable ts)
        {
            var f = sa.GetFacet <IContributedFunctionFacet>();

            return(f != null && f.IsContributedTo(ts));
        }
        public ITestAction CreateTestAction(IActionSpecImmutable actionSpecImm, ITestHasActions owningObject)
        {
            var actionSpec = metamodelManager.GetActionSpec(actionSpecImm);

            return(CreateTestAction(actionSpec, owningObject));
        }
Exemple #20
0
 protected override IImmutableDictionary <string, ITypeSpecBuilder> ProcessAction(MethodInfo actionMethod, MethodInfo[] actions, IActionSpecImmutable action, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) => ((SystemTypeFacetFactorySet)FacetFactorySet).Process(Reflector, actionMethod, new IntrospectorMethodRemover(actions), action, FeatureType.Actions, metamodel);
 public bool HasActionOrSuperMenuHasAction(IActionSpecImmutable action) =>
 HasAction(action) ||
 SuperMenu is MenuImpl superMenu &&
 private void AddContributedAction(IActionSpecImmutable ca, IObjectSpecImmutable spec) {
     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));
     }
 }
        private bool HasAction(IActionSpecImmutable action)
        {
            bool nativeAction = MenuItems.OfType <MenuAction>().Any(mi => mi.Action == action);

            return(nativeAction || MenuItems.OfType <MenuImpl>().Any(m => m.HasAction(action)));
        }
 public MenuAction(IActionSpecImmutable actionSpec, string renamedTo = null)
 {
     Action = actionSpec;
     Name   = renamedTo ?? actionSpec.Name;
 }
 public IActionSpec GetActionSpec(IActionSpecImmutable spec) {
     return specFactory.CreateActionSpec(spec);
 }
 public MenuAction(IActionSpecImmutable actionSpec, string renamedTo = null) {
     Action = actionSpec;
     Name = renamedTo ?? actionSpec.Name;
 }
Exemple #27
0
 public IActionSpec CreateActionSpec(IActionSpecImmutable specImmutable) {
     Assert.AssertNotNull(framework);
     return new ActionSpec(this, framework.MetamodelManager, framework.LifecycleManager, framework.Session, framework.ServicesManager, framework.NakedObjectManager, specImmutable, framework.MessageBroker, framework.TransactionManager);
 }
 public IActionSpec CreateActionSpec(IActionSpecImmutable specImmutable)
 {
     Assert.AssertNotNull(framework);
     return(new ActionSpec(this, framework.MetamodelManager, framework.LifecycleManager, framework.Session, framework.ServicesManager, framework.NakedObjectManager, specImmutable, framework.MessageBroker, framework.TransactionManager));
 }
 private static bool IsContributedFunction(IActionSpecImmutable sa, ITypeSpecImmutable ts) => sa.GetFacet <IContributedFunctionFacet>()?.IsContributedTo(ts) == true;
 public bool HasActionOrSuperMenuHasAction(IActionSpecImmutable action) {
     if (HasAction(action)) {
         return true;
     }
     var superMenu = SuperMenu as MenuImpl;
     return superMenu != null && superMenu.HasActionOrSuperMenuHasAction(action);
 }
 public IActionSpec GetActionSpec(IActionSpecImmutable spec) => specFactory.CreateActionSpec(spec);
 public ITestAction CreateTestAction(IActionSpecImmutable actionSpecImm, ITestHasActions owningObject) {
     IActionSpec actionSpec = metamodelManager.GetActionSpec(actionSpecImm);
     return CreateTestAction(actionSpec, owningObject);
 }
 public IActionSpec GetActionSpec(IActionSpecImmutable spec)
 {
     return(specFactory.CreateActionSpec(spec));
 }
        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);
        }
 private static void DecorateAction(IFacetDecoratorSet decorator, IActionSpecImmutable action)
 {
     decorator.DecorateAllHoldersFacets(action);
     action.Parameters.ForEach(decorator.DecorateAllHoldersFacets);
 }
 private static void DecorateAction(IFacetDecoratorSet decorator, IActionSpecImmutable action) {
     decorator.DecorateAllHoldersFacets(action);
     action.Parameters.ForEach(decorator.DecorateAllHoldersFacets);
 }