/// <summary> /// Configures StructureMap to look for registries. /// </summary> /// <returns></returns> public static IContainer Initialize() { ObjectFactory.Initialize(x => { var documentStore = new EmbeddableDocumentStore { ConnectionStringName = "RavenDB" }; documentStore.Conventions.FindTypeTagName = type => typeof(IPageModel).IsAssignableFrom(type) ? "Pages" : null; documentStore.RegisterListener(new StoreListener()); documentStore.Initialize(); IndexCreation.CreateIndexes(typeof(Documents_ByParent).Assembly, documentStore); x.For<IDocumentStore>().Use(documentStore); x.For<IDocumentSession>() .HybridHttpOrThreadLocalScoped() .Use(y => { var store = y.GetInstance<IDocumentStore>(); return store.OpenSession(); }); x.For<IVirtualPathResolver>().Use<VirtualPathResolver>(); x.For<IPathResolver>().Use<PathResolver>(); x.For<IPathData>().Use<PathData>(); x.For<IControllerMapper>().Use<ControllerMapper>(); x.For<ISettings>().Use<Settings>(); x.Scan(scanner => { scanner.AssembliesFromApplicationBaseDirectory(); scanner.Convention<PageTypeRegistrationConvetion>(); }); x.For<IPageModel>().UseSpecial(y => y.ConstructedBy( r => ((MvcHandler) HttpContext.Current.Handler).RequestContext.RouteData.GetCurrentPage<IPageModel>())); x.For<IStructureInfo>().UseSpecial(y => y.ConstructedBy(r => ((MvcHandler)HttpContext.Current.Handler).RequestContext.RouteData.Values["StructureInfo"] as IStructureInfo)); }); return ObjectFactory.Container; }
public void CanQueryMetadata() { using (var store = new EmbeddableDocumentStore { RunInMemory = true }) { store.Initialize(); using (var s = store.OpenSession()) { s.Store(new User { Metadata = { IsActive = true } }); s.SaveChanges(); } using (var s = store.OpenSession()) { var actual = s.Query<User>() .Customize(x=>x.WaitForNonStaleResultsAsOfLastWrite()) .Where(x => x.Metadata.IsActive == true) .Count(); Assert.Equal(1, actual); } } }
public static EmbeddableDocumentStore GetInMemoryStore(bool withExpiration = false) { var store = new EmbeddableDocumentStore { Configuration = { RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, RunInMemory = true }, Conventions = { SaveEnumsAsIntegers = true } }; store.Configuration.CompiledIndexCacheDirectory = Path.GetTempPath(); // RavenDB-2236 if (withExpiration) { Settings.ExpirationProcessTimerInSeconds = 1; // so we don't have to wait too much in tests store.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(typeof(ExpiredDocumentsCleaner).Assembly)); store.Configuration.Settings.Add("Raven/ActiveBundles", "CustomDocumentExpiration"); // Enable the expiration bundle } store.Initialize(); if (withExpiration) { new ExpiryProcessedMessageIndex().Execute(store); // this index is being queried by our expiration bundle } return store; }
public void Test_paralel_operations_with_multiple_EmbeddableDocumentStores() { Action storeAndRead = () => { using (var store = new EmbeddableDocumentStore { RunInMemory = true }) { store.Initialize(); using (var session = store.OpenSession()) { session.Store(new Document { Value = "foo" }, "documents/1"); session.SaveChanges(); } using (var session = store.OpenSession()) { var doc = session.Load<Document>("documents/1"); Assert.Equal("foo", doc.Value); } } }; storeAndRead(); var tasks = Enumerable.Range(1, 10).Select(_ => Task.Run(storeAndRead)).ToArray(); Task.WaitAll(tasks); }
static void Main(string[] args) { var sub = new TestThingySub { Name = "Sub Thingy", widgetCount = 2 }; var thingy = new TestThingy { Name = "Balls", SubThingy=sub, WidgetIDs = Enumerable.Range(0, 23).ToList() }; thingy.SetId(342); TestThingy thing2; using (var documentStore = new EmbeddableDocumentStore { DataDirectory = @"C:\Users\Andrew\Dropbox\Code\Projects\RavenDBEmbeddedPOC\packages\RavenDB-Embedded.1.0.701\lib\net40" }) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { thing2 = (from t in session.Query<TestThingy>() select t).First(); } } Console.WriteLine("we just ran this bitch"); Console.Read(); }
private static void DoTest(DateTime dt, DateTimeKind inKind, DateTimeKind outKind) { Assert.Equal(inKind, dt.Kind); using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true }) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { session.Store(new Foo { Id = "foos/1", DateTime = dt }); session.SaveChanges(); } using (var session = documentStore.OpenSession()) { var foo = session.Query<Foo>() .Customize(x => x.WaitForNonStaleResults()) .FirstOrDefault(x => x.DateTime == dt); WaitForUserToContinueTheTest(documentStore); Assert.Equal(dt, foo.DateTime); Assert.Equal(outKind, foo.DateTime.Kind); } } }
private static void InitialiseRavenDB(ContainerBuilder builder) { var documentStore = new EmbeddableDocumentStore {DataDirectory = "~/DataDir"}; documentStore.Initialize(); builder.RegisterInstance(documentStore).As<IDocumentStore>(); }
public void CanShutdown() { DocumentStore docStore; using (var store = new EmbeddableDocumentStore { UseEmbeddedHttpServer = true, RunInMemory = true }) { store.Configuration.Port = 8079; store.Initialize(); docStore = new DocumentStore { Url = "http://127.0.0.1:8079/", DefaultDatabase = "test" }; docStore.Initialize(); new RavenDocumentsByEntityName().Execute(docStore); docStore.DatabaseCommands.EnsureDatabaseExists("database"); using (docStore.OpenSession("database")) { } } docStore.Dispose(); }
public CryptTest() { documentStore = new EmbeddableDocumentStore { RunInMemory = true }; documentStore.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(typeof (DocumentCodec).Assembly)); documentStore.Initialize(); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> public static void RegisterServices(IKernel kernel) { kernel.Bind<IApiHttpChannel>().To<ApiHttpChannel>(); kernel.Bind<IRepresentationBuilder>().To<XmlRepresentationBuilder>(); kernel.Bind<IRepresentationBuilder>().To<JsonRepresentationBuilder>(); kernel.Bind<IAgentManager>().To<AgentManager>().InRequestScope(); kernel.Bind<IPackageStore>().To<LocalPackageStore>(); kernel.Bind<IAgentRemoteService>().To<AgentRemoteService>(); kernel.Bind<IDocumentStore>() .ToMethod(ctx => { //var documentStore = new DocumentStore() { Url = "http://localhost:8080" }; var documentStore = new EmbeddableDocumentStore() {DataDirectory = "App_Data/Database"}; documentStore.Initialize(); return documentStore; }).InSingletonScope(); kernel.Bind<IDocumentSession, DocumentSession>() .ToMethod(ctx => { var session = ctx.Kernel.Get<IDocumentStore>().OpenSession(); session.Advanced.UseOptimisticConcurrency = true; return session as DocumentSession; }) .InRequestScope() .OnDeactivation((ctx, session) => { if (session.Advanced.HasChanges) { session.SaveChanges(); } }); }
public static DocumentStore GetAndInitializeByPath(string path, bool enableManagementStudio, int managementStudioPort) { if (!_documentStores.ContainsKey(path)) { if( enableManagementStudio ) NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(managementStudioPort); var documentStore = new EmbeddableDocumentStore { DataDirectory = path, }; if (enableManagementStudio) documentStore.UseEmbeddedHttpServer = true; documentStore.Conventions.CustomizeJsonSerializer = s => { s.Converters.Add(new MethodInfoConverter()); }; documentStore.Initialize(); _documentStores[path] = documentStore; } return _documentStores[path]; }
static RavenDbProvider() { _documentStore = new EmbeddableDocumentStore() { DataDirectory = SpruceSettings.UserSettingsDirectory }; #if DEBUG //_documentStore.UseEmbeddedHttpServer = true; //NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8081); #endif try { NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8081); } catch (Exception e) { Log.Warn(e, "RavenDb: NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8081) threw an exception"); } _documentStore.Initialize(); // Access RavenDb using http://localhost:8081. Make sure the XAP file from the lib/ravendb folder is in the Spruce.Site root. }
public void Should_retrieve_all_entities_using_connection_string() { using (var documentStore = new EmbeddableDocumentStore { ConnectionStringName = "Local", Configuration = { RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true } }) { path = documentStore.DataDirectory; documentStore.Initialize(); var session1 = documentStore.OpenSession(); session1.Store(new Company { Name = "Company 1" }); session1.Store(new Company { Name = "Company 2" }); session1.SaveChanges(); var session2 = documentStore.OpenSession(); var companyFound = session2.Advanced.DocumentQuery<Company>() .WaitForNonStaleResults() .ToArray(); Assert.Equal(2, companyFound.Length); } }
/// <summary> /// Configures StructureMap to look for registries. /// </summary> /// <returns></returns> public static IContainer Initialize() { ObjectFactory.Initialize(x => { var documentStore = new EmbeddableDocumentStore { ConnectionStringName = "RavenDB" }; documentStore.Initialize(); documentStore.Conventions.FindTypeTagName = type => typeof(IPageModel).IsAssignableFrom(type) ? "pages" : null; Raven.Client.MvcIntegration.RavenProfiler.InitializeFor(documentStore); IndexCreation.CreateIndexes(typeof(Documents_ByParent).Assembly, documentStore); x.For<IDocumentStore>().Use(documentStore); x.For<IDocumentSession>() .HybridHttpOrThreadLocalScoped() .Use(y => { var store = y.GetInstance<IDocumentStore>(); return store.OpenSession(); }); x.For<IVirtualPathResolver>().Use<VirtualPathResolver>(); x.For<IPathResolver>().Use<PathResolver>(); x.For<IPathData>().Use<PathData>(); x.For<IControllerMapper>().Use<ControllerMapper>(); x.For<ISettings>().Use<Settings>(); x.For<IPageModel>().UseSpecial(y => y.ConstructedBy( r => ((MvcHandler) HttpContext.Current.Handler).RequestContext.RouteData.GetCurrentModel<IPageModel>())); }); return ObjectFactory.Container; }
public static IContainer InMemoryStartup() { var presentationdocumentStore = new EmbeddableDocumentStore { RunInMemory = true, }; presentationdocumentStore.Initialize(); ObjectFactory.Initialize(config => { config.Scan(scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); }); config.AddRegistry(new CoreRegistry(presentationdocumentStore)); }); ObjectFactory.AssertConfigurationIsValid(); ObjectFactory.WhatDoIHave(); WaitForIndexes(presentationdocumentStore); IndexCreation.CreateIndexes(typeof(Users_ByUsername).Assembly, presentationdocumentStore); WaitForIndexes(presentationdocumentStore); return ObjectFactory.Container; }
public void can_persist_and_query_documents() { using (var store = new EmbeddableDocumentStore { RunInMemory = true, DataDirectory = "RavenData" } ) { store.Initialize(); using (var session = store.OpenSession()) { var user = new User { Email = "*****@*****.**", FirstName = "Micky", LastName = "Bubbles", }; session.Store(user); session.SaveChanges(); Assert.AreEqual(true, session.Query<User>().Where(x => x.Email == "*****@*****.**").Any()); } } }
public void Should_give_documents_where_ExpirationDate_is_null_or_expirationdate_greater_than_today() { using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true, Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites } }) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { session.Store(new Foo()); session.Store(new Foo()); session.SaveChanges(); } using (var session = documentStore.OpenSession()) { var bar = session.Query<Foo>() .Where(foo => foo.ExpirationTime == null || foo.ExpirationTime > DateTime.Now) .ToList(); Assert.That(bar.Count, Is.EqualTo(2)); } } }
public override void Load() { Bind<IDocumentStore>().ToMethod(context => { using (var d1 = new EmbeddableDocumentStore { RunInMemory = true, UseEmbeddedHttpServer = false }.Initialize()) using (var d2 = new EmbeddableDocumentStore { RunInMemory = true, UseEmbeddedHttpServer = false }.Initialize()) NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8080); var documentstore = new EmbeddableDocumentStore { // DataDirectory = "App_Data", ConnectionStringName="RavenHQ", UseEmbeddedHttpServer = true }; return documentstore.Initialize(); }).InSingletonScope(); Bind<IDocumentSession>().ToMethod(Context => Context.Kernel.Get<IDocumentStore>().OpenSession()).InRequestScope(); }
/// <summary> /// Creates the kernel that will manage your application. /// </summary> /// <returns>The created kernel.</returns> private static IKernel CreateKernel() { var documentStore = new EmbeddableDocumentStore { UseEmbeddedHttpServer = true, DataDirectory = "App_Data", Configuration = { Port = 12345, }, Conventions = { CustomizeJsonSerializer = MvcApplication.SetupSerializer } }; documentStore.Initialize(); var manager = new SubscriptionManager(documentStore); var kernel = new StandardKernel(); kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); kernel.Bind<IDocumentStore>() .ToMethod(context => documentStore) .InSingletonScope(); RegisterServices(kernel); kernel.Bind<SubscriptionManager>().ToMethod(context => manager).InSingletonScope(); return kernel; }
public EmbeddableDocumentStore NewDocumentStore(string storageType, bool inMemory, int? allocatedMemory) { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); var documentStore = new EmbeddableDocumentStore() { Configuration = { DataDirectory = path, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, DefaultStorageTypeName = storageType, RunInMemory = inMemory, } }; ModifyStore(documentStore); ModifyConfiguration(documentStore.Configuration); if (documentStore.Configuration.RunInMemory == false) IOExtensions.DeleteDirectory(path); documentStore.Initialize(); CreateDefaultIndexes(documentStore); if (allocatedMemory != null && inMemory) { var transactionalStorage = ((TransactionalStorage)documentStore.DocumentDatabase.TransactionalStorage); transactionalStorage.EnsureCapacity(allocatedMemory.Value); } return documentStore; }
protected AuthenticationTest() { database::Raven.Database.Extensions.IOExtensions.DeleteDirectory("Data"); embeddedStore = new EmbeddableDocumentStore() { Configuration = { AnonymousUserAccessMode = database::Raven.Database.Server.AnonymousUserAccessMode.Get, Catalog = {Catalogs = {new AssemblyCatalog(typeof (AuthenticationUser).Assembly)}}, DataDirectory = "Data", RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, AuthenticationMode = "oauth", Port = 8079, OAuthTokenCertificate = database::Raven.Database.Config.CertGenerator.GenerateNewCertificate("RavenDB.Test") }, UseEmbeddedHttpServer = true, }; embeddedStore.Configuration.Initialize(); embeddedStore.Initialize(); store = new DocumentStore { Url = embeddedStore.Configuration.ServerUrl, }; store.Initialize(); store.JsonRequestFactory. EnableBasicAuthenticationOverUnsecureHttpEvenThoughPasswordsWouldBeSentOverTheWireInClearTextToBeStolenByHackers = true; foreach (DictionaryEntry de in HttpRuntime.Cache) { HttpRuntime.Cache.Remove((string)de.Key); } }
static void Main(string[] args) { var cfg = new HttpSelfHostConfiguration("http://localhost:1337"); cfg.MaxReceivedMessageSize = 16L * 1024 * 1024 * 1024; cfg.TransferMode = TransferMode.StreamedRequest; cfg.ReceiveTimeout = TimeSpan.FromMinutes(20); cfg.Routes.MapHttpRoute( "API Default", "api/{controller}/{id}", new { id = RouteParameter.Optional }); cfg.Routes.MapHttpRoute( "Default", "{*res}", new { controller = "StaticFile", res = RouteParameter.Optional }); var db = new EmbeddableDocumentStore { DataDirectory = new FileInfo("db/").DirectoryName }; db.Initialize(); cfg.Filters.Add(new RavenDbApiAttribute(db)); using (HttpSelfHostServer server = new HttpSelfHostServer(cfg)) { Console.WriteLine("Initializing server."); server.OpenAsync().Wait(); Console.WriteLine("Server ready at: " + cfg.BaseAddress); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); } }
public void ShouldWork() { using (var _documentStore = new EmbeddableDocumentStore { RunInMemory = true, Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites } }) { _documentStore.Initialize(); using (var session = _documentStore.OpenSession()) { session.Store(new Foo()); session.Store(new Foo()); session.SaveChanges(); } using (var session = _documentStore.OpenSession()) { var bar = session.Query<Foo>().Where(foo => foo.ExpirationTime == null || foo.ExpirationTime > DateTime.Now).ToList(); Assert.Equal(2, bar.Count); } } }
public CommandStorageTests() { _store = new EmbeddableDocumentStore(); // _store.DataDirectory = Environment.CurrentDirectory + "Db"; _store.RunInMemory = true; _store.Initialize(); }
public static void Startup() { var sampleFrameworkDb = new EmbeddableDocumentStore { DataDirectory = "App_Data\\RavenDb", UseEmbeddedHttpServer = true }; sampleFrameworkDb.RegisterListener(new DocumentConversionListener()); sampleFrameworkDb.Conventions.FindClrTypeName = FindClrTypeName; sampleFrameworkDb.Conventions.FindTypeTagName = FindTypeTagName; sampleFrameworkDb.Conventions.JsonContractResolver = new DPContractResolver(); sampleFrameworkDb.Conventions.ShouldCacheRequest = url => false; sampleFrameworkDb.Conventions.CustomizeJsonSerializer = serializer => { serializer.ContractResolver = new DPContractResolver(); serializer.Converters.Add(new ModelCreationConverter()); }; sampleFrameworkDb.Initialize(); sampleFrameworkDb.DatabaseCommands.DisableAllCaching(); ObjectFactory.Initialize(x => { x.AddRegistry(new RavenDbRegistry(sampleFrameworkDb)); x.AddRegistry(new RepositoryRegistry()); }); }
public RavenServer(Action<EmbeddableDocumentStore> initialization = null) { int port = 32076; DocumentStore = new EmbeddableDocumentStore { DataDirectory = "Data", UseEmbeddedHttpServer = true, DefaultDatabase = "NServiceBus", Configuration = { Port = port, PluginsDirectory = Environment.CurrentDirectory, HostName = "localhost" } }; if (initialization != null) { initialization(DocumentStore); } DocumentStore.Initialize(); //since we are hosting a fake raven server in process we need to remove it from the logging pipeline Trace.Listeners.Clear(); Trace.Listeners.Add(new DefaultTraceListener()); ManagementUrl = string.Format("http://localhost:{0}/", port); Console.WriteLine("Raven server started on {0}" + ManagementUrl); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RequiredIfAttribute), typeof(RequiredIfValidator)); DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(AssertThatAttribute), typeof(AssertThatValidator)); // override standard error messages ClientDataTypeModelValidatorProvider.ResourceClassKey = "DefaultResources"; DefaultModelBinder.ResourceClassKey = "DefaultResources"; DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RequiredAttribute), typeof(MyRequiredAttributeAdapter)); // setting locale var culture = new CultureInfo("nb-NO"); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; // init log4net log4net.Config.XmlConfigurator.Configure(); MvcHandler.DisableMvcResponseHeader = true; Store = new EmbeddableDocumentStore { ConnectionStringName = "RavenDB" }; Store.Initialize(); }
public ScriptHelper() { var p1 = Path.Combine("Data", "System.db"); SystemStore = new EmbeddableDocumentStore { DataDirectory = p1 }; SystemStore.Initialize(); System = SystemStore.OpenSession(); SystemStore.Conventions.RegisterIdConvention<DbSetting>((db, cmds, setting) => "Settings/" + setting.Name); SystemStore.Conventions.RegisterIdConvention<DbScript>((db, cmds, script) => "Scripts/" + script.Name); try { SystemStore.DatabaseCommands.PutIndex("Settings/ByName", new IndexDefinitionBuilder<DbSetting> { Map = settings => from setting in settings select new { setting.Name } }); SystemStore.DatabaseCommands.PutIndex("Scripts/ByName", new IndexDefinitionBuilder<DbScript> { Map = scripts => from script in scripts select new { script.Name } }); } catch (Exception) { } IndexCreation.CreateIndexes(typeof(DbScript).Assembly,SystemStore); IndexCreation.CreateIndexes(typeof(DbSetting).Assembly, SystemStore); }
public Class1() { Person myObject = new Person() { Date = DateTime.Now, Name = "Jack" }; var documentStore = new EmbeddableDocumentStore() { DataDirectory = "Data" }; documentStore.Initialize(); Console.WriteLine("inited"); var session = documentStore.OpenSession(); Console.WriteLine("session open"); session.Store(myObject); session.SaveChanges(); Console.WriteLine("changes saved"); Thread.Sleep(1000); foreach (Person queryResponse in session.Query<Person>().Where(o => o.Name == "Jack")) { Console.WriteLine(queryResponse.Name + "."); } Console.WriteLine("done"); Console.ReadLine(); }
public when_querying_cases_by_name_using_danish_collation() { var culture = new CultureInfo("da"); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; store = new EmbeddableDocumentStore { RunInMemory = true }; store.Initialize(); using (var session = store.OpenSession()) { session.Store(new Case { Name = "bcda" }); session.Store(new Case { Name = "dacb" }); session.Store(new Case { Name = "daab" }); session.Store(new Case { Name = "dacb" }); session.Store(new Case { Name = "aacb" }); session.Store(new Case { Name = "aaac" }); session.Store(new Case { Name = "bcbb" }); session.Store(new Case { Name = "acba" }); session.Store(new Case { Name = "aaaa" }); session.Store(new Case { Name = "dada" }); session.SaveChanges(); } }
protected IDocumentStore NewInMemoryStore() { IDocumentStore documentStore = new Raven.Client.Embedded.EmbeddableDocumentStore() { RunInMemory = true, }; documentStore.Initialize(); return(documentStore); }