Inheritance: IDisposable
Example #1
0
		public WithCascade()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(WithCascade)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);
			database::Raven.Database.Extensions.IOExtensions.DeleteDirectory("Data");
			var ravenConfiguration = new database::Raven.Database.Config.RavenConfiguration
			{
				Port = 8079,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
				DataDirectory = path,
				Catalog =
					{
						Catalogs =
							{
								new AssemblyCatalog(typeof(CascadeDeleteTrigger).Assembly)
							}
					},
				Settings =
					{
						{"Raven/Expiration/DeleteFrequencySeconds", "1"},
						{"Raven/ActiveBundles", "documentExpiration"}
			}
			};
			ravenConfiguration.PostInit();
			ravenDbServer = new RavenDbServer(ravenConfiguration);
			documentStore = new DocumentStore
			{
				Url = "http://localhost:8079"
			};
			documentStore.Initialize();
		}
Example #2
0
        public CryptTest()
        {
            string path = Path.GetDirectoryName(Assembly.GetAssembly(typeof (CryptTest)).CodeBase);
            path = Path.Combine(path, "TestDb").Substring(6);

            IOExtensions.DeleteDirectory(path);

            ravenDbServer = new RavenDbServer(
                new RavenConfiguration
                {
                    Port = 8079,
                    DataDirectory = path,
                    Catalog =
                        {
                            Catalogs =
                                {
                                    new AssemblyCatalog(typeof (DocumentCodec).Assembly)
                                }
                        },
                    AnonymousUserAccessMode = AnonymousUserAccessMode.All
                });

            documentStore = new DocumentStore
            {
                Url = "http://localhost:8079"
            };
            documentStore.Initialize();
        }
 protected override void ConfigureServer(RavenDbServer server, string fileSystemName)
 {
     if (server.SystemDatabase.Configuration.Port == Ports[1]) // setup only for destination
     {
         server.SystemDatabase.Documents.Put("Raven/Authorization/WindowsSettings", null,
                                   RavenJObject.FromObject(new WindowsAuthDocument
                                   {
                                       RequiredUsers = new List<WindowsAuthData>
                                       {
                                           new WindowsAuthData()
                                           {
                                               Name = string.Format("{0}\\{1}", domain, username),
                                               Enabled = true,
                                               Databases = new List<DatabaseAccess>
                                               {
                                                   new DatabaseAccess {TenantId = Constants.SystemDatabase, Admin = true} // required to create file system
                                               },
                                               FileSystems = new List<FileSystemAccess>()
                                               {
                                                   new FileSystemAccess() {TenantId = fileSystemName}
                                               }
                                           }
                                       }
                                   }), new RavenJObject(), null);
     }
 }
Example #4
0
		private void createServer()
		{
            ravenDbServer = GetNewServer(runInMemory: false, dataDirectory: path, activeBundles: "Encryption", configureConfig: configuration =>
			{
				configuration.Settings["Raven/Encryption/Key"] = "3w17MIVIBLSWZpzH0YarqRlR2+yHiv1Zq3TCWXLEMI8=";
			});
		}
Example #5
0
		public Expiration()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Versioning.Versioning)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);
			database::Raven.Database.Extensions.IOExtensions.DeleteDirectory("Data");
			ravenDbServer = new RavenDbServer(
				new database::Raven.Database.Config.RavenConfiguration
				{
					Port = 8079,
					RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
					DataDirectory = path,
					Catalog =
						{
							Catalogs =
								{
									new AssemblyCatalog(typeof (ExpirationReadTrigger).Assembly)
								}
						},
					Settings =
						{
							{"Raven/Expiration/DeleteFrequencySeconds", "1"}
						}
				});
			ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow;
			documentStore = new DocumentStore
			{
				Url = "http://localhost:8079"
			};
			documentStore.Initialize();
		}
Example #6
0
        protected RavenDbServer GetNewServer()
        {
        	var ravenConfiguration = new RavenConfiguration
        	{
        		Port = 8080,
        		RunInMemory = true,
        		DataDirectory = "Data",
        		AnonymousUserAccessMode = AnonymousUserAccessMode.All
        	};

        	ConfigureServer(ravenConfiguration);

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

        	var ravenDbServer = new RavenDbServer(ravenConfiguration);

			using (var documentStore = new DocumentStore
			{
				Url = "http://localhost:8080"
			}.Initialize())
			{
				new RavenDocumentsByEntityName().Execute(documentStore);
			}

        	return ravenDbServer;
        }
