Dispose() public method

public Dispose ( ) : void
return void
Example #1
0
        protected override void OnStop()
        {
            var shutdownTask = startTask.ContinueWith(task =>
            {
                if (server != null)
                {
                    server.Dispose();
                }
                return(task);
            });

            var keepAliveTask = Task.Factory.StartNew(() =>
            {
                if (shutdownTask.Wait(9000))
                {
                    return;
                }
                do
                {
                    RequestAdditionalTime(10000);
                } while (!shutdownTask.Wait(9000));
            });

            Task.WaitAll(shutdownTask, keepAliveTask);
        }
Example #2
0
 protected override void OnStop()
 {
     if (server != null)
     {
         server.Dispose();
     }
 }
Example #3
0
 protected override void OnStop()
 {
     startTask.ContinueWith(task =>
     {
         if (server != null)
         {
             server.Dispose();
         }
         return(task);
     }).Wait();
 }
Example #4
0
        protected override void OnStop()
        {
            var shutdownTask = startTask.ContinueWith(task =>
            {
                if (server != null)
                {
                    try
                    {
                        server.Dispose();
                    }
                    catch (Exception e)
                    {
                        var message =
                            string.Format(
                                "Unhandled exception was thrown during stopping RavenDB service. Ignoring it to properly stop the service. Exception: {0}",
                                e.ToString());

                        LogManager.GetCurrentClassLogger().Error(message);

                        EventLog.WriteEntry(
                            message,
                            EventLogEntryType.Error);
                    }
                }
                return(task);
            });

            var keepAliveTask = Task.Factory.StartNew(() =>
            {
                if (shutdownTask.Wait(9000))
                {
                    return;
                }
                do
                {
                    RequestAdditionalTime(10000);
                } while (!shutdownTask.Wait(9000));
            });

            Task.WaitAll(shutdownTask, keepAliveTask);
        }
Example #5
0
 public IDocumentStore NewRemoteDocumentStoreWithUrl(int port, bool fiddler = false, RavenDbServer ravenDbServer = null, string databaseName = null,
     bool runInMemory = true,
     string dataDirectory = null,
     string requestedStorage = null,
     bool enableAuthentication = false)
 {
     ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory, dataDirectory: dataDirectory, requestedStorage: requestedStorage, enableAuthentication: enableAuthentication);
     ModifyServer(ravenDbServer);
     var store = new DocumentStore
     {
         Url = GetServerUrl(port),
         DefaultDatabase = databaseName,
     };
     stores.Add(store);
     store.AfterDispose += (sender, args) => ravenDbServer.Dispose();
     ModifyStore(store);
     return store.Initialize();
 }
