public IEnumerable<ActionCall> FindActions(TypePool types)
        {
            //var tpes = types.TypesMatching(t => t.Closes(typeof (StateMachine<>)));
            foreach(var sm in new List<Type>{typeof(TicketStateMachine)})
            {
                //TODO: Where can I load things into the container - using ObjDef?
                var machine = (StateMachine)Activator.CreateInstance(sm);

                var t = typeof (StateMachineOptionsAction<>).MakeGenericType(sm);
                var ta =  new ActionCall(t, t.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));
                //can I build the route here?

                yield return ta;

                var tt = typeof(StateMachineInstanceOptionsAction<>).MakeGenericType(sm);
                yield return new ActionCall(tt, tt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));

                var ttt = typeof(StateMachineCurrentStateAction<>).MakeGenericType(sm);
                yield return new ActionCall(ttt, ttt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));

                foreach (var @event in machine.Events)
                {
                    //need to track the event name
                    //between here and the event url generation
                    //so I used a custom ActionCall extension
                    var eventName = @event.Name;
                    var et = typeof (StateMachineRaiseEventAction<,>).MakeGenericType(sm, @event.GetType());
                    var call = new EventActionCall(eventName, et, et.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));
                    yield return call;
                }
            }
        }
Exemplo n.º 2
0
        public void removing_the_called_assembly()
        {
            var pool = new TypePool(GetType().Assembly);
            pool.IgnoreCallingAssembly();

            pool.Assemblies.ShouldNotContain(GetType().Assembly);
        }
        public IEnumerable<ActionCall> FindActions(TypePool types)
        {
            var awesomeEntities = types.EntityTypes();

            var openHandlers = new[]
            {
                typeof (RestfulCreateHandler<>),
                typeof (RestfulPatchHandler<>),
                typeof (RestfulDeleteHandler<>),
                typeof (RestfulFindHandler<>),
                typeof (RestfulIndexHandler<>),
                typeof (AwesomeCreateHandler<>),
                typeof (AwesomeEditHandler<>)
            };

            foreach (var awesomeEntity in awesomeEntities)
            {
                foreach(var openHandler in openHandlers)
                {
                    var closedHandler = openHandler.MakeGenericType(awesomeEntity);
                    var closedMethod = closedHandler.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance); //should drive from RestfulHandler

                    guard(closedHandler, closedMethod);

                    yield return new ActionCall(closedHandler, closedMethod);
                }
            }
        }
        public IEnumerable<ActionCall> FindActions(TypePool types)
        {
            var actionCalls = new List<ActionCall>();
            var viewModels = types.TypesMatching(t => IsAssignableFromGenericInterface(typeof(IEntityUpdateable<>), t));

            foreach (var viewModel in viewModels)
            {
                Type entityType = null;
                foreach (Type interfaceType in viewModel.GetInterfaces())
                {
                    if (interfaceType.IsGenericType
                        && interfaceType.GetGenericTypeDefinition() == typeof(IEntityUpdateable<>))
                    {
                        entityType = interfaceType.GetGenericArguments().Single();
                        break;
                    }
                }

                Type queryType = typeof(SaveHandler<,>).MakeGenericType(viewModel, entityType);
                MethodInfo retrievalMethod = queryType.GetMethod("Save");

                actionCalls.Add(new ActionCall(queryType, retrievalMethod));
            }

            return actionCalls;
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            graph = new BehaviorGraph(null);
            matcher = new ActionSourceMatcher();

            pool = new TypePool();
        }
        public void Setup()
        {
            var types = new TypePool();
            types.AddAssembly(GetType().Assembly);

            _runner = new ViewEngineSettings();
        }
Exemplo n.º 7
0
        public void SetUp()
        {
            var pool = new TypePool();
            pool.AddAssembly(Assembly.GetExecutingAssembly());

            views = new WebFormViewFacility().FindViews(pool);
        }
Exemplo n.º 8
0
        public AssemblyScanner()
        {
            _types       = new TypePool(GetType().Assembly);
            _typeFilters = new CompositeFilter <Type>();

            IncludeTypes(t => true);
        }
        public IEnumerable<ActionCall> FindActions(TypePool types)
        {
            var awesomeEntities = (from entities in types.TypesMatching(AwesomeConfiguration.AwesomeEntities)
                                  where entities.IsConcrete()
                                  select entities).ToList()
                                  .Distinct();

            var openHandlers = new[]
            {
                typeof (RestfulCreateHandler<>),
                typeof (RestfulPatchHandler<>),
                typeof (RestfulDeleteHandler<>),
                typeof (RestfulFindHandler<>),
                typeof (RestfulIndexHandler<>),
                typeof (AwesomeCreateHandler<>),
                typeof (AwesomeEditHandler<>)
            };

            foreach (var awesomeEntity in awesomeEntities)
            {
                foreach(var openHandler in openHandlers)
                {
                    var closedHandler = openHandler.MakeGenericType(awesomeEntity);
                    var closedMethod = closedHandler.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance); //should drive from RestfulHandler

                    guard(closedHandler, closedMethod);

                    yield return new ActionCall(closedHandler, closedMethod);
                }
            }
        }
