예제 #1
0
		public static IAppBuilder UseRavenDB(this IAppBuilder app, RavenDBOptions options)
		{
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}

			if (app.Properties.ContainsKey(HostOnAppDisposing))
			{
				// This is a katana specific key (i.e. not a standard OWIN key) to be notified
				// when the host in being shut down. Works both in HttpListener and SystemWeb hosting
				// Until owin spec is officially updated, there is no other way to know the host
				// is shutting down / disposing
				var appDisposing = app.Properties[HostOnAppDisposing] as CancellationToken?;
				if (appDisposing.HasValue)
				{
					appDisposing.Value.Register(options.Dispose);
				}
			}

			AssemblyExtractor.ExtractEmbeddedAssemblies(options.SystemDatabase.Configuration);

#if DEBUG
			app.UseInterceptor();
#endif

			app.Use((context, func) => UpgradeToWebSockets(options, context, func));

			app.UseWebApi(CreateHttpCfg(options));


			return app;
		}
예제 #2
0
		private static HttpConfiguration CreateHttpCfg(RavenDBOptions options)
		{
			var cfg = new HttpConfiguration();
			cfg.Properties[typeof(DatabasesLandlord)] = options.DatabaseLandlord;
            cfg.Properties[typeof(FileSystemsLandlord)] = options.FileSystemLandlord;
			cfg.Properties[typeof(CountersLandlord)] = options.CountersLandlord;
			cfg.Properties[typeof(MixedModeRequestAuthorizer)] = options.MixedModeRequestAuthorizer;
			cfg.Properties[typeof(RequestManager)] = options.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", "fs/{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;
		}
예제 #3
0
		private static async Task UpgradeToWebSockets(RavenDBOptions options, IOwinContext context, Func<Task> next)
		{
			var accept = context.Get<Action<IDictionary<string, object>, Func<IDictionary<string, object>, Task>>>("websocket.Accept");
			if (accept == null)
			{
				// Not a websocket request
				await next();
				return;
			}

			WebSocketsTransport webSocketsTrasport = WebSocketTransportFactory.CreateWebSocketTransport(options, context);

			if (webSocketsTrasport != null)
			{
				if (await webSocketsTrasport.TrySetupRequest())
				{
					accept(new Dictionary<string, object>()
					{
						{"websocket.ReceiveBufferSize", 256},
						{"websocket.Buffer", webSocketsTrasport.PreAllocatedBuffer},
						{"websocket.KeepAliveInterval", WebSocket.DefaultKeepAliveInterval}
					}, webSocketsTrasport.Run);
				}
			}
		}
예제 #4
0
	    public RavenDbServer Initialize(Action<RavenDBOptions> configure = null)
	    {
            owinHttpServer = new OwinHttpServer(configuration, useHttpServer: UseEmbeddedHttpServer, configure: configure);
            options = owinHttpServer.Options;
            serverThingsForTests = new ServerThingsForTests(options);
	        documentStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke);
	        documentStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url;
	        documentStore.Initialize();
	        return this;
	    }
		public void Execute(RavenDBOptions serverOptions)
		{
			options = serverOptions;

			int val;
			if (int.TryParse(ConfigurationManager.AppSettings["Raven/Bundles/LiveTest/Tenants/MaxIdleTimeForTenantResource"], out val) == false)
				val = 900;

			maxTimeResourceCanBeIdle = TimeSpan.FromSeconds(val);

			log.Info("LiveTestResourceCleanerStartupTask started. MaxTimeResourceCanBeIdle: " + maxTimeResourceCanBeIdle.TotalSeconds + " seconds.");

			options.SystemDatabase.TimerManager.NewTimer(ExecuteCleanup, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(10));
		}