Example #6
0
        protected RavenDbServer GetNewServer(int port = 8079,
            string dataDirectory = null,
            bool runInMemory = true,
            string requestedStorage = null,
            bool enableAuthentication = false,
            string activeBundles = null,
            Action<RavenDBOptions> configureServer = null,
            Action<InMemoryRavenConfiguration> configureConfig = null,
            [CallerMemberName] string databaseName = null)
        {
            databaseName = NormalizeDatabaseName(databaseName != Constants.SystemDatabase ? databaseName : null);

            checkPorts = true;
            if (dataDirectory != null)
                pathsToDelete.Add(dataDirectory);

            var storageType = GetDefaultStorageType(requestedStorage);
            var directory = dataDirectory ?? NewDataPath(databaseName == Constants.SystemDatabase ? null : databaseName);
            var ravenConfiguration = new RavenConfiguration();

            ConfigurationHelper.ApplySettingsToConfiguration(ravenConfiguration);

            ravenConfiguration.Port = port;
            ravenConfiguration.DataDirectory = Path.Combine(directory, "System");
            ravenConfiguration.RunInMemory = runInMemory;
#if DEBUG
            ravenConfiguration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction = runInMemory;
#endif
            ravenConfiguration.DefaultStorageTypeName = storageType;
            ravenConfiguration.AnonymousUserAccessMode = enableAuthentication ? AnonymousUserAccessMode.None : AnonymousUserAccessMode.Admin;

            ravenConfiguration.FileSystem.DataDirectory = Path.Combine(directory, "FileSystem");
            ravenConfiguration.Encryption.UseFips = ConfigurationHelper.UseFipsEncryptionAlgorithms;

            ravenConfiguration.Settings["Raven/StorageTypeName"] = ravenConfiguration.DefaultStorageTypeName;

            if (activeBundles != null)
            {
                ravenConfiguration.Settings["Raven/ActiveBundles"] = activeBundles;
            }

            if (configureConfig != null)
                configureConfig(ravenConfiguration);
            ModifyConfiguration(ravenConfiguration);

            ravenConfiguration.PostInit();

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenConfiguration.Port);
            var ravenDbServer = new RavenDbServer(ravenConfiguration)
            {
                UseEmbeddedHttpServer = true,
            };
            ravenDbServer.Initialize(configureServer);
            servers.Add(ravenDbServer);

            try
            {
                using (var documentStore = new DocumentStore
                {
                    Url = "http://localhost:" + port,
                    Conventions =
                    {
                        FailoverBehavior = FailoverBehavior.FailImmediately
                    },
                    DefaultDatabase = databaseName
                }.Initialize())
                {
                    CreateDefaultIndexes(documentStore);
                }
            }
            catch
            {
                ravenDbServer.Dispose();
                throw;
            }

            if (enableAuthentication)
            {
                EnableAuthentication(ravenDbServer.SystemDatabase);
                ModifyConfiguration(ravenConfiguration);
                ravenConfiguration.PostInit();
            }

            return ravenDbServer;
        }
Example #7
0
        /// <summary>
        /// Creates a new document store connecting to a remote RavenDb server.
        /// </summary>
        /// <param name="fiddler">Are all requests to the remote RavenDb server passed through Fiddler? (NOTE: This is only* for a localhost RavenDb server).</param>
        /// <param name="ravenDbServer">A RavenDb server.</param>
        /// <param name="databaseName">Name of the server that will show up on /admin/stats endpoint.</param>
        /// <param name="runInMemory">Whatever the database should run purely in memory. When running in memory, nothing is written to disk and if the server is restarted all data will be lost.<br/>Default: <b>true</b></param>
        /// <param name="dataDirectory">The path for the database directory. Can use ~\ as the root, in which case the path will start from the server base directory. <br/>Default: <b>~\Databases\System</b></param>
        /// <param name="requestedStorage">What storage type to use (see: RavenDB Storage engines).<br/>Allowed values: <b>vornon</b>, <b>esent</b>.<br/>Default: <b>voron</b></param>
        /// <param name="enableAuthentication"></param>
        /// <param name="ensureDatabaseExists">For a multi-tenant RavenDb server, creates the database if it doesn't already exist.</param>
        /// <param name="configureStore">An action delegate which allows you to configure the document store instance that is returned. eg. <code>configureStore: store => store.DefaultDatabase = "MasterDb"</code></param>
        /// <param name="activeBundles">Semicolon separated list of bundles names, such as: 'Replication;Versioning'.<br/>Default: no bundles turned on.</param>
        /// <param name="indexes">A collection of indexes to execute.</param>
        /// <param name="transformers">A collection of transformers to execute.</param>
        /// <param name="seedData">A collection of some fake data that will be automatically stored into the document store.</param>
        /// <param name="noStaleQueries">When you query an index, the query will wait for the index to complete it's indexing and not be stale -before- the query is executred.</param>
        /// <returns></returns>
        public DocumentStore NewRemoteDocumentStore(bool fiddler = false,
            RavenDbServer ravenDbServer = null,
            [CallerMemberName] string databaseName = null,
            bool runInMemory = true,
            string dataDirectory = null,
            string requestedStorage = null,
            bool enableAuthentication = false,
            bool ensureDatabaseExists = true,
            Action<DocumentStore> configureStore = null,
            string activeBundles = null,
            IEnumerable<AbstractIndexCreationTask> indexes = null,
            IEnumerable<AbstractTransformerCreationTask> transformers = null,
            IEnumerable<IEnumerable> seedData = null,
            bool noStaleQueries = false)
        {
            databaseName = NormalizeDatabaseName(databaseName);

            checkPorts = true;
            ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory,
                dataDirectory: dataDirectory,
                requestedStorage: requestedStorage,
                enableAuthentication: enableAuthentication,
                databaseName: databaseName,
                activeBundles: activeBundles);
            ModifyServer(ravenDbServer);
            var documentStore = new DocumentStore
            {
                Url = GetServerUrl(fiddler, ravenDbServer.SystemDatabase.ServerUrl),
                DefaultDatabase = databaseName
            };
            pathsToDelete.Add(Path.Combine(ravenDbServer.SystemDatabase.Configuration.DataDirectory, @"..\Databases"));
            stores.Add(documentStore);
            documentStore.AfterDispose += (sender, args) => ravenDbServer.Dispose();

            if (configureStore != null)
            {
                configureStore(documentStore);
            }

            ModifyStore(documentStore);

            documentStore.Initialize(ensureDatabaseExists);

            if (indexes != null)
            {
                ExecuteIndexes(indexes, documentStore);
            }

            if (noStaleQueries)
            {
                // When querying any map/reduce indexes, we'll wait until
                // the index has stopped being stale.
                documentStore.Listeners.RegisterListener(new NoStaleQueriesListener());
            }

            if (transformers != null)
            {
                ExecuteTransformers(transformers, documentStore);
            }

            if (seedData != null)
            {
                StoreSeedData(seedData, documentStore);
            }

            return documentStore;
        }
