Example #1
0
        void ConfigureRegistrar(IControllerFactory factory, IControllerFactoryProcessor processor)
        {
            var r = new ControllerRegistrar(processor, factory);
            r.Add(new ReflectionControllerRegistrar());

            _registrar = r;
        }
        public void SetControllerFactory(IControllerFactory controllerFactory) {
            if (controllerFactory == null) {
                throw new ArgumentNullException("controllerFactory");
            }

            _factoryThunk = () => controllerFactory;
        }
        public ControllerActionInvoker(
            [NotNull] ActionContext actionContext,
            [NotNull] IReadOnlyList<IFilterProvider> filterProviders,
            [NotNull] IControllerFactory controllerFactory,
            [NotNull] ControllerActionDescriptor descriptor,
            [NotNull] IInputFormattersProvider inputFormatterProvider,
            [NotNull] IControllerActionArgumentBinder controllerActionArgumentBinder,
            [NotNull] IModelBinderProvider modelBinderProvider,
            [NotNull] IModelValidatorProviderProvider modelValidatorProviderProvider,
            [NotNull] IValueProviderFactoryProvider valueProviderFactoryProvider,
            [NotNull] IScopedInstance<ActionBindingContext> actionBindingContextAccessor,
            [NotNull] ITempDataDictionary tempData)
            : base(
                  actionContext, 
                  filterProviders,
                  inputFormatterProvider, 
                  modelBinderProvider, 
                  modelValidatorProviderProvider, 
                  valueProviderFactoryProvider,
                  actionBindingContextAccessor)
        {
            _descriptor = descriptor;
            _controllerFactory = controllerFactory;
            _argumentBinder = controllerActionArgumentBinder;
            _tempData = tempData;

            if (descriptor.MethodInfo == null)
            {
                throw new ArgumentException(
                    Resources.FormatPropertyOfTypeCannotBeNull("MethodInfo",
                                                               typeof(ControllerActionDescriptor)),
                    "descriptor");
            }
        }
        public void Execute(RequestContext requestContext)
        {
            HttpContextBase httpContext = requestContext.HttpContext;
            _factory = ControllerBuilder.Current.GetControllerFactory();

            if (httpContext.Request.Form.Count == 0) {
                // Raw HTTP Post request(s)

                var reader = new StreamReader(httpContext.Request.InputStream, new UTF8Encoding());
                string json = reader.ReadToEnd();

                if (json.StartsWith("[") && json.EndsWith("]")) {
                    // Batch of requests
                    var requests = JsonConvert.DeserializeObject<List<DirectRequest>>(json);
                    httpContext.Response.Write("[");
                    foreach (DirectRequest request in requests) {
                        ExecuteRequest(requestContext, request);
                        if (request != requests[requests.Count - 1]) {
                            httpContext.Response.Write(",");
                        }
                    }
                    httpContext.Response.Write("]");
                } else {
                    // Single request
                    var request = JsonConvert.DeserializeObject<DirectRequest>(json);
                    ExecuteRequest(requestContext, request);
                }
            } else {
                // Form Post request
                var request = new DirectRequest(httpContext.Request);
                ExecuteRequest(requestContext, request);
            }
        }
Example #5
0
		/// <summary>
		/// Contructor generally used for unit testing
		/// </summary>
		/// <param name="controllerFactory"></param>
		/// <param name="umbracoContext"></param>
		internal RenderRouteHandler(IControllerFactory controllerFactory, UmbracoContext umbracoContext)
		{
			if (controllerFactory == null) throw new ArgumentNullException("controllerFactory");
			if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
			_controllerFactory = controllerFactory;
			_umbracoContext = umbracoContext;
		}
        public MvcDynamicSessionControllerFactory(IControllerFactory originalFactory) {
            if (originalFactory == null) {
                throw new ArgumentNullException("originalFactory");
            }

            _originalFactory = originalFactory;
        }
            // IHttpAsyncHandler members
            public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback asyncCallback, object extraData)
            {
                IAsyncResult result = null;
                // Get the controller type
                string controllerName = _requestContext.RouteData.GetRequiredString("controller");

                // Obtain an instance of the controller
                _factory = ControllerBuilder.Current.GetControllerFactory();
                var controller = _factory.CreateController(_requestContext, controllerName) as ControllerBase;
                if (controller == null)
                  throw new InvalidOperationException("Can't locate the controller " + controllerName);

                try
                {
                  _asyncController = controller as AsyncController;
                  if (_asyncController == null)
                throw new InvalidOperationException("Controller isn't an AsyncController.");

                  // Set up asynchronous processing
                  _httpContext = HttpContext.Current; // Save this for later

                  result = _asyncController.Execute(_requestContext, asyncCallback);
                }
                finally
                {
                  if (result == null || result.CompletedSynchronously)
                  {
                this._factory.ReleaseController(controller);
                  }
                }

                return result;
            }
