Exemplo n.º 1
0
        public void AttemptToAttachViewToAction(ViewBag bag, ActionCall call, IConfigurationObserver observer)
        {
            foreach (var filter in _filters)
            {
                var viewTokens = filter.Apply(call, bag);
                var count = viewTokens.Count();

                observer.RecordCallStatus(call, "View filter '{0}' found {1} view token{2}".ToFormat(
                    filter.GetType().Name, count, (count != 1) ? "s" : "" ));

                if( count > 0 )
                {
                    viewTokens.Each(t =>
                        observer.RecordCallStatus(call, "Found view token: {0}".ToFormat(t)));
                }

                // if the filter returned more than one, consider it "failed", ignore it, and move on to the next
                if (count != 1) continue;

                var token = viewTokens.First();
                observer.RecordCallStatus(call, "Selected view token: {0}".ToFormat(token));
                call.AddToEnd(token.ToBehavioralNode());
                break;
            }
        }
Exemplo n.º 2
0
        public virtual void Attach(IViewProfile viewProfile, ViewBag bag, ActionCall action)
        {
            // No duplicate views!
            var outputNode = action.ParentChain().Output;
            if (outputNode.HasView(viewProfile.ConditionType)) return;

            var log = new ViewAttachmentLog(viewProfile);
            action.Trace(log);

            foreach (var filter in _filters)
            {
                var viewTokens = filter.Apply(action, bag);
                var count = viewTokens.Count();

                if (count > 0)
                {
                    log.FoundViews(filter, viewTokens.Select(x => x.Resolve()));
                }

                if (count != 1) continue;

                var token = viewTokens.Single().Resolve();
                outputNode.AddView(token, viewProfile.ConditionType);

                break;
            }
        }
Exemplo n.º 3
0
 public void Configure(ViewBag bag, BehaviorGraph graph)
 {
     graph.Behaviors
         .Select(x => x.FirstCall())
         .Where(x => x != null)
         .Each(a => AttemptToAttachViewToAction(bag, a, graph.Observer));
 }
Exemplo n.º 4
0
 IEnumerable<BehaviorChain> FindChainsWithoutViews(BehaviorGraph graph, ViewBag bag)
 {
     return from b in graph.Behaviors
            where b.ActionOutputType() != null
                 && b.ActionOutputType().Closes(typeof(AwesomeCreateModel<>))
            let output = b.ActionOutputType()
            where !bag.ViewsFor(output).Any()
            select b;
 }
Exemplo n.º 5
0
 public void ImportInto(IChainImporter graph, ViewBag views)
 {
     // TODO -- will want this to suck in the configuration log business somehow
     Registry.Compile();
     var childGraph = Registry.Configuration.BuildForImport(views);
     graph.Import(childGraph, b =>
     {
         b.PrependToUrl(Prefix);
         b.Origin = Registry.Name;
     });
 }
Exemplo n.º 6
0
        public void Configure(BehaviorGraph graph)
        {
            var views = new List <IViewToken>();

            foreach (var facility in _facilities)
            {
                views.AddRange(facility.FindViews(_types, graph));
            }

            var bag = new ViewBag(views);

            _conventions.Each(c => c.Configure(bag, graph));
        }
Exemplo n.º 7
0
        public void Configure(ViewBag bag, BehaviorGraph graph)
        {
            FindChainsWithoutViews(graph, bag).Each(b =>
            {
                var output = b.ActionOutputType();
                var entityType = output.GetGenericArguments()[0];
                var handlerType = typeof (AwesomeCreateHandler<>).MakeGenericType(entityType);
                var method = handlerType.GetMethod("DaisyChain");
                b.AddToEnd(new ActionCall(handlerType,method));

                var token = bag.ViewsFor(typeof (AwesomeEditModel)).First();
                b.AddToEnd(token.ToBehavioralNode());
            });
        }
        public void SetUp()
        {
            token = new FakeViewToken
            {
                ViewName = "AAction",
                Namespace = GetType().Namespace,
                ViewType =  typeof(AAction),
                ViewModel = typeof (ViewModel1)
            };
            var views = new List<IViewToken>
            {
                token
            };

            bag = new ViewBag(views);

            filter = new ActionWithSameNameAndFolderAsViewReturnsViewModelType();
        }
Exemplo n.º 9
0
        internal IEnumerable <ProfileViewBag> Profiles(ViewBag views)
        {
            if (_profiles.Any())
            {
                foreach (var profile in _profiles)
                {
                    yield return(new ProfileViewBag(profile, views));
                }

                Func <IViewToken, bool> defaultFilter = x => !_defaultExcludes.Any(test => test(x));
                var defaultProfile = new ViewProfile(Always.Flyweight, defaultFilter, x => x.Name());

                yield return(new ProfileViewBag(defaultProfile, views));
            }
            else
            {
                yield return(new ProfileViewBag(new DefaultProfile(), views));
            }
        }
