Example #1
0
 /// <summary>
 /// Creates a new instance of the DefaultFilesMiddleware.
 /// </summary>
 /// <param name="next">The next middleware in the pipeline.</param>
 /// <param name="hostingEnv">The <see cref="IGameHostEnvironment"/> used by this middleware.</param>
 /// <param name="options">The configuration options for this middleware.</param>
 public DefaultFilesMiddleware(RequestDelegate next, IGameHostEnvironment hostingEnv, IOptions <DefaultFilesOptions> options)
 {
     if (hostingEnv == null)
     {
         throw new ArgumentNullException(nameof(hostingEnv));
     }
     _next         = next ?? throw new ArgumentNullException(nameof(next));
     _options      = (options ?? throw new ArgumentNullException(nameof(options))).Value;
     _fileProvider = _options.FileProvider ?? Helpers.ResolveFileProvider(hostingEnv);
     _matchUrl     = _options.RequestPath;
 }
        public static void Initialize(this IGameHostEnvironment hostingEnvironment, string contentRootPath, GameHostOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (string.IsNullOrEmpty(contentRootPath))
            {
                throw new ArgumentException("A valid non-empty content root must be provided.", nameof(contentRootPath));
            }
            if (!Directory.Exists(contentRootPath))
            {
                throw new ArgumentException($"The content root '{contentRootPath}' does not exist.", nameof(contentRootPath));
            }

            hostingEnvironment.ApplicationName         = options.ApplicationName;
            hostingEnvironment.ContentRootPath         = contentRootPath;
            hostingEnvironment.ContentRootFileProvider = new PhysicalFileProvider(hostingEnvironment.ContentRootPath);

            var gameRoot = options.GameRoot;

            if (gameRoot == null)
            {
                // Default to /wwwroot if it exists.
                var gameroot = Path.Combine(hostingEnvironment.ContentRootPath, "gameroot");
                if (Directory.Exists(gameroot))
                {
                    hostingEnvironment.GameRootPath = gameroot;
                }
            }
            else
            {
                hostingEnvironment.GameRootPath = Path.Combine(hostingEnvironment.ContentRootPath, gameRoot);
            }

            if (!string.IsNullOrEmpty(hostingEnvironment.GameRootPath))
            {
                hostingEnvironment.GameRootPath = Path.GetFullPath(hostingEnvironment.GameRootPath);
                if (!Directory.Exists(hostingEnvironment.GameRootPath))
                {
                    Directory.CreateDirectory(hostingEnvironment.GameRootPath);
                }
                hostingEnvironment.GameRootFileProvider = new PhysicalFileProvider(hostingEnvironment.GameRootPath);
            }
            else
            {
                hostingEnvironment.GameRootFileProvider = new NullFileProvider();
            }

            hostingEnvironment.EnvironmentName =
                options.Environment ??
                hostingEnvironment.EnvironmentName;
        }
Example #3
0
 /// <summary>
 /// Creates a new instance of the StaticFileMiddleware.
 /// </summary>
 /// <param name="next">The next middleware in the pipeline.</param>
 /// <param name="hostingEnv">The <see cref="IGameHostEnvironment"/> used by this middleware.</param>
 /// <param name="options">The configuration options.</param>
 /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
 public StaticFileMiddleware(RequestDelegate next, IGameHostEnvironment hostingEnv, IOptions <StaticFileOptions> options, ILoggerFactory loggerFactory)
 {
     if (hostingEnv == null)
     {
         throw new ArgumentNullException(nameof(hostingEnv));
     }
     _next                = next ?? throw new ArgumentNullException(nameof(next));
     _options             = (options ?? throw new ArgumentNullException(nameof(options))).Value;
     _contentTypeProvider = options.Value.ContentTypeProvider ?? new FileExtensionContentTypeProvider();
     _fileProvider        = _options.FileProvider ?? Helpers.ResolveFileProvider(hostingEnv);
     _matchUrl            = _options.RequestPath;
     _logger              = (loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory))).CreateLogger <StaticFileMiddleware>();
 }
 /// <summary>
 /// Creates a new instance of the SendFileMiddleware.
 /// </summary>
 /// <param name="next">The next middleware in the pipeline.</param>
 /// <param name="hostingEnv">The <see cref="IGameHostEnvironment"/> used by this middleware.</param>
 /// <param name="encoder">The <see cref="HtmlEncoder"/> used by the default <see cref="HtmlDirectoryFormatter"/>.</param>
 /// <param name="options">The configuration for this middleware.</param>
 public DirectoryBrowserMiddleware(RequestDelegate next, IGameHostEnvironment hostingEnv, HtmlEncoder encoder, IOptions <DirectoryBrowserOptions> options)
 {
     if (hostingEnv == null)
     {
         throw new ArgumentNullException(nameof(hostingEnv));
     }
     if (encoder == null)
     {
         throw new ArgumentNullException(nameof(encoder));
     }
     _next         = next ?? throw new ArgumentNullException(nameof(next));
     _options      = (options ?? throw new ArgumentNullException(nameof(options))).Value;
     _fileProvider = _options.FileProvider ?? Helpers.ResolveFileProvider(hostingEnv);
     _formatter    = options.Value.Formatter ?? new HtmlDirectoryFormatter(encoder);
     _matchUrl     = _options.RequestPath;
 }
 public GenericGameHostService(IOptions <GenericGameHostServiceOptions> options,
                               IServer server,
                               ILoggerFactory loggerFactory,
                               DiagnosticListener diagnosticListener,
                               IProtoContextFactory protoContextFactory,
                               IApplicationBuilderFactory applicationBuilderFactory,
                               IEnumerable <IStartupFilter> startupFilters,
                               IConfiguration configuration,
                               IGameHostEnvironment hostingEnvironment)
 {
     Options                   = options.Value;
     Server                    = server;
     Logger                    = loggerFactory.CreateLogger <GenericGameHostService>();
     LifetimeLogger            = loggerFactory.CreateLogger("Microsoft.Hosting.Lifetime");
     DiagnosticListener        = diagnosticListener;
     ProtoContextFactory       = protoContextFactory;
     ApplicationBuilderFactory = applicationBuilderFactory;
     StartupFilters            = startupFilters;
     Configuration             = configuration;
     HostingEnvironment        = hostingEnvironment;
 }
 /// <summary>
 /// Creates a new instance of the SendFileMiddleware. Using <see cref="HtmlEncoder.Default"/> instance.
 /// </summary>
 /// <param name="next">The next middleware in the pipeline.</param>
 /// <param name="hostingEnv">The <see cref="IGameHostEnvironment"/> used by this middleware.</param>
 /// <param name="options">The configuration for this middleware.</param>
 public DirectoryBrowserMiddleware(RequestDelegate next, IGameHostEnvironment hostingEnv, IOptions <DirectoryBrowserOptions> options)
     : this(next, hostingEnv, HtmlEncoder.Default, options)
 {
 }
Example #7
0
 internal static IFileProvider ResolveFileProvider(IGameHostEnvironment hostingEnv) =>
 hostingEnv.GameRootFileProvider ?? throw new InvalidOperationException("Missing FileProvider.");