Example #7
0
        public RavenDB_560()
        {
            server1DataDir = NewDataPath("D1");
            server2DataDir = NewDataPath("D2");
            server1 = CreateServer(8079, server1DataDir);
            server2 = CreateServer(8078, server2DataDir);


            store1 = new DocumentStore
            {
                DefaultDatabase = "Northwind1",
                Url = server1.SystemDatabase.ServerUrl
            };
            store1.Initialize(false);

            store2 = new DocumentStore
            {
                DefaultDatabase = "Northwind2",
                Url = server2.SystemDatabase.ServerUrl
            };
            store2.Initialize(false);


            store1.DatabaseCommands.GlobalAdmin.CreateDatabase(new DatabaseDocument
            {
                Id = "Northwind1",
                Settings = { { "Raven/ActiveBundles", "replication" }, { "Raven/DataDir", @"~\Databases1\Northwind" } }
            });

            store2.DatabaseCommands.GlobalAdmin.CreateDatabase(new DatabaseDocument
            {
                Id = "Northwind2",
                Settings = { { "Raven/ActiveBundles", "replication" }, { "Raven/DataDir", @"~\Databases2\Northwind" } }
            });
        }
		protected TestWithInMemoryDatabase(Action<Raven.Database.Config.RavenConfiguration> configModifier)
		{
			var ravenConfiguration = new Raven.Database.Config.RavenConfiguration
			{
				Port = 8079,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
			};

			configModifier(ravenConfiguration);

			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(TestWithInMemoryDatabase)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);

			ravenConfiguration.DataDirectory = path;

			Raven.Database.Extensions.IOExtensions.DeleteDirectory(path);

			ravenDbServer = new RavenDbServer(ravenConfiguration);

			documentStore = new DocumentStore
			{
				Url = "http://localhost:8079"
			};
			documentStore.Initialize();
		}
Example #9
0
 public Versioning()
 {
     path = Path.GetDirectoryName(Assembly.GetAssembly(typeof (Versioning)).CodeBase);
     path = Path.Combine(path, "TestDb").Substring(6);
     if (Directory.Exists(path))
         Directory.Delete(path, true);
     ravenDbServer = new RavenDbServer(
         new RavenConfiguration
         {
             Port = 58080,
             DataDirectory = path,
             RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
             Catalog =
             {
                 Catalogs =
             {
                 new AssemblyCatalog(typeof (VersioningPutTrigger).Assembly)
             }
             },
             Settings =
             {
                 {"Raven/Versioning/MaxRevisions", "5"},
                 {"Raven/Versioning/Exclude", "Users;Comments;"}
             }
         });
     documentStore = new DocumentStore
     {
         Url = "http://localhost:58080"
     };
     documentStore.Initialize();
 }
Example #10
0
        public void ProperlyHandleDataDirectoryWhichEndsWithSlash()
        {
            server1 = CreateServer(8079, "D1");

            store1 = new DocumentStore
            {
                DefaultDatabase = "Northwind",
                Url = "http://*****:*****@"~\D1\N" } }
                });

            store1.DatabaseCommands.ForDatabase("Northwind").Get("force/load/of/db");

            Assert.True(
                Directory.Exists(Path.Combine(server1.SystemDatabase.Configuration.DataDirectory,
                                              "N")));


        }
		public WhenUsingShardedServers()
		{
			const string server = "localhost";

			const int port1 = 8079;
			const int port2 = 8081;

			path1 = GetPath("TestShardedDb1");
			path2 = GetPath("TestShardedDb2");

			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port1);
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port2);

			company1 = new Company { Name = "Company1" };
			company2 = new Company { Name = "Company2" };

			server1 = GetNewServer(port1, path1);
			server2 = GetNewServer(port2, path2);

			shards = new List<IDocumentStore> { 
				new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1}, 
				new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2} 
			}.ToDictionary(x => x.Identifier, x => x);

			shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();
			shardResolution.Stub(x => x.GenerateShardIdFor(company1)).Return("Shard1");
			shardResolution.Stub(x => x.GenerateShardIdFor(company2)).Return("Shard2");

			shardResolution.Stub(x => x.MetadataShardIdFor(company1)).Return("Shard1");
			shardResolution.Stub(x => x.MetadataShardIdFor(company2)).Return("Shard1");

			shardStrategy = new ShardStrategy(shards) { ShardResolutionStrategy = shardResolution };
		}
