Dispose() public method

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public Dispose ( ) : void
return void
		public void RunningInEmbeddedMode()
		{
			#region running_in_embedded_mode
			var documentStore = new EmbeddableDocumentStore { DataDirectory = "path/to/database/directory" };
			documentStore.Initialize();

			#endregion

			documentStore.Dispose();
		}
Exemplo n.º 2
0
        public dynamic SupportsEmbeddedHttpServer()
        {
            var dirname = Guid.NewGuid().ToString("N");
            try
            {
                int ravenPort = 8181;
                NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenPort);
                var documentStore = new EmbeddableDocumentStore
                {
                    DataDirectory = "~/App_Data/" + dirname,
                    UseEmbeddedHttpServer = true,
                    Configuration = { Port = ravenPort }

                };

                documentStore.Initialize();
                documentStore.Dispose();
                return new
                {
                    success = true
                };
            }
            catch (Exception ex)
            {
                return new
                {
                    success = false,
                    error = ex.Message
                };
            }
            finally
            {
                try
                {
                    Directory.Delete(HttpContext.Current.Server.MapPath("~/App_Data/" + dirname), true);
                }
                catch (Exception ex)
                {
                    var x = ex.Message;
                }
            }
        }
Exemplo n.º 3
0
        public dynamic IsEmbeddable()
        {
            var dirname = Guid.NewGuid().ToString("N");

            try
            {
                var documentStore = new EmbeddableDocumentStore
                {
                    DataDirectory = "~/App_Data/" + dirname,
                    UseEmbeddedHttpServer = false
                };

                documentStore.Initialize();
                documentStore.Dispose();
                return new
                {
                    success = true
                };
            }
            catch (Exception ex)
            {
                return new
                {
                    success = false,
                    error = ex.Message
                };
            }
            finally
            {
                try
                {
                    Directory.Delete(HttpContext.Current.Server.MapPath("~/App_Data/" + dirname), true);
                }
                catch (Exception ex)
                {
                    var x = ex.Message;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new Embeddable document store.
        /// </summary>
        /// <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="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="catalog">Custom bundles that are not provided by RavenDb.</param>
        /// <param name="dataDir">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="enableAuthentication"></param>
        /// <param name="activeBundles">Semicolon separated list of bundles names, such as: 'Replication;Versioning'.<br/>Default: no bundles turned on.</param>
        /// <param name="port">The port to use when creating the http listener. Allowed: 1 - 65,536 or * (find first available port from 8079 and upward).<br/>Default: <b>8079</b></param>
        /// <param name="anonymousUserAccessMode">Determines what actions an anonymous user can do. Get - read only, All - read & write, None - allows access to only authenticated users, Admin - all (including administrative actions).<br/>Default: <b>Get</b></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="databaseName">Name of the server that will show up on /admin/stats endpoint.</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 executed.</param>
        /// <param name="conventions">The conventions to be used when creating a new embeddable document store</param>
        /// <remarks>Besides the document store being instantiated, it is also Initialized.<br/>Also, if you provide some indexes to be used, make sure you understand that they might be stale when you query them. To make sure you're querying against indexes that have completed their indexing (ie. index is not stale), use the <code>noStaleQueries</code> parameter to determine if you wish to query against a stale or not-stale query.</remarks>
        /// <returns>A new instance of an EmbeddableDocumentStore.</returns>
        public EmbeddableDocumentStore NewDocumentStore(
            bool runInMemory = true,
            string requestedStorage = null,
            ComposablePartCatalog catalog = null,
            string dataDir = null,
            bool enableAuthentication = false,
            string activeBundles = null,
            int? port = null,
            AnonymousUserAccessMode anonymousUserAccessMode = AnonymousUserAccessMode.Admin,
            Action<EmbeddableDocumentStore> configureStore = null,
            [CallerMemberName] string databaseName = null,
            IEnumerable<AbstractIndexCreationTask> indexes = null,
            IEnumerable<AbstractTransformerCreationTask> transformers = null,
            IEnumerable<IEnumerable> seedData = null,
            bool noStaleQueries = false,
            DocumentConvention conventions = null)
        {
            databaseName = NormalizeDatabaseName(databaseName);

            var storageType = GetDefaultStorageType(requestedStorage);
            var dataDirectory = dataDir ?? NewDataPath(databaseName);
            var documentStore = new EmbeddableDocumentStore
            {
                UseEmbeddedHttpServer = port.HasValue,
                Conventions = conventions ?? new DocumentConvention()
            };

            ConfigurationHelper.ApplySettingsToConfiguration(documentStore.Configuration);

            documentStore.Configuration.DefaultStorageTypeName = storageType;
            documentStore.Configuration.DataDirectory = Path.Combine(dataDirectory, "System");
            documentStore.Configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true;
            documentStore.Configuration.RunInMemory = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false && runInMemory;
            documentStore.Configuration.Port = port ?? 8079;
            documentStore.Configuration.AnonymousUserAccessMode = anonymousUserAccessMode;

            documentStore.Configuration.FileSystem.DataDirectory = Path.Combine(dataDirectory, "FileSystem");
            documentStore.Configuration.Encryption.UseFips = ConfigurationHelper.UseFipsEncryptionAlgorithms;

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

            if (catalog != null)
            {
                documentStore.Configuration.Catalog.Catalogs.Add(catalog);
            }

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

                ModifyStore(documentStore);
                ModifyConfiguration(documentStore.Configuration);
                documentStore.Configuration.PostInit();
                documentStore.Initialize();

                if (enableAuthentication)
                {
                    EnableAuthentication(documentStore.SystemDatabase);
                }

                CreateDefaultIndexes(documentStore);

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

                if (noStaleQueries)
                {
                    documentStore.Listeners.RegisterListener(new NoStaleQueriesListener());
                }

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

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

                return documentStore;
            }
            catch
            {
                // We must dispose of this object in exceptional cases, otherwise this test will break all the following tests.
                documentStore.Dispose();
                throw;
            }
            finally
            {
                stores.Add(documentStore);
            }
        }
Exemplo n.º 5
0
		public EmbeddableDocumentStore NewDocumentStore(
			bool deleteDirectory = true,
			string requestedStorage = null,
			ComposablePartCatalog catalog = null,
			bool deleteDirectoryOnDispose = true)
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);

			string defaultStorageType = GetDefaultStorageType(requestedStorage);

			var documentStore = new EmbeddableDocumentStore
			{
				Configuration =
				{
					DefaultStorageTypeName = defaultStorageType,
					DataDirectory = path,
					RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
					RunInMemory = false,
					Port = 8079
				}
			};

			if (catalog != null)
				documentStore.Configuration.Catalog.Catalogs.Add(catalog);

			try
			{
				ModifyStore(documentStore);
				ModifyConfiguration(documentStore.Configuration);

				if (deleteDirectory)
					IOExtensions.DeleteDirectory(path);

				documentStore.Initialize();

				CreateDefaultIndexes(documentStore);

				if (deleteDirectoryOnDispose)
					documentStore.Disposed += ClearDatabaseDirectory;

				return documentStore;
			}
			catch
			{
				// We must dispose of this object in exceptional cases, otherwise this test will break all the following tests.
				documentStore.Dispose();
				throw;
			}
			finally
			{
				stores.Add(documentStore);
			}
		}