Exemplo n.º 10
0
        public void Configure(ServiceRegistry services)
        {
            var types = _applies.BuildPool(TypePool.FindTheCallingAssembly());

            var matchedTypes = types.TypesMatching(_typeFilters.Matches);

            _conventions
            .Each(convention => convention.Register(matchedTypes, services));
        }
Exemplo n.º 11
0
 public IEnumerable<ActionCall> FindActions(TypePool types)
 {
     return types.TypesMatching(t => t.Name.EndsWith("Endpoint") || t.Name.EndsWith("Endpoints"))
         .SelectMany(type =>
         {
             var methods = type.GetMethods().Where(ActionSource.IsCandidate);
             return methods.Select(m => new ActionCall(type, m));
         });
 }
Exemplo n.º 12
0
 public IEnumerable <ActionCall> FindActions(TypePool types)
 {
     return(types.TypesMatching(t => t.Name.EndsWith("Endpoint") || t.Name.EndsWith("Endpoints"))
            .SelectMany(type =>
     {
         var methods = type.GetMethods().Where(ActionSource.IsCandidate);
         return methods.Select(m => new ActionCall(type, m));
     }));
 }
Exemplo n.º 13
0
        public void should_return_all_types_with_full_name()
        {
            var pool = new TypePool(GetType().Assembly) {ShouldScanAssemblies = true };

            pool.AddType(generateType("namespace FubuMVC.Core{public class Endpoint{}}", "FubuMVC.Core.Endpoint"));
            pool.AddType(typeof(Core.Endpoint));

            pool.TypesWithFullName(typeof(Core.Endpoint).FullName).ShouldHaveCount(2);
        }
Exemplo n.º 14
0
        public void SetUp()
        {
            var pool = new TypePool(null){
                ShouldScanAssemblies = true
            };
            pool.AddAssembly(Assembly.GetExecutingAssembly());

            views = new WebFormViewFacility().FindViews(pool, new BehaviorGraph());
        }
        public IEnumerable<IViewToken> FindViews(BehaviorGraph graph)
        {
            var types = new TypePool();
            types.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            types.IgnoreExportTypeFailures = true;

            return types.TypesMatching(t => t.IsConcrete() && t.Closes(typeof (FubuHtmlDocument<>)) && !t.Equals(typeof(FubuHtmlDocument<>)))
                .Select(t => new HtmlDocumentViewToken(t));
        }
Exemplo n.º 16
0
 public IEnumerable<IViewToken> FindViews(TypePool types)
 {
     // clean up pending
     return _templateRegistry
         .AllTemplates()
         .Where(x => x.Descriptor is ViewDescriptor<IRazorTemplate>)
         .Select(x => x.Descriptor.As<ViewDescriptor<IRazorTemplate>>())
         .Where(x => x.HasViewModel())
         .Select(x => new RazorViewToken(x));
 }
Exemplo n.º 17
0
 public IEnumerable<IViewToken> FindViews(TypePool types, BehaviorGraph graph)
 {
     return _composer.Compose(types)
         .AllTemplates()
         // TODO : Clean this up
         .Where(x => x.Descriptor is ViewDescriptor)
         .Select(x => x.Descriptor.As<ViewDescriptor>())
         .Where(x => x.HasViewModel())
         .Select(x => new SparkViewToken(x));
 }
Exemplo n.º 18
0
        /// <summary>
        /// All types in the AppDomain in non dynamic assemblies
        /// </summary>
        public static TypePool AppDomainTypes()
        {
            var pool = new TypePool {
                IgnoreExportTypeFailures = true
            };

            pool.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies().Where(x => !x.IsDynamic));

            return(pool);
        }
Exemplo n.º 19
0
        public AssemblyScanner()
        {
            _types = new TypePool(GetType().Assembly)
            {
                IgnoreExportTypeFailures = false
            };
            _typeFilters = new CompositeFilter <Type>();

            IncludeTypes(t => true);
        }