Example #12
0
		public Expiration()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Versioning.Versioning)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);
			Raven.Database.Extensions.IOExtensions.DeleteDirectory(path);
			var ravenConfiguration = new Raven.Database.Config.RavenConfiguration
			{
				Port = 8079,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
				DataDirectory = path,
				Settings =
					{
						{"Raven/Expiration/DeleteFrequencySeconds", "1"},
						{"Raven/ActiveBundles", "DocumentExpiration"}
					}
			};
			ravenConfiguration.PostInit();
			ravenDbServer = new RavenDbServer(
				ravenConfiguration);
			SystemTime.UtcDateTime = () => DateTime.UtcNow;
			documentStore = new DocumentStore
			{
				Url = "http://localhost:8079"
			};
			documentStore.Initialize();
		}
Example #13
0
        public CascadeDelete()
        {
            path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(CascadeDelete)).CodeBase);
            path = Path.Combine(path, "TestDb").Substring(6);
            database::Raven.Database.Extensions.IOExtensions.DeleteDirectory("Data");
            ravenDbServer = new RavenDbServer(
                new database::Raven.Database.Config.RavenConfiguration
                {
                    Port = 58080,
                    RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
                    DataDirectory = path,
                    Catalog =
                    {
                        Catalogs =
                                {
                                    new AssemblyCatalog(typeof (CascadeDeleteTrigger).Assembly)
                                }
                    },
                });

            documentStore = new DocumentStore
            {
                Url = "http://localhost:58080"
            };
            documentStore.Initialize();
        }
        public When_Using_Sharded_Servers()
        {
            server = "localhost";

            port1 = 8080;
            port2 = 8081;

            path1 = GetPath("TestShardedDb1");
            path2 = GetPath("TestShardedDb2");

            RavenDbServer.EnsureCanListenToWhenInNonAdminContext(port1);
            RavenDbServer.EnsureCanListenToWhenInNonAdminContext(port2);

            company1 = new Company { Name = "Company1" };
            company2 = new Company { Name = "Company2" };

            server1 = GetNewServer(port1, path1);
            server2 = GetNewServer(port2, path2);

            shards = new Shards {
                new DocumentStore(server, port1) { Identifier="Shard1" },
                new DocumentStore(server, port2) { Identifier="Shard2" }
            };

            shardSelection = MockRepository.GenerateStub<IShardSelectionStrategy>();
            shardSelection.Stub(x => x.SelectShardIdForNewObject(company1)).Return("Shard1");
            shardSelection.Stub(x => x.SelectShardIdForNewObject(company2)).Return("Shard2");

            shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();

            shardStrategy = MockRepository.GenerateStub<IShardStrategy>();
            shardStrategy.Stub(x => x.ShardSelectionStrategy).Return(shardSelection);
            shardStrategy.Stub(x => x.ShardResolutionStrategy).Return(shardResolution);
        }
Example #15
0
 protected Compression()
 {
     // This will be disposed by the RavenTestBase.Dispose method
     path = NewDataPath("Compression");
     ravenDbServer = GetNewServer(activeBundles: "Compression", dataDirectory: path, runInMemory:false);
     documentStore = NewRemoteDocumentStore(ravenDbServer: ravenDbServer);
 }