Example #8
0
		protected RavenDbServer GetNewServer(int port = 8079, string dataDirectory = "Data")
		{
			var ravenConfiguration = new RavenConfiguration
									 {
										 Port = port,
										 DataDirectory = dataDirectory,
										 RunInMemory = true,
										 AnonymousUserAccessMode = AnonymousUserAccessMode.All
									 };

			ModifyConfiguration(ravenConfiguration);

			if (ravenConfiguration.RunInMemory == false)
				IOExtensions.DeleteDirectory(ravenConfiguration.DataDirectory);

			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenConfiguration.Port);
			var ravenDbServer = new RavenDbServer(ravenConfiguration);

			try
			{
				using (var documentStore = new DocumentStore
											{
												Conventions =
													{
														FailoverBehavior = FailoverBehavior.FailImmediately
													},
												Url = "http://localhost:" + port
											}.Initialize())
				{
					CreateDefaultIndexes(documentStore);
				}
			}
			catch
			{
				ravenDbServer.Dispose();
				throw;
			}
			return ravenDbServer;
		}
Example #9
0
 private void StopServer(RavenDbServer server)
 {
     server.Dispose();
     SystemTime.UtcDateTime = () => DateTime.UtcNow.AddSeconds(4); // just to prevent Raven-Client-Primary-Server-LastCheck to have same second
 }
Example #10
0
		protected RavenDbServer GetNewServer(int port = 8079,
			string dataDirectory = null, 
			bool runInMemory = true,
			string requestedStorage = null,
			bool deleteDirectory = true, 
			bool enableAuthentication = false)
		{
			var storageType = GetDefaultStorageType(requestedStorage);
			var ravenConfiguration = new RavenConfiguration
			{
				Port = port,
				DataDirectory = dataDirectory ?? DataDir,
				RunInMemory = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false && runInMemory,
				DefaultStorageTypeName = storageType,
				AnonymousUserAccessMode = enableAuthentication ? AnonymousUserAccessMode.None : AnonymousUserAccessMode.Admin
			};

			ModifyConfiguration(ravenConfiguration);

			ravenConfiguration.PostInit();

			if (ravenConfiguration.RunInMemory == false && deleteDirectory)
				IOExtensions.DeleteDirectory(ravenConfiguration.DataDirectory);

			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenConfiguration.Port);
			var ravenDbServer = new RavenDbServer(ravenConfiguration);

			try
			{
				using (var documentStore = new DocumentStore
				{
					Url = "http://localhost:" + port,
					Conventions =
					{
						FailoverBehavior = FailoverBehavior.FailImmediately
					},
				}.Initialize())
				{
					CreateDefaultIndexes(documentStore);
				}
			}
			catch
			{
				ravenDbServer.Dispose();
				throw;
			}

			if (enableAuthentication)
			{
				EnableAuthentication(ravenDbServer.Database);
				ModifyConfiguration(ravenConfiguration);
			}

			return ravenDbServer;
		}