Exemplo n.º 20
0
 public IEnumerable<IViewToken> FindViews(TypePool types, BehaviorGraph graph)
 {
     // clean up pending
     return _templateRegistry
         .AllTemplates()
         .Where(x => x.Descriptor is ViewDescriptor)
         .Select(x => x.Descriptor.As<ViewDescriptor>())
         .Where(x => x.HasViewModel())
         .Select(x => new SparkViewToken(x));
 }
        public void FindActions_should_skip_view_models_that_dont_have_an_entity_type_attribute()
        {
            IActionSource actionSource = new ListingHandlerActionSource();
            TypePool typePool = new TypePool(Assembly.GetExecutingAssembly());

            var actionCalls = actionSource.FindActions(typePool).ToList();

            Assert.GreaterOrEqual(actionCalls.Count, 1);
            Assert.IsFalse(actionCalls.Any(
                ac => ac.HandlerType == typeof(ListingHandler<NoEntityTypeViewModel, StubEntity>)
            ));
        }
        public void FindActions_should_return_actions_calls_for_view_models_only()
        {
            IActionSource actionSource = new ListingHandlerActionSource();
            TypePool typePool = new TypePool(Assembly.GetExecutingAssembly());

            var actionCalls = actionSource.FindActions(typePool).ToList();

            Assert.GreaterOrEqual(actionCalls.Count, 1);
            Assert.IsTrue(actionCalls.Any(
                ac => ac.HandlerType == typeof(ListingHandler<StubViewModel, StubEntity>)
            ));
        }
Exemplo n.º 23
0
        public void Configure(BehaviorGraph graph)
        {
            var rules = graph.Settings.Get <AccessorRules>();

            TypePool.AppDomainTypes().TypesMatching(x => x.CanBeCastTo <IAccessorRulesRegistration>() && x.IsConcreteWithDefaultCtor() && !x.IsOpenGeneric()).
            Distinct().Select(x => {
                return(Activator.CreateInstance(x).As <IAccessorRulesRegistration>());
            })
            .Each(x => x.AddRules(rules));

            graph.Settings.Replace(rules);
        }
Exemplo n.º 24
0
        public TypePool Types()
        {
            var types = new TypePool();

            if (ApplicationAssembly != null)
            {
                types.AddAssembly(ApplicationAssembly);
            }
            types.AddAssemblies(PackageRegistry.PackageAssemblies);

            return(types);
        }
        public IEnumerable<ActionCall> FindActions(Assembly applicationAssembly)
        {
            var types = new TypePool();
            types.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            types.IgnoreExportTypeFailures = true;

            return types.TypesMatching(type => type.IsConcreteTypeOf<ILookupProvider>()).Select(type =>
            {
                var method = GetLookupMethod(type);
                return new ActionCall(type, method);
            });
        }
Exemplo n.º 26
0
        private static TypePool getTypes()
        {
            var types = new TypePool(ConfigurationGraph.FindTheCallingAssembly());

            var filter = new CompositeFilter<Assembly>();
            filter.Excludes.Add(a => a.IsDynamic);
            filter.Excludes.Add(a => types.HasAssembly(a));
            filter.Includes += (t => true);

            types.AddSource(() => AppDomain.CurrentDomain.GetAssemblies().Where(filter.MatchesAll));

            return types;
        }
        public void FindActions_should_return_actions_calls_for_retrieve_method()
        {
            IActionSource actionSource = new ListingHandlerActionSource();
            TypePool typePool = new TypePool(Assembly.GetExecutingAssembly());

            var actionCalls = actionSource.FindActions(typePool).ToList();

            Assert.GreaterOrEqual(actionCalls.Count, 1);
            Assert.IsTrue(actionCalls.Any(
                ac => ac.Method.Name == "Retrieve"
                    && ac.Method.GetParameters()[0].ParameterType == typeof(ListingOf<StubViewModel>)
            ));
        }
Exemplo n.º 28
0
        public IEnumerable<IViewToken> FindViews(TypePool types)
        {
            IEnumerable<Type> actionTypes = types.TypesMatching(_sparkActionEndPointConventionFilter);

            var viewTokens = new List<IViewToken>();
            actionTypes.Each(actionType =>
                                 {
                                     var sparkBatchEntry = new SparkBatchEntry {ControllerType = actionType};
                                     IList<SparkViewDescriptor> descriptors = _viewFactory.CreateDescriptors(sparkBatchEntry, _getActionNameFromCallConvention);
                                     viewTokens.Add(new SparkViewToken(descriptors));
                                 });
            return viewTokens;
        }