Example #16
0
		public RavenDB_560()
		{
			server1DataDir = NewDataPath("D1");
			server2DataDir = NewDataPath("D2");
			server1 = CreateServer(8001, server1DataDir);
			server2 = CreateServer(8002, server2DataDir);


			store1 = new DocumentStore
			{
				DefaultDatabase = "Northwind",
				Url = "http://" + Environment.MachineName + ":8001",
			};
			store1.Initialize(false);

			store2 = new DocumentStore
			{
				DefaultDatabase = "Northwind",
				Url = "http://" + Environment.MachineName + ":8002"
			};
			store2.Initialize(false);


			store1.DatabaseCommands.GlobalAdmin.CreateDatabase(new DatabaseDocument
			{
				Id = "Northwind",
				Settings = { { "Raven/ActiveBundles", "replication" }, { "Raven/DataDir", @"~\Databases1\Northwind" } }
			});

			store2.DatabaseCommands.GlobalAdmin.CreateDatabase(new DatabaseDocument
			{
				Id = "Northwind",
				Settings = { { "Raven/ActiveBundles", "replication" }, { "Raven/DataDir", @"~\Databases2\Northwind" } }
			});
		}
Example #17
0
        private RavenDbServer CreateServer(int port, string dataDirectory, bool removeDataDirectory = true)
        {
            Database.Server.NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port);

            var serverConfiguration = new Database.Config.RavenConfiguration
            {
                AnonymousUserAccessMode = Database.Server.AnonymousUserAccessMode.Admin,
                DataDirectory = dataDirectory,
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
                RunInMemory = false,
                Port = port,
                DefaultStorageTypeName = "esent"
            };

            if (removeDataDirectory)
                IOExtensions.DeleteDirectory(serverConfiguration.DataDirectory);

            var server = new RavenDbServer(serverConfiguration)
            {
                UseEmbeddedHttpServer = true
            };
            server.Initialize();
            serverConfiguration.PostInit();

            return server;
        }
		public CompressionAndEncryption()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Versioning.Versioning)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);
			Raven.Database.Extensions.IOExtensions.DeleteDirectory(path);
			settings = new Raven.Database.Config.RavenConfiguration
			{
				Port = 8079,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
				DataDirectory = path,
				Settings =
					{
						{"Raven/Encryption/Key", "3w17MIVIBLSWZpzH0YarqRlR2+yHiv1Zq3TCWXLEMI8="},
						{"Raven/ActiveBundles", "Compression;Encryption"}
					}
			};
			ConfigureServer(settings);
			settings.PostInit();
			ravenDbServer = new RavenDbServer(settings);
			documentStore = new DocumentStore
			{
				Url = "http://localhost:8079"
			};
			documentStore.Initialize();
		}
        public WhenUsingShardedServers()
        {
            const string server = "localhost";

            const int port1 = 8079;
            const int port2 = 8081;

            company1 = new Company { Name = "Company1" };
            company2 = new Company { Name = "Company2" };

            server1 = GetNewServer(port1);
            server2 = GetNewServer(port2);

            shards = new List<IDocumentStore> {
                new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1},
                new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2}
            }.ToDictionary(x => x.Identifier, x => x);

            shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();
            shardResolution.Stub(x => x.GenerateShardIdFor(Arg.Is(company1), Arg<ITransactionalDocumentSession>.Is.Anything)).Return("Shard1");
            shardResolution.Stub(x => x.GenerateShardIdFor(Arg.Is(company2), Arg<ITransactionalDocumentSession>.Is.Anything)).Return("Shard2");

            shardResolution.Stub(x => x.MetadataShardIdFor(company1)).Return("Shard1");
            shardResolution.Stub(x => x.MetadataShardIdFor(company2)).Return("Shard1");

            shardStrategy = new ShardStrategy(shards) { ShardResolutionStrategy = shardResolution };
        }
Example #20
0
		public VersioningTest()
		{
			testAssemblyPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Versioning)).CodeBase);

			ravenDbServer = CreateRavenDbServer(port: 8079);
			documentStore = CreateDocumentStore(port: 8079);
		}
Example #21
0
 public Expiration()
 {
     path = Path.GetDirectoryName(Assembly.GetAssembly(typeof (Versioning)).CodeBase);
     path = Path.Combine(path, "TestDb").Substring(6);
     if (Directory.Exists(path))
         Directory.Delete(path, true);
     ravenDbServer = new RavenDbServer(
         new database::Raven.Database.RavenConfiguration
         {
             Port = 58080,
             RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
             DataDirectory = path,
             Catalog =
                 {
                     Catalogs =
                         {
                             new AssemblyCatalog(typeof (ExpirationReadTrigger).Assembly)
                         }
                 },
         });
     ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow;
     documentStore = new DocumentStore
     {
         Url = "http://localhost:58080"
     };
     documentStore.Initialize();
 }
		public OverwriteIndexRemotely()
		{
			const int port = 8079;
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8079);

			ravenDbServer = GetNewServer(port);
			documentStore = new DocumentStore {Url = "http://localhost:" + port}.Initialize();
		}
		public DocumentStoreServerTests()
		{
			port = 8079;
			path = GetPath("TestDb");
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8079);

			server = GetNewServer(port, path);
			documentStore = new DocumentStore {Url = "http://localhost:" + port}.Initialize();
		}