Example #11
0
		public IDocumentStore NewRemoteDocumentStore(bool fiddler = false, RavenDbServer ravenDbServer = null, string databaseName = null,
			bool deleteDirectoryAfter = true,
			bool deleteDirectoryBefore = true,
			bool runInMemory = true,
			string requestedStorage = null,
			bool enableAuthentication = false)
		{
			ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory, requestedStorage: requestedStorage, deleteDirectory: deleteDirectoryBefore, enableAuthentication: enableAuthentication);
			ModifyServer(ravenDbServer);
			var store = new DocumentStore
			{
				Url = GetServerUrl(fiddler),
				DefaultDatabase = databaseName,
			};
			store.AfterDispose += (sender, args) =>
			{
				ravenDbServer.Dispose();
				if (deleteDirectoryAfter)
					ClearDatabaseDirectory();
			};
			ModifyStore(store);
			return store.Initialize();
		}
Example #12
0
		private void StopServer(RavenDbServer server)
		{
			server.Dispose();
		}
Example #13
0
		protected RavenDbServer GetNewServer(int port, string path)
		{
			var ravenDbServer = new RavenDbServer(new RavenConfiguration
			{
				Port = port,
				DataDirectory = path,
				RunInMemory = true,
				AnonymousUserAccessMode = AnonymousUserAccessMode.All
			});

			try
			{
				using (var documentStore = new DocumentStore
				{
					Url = "http://localhost:" + port
				}.Initialize())
				{
					new RavenDocumentsByEntityName().Execute(documentStore);
				}
			}
			catch 
			{
				ravenDbServer.Dispose();
				throw;
			}
			return ravenDbServer;
		}
Example #14
0
		protected RavenDbServer GetNewServer(bool initializeDocumentsByEntitiyName = true)
		{
			var ravenConfiguration = new RavenConfiguration
			{
				Port = 8079,
				RunInMemory = true,
				DataDirectory = "Data",
				AnonymousUserAccessMode = AnonymousUserAccessMode.All
			};

			ConfigureServer(ravenConfiguration);

			if(ravenConfiguration.RunInMemory == false)
				IOExtensions.DeleteDirectory(ravenConfiguration.DataDirectory);

			var ravenDbServer = new RavenDbServer(ravenConfiguration);

			if (initializeDocumentsByEntitiyName)
			{
				try
				{
					using (var documentStore = new DocumentStore
					{
						Url = "http://localhost:8079"
					}.Initialize())
					{
						new RavenDocumentsByEntityName().Execute(documentStore);
					}
				}
				catch
				{
					ravenDbServer.Dispose();
					throw;
				}
			}

			return ravenDbServer;
		}
Example #15
0
		public DocumentStore NewRemoteDocumentStore(bool fiddler = false, RavenDbServer ravenDbServer = null, [CallerMemberName] string databaseName = null,
				bool runInMemory = true,
				string dataDirectory = null,
				string requestedStorage = null,
				bool enableAuthentication = false,
                bool ensureDatabaseExists = true,
				Action<DocumentStore> configureStore = null)
		{
		    databaseName = NormalizeDatabaseName(databaseName);
            
		    checkPorts = true;
			ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory, dataDirectory: dataDirectory, requestedStorage: requestedStorage, enableAuthentication: enableAuthentication, databaseName: databaseName);
			ModifyServer(ravenDbServer);
			var store = new DocumentStore
			{
				Url = GetServerUrl(fiddler, ravenDbServer.SystemDatabase.ServerUrl),
				DefaultDatabase = databaseName				
			};
		    pathsToDelete.Add(Path.Combine(ravenDbServer.SystemDatabase.Configuration.DataDirectory, @"..\Databases"));
			stores.Add(store);
			store.AfterDispose += (sender, args) => ravenDbServer.Dispose();

			if (configureStore != null)
				configureStore(store);
			ModifyStore(store);

		    store.Initialize(ensureDatabaseExists);
			return store;
		}