private async Task<HttpResponseMessage> ExecuteActualRequest(HttpControllerContext controllerContext, CancellationToken cancellationToken, MixedModeRequestAuthorizer authorizer) { if (SkipAuthorizationSinceThisIsMultiGetRequestAlreadyAuthorized == false) { HttpResponseMessage authMsg; if (authorizer.TryAuthorize(this, out authMsg) == false) return authMsg; } if (IsInternalRequest == false) RequestManager.IncrementRequestCount(); if (DatabaseName != null && await DatabasesLandlord.GetDatabaseInternal(DatabaseName) == null) { var msg = "Could not find a database named: " + DatabaseName; return GetMessageWithObject(new { Error = msg }, HttpStatusCode.ServiceUnavailable); } var sp = Stopwatch.StartNew(); var result = await base.ExecuteAsync(controllerContext, cancellationToken); sp.Stop(); AddRavenHeader(result, sp); return result; }
public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) throw new ArgumentNullException("configuration"); try { HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); if (db == null) { configuration.UpdateDataDirForLegacySystemDb(); systemDatabase = new DocumentDatabase(configuration); systemDatabase.SpinBackgroundWorkers(); } else { systemDatabase = db; } fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); } catch { if (systemDatabase != null) systemDatabase.Dispose(); throw; } }
private async Task<HttpResponseMessage> ExecuteActualRequest(HttpControllerContext controllerContext, CancellationToken cancellationToken, MixedModeRequestAuthorizer authorizer) { HttpResponseMessage authMsg; if (authorizer.TryAuthorize(this, out authMsg) == false) return authMsg; if (IsInternalRequest == false) RequestManager.IncrementRequestCount(); var fileSystemInternal = await CountersLandlord.GetCounterInternal(CountersName); if (fileSystemInternal == null) { var msg = "Could not find a counters named: " + CountersName; return GetMessageWithObject(new { Error = msg }, HttpStatusCode.ServiceUnavailable); } var sp = Stopwatch.StartNew(); var result = await base.ExecuteAsync(controllerContext, cancellationToken); sp.Stop(); AddRavenHeader(result, sp); return result; }
public WebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix) { DatabasesLandlord = databasesLandlord; this.countersLandlord = countersLandlord; this.fileSystemsLandlord = fileSystemsLandlord; this.authorizer = authorizer; this.expectedRequestSuffix = expectedRequestSuffix; }
public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) throw new ArgumentNullException("configuration"); try { HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); ThreadPool.SetMinThreads(configuration.MinThreadPoolWorkerThreads, configuration.MinThreadPoolCompletionThreads); if (db == null) { configuration.UpdateDataDirForLegacySystemDb(); systemDatabase = new DocumentDatabase(configuration); systemDatabase.SpinBackgroundWorkers(false); } else { systemDatabase = db; } WebSocketBufferPool.Initialize(configuration.WebSockets.InitialBufferPoolSize); fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); serverStartupTasks = configuration.Container.GetExportedValues<IServerStartupTask>(); foreach (var task in serverStartupTasks) { toDispose.Add(task); task.Execute(this); } } catch { if (systemDatabase != null) systemDatabase.Dispose(); throw; } }
private static HttpConfiguration CreateHttpCfg( DatabasesLandlord databasesLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer mixedModeRequestAuthorizer, RequestManager requestManager) { var cfg = new HttpConfiguration(); cfg.Properties[typeof(DatabasesLandlord)] = databasesLandlord; cfg.Properties[typeof(FileSystemsLandlord)] = fileSystemsLandlord; cfg.Properties[typeof(MixedModeRequestAuthorizer)] = mixedModeRequestAuthorizer; cfg.Properties[typeof(RequestManager)] = requestManager; cfg.Formatters.Remove(cfg.Formatters.XmlFormatter); cfg.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new NaveValueCollectionJsonConverterOnlyForConfigFormatters()); cfg.Services.Replace(typeof(IAssembliesResolver), new MyAssemblyResolver()); cfg.Filters.Add(new RavenExceptionFilterAttribute()); cfg.MapHttpAttributeRoutes(); cfg.Routes.MapHttpRoute( "RavenFs", "ravenfs/{controller}/{action}", new {id = RouteParameter.Optional}); cfg.Routes.MapHttpRoute( "API Default", "{controller}/{action}", new { id = RouteParameter.Optional }); cfg.Routes.MapHttpRoute( "Database Route", "databases/{databaseName}/{controller}/{action}", new { id = RouteParameter.Optional }); cfg.MessageHandlers.Add(new GZipToJsonAndCompressHandler()); cfg.Services.Replace(typeof(IHostBufferPolicySelector), new SelectiveBufferPolicySelector()); cfg.EnsureInitialized(); return cfg; }
public HttpServer(InMemoryRavenConfiguration configuration, DocumentDatabase resourceStore) { HttpEndpointRegistration.RegisterHttpEndpointTarget(); if (configuration.RunInMemory == false) { if (configuration.CreatePluginsDirectoryIfNotExisting) { TryCreateDirectory(configuration.PluginsDirectory); } if (configuration.CreateAnalyzersDirectoryIfNotExisting) { TryCreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Analyzers")); } } SystemDatabase = resourceStore; SystemConfiguration = configuration; int val; if (int.TryParse(configuration.Settings["Raven/Tenants/MaxIdleTimeForTenantDatabase"], out val) == false) val = 900; maxTimeDatabaseCanBeIdle = TimeSpan.FromSeconds(val); if (int.TryParse(configuration.Settings["Raven/Tenants/FrequencyToCheckForIdleDatabases"], out val) == false) val = 60; frequencyToCheckForIdleDatabases = TimeSpan.FromSeconds(val); configuration.Container.SatisfyImportsOnce(this); InitializeRequestResponders(SystemDatabase); requestAuthorizer = new MixedModeRequestAuthorizer(); requestAuthorizer.Initialize(SystemDatabase, SystemConfiguration, () => currentTenantId.Value, this); foreach (var task in configuration.Container.GetExportedValues<IServerStartupTask>()) { task.Execute(this); } }
public AdminLogsWebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix) : base(databasesLandlord, countersLandlord, fileSystemsLandlord, authorizer, expectedRequestSuffix) { }