Example #24
0
 public Expiration()
 {
     SystemTime.UtcDateTime = () => DateTime.UtcNow;
     ravenDbServer = GetNewServer(activeBundles: "DocumentExpiration", configureConfig: configuration =>
     {
         configuration.Settings["Raven/Expiration/DeleteFrequencySeconds"] = "1";
     });
     documentStore = NewRemoteDocumentStore(ravenDbServer: ravenDbServer);
 }
		public SortingWithWildcardQuery()
		{
			const int port = 8079;
			path = GetPath("TestDb");
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8079);

			ravenDbServer = GetNewServer(port, path);
			documentStore = new DocumentStore {Url = "http://localhost:" + port}.Initialize();
		}
		public UsingDynamicQueryWithRemoteServer()
		{
			const int port = 8079;
			path = GetPath("TestDb");
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port);

			ravenDbServer = GetNewServer(port, path);
			documentStore = new DocumentStore {Url = "http://localhost:" + port}.Initialize();
		}
Example #27
0
        public Includes()
        {
            server = GetNewServer(8079, GetPath(DbName));

            store = new DocumentStore
            {
                Url = "http://localhost:8079"
            }.Initialize();
        }
 protected void RecycleServer()
 {
     ravenDbServer.Dispose();
     ravenDbServer =  new RavenDbServer(settings)
     {
         UseEmbeddedHttpServer = true
     };
     ravenDbServer.Initialize();
 }
Example #29
0
		public ReplicateToRedis()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Versioning.Versioning)).CodeBase);

			path = Path.Combine(path, "TestDb").Substring(6);

			database::Raven.Database.Extensions.IOExtensions.DeleteDirectory(path);

			ravenDbServer = new RavenDbServer(
				new database::Raven.Database.Config.RavenConfiguration
				{
					Port = 8079,
					DataDirectory = path,
					RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
					Catalog =
					{
						Catalogs =
								{
									new AssemblyCatalog(typeof (IndexReplicationToRedisIndexUpdateTrigger).Assembly)
								}
					},
				});
			ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow;
			documentStore = new DocumentStore
			{
				Url = "http://*****:*****@"
from q in docs.Questions
select new 
	{
		q.Title, 
		UpVotes = q.Votes.Count(((Func<dynamic,bool>)(x=>x.Up))), 
		DownVotes = q.Votes.Count(((Func<dynamic,bool>)(x=>!x.Up))),
		q.QuestionDate,
		SumPoints = q.Votes.Sum(((Func<dynamic,double>)(x=>x.Points)))
	}
",
					Stores =
						{
							{"Title", FieldStorage.Yes},
							{"UpVotes", FieldStorage.Yes},
							{"DownVotes", FieldStorage.Yes},
							{"QuestionDate", FieldStorage.Yes},
							{"SumPoints", FieldStorage.Yes}
						},
					Indexes = { { "Title", FieldIndexing.NotAnalyzed } }
				});
		}
Example #30
0
		public LinqTest()
		{
			ravenDbServer = GetNewServer();

			documentStore = new DocumentStore
			           	{
			           		Url = "http://localhost:8079",
			           		Conventions = {DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites}
			           	}.Initialize();
		}
