public Task GetSetupFile() { string serverRelativeFileName = new StringSegment( RouteMatch.Url, RouteMatch.MatchLength, RouteMatch.Url.Length - RouteMatch.MatchLength); return(GetStudioFileInternal(serverRelativeFileName)); }
public async Task GetStudioFile() { var filename = new StringSegment( RouteMatch.Url, RouteMatch.MatchLength, RouteMatch.Url.Length - RouteMatch.MatchLength); var env = (IHostingEnvironment)HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)); var basePath = Server.Configuration.Core.StudioDirectory ?? env.ContentRootPath; var file = TryGetFileName(basePath, filename); if (file != null) { await WriteFile(file); return; } var zipFilePath = Path.Combine(basePath, "Raven.Studio.zip"); if (File.Exists(zipFilePath) == false) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } WriteFileFromZip(zipFilePath, filename); }
public Task GetStudioFile() { // This is casted to string on purpose here. Everything else works // with strings, so reifying this now is good. string serverRelativeFileName = new StringSegment( RouteMatch.Url, RouteMatch.MatchLength, RouteMatch.Url.Length - RouteMatch.MatchLength); return(GetStudioFileInternal(serverRelativeFileName)); }
public async Task GetStudioFile() { // This is casted to string on purpose here. Everything else works // with strings, so reifying this now is good. string serverRelativeFileName = new StringSegment( RouteMatch.Url, RouteMatch.MatchLength, RouteMatch.Url.Length - RouteMatch.MatchLength); HttpContext.Response.Headers["Raven-Static-Served-From"] = "Cache"; if (await ServeFromCache(serverRelativeFileName)) { return; } if (Server.Configuration.Http.UseResponseCompression) { // We may create a cache compression task if it is needed if (_pendingEntriesToCompress > PendingEntriesToProcess && CacheProcessingHappening.Raise()) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(() => CacheCompress()).ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } } var env = (IHostingEnvironment)HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)); var basePath = Server.Configuration.Studio.Path ?? env.ContentRootPath; HttpContext.Response.Headers["Raven-Static-Served-From"] = "ZipFile"; if (await ServeFromZipFile(basePath, serverRelativeFileName)) { return; } HttpContext.Response.Headers["Raven-Static-Served-From"] = "FileSystem"; if (await ServeFromFileSystem(basePath, serverRelativeFileName)) { return; } // If nothing worked, just inform that the page was not found. HttpContext.Response.Headers["Raven-Static-Served-From"] = "Unserved"; var message = $"The following file was not available: " + $"{serverRelativeFileName}. Please make sure that the Raven" + $".Studio.zip file exist in the main directory (near the " + $"Raven.Server.exe)."; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; HttpContext.Response.Headers["Content-Type"] = "text/plain; charset=utf-8"; await HttpContext.Response.WriteAsync(message); }
public Task GetSetupFile() { string serverRelativeFileName = new StringSegment( RouteMatch.Url, RouteMatch.MatchLength, RouteMatch.Url.Length - RouteMatch.MatchLength); // if user asks for entry point but we are already configured redirect to studio if (ServerStore.Configuration.Core.SetupMode != SetupMode.Initial) { HttpContext.Response.Headers["Location"] = "/studio/" + serverRelativeFileName; HttpContext.Response.StatusCode = (int)HttpStatusCode.Moved; return(Task.CompletedTask); } return(GetStudioFileInternal(serverRelativeFileName)); }
public Task GetEulaFile() { if (ServerStore.LicenseManager.IsEulaAccepted) { // redirect to studio - if user didn't configured it yet // then studio endpoint redirect to wizard HttpContext.Response.Headers["Location"] = "/studio/index.html"; HttpContext.Response.StatusCode = (int)HttpStatusCode.Moved; return(Task.CompletedTask); } string serverRelativeFileName = new StringSegment( RouteMatch.Url, RouteMatch.MatchLength, RouteMatch.Url.Length - RouteMatch.MatchLength); return(GetStudioFileInternal(serverRelativeFileName)); }
private static void ThrowDatabaseLoadTimeoutWithLog(StringSegment databaseName, TimeSpan timeout, string log) { throw new DatabaseLoadTimeoutException($"Database {databaseName} after {timeout} is still loading, try again later. Database initialization log: " + Environment.NewLine + log); }
private static void ThrowDatabaseLoadTimeout(StringSegment databaseName, TimeSpan timeout) { throw new DatabaseLoadTimeoutException($"Timeout when loading database {databaseName} after {timeout}, try again later"); }
private async Task UnlikelyWaitForDatabaseToLoad(RequestHandlerContext context, Task <DocumentDatabase> database, DatabasesLandlord databasesLandlord, StringSegment databaseName) { var time = databasesLandlord.DatabaseLoadTimeout; await Task.WhenAny(database, Task.Delay(time)); if (database.IsCompleted == false) { if (databasesLandlord.InitLog.TryGetValue(databaseName.Value, out var initLogQueue)) { var sb = new StringBuilder(); foreach (var logline in initLogQueue) { sb.AppendLine(logline); } ThrowDatabaseLoadTimeoutWithLog(databaseName, databasesLandlord.DatabaseLoadTimeout, sb.ToString()); } ThrowDatabaseLoadTimeout(databaseName, databasesLandlord.DatabaseLoadTimeout); } context.Database = await database; if (context.Database == null) { DatabaseDoesNotExistException.Throw(databaseName.Value); } }
private async Task UnlikelyWaitForDatabaseToUnload(RequestHandlerContext context, DocumentDatabase database, DatabasesLandlord databasesLandlord, StringSegment databaseName) { var time = databasesLandlord.DatabaseLoadTimeout; if (await database.DatabaseShutdownCompleted.WaitAsync(time) == false) { ThrowDatabaseUnloadTimeout(databaseName, databasesLandlord.DatabaseLoadTimeout); } await CreateDatabase(context); }