Exemplo n.º 6
0
		public EmbeddableDocumentStore NewDocumentStore(
			bool runInMemory = true,
			string requestedStorage = null,
			ComposablePartCatalog catalog = null,
			bool deleteDirectory = true,
			bool deleteDirectoryOnDispose = true,
			bool enableAuthentication = false)
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(RavenTestBase)).CodeBase);
            
            if (path.StartsWith(@"file:\", StringComparison.InvariantCultureIgnoreCase))
                path = path.Substring(6);

            path = Path.Combine(path, Path.GetFileName(Path.GetDirectoryName(DataDir)));

			var storageType = GetDefaultStorageType(requestedStorage);
			var documentStore = new EmbeddableDocumentStore
			{
				Configuration =
				{
					DefaultStorageTypeName = storageType,
					DataDirectory = path,
					RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
					RunInMemory = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false && runInMemory,
					Port = 8079
				}
			};

			if (catalog != null)
				documentStore.Configuration.Catalog.Catalogs.Add(catalog);

			try
			{
				ModifyStore(documentStore);
				ModifyConfiguration(documentStore.Configuration);

				if (deleteDirectory)
					IOExtensions.DeleteDirectory(path);

				documentStore.Initialize();

				if (enableAuthentication)
				{
					EnableAuthentication(documentStore.DocumentDatabase);
					ModifyConfiguration(documentStore.Configuration);
				}

				CreateDefaultIndexes(documentStore);

				if (deleteDirectoryOnDispose)
					documentStore.Disposed += ClearDatabaseDirectory;

				return documentStore;
			}
			catch
			{
				// We must dispose of this object in exceptional cases, otherwise this test will break all the following tests.
				documentStore.Dispose();
				throw;
			}
			finally
			{
				stores.Add(documentStore);
			}
		}
Exemplo n.º 7
0
		public EmbeddableDocumentStore NewDocumentStore(
			bool runInMemory = true,
			string requestedStorage = null,
			ComposablePartCatalog catalog = null,
			string dataDir = null,
			bool enableAuthentication = false)
		{
			var storageType = GetDefaultStorageType(requestedStorage);
			var documentStore = new EmbeddableDocumentStore
			{
				Configuration =
				{
					DefaultStorageTypeName = storageType,
					DataDirectory = dataDir ?? NewDataPath(),
					RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
					RunInMemory = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false && runInMemory,
					Port = 8079
				}
			};

			if (catalog != null)
				documentStore.Configuration.Catalog.Catalogs.Add(catalog);

			try
			{
				ModifyStore(documentStore);
				ModifyConfiguration(documentStore.Configuration);

				documentStore.Initialize();

				if (enableAuthentication)
				{
					EnableAuthentication(documentStore.DocumentDatabase);
					ModifyConfiguration(documentStore.Configuration);
				}

				CreateDefaultIndexes(documentStore);

				return documentStore;
			}
			catch
			{
				// We must dispose of this object in exceptional cases, otherwise this test will break all the following tests.
				documentStore.Dispose();
				throw;
			}
			finally
			{
				stores.Add(documentStore);
			}
		}
Exemplo n.º 8
0
		public EmbeddableDocumentStore NewDocumentStore(
			bool runInMemory = true,
			string requestedStorage = null,
			ComposablePartCatalog catalog = null,
			string dataDir = null,
			bool enableAuthentication = false,
			string activeBundles = null,
			int? port = null,
			AnonymousUserAccessMode anonymousUserAccessMode = AnonymousUserAccessMode.Admin,
			Action<EmbeddableDocumentStore> configureStore = null,
            [CallerMemberName] string databaseName = null)
		{
		    databaseName = NormalizeDatabaseName(databaseName);

			var storageType = GetDefaultStorageType(requestedStorage);
			var dataDirectory = dataDir ?? NewDataPath(databaseName);
			var documentStore = new EmbeddableDocumentStore
			{
				UseEmbeddedHttpServer = port.HasValue,
				Configuration =
				{
					DefaultStorageTypeName = storageType,
					DataDirectory = Path.Combine(dataDirectory, "System"),
					FileSystemDataDirectory = Path.Combine(dataDirectory, "FileSystem"),
					RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
					RunInMemory = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false && runInMemory,
					Port = port == null ? 8079 : port.Value,
					UseFips = SettingsHelper.UseFipsEncryptionAlgorithms,
					AnonymousUserAccessMode = anonymousUserAccessMode,
				}
			};

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

			if (catalog != null)
				documentStore.Configuration.Catalog.Catalogs.Add(catalog);

			try
			{
				if (configureStore != null) 
					configureStore(documentStore);
				ModifyStore(documentStore);
				ModifyConfiguration(documentStore.Configuration);
                documentStore.Configuration.PostInit();
				documentStore.Initialize();

				if (enableAuthentication)
				{
					EnableAuthentication(documentStore.DocumentDatabase);
				}

				CreateDefaultIndexes(documentStore);

				return documentStore;
			}
			catch
			{
				// We must dispose of this object in exceptional cases, otherwise this test will break all the following tests.
				documentStore.Dispose();
				throw;
			}
			finally
			{
				stores.Add(documentStore);
			}
		}
Exemplo n.º 9
0
        public void Must_have_a_document_store()
        {
            // DocumentStores are at the core of RavenDB.
            // They allow you to access the database instance
            // of the application.
            // DocumentStores come in three flavors:
            //      - Remote
            //      - Embedded
            //      - In Memory

            // This is a RavenDB running in memory
            var documentStore = new EmbeddableDocumentStore {
                RunInMemory = true
            }
            // You need to initialize your documentstore
            // after you set the configuration above.
            .Initialize();

            // Remote example
            // var documentStore = new DocumentStore {
            //      ConnectionStringName = "RavenDb"
            //  }.Initialize();

            // Embedded example
            // var documentStore = new EmbeddableDocumentStore {
            //     ConnectionStringName = "RavenDb"
            // }

            documentStore.Should()
                .NotBeNull();

            // remember to dispose your document store
            // or let the application shutdown dispose it
            documentStore.Dispose();
        }
Exemplo n.º 10
0
        private static void Main()
        {
            // Initialize the database and create indexes
            var documentStore = new EmbeddableDocumentStore {
                                                                UseEmbeddedHttpServer = true,
            #if DEBUG
                                                                RunInMemory = true
            #endif
                                                            };
            _documentStore = documentStore;
            documentStore.SetStudioConfigToAllowSingleDb();
            documentStore.Configuration.AnonymousUserAccessMode = AnonymousUserAccessMode.All;
            documentStore.Configuration.Settings.Add("Raven/ActiveBundles", "Expiration");
            documentStore.Configuration.Settings.Add("Raven/Expiration/DeleteFrequencySeconds", "10");
            documentStore.Initialize();
            IndexCreation.CreateIndexes(typeof(Program).Assembly, documentStore);

            // Set up some pressure gauge simulators at different starting points and speeds
            AddPressureGauge("Pressure Gague 1", 30, 10);
            AddPressureGauge("Pressure Gague 2", 50, 20);
            AddPressureGauge("Pressure Gague 3", 70, 30);

            // Set up the polling timer to read the gauges periodically
            PollingTimer.Interval = TakeReadingsEvery.TotalMilliseconds;
            PollingTimer.Elapsed += PollingTimerElapsed;
            PollingTimer.Start();

            while (DoMenu())
            {
            }

            PollingTimer.Stop();
            PollingTimer.Dispose();
            foreach (var sensor in Sensors.Values)
                sensor.Dispose();

            documentStore.DocumentDatabase.StopBackgroundWorkers();
            documentStore.Dispose();
        }