/// <summary> /// Creates database if it does not exist. /// </summary> /// <param name="builder">The <see cref="IApplicationBuilder"/> instance.</param> /// <param name="env">The <see cref="IApplicationBuilder"/> instance.</param> private static void CreateDatabaseSchema(IApplicationBuilder builder, IHostingEnvironment env) { bool databaseExists = false; DavContextOptions contextOptions = builder.ApplicationServices.GetService <IOptions <DavContextOptions> >().Value; SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(contextOptions.ConnectionString); // extracts initial catalog name string databaseName = sqlConnectionStringBuilder.InitialCatalog; // sets initial catalog to master sqlConnectionStringBuilder.InitialCatalog = "master"; using (SqlConnection sqlConnection = new SqlConnection(sqlConnectionStringBuilder.ConnectionString)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand($"SELECT db_id('{databaseName}')", sqlConnection)) { databaseExists = (sqlCommand.ExecuteScalar() != DBNull.Value); } if (!databaseExists) { RunScript(sqlConnection, File.ReadAllText(env.ContentRootPath + "\\DB.sql")); } } }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="httpContextAccessor">Http context.</param> /// <param name="configOptions">WebDAV Context configuration options.</param> /// <param name="socketService">Singleton instance of <see cref="WebSocketsService"/>.</param> public DavContext(IHttpContextAccessor httpContextAccessor, IOptions <DavContextOptions> configOptions , WebSocketsService socketService ) : base(httpContextAccessor.HttpContext) { this.contextOptions = configOptions.Value; this.currentUser = httpContextAccessor.HttpContext.User; this.socketService = socketService; }
/// <summary> /// Creates instance of this class. /// </summary> /// <param name="contextOptions">Context options.</param> /// <param name="userOptions">User options.</param> /// <param name="logger">Logger instance.</param> /// <param name="logMethod">Logging method for specific platform.</param> /// <param name="eventsService">Server sent events service for user notifications.</param> /// <param name="engine">Engine instance.</param> public WebDAVHttpListener( IOptions <DavContextOptions> contextOptions, IOptions <DavUserOptions> userOptions, ILogger logger, ILogMethod logMethod, EventsService eventsService, DavEngineAsync engine ) { this.contextOptions = contextOptions.Value; this.userOptions = userOptions.Value; this.logger = logger; this.eventsService = eventsService; this.engine = engine; this.logMethod = logMethod; Features.Set <IHttpRequestFeature>(new HttpRequestFeature()); Features.Set <IHttpResponseFeature>(new HttpResponseFeature()); digestProvider = new DigestAuthenticationProvider(GetPasswordAndRoles); }