示例#1
0
        /// <summary>
        /// Creates a new <see cref="WebServer"/>.
        /// </summary>
        /// <param name="options">Web server options to use; set to <c>null</c> for defaults.</param>
        /// <param name="razorEngineCS">Razor engine instance for .cshtml templates; uses default instance if not provided.</param>
        /// <param name="razorEngineVB">Razor engine instance for .vbhtml templates; uses default instance if not provided.</param>
        public WebServer(WebServerOptions options = null, IRazorEngine razorEngineCS = null, IRazorEngine razorEngineVB = null)
        {
            m_releaseMode = !AssemblyInfo.EntryAssembly.Debuggable;

            if ((object)options == null)
            {
                options = new WebServerOptions();
            }

            m_options           = options;
            RazorEngineCS       = razorEngineCS ?? (m_releaseMode ? RazorEngine <CSharp> .Default : RazorEngine <CSharpDebug> .Default as IRazorEngine);
            RazorEngineVB       = razorEngineVB ?? (m_releaseMode ? RazorEngine <VisualBasic> .Default : RazorEngine <VisualBasicDebug> .Default as IRazorEngine);
            PagedViewModelTypes = new ConcurrentDictionary <string, Tuple <Type, Type> >(StringComparer.InvariantCultureIgnoreCase);
            m_etagCache         = new ConcurrentDictionary <string, long>(StringComparer.InvariantCultureIgnoreCase);
            m_handlerTypeCache  = new ConcurrentDictionary <string, Type>(StringComparer.InvariantCultureIgnoreCase);

            // Validate web root path
            m_options.WebRootPath = FilePath.AddPathSuffix(m_options.WebRootPath ?? RazorEngineCS.TemplatePath);

            m_fileWatcher = new SafeFileWatcher(m_options.WebRootPath)
            {
                IncludeSubdirectories = true,
                EnableRaisingEvents   = true
            };

            m_fileWatcher.Changed += m_fileWatcher_FileChange;
            m_fileWatcher.Deleted += m_fileWatcher_FileChange;
            m_fileWatcher.Renamed += m_fileWatcher_FileChange;
        }
示例#2
0
        public static WebServer GetConfiguredServer(string settingsCategory = null, IRazorEngine razorEngineCS = null, IRazorEngine razorEngineVB = null)
        {
            lock (typeof(WebServer))
            {
                if (string.IsNullOrWhiteSpace(settingsCategory))
                {
                    settingsCategory = "systemSettings";
                }

                return(s_configuredServers.GetOrAdd(settingsCategory, category =>
                {
                    // Get configured web server settings
                    CategorizedSettingsElementCollection settings = ConfigurationFile.Current.Settings[category];

                    settings.Add(nameof(WebServerOptions.WebRootPath), WebServerOptions.DefaultWebRootPath, "The root path for the hosted web server files. Location will be relative to install folder if full path is not specified.");
                    settings.Add(nameof(WebServerOptions.ClientCacheEnabled), WebServerOptions.DefaultClientCacheEnabled, "Determines if cache control is enabled for web server when rendering content to browser clients.");
                    settings.Add(nameof(WebServerOptions.MinifyJavascript), WebServerOptions.DefaultMinifyJavascript, "Determines if minification should be applied to rendered Javascript files.");
                    settings.Add(nameof(WebServerOptions.MinifyJavascriptExclusionExpression), WebServerOptions.DefaultMinifyJavascriptExclusionExpression, "Defines the regular expression that will exclude Javascript files from being minified. Empty value will target all files for minification.");
                    settings.Add(nameof(WebServerOptions.MinifyStyleSheets), WebServerOptions.DefaultMinifyStyleSheets, "Determines if minification should be applied to rendered CSS files.");
                    settings.Add(nameof(WebServerOptions.MinifyStyleSheetsExclusionExpression), WebServerOptions.DefaultMinifyStyleSheetsExclusionExpression, "Defines the regular expression that will exclude CSS files from being minified. Empty value will target all files for minification.");
                    settings.Add(nameof(WebServerOptions.UseMinifyInDebug), WebServerOptions.DefaultUseMinifyInDebug, "Determines if minification should be applied when running a Debug build.");
                    settings.Add(nameof(SessionHandler.SessionToken), SessionHandler.DefaultSessionToken, "Defines the token used for identifying the session ID in cookie headers.");
                    settings.Add(nameof(AuthenticationOptions.AuthTestPage), AuthenticationOptions.DefaultAuthTestPage, "Defines the page name for the web server to test if a user is authenticated.");
                    settings.Add(nameof(WebServerOptions.ErrorTemplateName), WebServerOptions.DefaultErrorTemplateName, "Defines the template file name to use when a Razor compile or execution exception occurs. Leave blank for none.");

                    WebServerOptions options = new WebServerOptions
                    {
                        WebRootPath = settings[nameof(WebServerOptions.WebRootPath)].ValueAs(WebServerOptions.DefaultWebRootPath),
                        ClientCacheEnabled = settings[nameof(WebServerOptions.ClientCacheEnabled)].ValueAsBoolean(WebServerOptions.DefaultClientCacheEnabled),
                        MinifyJavascript = settings[nameof(WebServerOptions.MinifyJavascript)].ValueAsBoolean(WebServerOptions.DefaultMinifyJavascript),
                        MinifyJavascriptExclusionExpression = settings[nameof(WebServerOptions.MinifyJavascriptExclusionExpression)].ValueAs(WebServerOptions.DefaultMinifyJavascriptExclusionExpression),
                        MinifyStyleSheets = settings[nameof(WebServerOptions.MinifyStyleSheets)].ValueAsBoolean(WebServerOptions.DefaultMinifyStyleSheets),
                        MinifyStyleSheetsExclusionExpression = settings[nameof(WebServerOptions.MinifyStyleSheetsExclusionExpression)].ValueAs(WebServerOptions.DefaultMinifyStyleSheetsExclusionExpression),
                        UseMinifyInDebug = settings[nameof(WebServerOptions.UseMinifyInDebug)].ValueAsBoolean(WebServerOptions.DefaultUseMinifyInDebug),
                        SessionToken = settings[nameof(SessionHandler.SessionToken)].ValueAs(SessionHandler.DefaultSessionToken),
                        AuthTestPage = settings[nameof(AuthenticationOptions.AuthTestPage)].ValueAs(AuthenticationOptions.DefaultAuthTestPage),
                        ErrorTemplateName = settings[nameof(WebServerOptions.ErrorTemplateName)].ValueAs(WebServerOptions.DefaultErrorTemplateName)
                    };

                    return new WebServer(options, razorEngineCS, razorEngineVB);
                }));
            }
        }