예제 #6
0
	    public RavenDbServer Initialize(Action<RavenDBOptions> configure = null)
	    {
            owinHttpServer = new OwinHttpServer(configuration, useHttpServer: UseEmbeddedHttpServer, configure: configure);
            options = owinHttpServer.Options;
            serverThingsForTests = new ServerThingsForTests(options);
	        documentStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke);
	        documentStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url;
	        documentStore.Initialize();

			foreach (var task in configuration.Container.GetExportedValues<IServerStartupTask>())
			{
				task.Execute(this);
			}

	        return this;
	    }
예제 #7
0
		public void When_HostOnAppDisposing_key_not_exist_then_should_not_throw()
		{
			string path = NewDataPath();
			var configuration = new InMemoryRavenConfiguration { Settings =
			{
				{ "Raven/DataDir", path },
				{ Constants.FileSystem.DataDirectory, Path.Combine(path, "FileSystem")}
			} };

			configuration.Initialize();

			using (var options = new RavenDBOptions(configuration))
			{
				Assert.DoesNotThrow(() => new AppBuilder().UseRavenDB(options));
			}
			
		}
예제 #8
0
 private static async Task UpgradeToWebSockets(RavenDBOptions options, IOwinContext context, Func<Task> next)
 {
     var accept = context.Get<Action<IDictionary<string, object>, Func<IDictionary<string, object>, Task>>>("websocket.Accept");
     if (accept == null)
     {
         // Not a websocket request
         await next();
         return;
     }
     
     WebSocketsTransport webSocketsTrasport = WebSocketTransportFactory.CreateWebSocketTransport(options, context);
     
     if (webSocketsTrasport != null)
     {
         if (await webSocketsTrasport.TrySetupRequest())
             accept(null, webSocketsTrasport.Run);
     }
 }
예제 #9
0
파일: Startup.cs 프로젝트: j2jensen/ravendb
        public void Configuration(IAppBuilder app)
        {
            if (_server == null)
            {
                lock (locker)
                {
                    if (_server == null)
                    {
                        var p = Process.GetCurrentProcess();
                        var aid = AppDomain.CurrentDomain.Id;
                        bool explicitError = false;
                        try
                        {
                            Log.Info("Startup Configuration Called {0} times, process: {1}, app  domain: {2}", counter, p.Id, aid);
                            counter++;
                            var sp = Stopwatch.StartNew();
                            _server = new RavenDBOptions(new RavenConfiguration());
                            Log.Info("Startup Configuration completed in {0} , process: {1}, app  domain: {2}", sp.ElapsedMilliseconds, p.Id, aid);
                        }
                        catch (Exception ex)
                        {
                            Log.ErrorException(string.Format("Startup Configuration Failed, process: {0}, app  domain: {1}", p.Id, aid), ex);
                            explicitError = true;
                            if (_server != null)
                            {
                                _server.Dispose();
                                _server = null;
                            }

                            throw new HttpException(503, "Startup Configuration Failed", ex);
                        }
                        finally
                        {
                            if (_server == null && explicitError == false)
                            {
                                Log.Error("Statrup configuration completed without creating RavenDBOptions, probably aborted, process: {0}, app  domain: {1}", p.Id, aid);
                            }

                        }
                    }
                }
            }
            app.UseRavenDB(_server);
        }
예제 #10
0
파일: Startup.cs 프로젝트: j2jensen/ravendb
 public Startup(InMemoryRavenConfiguration config, DocumentDatabase db = null)
 {
     options = new RavenDBOptions(config, db);
 }
예제 #11
0
 public Startup(RavenConfiguration config, DocumentDatabase db = null)
 {
     options = new RavenDBOptions(config, db);
 }