Exemplo n.º 29
0
        public IEnumerable<IViewToken> FindViews(TypePool types)
        {
            IEnumerable<Type> actionTypes = types.TypesMatching(_actionEndPointFilter);

            var viewTokens = new List<IViewToken>();
            actionTypes.Each(actionType =>
                                 {
                                     var sparkBatchEntry = new SparkBatchEntry { ControllerType = actionType };
                                     string viewLocatorName = _getViewLocatorNameFromActionType(actionType);
                                     IList<SparkViewDescriptor> descriptors = _viewFactory.CreateDescriptors(sparkBatchEntry, viewLocatorName);
                                     viewTokens.Add(new SparkViewToken(descriptors));
                                 });
            return viewTokens;
        }
Exemplo n.º 30
0
 public void Setup()
 {
     var types = new TypePool(null);
     _observer = new RecordingConfigurationObserver();
     _action = ActionCall.For<ViewsForActionFilterTesterController>(x => x.AAction());
     _fromFindsOne = new FakeViewToken();
     _fromSecondFindsOne = new FakeViewToken();
     _views = new ViewBag(new IViewToken[] { _fromFindsOne, _fromSecondFindsOne });
     _filterThatFindsNone = createFilterThatReturns(new IViewToken[0]);
     _firstFilterThatFindsExactlyOne = createFilterThatReturns(_fromFindsOne);
     _secondFilterThatFindsExactlyOne = createFilterThatReturns(_fromSecondFindsOne);
     _filterThatFindsMultiple = createFilterThatReturns(_fromFindsOne, _fromSecondFindsOne);
     _viewAttacher = new ViewAttacher(types);
 }
Exemplo n.º 31
0
        public static IEnumerable<IFubuRegistryExtension> FindAllExtensions()
        {
            if (!PackageRegistry.PackageAssemblies.Any()) return new IFubuRegistryExtension[0];

            var pool = new TypePool(null);

            pool.AddAssemblies(PackageRegistry.PackageAssemblies);

            // Yeah, it really does have to be this way
            return pool.TypesMatching(
                t =>
                hasDefaultCtor(t) && t.GetInterfaces().Any(i => i.FullName == typeof (IFubuRegistryExtension).FullName))
                .Select(buildExtension);
        }
Exemplo n.º 32
0
        public IEnumerable<IViewToken> FindViews(TypePool types, BehaviorGraph graph)
        {
            // TODO: Make it not filter against view model as the
            // default view attacher conventions will do this.
            // Opens up for returning view with no model in edge cases
            // and add custom view attacher convention.

            return _templateRegistry
                .AllTemplates()
                .Where(x => x.Descriptor is ViewDescriptor)
                .Select(x => x.Descriptor.As<ViewDescriptor>())
                .Where(x => x.HasViewModel())
                .Select(x => new SparkViewToken(x));
        }
Exemplo n.º 33
0
        public IEnumerable<Type> FindApplicationSourceTypes(ApplicationSettings settings)
        {
            var assemblies = AssembliesFromApplicationBaseDirectory(x => true);
            if (!assemblies.Any())
            {
                var assemblyName = Path.GetFileName(settings.GetApplicationFolder());
                assemblies = AssembliesFromApplicationBaseDirectory(x => x.GetName().Name == assemblyName);
            }

            var types = new TypePool {IgnoreExportTypeFailures = true};
            types.AddAssemblies(assemblies);

            return types.TypesMatching(x => x.CanBeCastTo<IApplicationSource>() && x.IsConcreteWithDefaultCtor());
        }
Exemplo n.º 34
0
        public BehaviorGraph()
        {
            _log = new ConfigLog(this);

            _settings = new SettingsCollection(null);
            _settings.Replace(SessionStateRequirement.RequiresSessionState);

            RouteIterator = new SortByRouteRankIterator(); // can override in a registry

            TypeResolver = new TypeResolver();
            _services.AddService <ITypeResolver>(TypeResolver);

            Types = new TypePool(null); // need a default for some tests
        }