Example #31
0
        private static bool RunServerInDebugMode(RavenConfiguration ravenConfiguration, bool launchBrowser, Func <RavenDbServer, bool> afterOpen, bool useEmbeddedServer = true)
        {
            var sp = Stopwatch.StartNew();

            using (var server = new RavenDbServer(ravenConfiguration)
            {
                UseEmbeddedHttpServer = useEmbeddedServer
            }.Initialize())
            {
                sp.Stop();
                var path = Path.Combine(Environment.CurrentDirectory, "default.raven");
                if (File.Exists(path))
                {
                    Console.WriteLine("Loading data from: {0}", path);
                    //new SmugglerApi(new SmugglerDatabaseOptions(), new RavenConnectionStringOptions {Url = ravenConfiguration.ServerUrl}).ImportData(new SmugglerDatabaseOptions {BackupPath = path});
                }

                Console.WriteLine("Raven is ready to process requests. Build {0}, Version {1}", DocumentDatabase.BuildVersion, DocumentDatabase.ProductVersion);
                Console.WriteLine("Server started in {0:#,#;;0} ms", sp.ElapsedMilliseconds);
                ConsoleWriteLineWithColor(ConsoleColor.Green, "Working directory: {0}", ravenConfiguration.RunInMemory ? "RAM" : ravenConfiguration.WorkingDirectory);
                ConsoleWriteLineWithColor(ConsoleColor.Green, "Data directory: {0}", ravenConfiguration.RunInMemory ? "RAM" : ravenConfiguration.DataDirectory);
                ConsoleWriteLineWithColor(ConsoleColor.Green, "Index cache directory: {0}", ravenConfiguration.RunInMemory ? "RAM" : ravenConfiguration.CompiledIndexCacheDirectory);
                ConsoleWriteLineWithColor(ConsoleColor.Green, "Plugins directory: {0}", ravenConfiguration.RunInMemory ? "RAM" : ravenConfiguration.PluginsDirectory);
                Console.WriteLine("HostName: {0} Port: {1}, Storage: {2}", ravenConfiguration.HostName ?? "<any>",
                                  ravenConfiguration.Port,
                                  server.SystemDatabase.TransactionalStorage.FriendlyName);
                Console.WriteLine("Server Url: {0}", ravenConfiguration.ServerUrl);

                if (launchBrowser)
                {
                    try
                    {
                        Process.Start(ravenConfiguration.ServerUrl);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Could not start browser: " + e.Message);
                    }
                }
                return(afterOpen(server));
            }
        }
Example #32
0
        private static bool RunServer(RavenConfiguration ravenConfiguration)
        {
            var sp = Stopwatch.StartNew();

            using (var server = new RavenDbServer(ravenConfiguration))
            {
                sp.Stop();
                var path = Path.Combine(Environment.CurrentDirectory, "default.raven");
                if (File.Exists(path))
                {
                    Console.WriteLine("Loading data from: {0}", path);
                    Smuggler.Smuggler.ImportData(ravenConfiguration.ServerUrl, path);
                }

                Console.WriteLine("Raven is ready to process requests. Build {0}, Version {1}", DocumentDatabase.BuildVersion, DocumentDatabase.ProductVersion);
                Console.WriteLine("Server started in {0:#,#} ms", sp.ElapsedMilliseconds);
                Console.WriteLine("Data directory: {0}", ravenConfiguration.DataDirectory);
                Console.WriteLine("HostName: {0} Port: {1}, Storage: {2}", ravenConfiguration.HostName ?? "<any>",
                                  ravenConfiguration.Port,
                                  server.Database.TransactionalStorage.FriendlyName);
                Console.WriteLine("Server Url: {0}", ravenConfiguration.ServerUrl);
                Console.WriteLine("Press <enter> to stop or 'cls' and <enter> to clear the log");
                while (true)
                {
                    var readLine = Console.ReadLine() ?? "";
                    switch (readLine.ToLowerInvariant())
                    {
                    case "cls":
                        Console.Clear();
                        break;

                    case "reset":
                        Console.Clear();
                        return(true);

                    default:
                        return(false);
                    }
                }
            }
        }
