Пример #1
0
        public void SetVariables(IDIResolver resolver)
        {
            var environment       = resolver.Resolve <IEnvironment>();
            var languageManager   = resolver.Resolve <ILanguageManagerProvider>().Get();
            var context           = resolver.Resolve <IWebContextProvider>().Get();
            var stopWatchProvider = resolver.Resolve <IStopwatchProvider>();

            _dataCollector.Add(VariableNameTemplatesPath, environment.TemplatesPath);
            _dataCollector.Add(VariableNameSiteStyle, environment.SiteStyle);

            if (!string.IsNullOrEmpty(languageManager.Language))
            {
                _dataCollector.Add(VariableNameCurrentLanguage, languageManager.Language);
                _dataCollector.Add(VariableNameCurrentLanguageExtension, "." + languageManager.Language);
                _dataCollector.Add(VariableNameCurrentLanguageCultureName, Thread.CurrentThread.CurrentCulture.TextInfo.CultureName);
                _dataCollector.Add(VariableNameCurrentLanguageCultureNameExtension, "." + Thread.CurrentThread.CurrentCulture.TextInfo.CultureName);
            }
            else
            {
                _dataCollector.Add(VariableNameCurrentLanguage, (string)null);
                _dataCollector.Add(VariableNameCurrentLanguageExtension, (string)null);
                _dataCollector.Add(VariableNameCurrentLanguageCultureName, (string)null);
                _dataCollector.Add(VariableNameCurrentLanguageCultureNameExtension, (string)null);
            }

            _dataCollector.Add(VariableNameSiteUrl, context.SiteUrl);
            _dataCollector.Add(VariableNameSiteVirtualPath, context.VirtualPath);

            if (!_disableAutomaticSiteTitleSet)
            {
                SetSiteTitleFromStringTable(context.Request.Path.Value, resolver.Resolve <IStringTable>());
            }

            _dataCollector.Add(VariableNameExecutionTime, stopWatchProvider.StopAndGetMeasurement().ToString("mm\\:ss\\:fff"));
        }
Пример #2
0
        /// <summary>
        /// Builds the modules accessor properties.
        /// </summary>
        /// <param name="modulesAccessor">The modules accessor.</param>
        /// <param name="resolver">The DI container resolver.</param>
        protected void BuildActionModulesAccessorProperties(ActionModulesAccessor modulesAccessor, IDIResolver resolver)
        {
            BuildModulesAccessorProperties(modulesAccessor, resolver);

            modulesAccessor.Context         = resolver.Resolve <IWebContextProvider>().Get();
            modulesAccessor.DataCollector   = resolver.Resolve <IDataCollector>();
            modulesAccessor.Redirector      = resolver.Resolve <IRedirector>();
            modulesAccessor.LanguageManager = resolver.Resolve <ILanguageManagerProvider>().Get();
            modulesAccessor.FileReader      = resolver.Resolve <IFileReader>();
        }
Пример #3
0
        /// <summary>
        /// Creates the view.
        /// </summary>
        /// <param name="viewType">Type of the view.</param>
        /// <param name="resolver"></param>
        /// <returns></returns>
        public View CreateView(Type viewType, IDIResolver resolver)
        {
            var view = (View)resolver.Resolve(viewType);

            BuildModulesAccessorProperties(view, resolver);

            view.Language = resolver.Resolve <ILanguageManagerProvider>().Get().Language;
            view.SiteUrl  = resolver.Resolve <IWebContextProvider>().Get().SiteUrl;

            return(view);
        }
Пример #4
0
        /// <summary>
        /// Builds a web page
        /// </summary>
        /// <param name="resolver">The DI container resolver.</param>
        /// <returns></returns>
        public string Build(IDIResolver resolver)
        {
            resolver.Resolve <IStringTableItemsSetter>().Set();
            resolver.Resolve <IContextVariablesSetter>().SetVariables(resolver);

            var tpl = _templateFactory.Load(resolver.Resolve <IEnvironment>().MasterTemplateFileName);

            foreach (var item in _dataCollector.Items.Keys)
            {
                tpl.Set(item, _dataCollector.Items[item]);
            }

            return(tpl.Get());
        }
Пример #5
0
        /// <summary>
        /// Creates the controller.
        /// </summary>
        /// <param name="controllerType">Type of the controller.</param>
        /// <param name="resolver">The DI container resolver.</param>
        /// <param name="context">The context.</param>
        /// <param name="routeParameters">The route parameters.</param>
        /// <returns></returns>
        public ControllerBase CreateController(Type controllerType, IDIResolver resolver, HttpContext context,
                                               dynamic?routeParameters = null)
        {
            var controller = (ControllerBase)resolver.Resolve(controllerType);

            BuildActionModulesAccessorProperties(controller, resolver);

            controller.RouteParameters = routeParameters;

            return(controller);
        }