Example #8
0
 public void SetControllerFactory(IControllerFactory controllerFactory)
 {
     FactoryThunk += delegate()
     {
         return controllerFactory;
     };
 }
Example #9
0
 public static void Init(IControllerFactory controllerFactory)
 {
     if (instance == null)
     {
         instance = new Localization(controllerFactory);
     }
 }
        /// <summary>
        /// 创建控制器
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="controllerName"></param>
        /// <returns></returns>
        public IController CreateController(RequestContext requestContext, string controllerName)
        {
            try
            {
                IApplicationContext appContext = ContextRegistry.GetContext();
                string typeName = string.Format("{0}Controller", controllerName);
                IController controller = null;

                if (appContext.ContainsObject(typeName))
                {
                    controller = appContext.GetObject(typeName, typeof(IController)) as IController;
                }
                else
                {
                    if (this.m_defaultControllerFactory == null)
                    {
                        this.m_defaultControllerFactory = new DefaultControllerFactory();
                    }
                    controller = this.m_defaultControllerFactory.CreateController(requestContext, controllerName);
                }

                //logger.Debug(string.Format("CreateController: {0} - {1}", controllerName, controller));
                return controller;
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("CreateController: {0} - FAILED", controllerName), ex);
                return null;
            }
        }
Example #11
0
        public Func<IRequest, IArguments, Context, object> BuildExecuteFunc(MethodInfo methodInfo, IControllerFactory controllerFactory, IBinderFactory binderFactory)
        {
            var parameters = methodInfo.GetParameters();
            var localVars = new List<ParameterExpression>();
            var typedVars = new Dictionary<int, ParameterExpression>();
            var paramVars = new List< ParameterExpression>();
            var codeExprs = new List<Expression>();
            foreach (ParameterInfo paramInfo in parameters) {
               // BuildAssign
            }

            var getControllerInstance = Expression.Call(Expression.Constant(controllerFactory), GetOrCreateFactoryMethodInfo);
            var callAction = Expression.Call(getControllerInstance, methodInfo, paramVars);

            var labelTarget = Expression.Label(typeof(object));
            var returnValueExpr = Expression.Convert(callAction, typeof(object));
            var retExpr = Expression.Return(labelTarget, returnValueExpr);
            var labelExpr = Expression.Label(labelTarget, Expression.Constant(null,typeof(object)));
            codeExprs.Add(retExpr);
            codeExprs.Add(labelExpr);

            Expression block = Expression.Block(localVars,codeExprs);
            if (block.CanReduce)
            {
                block = block.ReduceAndCheck();
            }
            var lamda = Expression.Lambda<Func<IRequest, IArguments, Context,object>>(block);

            var result = lamda.Compile();
            return result;
        }