예제 #12
0
		private static HttpConfiguration CreateHttpCfg(RavenDBOptions options)
		{
			var cfg = new HttpConfiguration();

			cfg.Properties[typeof(DatabasesLandlord)] = options.DatabaseLandlord;
			cfg.Properties[typeof(FileSystemsLandlord)] = options.FileSystemLandlord;
			cfg.Properties[typeof(CountersLandlord)] = options.CountersLandlord;
			cfg.Properties[typeof(MixedModeRequestAuthorizer)] = options.MixedModeRequestAuthorizer;
			cfg.Properties[typeof(RequestManager)] = options.RequestManager;
			cfg.Properties[Constants.MaxConcurrentRequestsForDatabaseDuringLoad] = new SemaphoreSlim(options.SystemDatabase.Configuration.MaxConcurrentRequestsForDatabaseDuringLoad);
            cfg.Properties[Constants.MaxSecondsForTaskToWaitForDatabaseToLoad] = options.SystemDatabase.Configuration.MaxSecondsForTaskToWaitForDatabaseToLoad;
			cfg.Formatters.Remove(cfg.Formatters.XmlFormatter);
			cfg.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new NaveValueCollectionJsonConverterOnlyForConfigFormatters());
			cfg.Services.Replace(typeof(IAssembliesResolver), new RavenAssemblyResolver());
			cfg.Filters.Add(new RavenExceptionFilterAttribute());

			cfg.MessageHandlers.Add(new ThrottlingHandler(options.SystemDatabase.Configuration.MaxConcurrentServerRequests));
			cfg.MessageHandlers.Add(new GZipToJsonAndCompressHandler());

			cfg.Services.Replace(typeof(IHostBufferPolicySelector), new SelectiveBufferPolicySelector());

			if (RouteCacher.TryAddRoutesFromCache(cfg) == false)
				AddRoutes(cfg);

			cfg.EnsureInitialized();

			RouteCacher.CacheRoutesIfNecessary(cfg);

			return cfg;
		}
예제 #13
0
        public RavenDbServer Initialize(Action<RavenDBOptions> configure = null)
        {
            if (configuration.IgnoreSslCertificateErrors == IgnoreSslCertificateErrorsMode.All)
            {
                // we ignore either all or none at the moment
                ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
            }
            BooleanQuery.MaxClauseCount = configuration.MaxClauseCount;

            owinHttpServer = new OwinHttpServer(configuration, useHttpServer: UseEmbeddedHttpServer, configure: configure);
            options = owinHttpServer.Options;
            serverThingsForTests = new ServerThingsForTests(options);
            Func<HttpMessageHandler> httpMessageHandlerFactory = ()=>new OwinClientHandler(owinHttpServer.Invoke, options.SystemDatabase.Configuration.EnableResponseLoggingForEmbeddedDatabases);
            documentStore.HttpMessageHandlerFactory = httpMessageHandlerFactory;
            documentStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url;
            documentStore.Initialize();

            filesStore.HttpMessageHandlerFactory = httpMessageHandlerFactory;
            filesStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url;
            filesStore.Initialize();

            return this;
        }
예제 #14
0
 public ServerThingsForTests(RavenDBOptions options)
 {
     this.options = options;
 }
예제 #15
0
		public RavenDbServer Initialize(Action<RavenDBOptions> configure = null)
		{
			if (configuration.IgnoreSslCertificateErros == IgnoreSslCertificateErrorsMode.All)
			{
				// we ignore either all or none at the moment
				ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
			}

			owinHttpServer = new OwinHttpServer(configuration, useHttpServer: UseEmbeddedHttpServer, configure: configure);
			options = owinHttpServer.Options;
			serverThingsForTests = new ServerThingsForTests(options);
			documentStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke);
			documentStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url;
			documentStore.Initialize();

			filesStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke);
			filesStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url;
			filesStore.Initialize();

			serverStartupTasks = configuration.Container.GetExportedValues<IServerStartupTask>();

			foreach (var task in serverStartupTasks)
			{
				toDispose.Add(task);
				task.Execute(this);
			}

	        return this;
	    }
예제 #16
0
 public void Execute(RavenDBOptions serverOptions)
 {
     options = serverOptions;
     options.SystemDatabase.TimerManager.NewTimer(ExecuteCheck, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(5));
 }
예제 #17
0
	    public void Execute(RavenDBOptions serverOptions)
		{
			options = serverOptions;
			options.SystemDatabase.TimerManager.NewTimer(ExecuteCheck, TimeSpan.Zero, frequency);
		}