Exemplo n.º 1
0
        public static ResolvedTreeRoot ParseResolvedTree(string markup, string fileName = "default.dothtml", DotvvmConfiguration configuration = null, bool checkErrors = true)
        {
            configuration = configuration ?? DefaultConfig;

            var tokenizer = new DothtmlTokenizer();

            tokenizer.Tokenize(markup);

            var parser = new DothtmlParser();
            var tree   = parser.Parse(tokenizer.Tokens);

            if (checkErrors)
            {
                CheckForErrors(tree);
            }

            var controlTreeResolver = configuration.ServiceProvider.GetRequiredService <IControlTreeResolver>();
            var validator           = ActivatorUtilities.CreateInstance <ControlUsageValidationVisitor>(configuration.ServiceProvider);

            return(controlTreeResolver.ResolveTree(tree, fileName)
                   .CastTo <ResolvedTreeRoot>()
                   .ApplyAction(new DataContextPropertyAssigningVisitor().VisitView)
                   .ApplyAction(x => { if (checkErrors)
                                       {
                                           CheckForErrors(x.DothtmlNode);
                                       }
                                })
                   .ApplyAction(new StylingVisitor(configuration).VisitView)
                   .ApplyAction(x => { if (checkErrors)
                                       {
                                           validator.VisitAndAssert(x);
                                       }
                                       else
                                       {
                                           validator.VisitView(x);
                                       } }));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DotvvmRouteTable"/> class.
 /// </summary>
 public DotvvmRouteTable(DotvvmConfiguration configuration)
 {
     this.configuration = configuration;
 }
Exemplo n.º 3
0
 private void ConfigureResources(DotvvmConfiguration config, string applicationPath)
 {
     // register custom resources and adjust paths to the built-in resources
 }
Exemplo n.º 4
0
 public StyleRepository(DotvvmConfiguration configuration)
 {
     this.configuration = configuration;
 }
 private void ConfigureResources(DotvvmConfiguration config, string applicationPath)
 {
     // register custom resources and adjust paths to the built-in resources
     config.Resources.Register("site", new StylesheetResource(new FileResourceLocation("~/Style/css/all.css")));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultViewModelSerializer"/> class.
 /// </summary>
 public DefaultViewModelSerializer(DotvvmConfiguration configuration)
 {
     this.viewModelProtector = configuration.ServiceLocator.GetService <IViewModelProtector>();
     this.JsonFormatting     = configuration.Debug ? Formatting.Indented : Formatting.None;
     this.viewModelMapper    = configuration.ServiceLocator.GetService <IViewModelSerializationMapper>();
 }
Exemplo n.º 7
0
 private void ConfigureControls(DotvvmConfiguration config, string applicationPath)
 {
     // register code-only controls and markup controls
     config.Markup.AddMarkupControl("cc", "Sample", "Home/Controls/Sample.dotcontrol");
 }
Exemplo n.º 8
0
 public DiagnosticsDataStore(IViewModelServerStore store, ServerSideCacheDiagnosticsOptions options, DotvvmConfiguration dotvvmConfiguration)
 {
     this.store               = store;
     this.options             = options;
     this.dotvvmConfiguration = dotvvmConfiguration;
 }
Exemplo n.º 9
0
 public DotvvmFileUploadMiddleware(OwinMiddleware next, DotvvmConfiguration configuration) : base(next)
 {
     this.configuration = configuration;
 }
Exemplo n.º 10
0
 public void Configure(DotvvmConfiguration config, string applicationPath)
 {
     config.AddBootstrap4Configuration();
     config.RouteTable.AutoDiscoverRoutes(new WebRouteStrategy(config));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultControlTreeResolver"/> class.
 /// </summary>
 public DefaultControlTreeResolver(DotvvmConfiguration configuration)
     : base(configuration.ServiceLocator.GetService <IControlResolver>(), configuration.ServiceLocator.GetService <IAbstractTreeBuilder>())
 {
     this.bindingExpressionBuilder = configuration.ServiceLocator.GetService <IBindingExpressionBuilder>();
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceManager"/> class.
 /// </summary>
 public ResourceManager(DotvvmConfiguration configuration)
 {
     this.configuration = configuration;
 }
        public TextFileDiagnosticsInformationSender(DotvvmConfiguration config)
        {
            this.config = config;

            logFilePath = GetFilePath();
        }
Exemplo n.º 14
0
 public static DotvvmConfiguration CreateConfiguration(Action <IServiceCollection> customServices = null) =>
 DotvvmConfiguration.CreateDefault(s => {
     customServices?.Invoke(s);
     RegisterMoqServices(s);
 });
Exemplo n.º 15
0
 private void ConfigureRoutes(DotvvmConfiguration config, string applicationPath)
 {
     config.RouteTable.Add("_Default", "", "Views/_default.dothtml");
     config.RouteTable.AutoDiscoverRoutes(new SamplesRouteStrategy(config));
 }
Exemplo n.º 16
0
 public BindingCompiler(DotvvmConfiguration configuration)
 {
     this.configuration = configuration;
 }
Exemplo n.º 17
0
 public SamplesRouteStrategy(DotvvmConfiguration config) : base(config)
 {
 }
Exemplo n.º 18
0
 public BindingPropertyResolvers(IBindingExpressionBuilder bindingParser, StaticCommandBindingCompiler staticCommandBindingCompiler, JavascriptTranslator javascriptTranslator, DotvvmConfiguration configuration)
 {
     this.configuration = configuration;
     this.bindingParser = bindingParser;
     this.staticCommandBindingCompiler = staticCommandBindingCompiler;
     this.javascriptTranslator         = javascriptTranslator;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultDotvvmViewBuilder"/> class.
 /// </summary>
 public DefaultDotvvmViewBuilder(DotvvmConfiguration configuration)
 {
     markupFileLoader      = configuration.ServiceLocator.GetService <IMarkupFileLoader>();
     controlBuilderFactory = configuration.ServiceLocator.GetService <IControlBuilderFactory>();
 }
Exemplo n.º 20
0
 private void ConfigureControls(DotvvmConfiguration config, string applicationPath)
 {
     // register code-only controls and markup controls
     config.Markup.AutoDiscoverControls(new DefaultControlRegistrationStrategy(config, "controls", "Controls"));
 }
Exemplo n.º 21
0
 private DotvvmConfiguration ApplyPatches(params JObject[] patches) => ApplyPatches(DotvvmConfiguration.CreateDefault(), patches);
Exemplo n.º 22
0
 public static ViewModelValidationError CreateModelError <T, TProp>(DotvvmConfiguration config, Expression <Func <T, TProp> > expr, string error) =>
 CreateModelError(config, (LambdaExpression)expr, error);
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DotvvmMiddleware" /> class.
 /// </summary>
 public DotvvmMiddleware(OwinMiddleware next, DotvvmConfiguration configuration, IList <IMiddleware> middlewares)
     : base(next)
 {
     Configuration    = configuration;
     this.middlewares = middlewares;
 }
Exemplo n.º 24
0
 public static ValidationResult CreateValidationResult <T>(DotvvmConfiguration config, string error, params Expression <Func <T, object> >[] expressions) =>
 CreateValidationResult(config, error, (LambdaExpression[])expressions);
Exemplo n.º 25
0
 public void Configure(DotvvmConfiguration config, string applicationPath)
 {
     config.RouteTable.Add("SampleA", "SampleA", "SampleA.dothtml", null);
 }
Exemplo n.º 26
0
 public static ViewModelValidationError CreateModelError(DotvvmConfiguration config, LambdaExpression expr, string error) =>
 new ViewModelValidationError
 {
     ErrorMessage = error,
     PropertyPath = GetPathFromExpression(config, expr)
 };
Exemplo n.º 27
0
 private void ConfigureControls(DotvvmConfiguration config, string applicationPath)
 {
     // register code-only controls and markup controls
 }
Exemplo n.º 28
0
 public static ValidationResult CreateValidationResult(DotvvmConfiguration config, string error, LambdaExpression[] expr) =>
 new ValidationResult(
     error,
     expr.Select(e => GetPathFromExpression(config, e)).ToArray()
     );
Exemplo n.º 29
0
 // For more information about this class, visit https://dotvvm.com/docs/tutorials/basics-project-structure
 public void Configure(DotvvmConfiguration config, string applicationPath)
 {
     ConfigureRoutes(config, applicationPath);
     ConfigureControls(config, applicationPath);
     ConfigureResources(config, applicationPath);
 }
Exemplo n.º 30
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                LoginPath            = new PathString("/ComplexSamples/Auth/Login"),
                AuthenticationScheme = "Scheme1"
            });
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                LoginPath            = new PathString("/ComplexSamples/SPARedirect/login"),
                AuthenticationScheme = "Scheme2"
            });
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme = "Scheme3"
            });
            //     app.UseMiddleware<SwitchMiddleware>(
            //         new List<SwitchMiddlewareCase>() {
            //             new SwitchMiddlewareCase(
            //                 c => c.Request.Uri.PathAndQuery.StartsWith("/ComplexSamples/Auth"), next =>
            //                 new CookieAuthenticationMiddleware(next, app, new CookieAuthenticationOptions()
            //                 {
            //                     LoginPath = new PathString("/ComplexSamples/Auth/Login"),
            //AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme,

            //                     Provider = new CookieAuthenticationProvider()
            //                     {
            //                         OnApplyRedirect = c =>
            //                         {
            //                             // redirect to login page on 401 request
            //                             if (c.Response.StatusCode == 401 && c.Request.Method == "GET")
            //                             {
            //                                 c.Response.StatusCode = 302;
            //                                 c.Response.Headers["Location"] = c.RedirectUri;
            //                             }
            //                             // do not do anything on redirection to returnurl
            //                             // to not return page when ViewModel is expected
            //                             // we should implement this in DotVVM framework,
            //                             // not samples
            //                         }
            //                     }
            //                 })
            //             ),
            //             new SwitchMiddlewareCase(
            //                 c => c.Request.Uri.PathAndQuery.StartsWith("/ComplexSamples/SPARedirect"), next =>
            //                 new CookieAuthenticationMiddleware(next, app, new CookieAuthenticationOptions()
            //                 {
            //                     LoginPath = new PathString("/ComplexSamples/SPARedirect/login"),
            //                     AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            //                     Provider = new CookieAuthenticationProvider()
            //                     {
            //                         OnApplyRedirect = c =>
            //                         {
            //                             // redirect to login page on 401 request
            //                             if (c.Response.StatusCode == 401 && c.Request.Method == "GET")
            //                             {
            //                                 c.Response.StatusCode = 302;
            //                                 c.Response.Headers["Location"] = c.RedirectUri;
            //                             }
            //                             // do not do anything on redirection to returnurl
            //                             // to not return page when ViewModel is expected
            //                             // we should implement this in DotVVM framework,
            //                             // not samples
            //                         }
            //                     }
            //                 })
            //             ),
            //              new SwitchMiddlewareCase(
            //                 c => c.Request.Uri.PathAndQuery.StartsWith("/ControlSamples/AuthenticatedView")
            //                     || c.Request.Uri.PathAndQuery.StartsWith("/ControlSamples/RoleView"), next =>
            //                 new CookieAuthenticationMiddleware(next, app, new CookieAuthenticationOptions()
            //                 {
            //                     AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie
            //                 })
            //             ),
            //         }
            //     );

            var applicationPhysicalPath = env.ContentRootPath;

            // use DotVVM
            DotvvmConfiguration dotvvmConfiguration = app.UseDotVVM <DotvvmStartup>(applicationPhysicalPath);

            dotvvmConfiguration.Debug = true;

            // use static files
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(applicationPhysicalPath)
            });
        }