Exemplo n.º 10
0
        public void Configure(BehaviorGraph graph)
        {
            _types.ShouldScanAssemblies = true;
            var views = new List <IViewToken>();

            foreach (var facility in _facilities)
            {
                views.AddRange(facility.FindViews(_types, graph));
            }

            //= _facilities.SelectMany(x => x.FindViews(_types));

            var bag = new ViewBag(views);

            graph.Behaviors
            .Select(x => x.FirstCall())
            .Where(x => x != null)
            .Each(a => AttemptToAttachViewToAction(bag, a, graph.Observer));
        }
Exemplo n.º 11
0
        public void Attach(IViewProfile viewProfile, ViewBag bag, ActionCall action)
        {
            // No duplicate views!
            var outputNode = action.ParentChain().Output;
            if (outputNode.HasView(viewProfile.Condition)) return;

            foreach (var filter in _policy.Filters())
            {
                var viewTokens = filter.Apply(action, bag);
                var count = viewTokens.Count();

                if (count != 1) continue;

                var token = viewTokens.Single().Resolve();

                _attached.Add(token);
                outputNode.AddView(token, viewProfile.Condition);

                break;
            }
        }
Exemplo n.º 12
0
 public ViewBag Filter(ViewBag bag)
 {
     return bag;
 }
 public void Configure(ViewBag bag, BehaviorGraph graph)
 {
     Invocations++;
 }
Exemplo n.º 14
0
 public ViewAttachmentWorker(ViewBag views, ViewAttachmentPolicy policy)
 {
     _views = views;
     _policy = policy;
 }
Exemplo n.º 15
0
        public virtual void Attach(ViewAttachmentPolicy policy, IViewProfile viewProfile, ViewBag bag, ActionCall action)
        {
            // No duplicate views!
            var outputNode = action.ParentChain().Output;

            if (outputNode.HasView(viewProfile.ConditionType))
            {
                return;
            }

            var log = new ViewAttachmentLog(viewProfile);

            action.Trace(log);

            foreach (var filter in policy.Filters())
            {
                var viewTokens = filter.Apply(action, bag);
                var count      = viewTokens.Count();

                if (count > 0)
                {
                    log.FoundViews(filter, viewTokens.Select(x => x.Resolve()));
                }

                if (count != 1)
                {
                    continue;
                }

                var token = viewTokens.Single().Resolve();
                outputNode.AddView(token, viewProfile.ConditionType);

                break;
            }
        }
Exemplo n.º 16
0
 public IEnumerable <IViewToken> Apply(ActionCall call, ViewBag views)
 {
     return(views.ViewsFor(call.OutputType()).Where(view => view.Name == call.Method.Name && view.Folder == call.HandlerType.Namespace));
 }
Exemplo n.º 17
0
 public ViewBag Filter(ViewBag bag)
 {
     return(bag);
 }
Exemplo n.º 18
0
        public void Configure(BehaviorGraph graph)
        {
            _types.ShouldScanAssemblies = true;
            var views = new List<IViewToken>();

            foreach (var facility in _facilities)
            {
                views.AddRange(facility.FindViews(_types, graph));
            }

            //= _facilities.SelectMany(x => x.FindViews(_types));

            var bag = new ViewBag(views);

            graph.Behaviors
                .Select(x => x.FirstCall())
                .Where(x => x != null)
                .Each(a => AttemptToAttachViewToAction(bag, a, graph.Observer));
        }
Exemplo n.º 19
0
 public ProfileViewBag(IViewProfile profile, ViewBag views)
 {
     Profile = profile;
     Views   = profile.Filter(views);
 }
Exemplo n.º 20
0
 public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views)
 {
     return views.ViewsFor(call.OutputType());
 }
Exemplo n.º 21
0
        public ViewBag Filter(ViewBag bag)
        {
            var views = bag.Views.Where(_filter).Select(x => new ProfileViewToken(x, _getName(x)));

            return(new ViewBag(views));
        }
Exemplo n.º 22
0
 public IEnumerable <IViewToken> Apply(ActionCall call, ViewBag views)
 {
     return(views.ViewsFor(call.OutputType()));
 }
 public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views)
 {
     return views.ViewsFor(call.OutputType()).Where(view => view.Name == call.Method.Name && view.Folder == call.HandlerType.Namespace);
 }
Exemplo n.º 24
0
 public ViewBag Filter(ViewBag bag)
 {
     var views = bag.Views.Where(_filter).Select(x => new ProfileViewToken(x, _getName(x)));
     return new ViewBag(views);
 }
Exemplo n.º 25
0
 public ViewAttachmentWorker(ViewBag views, ViewAttachmentPolicy policy)
 {
     _views  = views;
     _policy = policy;
 }