Example #33
0
        private static bool RunServerInDebugMode(RavenConfiguration ravenConfiguration, bool lauchBrowser)
        {
            var sp = Stopwatch.StartNew();

            using (var server = new RavenDbServer(ravenConfiguration))
            {
                sp.Stop();
                var path = Path.Combine(Environment.CurrentDirectory, "default.raven");
                if (File.Exists(path))
                {
                    Console.WriteLine("Loading data from: {0}", path);
                    new SmugglerApi(new SmugglerOptions(), new RavenConnectionStringOptions {
                        Url = ravenConfiguration.ServerUrl
                    }).ImportData(new SmugglerOptions {
                        BackupPath = path
                    });
                }

                Console.WriteLine("Raven is ready to process requests. Build {0}, Version {1}", DocumentDatabase.BuildVersion, DocumentDatabase.ProductVersion);
                Console.WriteLine("Server started in {0:#,#;;0} ms", sp.ElapsedMilliseconds);
                Console.WriteLine("Data directory: {0}", ravenConfiguration.RunInMemory ? "RAM" : ravenConfiguration.DataDirectory);
                Console.WriteLine("HostName: {0} Port: {1}, Storage: {2}", ravenConfiguration.HostName ?? "<any>",
                                  ravenConfiguration.Port,
                                  server.Database.TransactionalStorage.FriendlyName);
                Console.WriteLine("Server Url: {0}", ravenConfiguration.ServerUrl);

                if (lauchBrowser)
                {
                    try
                    {
                        Process.Start(ravenConfiguration.ServerUrl);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Could not start browser: " + e.Message);
                    }
                }
                return(InteractiveRun());
            }
        }
Example #34
0
        protected override void OnStart(string[] args)
        {
            startTask = Task.Factory.StartNew(() =>
            {
                try
                {
                    server = new RavenDbServer(new RavenConfiguration());
                }
                catch (Exception e)
                {
                    EventLog.WriteEntry("RavenDB service failed to start because of an error" + Environment.NewLine + e, EventLogEntryType.Error);
                    Stop();
                }
            });

            if (startTask.Wait(TimeSpan.FromSeconds(20)) == false)
            {
                EventLog.WriteEntry(
                    "Startup for RavenDB service seems to be taking longer than usual, moving initialization to a background thread",
                    EventLogEntryType.Warning);
            }
        }
Example #35
0
 protected override void OnStart(string[] args)
 {
     server = new RavenDbServer(new RavenConfiguration());
 }
Example #36
0
        private static bool InteractiveRun(RavenDbServer server)
        {
            bool?done    = null;
            var  actions = new Dictionary <string, Action>
            {
                { "cls", TryClearingConsole },
                {
                    "reset", () =>
                    {
                        TryClearingConsole();
                        done = true;
                    }
                },
                {
                    "gc", () =>
                    {
                        long before = Process.GetCurrentProcess().WorkingSet64;
                        Console.WriteLine(
                            "Starting garbage collection (without LOH compaction), current memory is: {0:#,#.##;;0} MB",
                            before / 1024d / 1024d);
                        RavenGC.CollectGarbage(false, () => server.SystemDatabase.TransactionalStorage.ClearCaches());
                        var after = Process.GetCurrentProcess().WorkingSet64;
                        Console.WriteLine(
                            "Done garbage collection, current memory is: {0:#,#.##;;0} MB, saved: {1:#,#.##;;0} MB",
                            after / 1024d / 1024d,
                            (before - after) / 1024d / 1024d);
                    }
                },
                {
                    "loh-compaction", () =>
                    {
                        long before = Process.GetCurrentProcess().WorkingSet64;
                        Console.WriteLine(
                            "Starting garbage collection (with LOH compaction), current memory is: {0:#,#.##;;0} MB",
                            before / 1024d / 1024d);
                        RavenGC.CollectGarbage(true, () => server.SystemDatabase.TransactionalStorage.ClearCaches());
                        var after = Process.GetCurrentProcess().WorkingSet64;
                        Console.WriteLine(
                            "Done garbage collection, current memory is: {0:#,#.##;;0} MB, saved: {1:#,#.##;;0} MB",
                            after / 1024d / 1024d,
                            (before - after) / 1024d / 1024d);
                    }
                },
                { "q", () => done = false }
            };

            WriteInteractiveOptions(actions);
            while (true)
            {
                var readLine = Console.ReadLine() ?? "";

                Action value;
                if (actions.TryGetValue(readLine, out value) == false)
                {
                    Console.WriteLine("Could not understand: {0}", readLine);
                    WriteInteractiveOptions(actions);
                    continue;
                }

                value();
                if (done != null)
                {
                    return(done.Value);
                }
            }
        }