Пример #6
0
        /// <summary>
        /// Builds the modules accessor properties.
        /// </summary>
        /// <param name="modulesAccessor">The modules accessor.</param>
        /// <param name="resolver">The DI container resolver.</param>
        protected void BuildModulesAccessorProperties(ModulesAccessor modulesAccessor, IDIResolver resolver)
        {
            BuildViewAccessorProperties(modulesAccessor, resolver);

            modulesAccessor.Environment = resolver.Resolve <IEnvironment>();

            var stringTable = resolver.Resolve <IStringTable>();

            modulesAccessor.StringTable        = stringTable.Items;
            modulesAccessor.StringTableManager = stringTable;

            modulesAccessor.TemplateFactory = resolver.Resolve <ITemplateFactory>();

            var htmlWrapper = new HtmlWrapper
            {
                ListsGenerator = resolver.Resolve <IListsGenerator>()
            };

            modulesAccessor.Html = htmlWrapper;
        }
        /// <summary>
        /// Throws the custom or string table exception.
        /// </summary>
        /// <param name="resolver">The resolver.</param>
        /// <exception cref="ModelValidationException">
        /// </exception>
        protected void TryThrowCustomOrStringTableException(IDIResolver resolver)
        {
            if (string.IsNullOrEmpty(ErrorMessage))
            {
                return;
            }

            if (IsMessageFromStringTable)
            {
                throw new ModelValidationException(resolver.Resolve <IStringTable>().GetItem(ErrorMessage));
            }

            throw new ModelValidationException(ErrorMessage);
        }
Пример #8
0
 /// <summary>
 /// Resolves the specified type.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="resolver">The DI resolver.</param>
 /// <returns></returns>
 public static T Resolve <T>(this IDIResolver resolver)
 {
     return((T)resolver.Resolve(typeof(T)));
 }
Пример #9
0
        /// <summary>
        /// Parses model and validates it asynchronously
        /// </summary>
        /// <typeparam name="T">Model type</typeparam>
        /// <param name="resolver">The resolver.</param>
        /// <returns></returns>
        public async Task <T> ProcessAsync <T>(IDIResolver resolver)
        {
            var args = new ModelBinderEventArgs <T>(_context);

            foreach (var binder in ModelBindersTypes.Select(binderType => (IModelBinder)resolver.Resolve(binderType)))
            {
                await binder.BindAsync(args);

                if (!args.IsBound)
                {
                    continue;
                }

                Validate(args, resolver);

                return(args.Model);
            }

            throw new ModelBindingException($"Unrecognized request content type for binding: {_context.Request.ContentType}");
        }
Пример #10
0
 private static void Validate <T>(ModelBinderEventArgs <T> args, IDIResolver resolver)
 {
     foreach (var validator in ModelValidatorsTypes.Select(x => (IModelValidator)resolver.Resolve(x)))
     {
         validator.Validate(args.Model, resolver);
     }
 }
Пример #11
0
 /// <summary>
 /// Resolves the specified type.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="resolver">The DI resolver.</param>
 /// <returns></returns>
 public static T Resolve <T>(this IDIResolver resolver) => (T)resolver.Resolve(typeof(T));
 /// <summary>
 /// Builds the view accessor properties.
 /// </summary>
 /// <param name="viewAccessor">The view accessor.</param>
 /// <param name="resolver">The DI container resolver.</param>
 protected void BuildViewAccessorProperties(ViewAccessor viewAccessor, IDIResolver resolver)
 {
     viewAccessor.Resolver    = resolver;
     viewAccessor.ViewFactory = resolver.Resolve <IViewFactory>();
 }
Пример #13
0
 /// <summary>
 /// Gets the service object of the specified type.
 /// </summary>
 /// <param name="serviceType">An object that specifies the type of service object to get.</param>
 /// <returns>
 /// A service object of type <paramref name="serviceType">serviceType</paramref>.   -or-  null if there is no service object of type <paramref name="serviceType">serviceType</paramref>.
 /// </returns>
 public object GetService(Type serviceType)
 {
     return(_resolver.Resolve(serviceType));
 }
Пример #14
0
        /// <summary>
        /// Builds the controller response properties.
        /// </summary>
        /// <param name="controllerResponse">The controller response.</param>
        /// <param name="resolver">The DI container resolver.</param>
        public void BuildControllerResponseProperties(ControllerResponse controllerResponse, IDIResolver resolver)
        {
            BuildActionModulesAccessorProperties(controllerResponse, resolver);

            controllerResponse.ResponseWriter = resolver.Resolve <IResponseWriter>();
        }