Example #12
0
 public static void RegisterIocUnityControllerFactory()
 {
     //Set for Controller Factory
     controllerFactory = new UnityControllerFactory();
     ControllerBuilder.Current.SetControllerFactory(controllerFactory);
     GlobalHost.DependencyResolver = new UnityConnectionDependencyResolver();
 }
 public ModoAdministrador(IControllerFactory pFactory)
 {
     this.iContFactory = pFactory;
     this.iFactory = new AdminModePagesFactory(this.iContFactory);
         
     InitializeComponent();
     this.Load += ModoAdministrador_Load;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerRouteCatalog"/> class.
 /// </summary>
 /// <param name="controllerFactory">The controller factory.</param>
 /// <param name="viewActivator">The view activator that is used to instantiate views.</param>
 public ControllerRouteCatalog(IControllerFactory controllerFactory, IViewActivator viewActivator)
 {
     Guard.ArgumentNotNull(controllerFactory, "controllerFactory");
     this.controllerFactory = controllerFactory;
     viewEngines = Framework.ViewEngines.CreateDefaults(viewActivator);
     modelBinders = Framework.ModelBinders.CreateDefaults();
     handler = new ControllerRouteHandler(this.controllerFactory, viewEngines, modelBinders);
 }
 public ReflectedActionInvokerProvider(IControllerFactory controllerFactory,
                                       IActionBindingContextProvider bindingProvider,
                                       INestedProviderManager<FilterProviderContext> filterProvider)
 {
     _controllerFactory = controllerFactory;
     _bindingProvider = bindingProvider;
     _filterProvider = filterProvider;
 }
Example #16
0
 public ViewPageResult(ContentItem thePage, IControllerMapper controllerMapper, IWebContext webContext, IActionInvoker actionInvoker)
 {
     this.controllerFactory = ControllerBuilder.Current.GetControllerFactory();
     this.thePage = thePage;
     this.controllerMapper = controllerMapper;
     this.webContext = webContext;
     this.actionInvoker = actionInvoker;
 }
 public RenderRouteHandler(IControllerFactory controllerFactory, 
     IRebelApplicationContext applicationContext, 
     IRenderModelFactory modelFactory)
 {
     _modelFactory = modelFactory;
     _applicationContext = applicationContext;
     _controllerFactory = controllerFactory;
 }
        public DefaultMvcHandler(IControllerFactory controllerFactory, IViewEngine viewEngine)
        {
            Requires.NotNull(controllerFactory, "controllerFactory");
            Requires.NotNull(viewEngine, "viewEngine");

            _controllerFactory = controllerFactory;
            ViewEngineManager.Current.Add(viewEngine);
        }
        public void SetControllerFactory(IControllerFactory controllerFactory)
        {
            if (controllerFactory == null)
            {
                throw new ArgumentNullException("controllerFactory");
            }

            _factoryThunk = () => controllerFactory;
        }
Example #20
0
 public SpecKTestLoader(
     IControllerFactory controllerFactory,
     ISubjectFactory subjectFactory,
     IIntrospectionPresenter introspectionPresenter)
     : base(introspectionPresenter)
 {
     _controllerFactory = controllerFactory;
     _subjectFactory    = subjectFactory;
 }
Example #21
0
        Controller INavigationResult.GetController(IControllerFactory controllerFactory, Stack<Controller> controllerHistory)
        {
            if (controllerHistory.Count > 0)
            {
                return controllerHistory.Pop();
            }

            return null;
        }
Example #22
0
        /// <summary>
        /// Dispatches the request.
        /// </summary>
        /// <param name="controllerFactory">The controller factory.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="action">The action.</param>
        private void DispatchRequest(IControllerFactory controllerFactory, string controller, string action)
        {
            var srvUrl = _requestContext.HttpContext.Request.Url.Scheme + "://" + _requestContext.HttpContext.Request.Url.Authority + "/";

            string currentRoute = _requestContext.HttpContext.Request.CurrentExecutionFilePath;
            string defaultPage  = srvUrl + System.Configuration.ConfigurationManager.AppSettings["DefaultPage"].ToString();

            _requestContext.HttpContext.Response.Redirect(defaultPage + "?referral" + currentRoute + "&" + "CurrentRoute=" + currentRoute);
        }
        public static void PreStart()
        {
            _factory = ControllerBuilder.Current.GetControllerFactory();

            var engine = MvcEngine.Create();
            _cmsFactory = ControllerBuilder.Current.GetControllerFactory();

            RouteTable.Routes.MapContentRoute("Content", engine);
        }
 public SinkApplicationContext(
     IFileWatcherService fileWatcherService,
     IControllerFactory controllerFactory,
     ISinkApplicationSettings applicationSettings)
 {
     _controllerFactory = controllerFactory;
     _applicationSettings = applicationSettings;
     FileWatcherService = fileWatcherService;
 }
    /// <summary>
    /// Replaces the cache field of a the DefaultControllerFactory's ControllerTypeCache.
    /// This ensures that only the specified controller types will be searched when instantiating a controller.
    /// As the ControllerTypeCache is internal, this uses some reflection hackery.
    /// </summary>
    public static void InitializeWithControllerTypes(this IControllerFactory factory, params Type[] controllerTypes)
    {
        var cache = controllerTypes
                    .GroupBy(t => t.Name.Substring(0, t.Name.Length - "Controller".Length), StringComparer.OrdinalIgnoreCase)
                    .ToDictionary(g => g.Key, g => g.ToLookup(t => t.Namespace ?? string.Empty, StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
        var buildManager = _typeCacheProperty.GetValue(factory, null);

        _cacheField.SetValue(buildManager, cache);
    }
Example #26
0
 public TypeLoader(
 IControllerFactory controllerFactory,
 ISubjectFactory subjectFactory,
 IIntrospectionPresenter introspectionPresenter)
     : base(introspectionPresenter)
 {
     _controllerFactory = controllerFactory;
       _subjectFactory = subjectFactory;
 }
Example #27
0
 public void ProcessInit(out IControllerFactory controllerFactory,out IController controller,ControllerContext controllerContext)
 {
     //Instanciate controllerFactory
     string controllerName = controllerContext.RequestContext.RouteData.GetRequiredString("Controller");
     controllerFactory = new DefaultControllerFactory(); //又他么写死了。
     controller = controllerFactory.CreateController(controllerName);
     controllerContext.Controller = controller as Controller;
     //关于这边的写法,我认为controllerContext不应该属于defaultcontrollerfactory,而应该只是作为外界传进去的一个参数,所以不应该把controllerContext作为工厂的一个属性或者变量存在。
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ControllerFactoryWrapper"/> class that wraps the specified controller factory.
        /// </summary>
        /// <param name="controllerFactory">The controller factory to wrap.</param>
        /// <exception cref="ArgumentNullException"><paramref name="controllerFactory"/> is <c>null</c>.</exception>
        public ControllerFactoryWrapper(IControllerFactory controllerFactory)
        {
            if (controllerFactory == null)
            {
                throw new ArgumentNullException("controllerFactory");
            }

            this.mControllerFactory = controllerFactory;
        }
Example #29
0
        public void Action(string actionName, string controllerName, ICollection <object> actionParameters)
        {
            IControllerFactory controllerFactory = EAppRuntime.Instance.CurrentApp.WinMvcControllerBuilder.GetControllerFactory();

            Type controllerType = controllerFactory.GetControllerType(controllerName);

            if (controllerType == null)
            {
                throw new InfrastructureException("Please specify an valid controller name or controller type.");
            }

            ControllerDescriptor controllerDescriptor = null;

            if (!ControllerDescriptorFactory.Contains(controllerName))
            {
                ControllerDescriptor newControllerDescriptor = new ReflectedControllerDescriptor(controllerName, controllerType);

                ControllerDescriptorFactory.AddControllerDescriptor(controllerName, newControllerDescriptor);
            }

            controllerDescriptor = ControllerDescriptorFactory.GetControllerDescriptor(controllerName);

            IController controller = controllerFactory.CreateController(controllerName);

            controller.View = this.view;

            if (controller == null)
            {
                throw new InfrastructureException("Please specify an valid controller name or controller type.");
            }

            ActionDescriptor actionDescriptorToExecute = controllerDescriptor.FindAction(actionName);

            if (actionDescriptorToExecute == null)
            {
                throw new InfrastructureException("Please specify an valid action name.");
            }

            ParameterDescriptor[] parameterDescriptorArray = actionDescriptorToExecute.GetParameters();

            SortedList <string, object> argumentValuesPair = new SortedList <string, object>();

            if (!actionParameters.Count.Equals(parameterDescriptorArray.Length))
            {
                throw new InfrastructureException("The length of arguments for the action {0} is incorrect.Please specify the correct arguments matching the action {1}.", actionName, actionName);
            }

            for (int parameterDescriptorIndex = 0; parameterDescriptorIndex < parameterDescriptorArray.Length; parameterDescriptorIndex++)
            {
                ParameterDescriptor parameterDescriptor = parameterDescriptorArray[parameterDescriptorIndex];

                argumentValuesPair.Add(parameterDescriptor.ParameterName, actionParameters.ElementAt(parameterDescriptorIndex));
            }

            controller.Execute(actionName, argumentValuesPair);
        }
Example #30
0
        static void Main()
        {
            BootStrap.Configure();
            IControllerFactory lContFactory = BootStrap.GetControllerFactory();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new ModoAdministrador(lContFactory));
            Application.Run(new Player());
        }
Example #31
0
        public Engine(IReader reader, IWriter writer, IControllerFactory controllerFactory, IWoWDbContext dbContext)
        {
            this.reader            = reader;
            this.writer            = writer;
            this.controllerFactory = controllerFactory;
            this.dbContext         = dbContext;

            this.LoggedIn        = false;
            this.CurrentUsername = "";
        }
 public ControllerFactoryDecorator(
     IControllerFactory controllerFactory
     )
 {
     if (controllerFactory == null)
     {
         throw new ArgumentNullException("controllerFactory");
     }
     this.innerControllerFactory = controllerFactory;
 }
Example #33
0
 public static Task <IOperationResult <ControllerResult> > CreateAndWaitResultAsync <T>(
     this ControllerBase thisController,
     IControllerFactory factory,
     CancellationToken controllerCancellationToken)
     where T : ControllerWithResultBase
 {
     return(thisController.CreateAndWaitResultAsyncInternal <T, ControllerResult>(
                factory: factory,
                controllerCancellationToken: controllerCancellationToken));
 }
Example #34
0
 public GenericActionInvoker(
     ActionContext actionContext,
     INestedProviderManager <FilterProviderContext> filterProvider,
     IControllerFactory controllerFactory,
     IControllerActionArgumentBinder argumentBinder)
     : base(actionContext, filterProvider)
 {
     _controllerFactory = controllerFactory;
     _argumentBinder    = argumentBinder;
 }
Example #35
0
        public static void PreStart()
        {
            _factory = ControllerBuilder.Current.GetControllerFactory();

            var engine = MvcEngine.Create();

            _cmsFactory = ControllerBuilder.Current.GetControllerFactory();

            RouteTable.Routes.MapContentRoute("Content", engine);
        }
 public ControllerActionInvokerProvider(IControllerFactory controllerFactory,
                                        IInputFormattersProvider inputFormattersProvider,
                                        INestedProviderManager <FilterProviderContext> filterProvider,
                                        IControllerActionArgumentBinder actionInvocationInfoProvider)
 {
     _controllerFactory            = controllerFactory;
     _inputFormattersProvider      = inputFormattersProvider;
     _filterProvider               = filterProvider;
     _actionInvocationInfoProvider = actionInvocationInfoProvider;
 }
 public void FactoriesWillMatchParamsArray(IControllerFactory[] expectedFactories)
 {
     // Fixture setup
     var sut = new CompositeControllerFactory(expectedFactories);
     // Exercise system
     var result = sut.Factories;
     // Verify outcome
     Assert.True(expectedFactories.SequenceEqual(result));
     // Teardown
 }
Example #38
0
 public ReflectedActionInvokerProvider(IControllerFactory controllerFactory,
                                       IActionBindingContextProvider bindingProvider,
                                       IInputFormattersProvider inputFormattersProvider,
                                       INestedProviderManager <FilterProviderContext> filterProvider)
 {
     _controllerFactory       = controllerFactory;
     _bindingProvider         = bindingProvider;
     _inputFormattersProvider = inputFormattersProvider;
     _filterProvider          = filterProvider;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AutofacControllerFactory"/> class. 
        /// Creates a new instance of UnityControllerFactory.
        /// </summary>
        /// <param name="autofacContainer">
        /// The unity container.
        /// </param>
        /// <exception cref="ArgumentException">
        /// The Argument Exception
        /// </exception>
        public AutofacControllerFactory(IComponentContext autofacContainer)
        {
            if (autofacContainer == null)
            {
                throw new ArgumentException();
            }

            this.container = autofacContainer;
            this.defaultFactory = new DefaultControllerFactory();
        }
Example #40
0
        public void ProxyControllerFactory(ExecutionInspector sut, IInspectorContext context, IControllerFactory controllerFactory)
        {
            context.ProxyFactory.Setup(f => f.IsWrapInterfaceEligible<IControllerFactory>(It.IsAny<Type>())).Returns(true);
            context.ProxyFactory.Setup(f => f.WrapInterface(It.IsAny<IControllerFactory>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>())).Returns(controllerFactory);

            sut.Setup(context);

            Assert.Equal(ControllerBuilder.Current.GetControllerFactory(), controllerFactory);
            context.Logger.Verify(l => l.Debug(It.Is<string>(s => s.Contains("IControllerFactory")), It.IsAny<object[]>()));
        }
Example #41
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AutofacControllerFactory"/> class.
        /// Creates a new instance of UnityControllerFactory.
        /// </summary>
        /// <param name="autofacContainer">
        /// The unity container.
        /// </param>
        /// <exception cref="ArgumentException">
        /// The Argument Exception
        /// </exception>
        public AutofacControllerFactory(IComponentContext autofacContainer)
        {
            if (autofacContainer == null)
            {
                throw new ArgumentException();
            }

            this.container      = autofacContainer;
            this.defaultFactory = new DefaultControllerFactory();
        }
Example #42
0
 public GameplayController(
     ISpawnManager spawnManager,
     IStatisticsManager statisticsManager,
     ISoundManager soundManager,
     IControllerFactory controllerFactory) : base(controllerFactory)
 {
     _spawnManager      = spawnManager;
     _statisticsManager = statisticsManager;
     _soundManager      = soundManager;
 }
        public ServerEventsProcessor(IControllerFactory controllerFactory)
        {
            if (controllerFactory == null)
                throw new ArgumentNullException("controllerFactory");

            this.controllerFactory = controllerFactory;

            this.OperatorProcessor = new OperatorProcessor(this.controllerFactory);
            this.ChatProcessor = new ChatProcessor(this.controllerFactory);
        }
Example #44
0
 /// <summary>
 /// Resets the state (only used from test cases)
 /// </summary>
 public void ResetState()
 {
     configuration            = null;
     mrContainer              = null;
     urlTokenizer             = null;
     engineContextFactory     = null;
     serviceProviderLocator   = null;
     controllerFactory        = null;
     controllerContextFactory = null;
     staticResourceRegistry   = null;
 }
Example #45
0
        public void ControllerBuilderReturnsDefaultControllerBuilderByDefault()
        {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();

            // Act
            IControllerFactory cf = cb.GetControllerFactory();

            // Assert
            Assert.IsInstanceOfType(cf, typeof(DefaultControllerFactory));
        }
Example #46
0
 public void ResetState()
 {
     _Configuration            = null;
     _MonoRailContainer        = null;
     _UrlTokenizer             = null;
     _EngineContextFactory     = null;
     _ServiceProviderLocator   = null;
     _ControllerFactory        = null;
     _ControllerContextFactory = null;
     _StaticResourceRegistry   = null;
 }
        /// <summary>
        /// Creates a controller using the controller factory
        /// </summary>
        private static ControllerBase CreateController(ControllerContext context, IControllerFactory factory, RouteDefinition routeDef)
        {
            var controller = factory.CreateController(context.RequestContext, routeDef.ControllerName) as ControllerBase;

            if (controller == null)
            {
                throw new InvalidOperationException("Could not create controller with name " + routeDef.ControllerName + ".");
            }

            return(controller);
        }
        public void DefaultControllerFactoryIsDefaultControllerFactory()
        {
            // Arrange
            ControllerBuilder builder = new ControllerBuilder();

            // Act
            IControllerFactory returnedControllerFactory = builder.GetControllerFactory();

            //Assert
            Assert.Equal(typeof(DefaultControllerFactory), returnedControllerFactory.GetType());
        }
Example #49
0
        public ControllerFactoryProvider(IControllerProvider controllerProvider, IControllerFactory controllerFactory = null)
        {
            if (controllerProvider == null)
            {
                throw new ArgumentNullException(nameof(controllerProvider));
            }

            _controllerCollection = controllerProvider.GetControllerCollection();

            _controllerFactory = controllerFactory ?? new ControllerFactory(); // 如果没有指定的IControllerFactory,则使用默认的ControllerFactory
        }
Example #50
0
 public GameRootController(
     IControllerFactory controllerFactory,
     GameOverSignal gameOverSignal,
     TickManager tickManager
     )
     : base(controllerFactory)
 {
     GameContextControllerFactoryProvider.Setup(controllerFactory);
     _tickManager    = tickManager;
     _gameOverSignal = gameOverSignal;
 }
        public void ControllerBuilderReturnsDefaultControllerBuilderByDefault()
        {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();

            // Act
            IControllerFactory cf = cb.GetControllerFactory();

            // Assert
            Assert.IsType <DefaultControllerFactory>(cf);
        }
Example #52
0
        public static ControllerBase GetControllerByName(this HtmlHelper htmlHelper, string controllerName)
        {
            IControllerFactory factory    = ControllerBuilder.Current.GetControllerFactory();
            IController        controller = factory.CreateController(htmlHelper.ViewContext.RequestContext, controllerName);

            if (controller == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "The IControllerFactory '{0}' did not return a controller for the name '{1}'.", factory.GetType(), controllerName));
            }
            return((ControllerBase)controller);
        }
        /// <summary>
        /// Gets a controller type by the name
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="requestContext"></param>
        /// <param name="controllerName"></param>
        /// <returns></returns>
        /// <remarks>
        /// This is related to issue: http://issues.umbraco.org/issue/U4-1726. We already have a method called GetControllerTypeInternal on our MasterControllerFactory,
        /// however, we cannot always guarantee that the usage of this will be a MasterControllerFactory like during unit tests. So we needed to create
        /// this extension method to do the checks instead.
        /// </remarks>
        internal static Type GetControllerTypeInternal(this IControllerFactory factory, RequestContext requestContext, string controllerName)
        {
            if (factory is MasterControllerFactory controllerFactory)
            {
                return(controllerFactory.GetControllerTypeInternal(requestContext, controllerName));
            }

            //we have no choice but to instantiate the controller
            var instance = factory.CreateController(requestContext, controllerName);

            return(instance?.GetType());
        }
Example #54
0
 public static Task <IOperationResult <TResult> > CreateAndWaitResultAsync <T, TResult>(
     this ControllerBase thisController,
     object arg,
     IControllerFactory factory,
     CancellationToken controllerCancellationToken)
     where T : ControllerWithResultBase <TResult>
 {
     return(thisController.CreateAndWaitResultAsyncInternal <T, TResult>(
                arg,
                factory,
                controllerCancellationToken: controllerCancellationToken));
 }
 /// <summary>
 /// Unregisters a command executor
 /// </summary>
 /// <summary>
 /// Unregisters the specified controller factory
 /// </summary>
 public void UnregisterControllerFactory( IControllerFactory controllerFactory )
 {
     Arguments.CheckNotNull( controllerFactory, "controllerFactory" );
     if ( !m_Factories.Contains( controllerFactory ) )
     {
         m_Log.WarnFormat( "Controller factory registry doesn't contain a factory \"{0}\" - ignoring remove", controllerFactory );
     }
     else
     {
         m_Factories.Remove( controllerFactory );
     }
 }
 public ControllerFactoryDecorator(
     IControllerFactory controllerFactory,
     ConfigurationSettings settings
     )
 {
     if (controllerFactory == null)
         throw new ArgumentNullException("controllerFactory");
     if (settings == null)
         throw new ArgumentNullException("settings");
     this.innerControllerFactory = controllerFactory;
     this.settings = settings;
 }
        public DishAddViewModel(IControllerFactory factory, ICategorySubject subject)
        {
            this.factory = factory;
            this.dish    = new DishAddDTO();

            this.SaveCommand = new DelegateCommand(Save, CanSave);

            this.Categories = new ObservableCollection <CategoryDisplayDTO>();

            subject.Subscribe(this);
            Update();
        }
Example #58
0
        public void ProcessRequest(HttpContext context)
        {
            // 下面是从当前请求上下文中获取控制器的名称
            string controllerName = this.RequestContext.RouteData.Controller;
            // 下面是得到 MVC 注册的控制器工厂
            IControllerFactory controllerFactory = ControllerBuilder.Current.GetControllerFactory();
            // 下面是由控制器工厂生产出控制器
            IController controller = controllerFactory.CreateController(this.RequestContext, controllerName);

            // 执行控制器,以及控制器里面的 Action
            controller.Execute(this.RequestContext);
        }
 public JsonMessageServer(
     ILogger <JsonMessageServer> logger,
     IServiceProvider services,
     IControllerFactory factory,
     IAuthorizationService authorization)
 {
     this.logger        = logger;
     this.services      = services;
     this.factory       = factory;
     this.authorization = authorization;
     this.connections   = new ConcurrentDictionary <IJsonClient, byte>();
 }
        /// <summary>
        /// Cleans up the controller by releasing it using the controller factory, and by disposing it.
        /// </summary>
        private static void CleanupController(IController controller, IControllerFactory factory)
        {
            if (controller != null)
            {
                factory.ReleaseController(controller);
            }

            if (controller != null)
            {
                controller.DisposeIfDisposable();
            }
        }