public string GenerateDocumentKey(DocumentConvention conventions, object entity) { var shardId = shardedDocumentStore.ShardStrategy.ShardResolutionStrategy.MetadataShardIdFor(entity); if (shardId == null) throw new InvalidOperationException(string.Format( "ShardResolutionStrategy.MetadataShardIdFor cannot return null. You must specify where to store the metadata documents for the entity type '{0}'.", entity.GetType().FullName)); MultiTypeHiLoKeyGenerator value; if (generatorsByShard.TryGetValue(shardId, out value)) return value.GenerateDocumentKey(conventions, entity); lock (this) { if (generatorsByShard.TryGetValue(shardId, out value) == false) { value = new MultiTypeHiLoKeyGenerator(shardedDocumentStore.DatabaseCommandsFor(shardId), capacity); generatorsByShard = new Dictionary<string, MultiTypeHiLoKeyGenerator>(generatorsByShard) { {shardId, value} }; } } return value.GenerateDocumentKey(conventions, entity); }
public IDocumentStore Initialise() { try { #if !CLIENT if (configuration != null) { var embeddedDatabase = new Raven.Database.DocumentDatabase(configuration); embeddedDatabase.SpinBackgroundWorkers(); DatabaseCommands = new EmbededDatabaseCommands(embeddedDatabase, Conventions); } else #endif { DatabaseCommands = new ServerClient(Url, Conventions, credentials); } if (Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing { var generator = new MultiTypeHiLoKeyGenerator(DatabaseCommands, 1024); Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(Conventions, entity); } } catch (Exception) { Dispose(); throw; } return(this); }
public IDocumentStore Initialize() { try { if (!this.Conventions.DisableProfiling) { this.jsonRequestFactory.LogRequest += new EventHandler <RequestResultArgs>(this.profilingContext.RecordAction); } this.InitializeInternal(); if (this.Conventions.DocumentKeyGenerator == null) { MultiTypeHiLoKeyGenerator generator = new MultiTypeHiLoKeyGenerator((IDocumentStore)this, 1024); this.Conventions.DocumentKeyGenerator = (Func <object, string>)(entity => generator.GenerateDocumentKey(this.Conventions, entity)); } } catch (Exception ex) { this.Dispose(); throw; } if (!string.IsNullOrEmpty(this.DefaultDatabase)) { MultiTenancyExtensions.EnsureDatabaseExists(this.DatabaseCommands.GetRootDatabase(), this.DefaultDatabase); } return((IDocumentStore)this); }
public void WhenDocumentAlreadyExists_Can_Still_Generate_Values() { using (var store = NewDocumentStore()) { var mk = new MultiTypeHiLoKeyGenerator(store, 5); store.Conventions.DocumentKeyGenerator = o => mk.GenerateDocumentKey(store.Conventions, o); using (var session = store.OpenSession()) { var company = new Company(); session.Store(company); var contact = new Contact(); session.Store(contact); Assert.Equal("companies/1", company.Id); Assert.Equal("contacts/1", contact.Id); } mk = new MultiTypeHiLoKeyGenerator(store, 5); store.Conventions.DocumentKeyGenerator = o => mk.GenerateDocumentKey(store.Conventions, o); using (var session = store.OpenSession()) { var company = new Company(); session.Store(company); var contact = new Contact(); session.Store(contact); Assert.Equal("companies/6", company.Id); Assert.Equal("contacts/6", contact.Id); } } }
public void DoesNotLoseValuesWhenHighIsOver() { using (var store = NewDocumentStore()) { var mk = new MultiTypeHiLoKeyGenerator(store, 5); for (int i = 0; i < 15; i++) { Assert.Equal("companies/"+(i+1), mk.GenerateDocumentKey(store.Conventions, new Company())); } } }
public RavenDbRegistry(string connectionStringName) { // https://github.com/PureKrome/RavenOverflow/blob/master/Code/RavenOverflow.Web/DependencyResolution/RavenDbRegistry.cs For<IDocumentStore>() .Singleton() .Use(x => { var connectionString = ConfigurationManager.AppSettings[connectionStringName]; var parser = ConnectionStringParser<RavenConnectionStringOptions>.FromConnectionString(connectionString); parser.Parse(); var documentStore = new DocumentStore { ApiKey = parser.ConnectionStringOptions.ApiKey, Url = parser.ConnectionStringOptions.Url, }; var generator = new MultiTypeHiLoKeyGenerator(documentStore, 32); documentStore.Conventions.DocumentKeyGenerator = entity => { var special = entity as IGenerateMyId; return special == null ? generator.GenerateDocumentKey(documentStore.Conventions, entity) : special.GenerateId(); }; documentStore.Initialize(); InitializeRavenProfiler(documentStore); IndexCreation.CreateIndexes(typeof(CompetitionSearch).Assembly, documentStore); return documentStore; } ) .Named("RavenDB Document Store."); For<IDocumentSession>() .HttpContextScoped() .Use(x => { var documentStore = x.GetInstance<IDocumentStore>(); return documentStore.OpenSession(); }) .Named("RavenDb Session -> per Http Request."); }
public static IContainer Configure_Raven_For_Testing(this IContainer container) { var documentStore = new EmbeddableDocumentStore { RunInMemory = true }; documentStore.Initialize(); var generator = new MultiTypeHiLoKeyGenerator(documentStore, 10); documentStore.Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(documentStore.Conventions, entity); IndexCreation.CreateIndexes(typeof(Destination_ByLocation).Assembly, documentStore); var builder = new ContainerBuilder(); builder.RegisterInstance(documentStore).As<IDocumentStore>(); builder.Update(container); return container; }
/// <summary> /// Initializes this instance. /// </summary> /// <returns></returns> public IDocumentStore Initialize() { try { InitializeInternal(); if (Conventions.DocumentKeyGenerator == null) // don't overwrite what the user is doing { #if !SILVERLIGHT var generator = new MultiTypeHiLoKeyGenerator(this, 1024); Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(Conventions, entity); #else Conventions.DocumentKeyGenerator = entity => { var typeTagName = Conventions.GetTypeTagName(entity.GetType()); if (typeTagName == null) { return(Guid.NewGuid().ToString()); } return(typeTagName + "/" + Guid.NewGuid()); }; #endif } } catch (Exception) { Dispose(); throw; } #if !SILVERLIGHT if (string.IsNullOrEmpty(DefaultDatabase) == false) { DatabaseCommands.GetRootDatabase().EnsureDatabaseExists(DefaultDatabase); } #endif return(this); }
/// <summary> /// Initializes this instance. /// </summary> /// <returns></returns> public IDocumentStore Initialize() { try { InitializeInternal(); if(Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing { var generator = new MultiTypeHiLoKeyGenerator(this, 1024); Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(Conventions, entity); } } catch (Exception) { Dispose(); throw; } if(string.IsNullOrEmpty(DefaultDatabase) == false) { DatabaseCommands.EnsureDatabaseExists(DefaultDatabase); } return this; }
public void DocumentKeyGenerator() { var generator = new MultiTypeHiLoKeyGenerator(5); store.Conventions.DocumentKeyGenerator = (dbName, cmd, entity) => generator.GenerateDocumentKey(cmd, store.Conventions, entity); store.Initialize(); }
public IDocumentStore Initialize() { try { if (!this.Conventions.DisableProfiling) this.jsonRequestFactory.LogRequest += new EventHandler<RequestResultArgs>(this.profilingContext.RecordAction); this.InitializeInternal(); if (this.Conventions.DocumentKeyGenerator == null) { MultiTypeHiLoKeyGenerator generator = new MultiTypeHiLoKeyGenerator((IDocumentStore) this, 1024); this.Conventions.DocumentKeyGenerator = (Func<object, string>) (entity => generator.GenerateDocumentKey(this.Conventions, entity)); } } catch (Exception ex) { this.Dispose(); throw; } if (!string.IsNullOrEmpty(this.DefaultDatabase)) MultiTenancyExtensions.EnsureDatabaseExists(this.DatabaseCommands.GetRootDatabase(), this.DefaultDatabase); return (IDocumentStore) this; }
public IDocumentStore Initialize() { try { #if !CLIENT if (configuration != null) { DocumentDatabase = new Raven.Database.DocumentDatabase(configuration); DocumentDatabase.SpinBackgroundWorkers(); databaseCommandsGenerator = () => new EmbededDatabaseCommands(DocumentDatabase, Conventions); } else #endif { databaseCommandsGenerator = ()=>new ServerClient(Url, Conventions, credentials); asyncDatabaseCommandsGenerator = ()=>new AsyncServerClient(Url, Conventions, credentials); } if(Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing { var generator = new MultiTypeHiLoKeyGenerator(DatabaseCommands, 1024); Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(Conventions, entity); } } catch (Exception) { Dispose(); throw; } return this; }
private static void InitializeRaven() { try { _store = new DocumentStore { ConnectionStringName = "RavenDB" }; _store.Initialize(); var generator = new MultiTypeHiLoKeyGenerator(Store, 5); Store.Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(Store.Conventions, entity); IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), _store); using (var session = _store.OpenSession()) { if (session.Load<SiteConfig>(SiteConfig.ConfigName) == null) { session.Store(new SiteConfig { RequireRegistration = true }, SiteConfig.ConfigName); session.SaveChanges(); } } ConfigureVersioning(); } catch (Exception e) { if (RedirectToErrorPageIfRavenDbIsDown(e) == false) throw; } }
public void DocumentKeyGenerator() { var generator = new MultiTypeHiLoKeyGenerator(store, 5); store.Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(store.Conventions, entity); store.Initialize(); }
public static IDocumentStore Init_Document_Store() { var builder = new ContainerBuilder(); var documentStore = new DocumentStore { ConnectionStringName = "Routing_Test", // Url = @"http://server:8090", //Conventions = //{ // FindTypeTagName = type => typeof(Resource).IsAssignableFrom(type) ? "Resources" : null, //} //Conventions = //{ // FindTypeTagName = type => // { // if (typeof(Resource).IsAssignableFrom(type)) // return "Resources"; // if (typeof(Payment).IsAssignableFrom(type)) // return "Payments"; // return null; // } //} }; documentStore.Initialize(); var generator = new MultiTypeHiLoKeyGenerator(documentStore, 10); documentStore.Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(documentStore.Conventions, entity); // IndexCreation.CreateIndexes(typeof(LocalizedResource_ByLocation).Assembly, documentStore); builder.RegisterInstance(documentStore); builder.Register(c => c.Resolve<DocumentStore>().OpenSession()).InstancePerLifetimeScope(); return documentStore; }
public static ContainerBuilder Configure_Raven(ContainerBuilder builder) { var documentStore = new DocumentStore { ConnectionStringName = "Routing_Test", // Url = @"http://server:8090", //Conventions = //{ // FindTypeTagName = type => typeof(Resource).IsAssignableFrom(type) ? "Resources" : null, //} //Conventions = //{ // FindTypeTagName = type => // { // if (typeof(Resource).IsAssignableFrom(type)) // return "Resources"; // if (typeof(Payment).IsAssignableFrom(type)) // return "Payments"; // return null; // } //} }; documentStore.Initialize(); var generator = new MultiTypeHiLoKeyGenerator(documentStore, 10); documentStore.Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(documentStore.Conventions, entity); IndexCreation.CreateIndexes(typeof(Destination_ByLocation).Assembly, documentStore); //var builder = new ContainerBuilder(); builder.RegisterInstance(documentStore).As<IDocumentStore>(); //builder.Update(builder); return builder; }
/// <summary> /// Initializes this instance. /// </summary> /// <returns></returns> public override IDocumentStore Initialize() { if (initialized) { return(this); } AssertValidConfiguration(); #if !SILVERLIGHT jsonRequestFactory = new HttpJsonRequestFactory(MaxNumberOfCachedRequests); #else jsonRequestFactory = new HttpJsonRequestFactory(); #endif try { InitializeProfiling(); InitializeInternal(); InitializeSecurity(); #if !SILVERLIGHT if (Conventions.DocumentKeyGenerator == null) // don't overwrite what the user is doing { var generator = new MultiTypeHiLoKeyGenerator(32); Conventions.DocumentKeyGenerator = (databaseCommands, entity) => generator.GenerateDocumentKey(databaseCommands, Conventions, entity); } #endif #if !NET35 if (Conventions.AsyncDocumentKeyGenerator == null && asyncDatabaseCommandsGenerator != null) { #if !SILVERLIGHT var generator = new AsyncMultiTypeHiLoKeyGenerator(32); Conventions.AsyncDocumentKeyGenerator = (commands, entity) => generator.GenerateDocumentKeyAsync(commands, Conventions, entity); #else Conventions.AsyncDocumentKeyGenerator = (commands, entity) => { var typeTagName = Conventions.GetTypeTagName(entity.GetType()); if (typeTagName == null) { return(CompletedTask.With(Guid.NewGuid().ToString())); } return(CompletedTask.With(typeTagName + "/" + Guid.NewGuid())); }; #endif } #endif initialized = true; #if !SILVERLIGHT RecoverPendingTransactions(); if (string.IsNullOrEmpty(DefaultDatabase) == false) { DatabaseCommands.ForDefaultDatabase().EnsureDatabaseExists(DefaultDatabase, ignoreFailures: true); } #endif } catch (Exception) { Dispose(); throw; } return(this); }
/// <summary> /// Initializes this instance. /// </summary> /// <returns></returns> public IDocumentStore Initialize() { if (initialized) { return(this); } AssertValidConfiguration(); #if !SILVERLIGHT jsonRequestFactory = new HttpJsonRequestFactory(MaxNumberOfCachedRequests); #else jsonRequestFactory = new HttpJsonRequestFactory(); #endif try { #if !NET_3_5 if (Conventions.DisableProfiling == false) { jsonRequestFactory.LogRequest += profilingContext.RecordAction; } #endif InitializeInternal(); InitializeSecurity(); if (Conventions.DocumentKeyGenerator == null) // don't overwrite what the user is doing { #if !SILVERLIGHT var generator = new MultiTypeHiLoKeyGenerator(this, 1024); Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(Conventions, entity); #else Conventions.DocumentKeyGenerator = entity => { var typeTagName = Conventions.GetTypeTagName(entity.GetType()); if (typeTagName == null) { return(Guid.NewGuid().ToString()); } return(typeTagName + "/" + Guid.NewGuid()); }; #endif } } catch (Exception) { Dispose(); throw; } initialized = true; #if !SILVERLIGHT if (string.IsNullOrEmpty(DefaultDatabase) == false) { DatabaseCommands.GetRootDatabase().EnsureDatabaseExists(DefaultDatabase); } #endif return(this); }
/// <summary> /// Initializes this instance. /// </summary> /// <returns></returns> public IDocumentStore Initialize() { try { InitializeInternal(); if(Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing { var generator = new MultiTypeHiLoKeyGenerator(this, 1024); Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(Conventions, entity); } } catch (Exception) { Dispose(); throw; } return this; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); InitializeMothForDebugging(); MothRouteFactory.RegisterRoutes(RouteTable.Routes); RegisterRoutes(RouteTable.Routes); ValueProviderFactories.Factories.Insert(0, new SimpleCommandValueProviderFactory()); ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder()); //http://digitalbush.com/2011/04/24/asp-net-mvc3-json-decimal-binding-woes/ ModelBinders.Binders.Add(typeof(decimal?), new DecimalModelBinder()); ModelBinderProviders.BinderProviders.Insert(0, new SimpleRavenIdModelBinderProvider()); //BundleTable.Bundles.RegisterTemplateBundles(); //TOOD: Script netsh for installer: https://groups.google.com/forum/?fromgroups#!topic/ravendb/Wzl9jPq0m_0 //http://blogs.iis.net/webdevelopertips/archive/2009/10/02/tip-98-did-you-know-the-default-application-pool-identity-in-iis-7-5-windows-7-changed-from-networkservice-to-apppoolidentity.aspx RavenController.DocumentStore = new EmbeddableDocumentStore() { ConnectionStringName = "RavenDB", UseEmbeddedHttpServer = true, }; Raven.Database.Server.NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8085); RavenController.DocumentStore.Configuration.Port = 8085; RavenController.DocumentStore.RegisterListener(new NoStaleQueriesAllowedAsOfNow()); var generator = new MultiTypeHiLoKeyGenerator(RavenController.DocumentStore, 32); RavenController.DocumentStore.Conventions.DocumentKeyGenerator = entity => { var special = entity as IGenerateMyId; return special == null ? generator.GenerateDocumentKey(RavenController.DocumentStore.Conventions, entity) : special.GenerateId(); }; RavenController.DocumentStore.Initialize(); InitializeRavenProfiler(); IndexCreation.CreateIndexes(typeof(JudgeScoreIndex).Assembly, RavenController.DocumentStore); }