示例#3
0
        public static WebServer GetConfiguredServer(string settingsCategory = null, IRazorEngine razorEngineCS = null, IRazorEngine razorEngineVB = null)
        {
            lock (typeof(WebServer))
            {
                if (string.IsNullOrWhiteSpace(settingsCategory))
                {
                    settingsCategory = "systemSettings";
                }

                return(s_configuredServers.GetOrAdd(settingsCategory, category =>
                {
                    // Get configured web server settings
                    CategorizedSettingsElementCollection settings = ConfigurationFile.Current.Settings[category];

                    settings.Add("WebRootPath", WebServerOptions.DefaultWebRootPath, "The root path for the hosted web server files. Location will be relative to install folder if full path is not specified.");
                    settings.Add("ClientCacheEnabled", WebServerOptions.DefaultClientCacheEnabled, "Determines if cache control is enabled for web server when rendering content to browser clients.");
                    settings.Add("MinifyJavascript", WebServerOptions.DefaultMinifyJavascript, "Determines if minification should be applied to rendered Javascript files.");
                    settings.Add("MinifyStyleSheets", WebServerOptions.DefaultMinifyStyleSheets, "Determines if minification should be applied to rendered CSS files.");
                    settings.Add("UseMinifyInDebug", WebServerOptions.DefaultUseMinifyInDebug, "Determines if minification should be applied when running a Debug build.");
                    settings.Add("SessionToken", SessionHandler.DefaultSessionToken, "Defines the token used for identifying the session ID in cookie headers.");
                    settings.Add("AuthTestPage", AuthenticationOptions.DefaultAuthTestPage, "Defines the page name for the web server to test if a user is authenticated.");

                    WebServerOptions options = new WebServerOptions
                    {
                        WebRootPath = settings["WebRootPath"].ValueAs(WebServerOptions.DefaultWebRootPath),
                        ClientCacheEnabled = settings["ClientCacheEnabled"].ValueAsBoolean(WebServerOptions.DefaultClientCacheEnabled),
                        MinifyJavascript = settings["MinifyJavascript"].ValueAsBoolean(WebServerOptions.DefaultMinifyJavascript),
                        MinifyStyleSheets = settings["MinifyStyleSheets"].ValueAsBoolean(WebServerOptions.DefaultMinifyStyleSheets),
                        UseMinifyInDebug = settings["UseMinifyInDebug"].ValueAsBoolean(WebServerOptions.DefaultUseMinifyInDebug),
                        SessionToken = settings["SessionToken"].ValueAs(SessionHandler.DefaultSessionToken),
                        AuthTestPage = settings["AuthTestPage"].ValueAs(AuthenticationOptions.DefaultAuthTestPage)
                    };

                    return new WebServer(options, razorEngineCS, razorEngineVB);
                }));
            }
        }
示例#4
0
 internal ReadonlyWebServerOptions(WebServerOptions webServerOptions)
 {
     m_webServerOptions = webServerOptions;
 }