Exemplo n.º 35
0
 public IEnumerable<IViewToken> FindViews(TypePool types, BehaviorGraph graph)
 {
     var viewTokens = new List<IViewToken>();
     graph
         .Actions()
         .Where(call => _policyResolver.HasMatchFor(call))
         .Each(call =>
                     {
                         var sparkBatchEntry = new SparkBatchEntry { ControllerType = call.HandlerType };
                         string viewLocatorName = _policyResolver.ResolveViewLocator(call);
                         IList<SparkViewDescriptor> descriptors = _viewFactory.CreateDescriptors(sparkBatchEntry, viewLocatorName);
                         viewTokens.Add(new SparkViewToken(descriptors));
                     });
     return viewTokens;
 }
        public IEnumerable<ActionCall> FindActions(TypePool types)
        {
            var methodName = ReflectionHelper.GetMethod<ChannelWriter<Topic>>(x => x.Write(null))
                .Name;

            var topicTypes = types.TypesMatching(x => x.IsConcreteTypeOf<Topic>());

            foreach (var topicType in topicTypes)
            {
                var handlerType = typeof (ChannelWriter<>).MakeGenericType(topicType);
                var method = handlerType.GetMethod(methodName);

                yield return new ActionCall(handlerType, method);
            }
        }
Exemplo n.º 37
0
        public void Configure(BehaviorGraph graph)
        {
            var rules = graph.Settings.Get <AccessorRules>();

            var types = new TypePool(null);

            types.AddAssemblies(graph.Types.Assemblies.Union(PackageRegistry.PackageAssemblies));

            types.TypesMatching(x => x.CanBeCastTo <IAccessorRulesRegistration>() && x.IsConcreteWithDefaultCtor()).
            Distinct().Select(x => {
                return(Activator.CreateInstance(x).As <IAccessorRulesRegistration>());
            })
            .Each(x => x.AddRules(rules));

            graph.Services.AddService(rules);
        }
        public IEnumerable<ActionCall> FindActions(TypePool types)
        {
            var stateMachines = types.TypesMatching(t => t.Closes(typeof (StateMachine<>)));
            foreach(var sm in stateMachines)
            {
                //TODO: Where can I load things into the container - using ObjDef?
                var machine = (StateMachine)Activator.CreateInstance(sm);

                var t = typeof (StateMachineOptionsAction<>).MakeGenericType(sm);
                var ta =  new ActionCall(t, t.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));

                yield return ta;

                //need to fix this
                //current state?
                var tt = typeof(StateMachineInstanceOptionsAction<>).MakeGenericType(sm);
                yield return new ActionCall(tt, tt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));

                var ttt = typeof(StateMachineCurrentStateAction<>).MakeGenericType(sm);
                yield return new ActionCall(ttt, ttt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));

                foreach (var @event in machine.Events)
                {
                    //need to track the event name
                    //between here and the event url generation
                    //so I used a custom ActionCall extension
                    var eventName = @event.Name;

                    var tttt = typeof (StateMachineRaiseSimpleEventAction<>).MakeGenericType(sm);
                    var eventType = @event.GetType();
                    if (eventType != typeof (SimpleEvent))
                    {
                        tttt = typeof (StateMachineRaiseDataEventAction<,>).MakeGenericType(sm, eventType);
                    }

                    var call = new EventActionCall(eventName, tttt,
                                                   tttt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));
                    yield return call;
                }

                yield break;
            }
        }
Exemplo n.º 39
0
        public void Activate(IEnumerable<IPackageInfo> packages, IPackageLog log)
        {
            var pool = new TypePool();
            pool.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            pool.IgnoreExportTypeFailures = true;

            pool.TypesMatching(type => type.IsConcreteWithDefaultCtor() && type.CanBeCastTo<TopicRegistry>())
                .Each(type => {
                    // All we have to do is create it to work
                    Activator.CreateInstance(type);
                });

            TopicGraph.AllTopics.All().Each(node => {
                node.Url = _urls.UrlFor(node.TopicType);
                if (!node.Url.StartsWith("/"))
                {
                    node.Url = "/" + node.Url; // has to be an absolute
                }
            });
        }
Exemplo n.º 40
0
 public void BuildBehaviors(TypePool pool, BehaviorGraph graph)
 {
     _graph = graph;
     buildActions(pool).Each(registerBehavior);
     _graph = null;
 }
Exemplo n.º 41
0
 private IEnumerable <ActionCall> buildActions(TypePool types)
 {
     return(_actionSources.SelectMany(actionSource => actionSource.FindActions(types)));
 }
Exemplo n.º 42
0
 public BehaviorAggregator(TypePool types, IEnumerable <IActionSource> sources)
 {
     _types   = types;
     _sources = sources;
 }
Exemplo n.º 43
0
 public IEnumerable <ActionCall> FindActions(TypePool types)
 {
     return(_actionType.PublicInstanceMethods().Where(_methodFilter.Matches)
            .Select(method => new ActionCall(_actionType, method)));
 }
Exemplo n.º 44
0
 public IEnumerable <ActionCall> FindActions(TypePool types)
 {
     return(types.TypesMatching(_typeFilters.Matches).SelectMany(actionsFromType));
 }