public void Configure() { BsonSerializer.RegisterIdGenerator( typeof(Guid), CombGuidGenerator.Instance ); }
public void Register(ContainerBuilder container) { container.Register(r => { IScoutConfiguration config = r.Resolve <IScoutConfiguration>(); var settings = MongoClientSettings.FromUrl(new MongoUrl(config.MongoConnectionString)); var client = new MongoClient(settings); BsonSerializer.RegisterIdGenerator(typeof(Guid), GuidGenerator.Instance); ConventionPack pack = new ConventionPack { new LowerCaseNamingConvention(), new ProperPluralGrammarNamingConvention(), new SeparateWordsNamingConvetion() }; ConventionRegistry.Register("standard", pack, type => true); return(client.GetDatabase(config.DatabaseName)); }).As <IMongoDatabase>().SingleInstance(); Mapper.Initialize(cfg => { cfg.AddProfile(new DatabaseModelMap()); }); container.RegisterType <PlayerRepository>().As <IPlayerRepository>(); container.RegisterType <AccountRepository>().As <IAccountRepository>(); }
public static IServiceCollection AddMongoClient( this IServiceCollection services, string connectionString, Action <CommandStartedEvent> queryLogger = null) { ConventionRegistry.Register("EnumStringConversion", new ConventionPack { new EnumRepresentationConvention(BsonType.String) }, t => true); BsonSerializer.RegisterIdGenerator( typeof(string), StringObjectIdGenerator.Instance); return(services .AddSingleton <MongoUrl>(s => new MongoUrl(connectionString)) .AddSingleton <IMongoClient>(s => { var settings = MongoClientSettings.FromUrl(s.GetRequiredService <MongoUrl>()); if (queryLogger != null) { settings.ClusterConfigurator = cb => { cb.Subscribe(queryLogger); }; } return new MongoClient(settings); }) .AddSingleton <IMongoDatabase>(s => { return s.GetRequiredService <IMongoClient>() .GetDatabase(s.GetRequiredService <MongoUrl>().DatabaseName); })); }
private void ConfigureBsonClassMaps() { var listOfClassMapsRegistered = BsonClassMap.GetRegisteredClassMaps(); listOfClassMapsRegistered = BsonClassMap.GetRegisteredClassMaps(); var testIntSequenceCollection = Client.GetDatabase(DefaultTestDatabaseName).GetCollection <IntSequenceCounterEntity>(DefaultTestCollectionForIntSequences); var intSequenceCounterRepository = new IntSequenceCounterRepository(testIntSequenceCollection); var intSequenceCounterGenerator = new IntSequenceCounterGenerator(intSequenceCounterRepository); BsonSerializer.RegisterIdGenerator(typeof(int), intSequenceCounterGenerator); var classMap = BsonClassMap.LookupClassMap(typeof(SampleEntityWithIntId)); /* * if (!BsonClassMap.IsClassMapRegistered(typeof(SampleEntityWithIntId))) * { * BsonClassMap.RegisterClassMap<SampleEntityWithIntId>(cm => * { * cm.AutoMap(); * cm.SetIsRootClass(true); * cm.SetIgnoreExtraElements(true); * cm.SetIdMember(cm.GetMemberMap(c => c.Id)); * cm.MapProperty(p => p.Id).SetIdGenerator(intSequenceCounterGenerator); * }); * } */ }
static void Main() { BsonSerializer.RegisterIdGenerator(typeof(string), new StringObjectIdGenerator()); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FrmPrincipal()); }
public static void RegisterCollectionMappings() { BsonSerializer.RegisterIdGenerator(typeof(ObjectId), ObjectIdGenerator.Instance); BsonClassMap.RegisterClassMap <Entity>(cm => { cm.AutoMap(); cm.MapIdMember(m => m.Id); }); }
public DatabaseFacade(string connectionString, string databaseName) { var client = new MongoClient(connectionString); var server = client.GetServer(); Database = server.GetDatabase(databaseName); BsonSerializer.RegisterIdGenerator(typeof(Guid), GuidGenerator.Instance); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { BsonSerializer.RegisterIdGenerator(typeof(string), new StringObjectIdGenerator()); services.Configure <BookstoreDatabaseSettings>( Configuration.GetSection(nameof(BookstoreDatabaseSettings))); services.AddServices(); services.AddInfrastructure(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
public static void Configure() { BsonSerializer.RegisterIdGenerator(typeof(Guid), CombGuidGenerator.Instance); BsonDefaults.GuidRepresentation = GuidRepresentation.Standard; BsonClassMap.RegisterClassMap <Article>(c => { c.AutoMap(); c.SetIdMember(c.GetMemberMap(p => p.Id)); }); }
private void RegisterConventions() { ConventionRegistry.Register("ActioConventions", new MongoConvention(), x => true); BsonSerializer.RegisterIdGenerator(typeof(Guid), CombGuidGenerator.Instance); var mappings = _serviceProvider.GetServices <IMongoMapping>(); foreach (var mapping in mappings) { mapping.Map(); } }
static MongoContext() { BsonSerializer.RegisterSerializer(typeof(Guid), new GuidSerializer(BsonType.String)); BsonSerializer.RegisterIdGenerator(typeof(Guid), new GuidGenerator()); var pack = new ConventionPack { new CamelCaseElementNameConvention(), new IgnoreExtraElementsConvention(true) }; ConventionRegistry.Register("Custom Conventions", pack, t => true); }
public static IServiceCollection AddInfrastructure(this IServiceCollection services) { BsonSerializer.RegisterIdGenerator(typeof(Guid), CombGuidGenerator.Instance); services.AddHttpContextAccessor(); services.AddScoped <IMongoDatabaseNameProvider, MongoDatabaseNameProvider>(); services.AddScoped(MongoDatabaseFactory.CreateDatabase); // Repositories services.AddScoped <IPersonRepository, PersonRepository>(); services.AddScoped <IApplicantRepository, ApplicantRepository>(); services.AddScoped <IApplicationRepository, ApplicationRepository>(); services.AddScoped <IOpeningRepository, OpeningRepository>(); return(services); }
private static void ConfigureMongo() { var conventionPack = new ConventionPack { new CamelCaseElementNameConvention(), new IgnoreIfNullConvention(true), new IgnoreExtraElementsConvention(true), new EnumRepresentationConvention(BsonType.String) }; BsonSerializer.RegisterIdGenerator(typeof(Guid), GuidGenerator.Instance); ConventionRegistry.Register("MongoConventions", conventionPack, t => t.Namespace != null && t.Namespace.StartsWith("dinopays.web")); }
public void ConfigureServices(IServiceCollection services) { services.AddAutoMapper(typeof(Startup)); //Database services.Configure <DatabaseSettings>(Configuration.GetSection(nameof(DatabaseSettings))); services.AddSingleton(sp => sp.GetRequiredService <IOptions <DatabaseSettings> >().Value ?? new DatabaseSettings()); BsonSerializer.RegisterIdGenerator(typeof(string), new StringObjectIdGenerator()); //Repositories services.AddTransient <IUserRepository, UserRepository>(); services.AddTransient <IFormRepository, FormRepository>(); //Services services.AddTransient <UserService, UserService>(); services.AddTransient <FormService, FormService>(); services.AddControllers().AddNewtonsoftJson(); }
public RmanagerService(IDatabaseSettings settings, IHostEnvironment env, IMapper mapper) { BsonSerializer.RegisterIdGenerator(typeof(Guid), GuidGenerator.Instance); try { OrganizationService = new OrganizationService(settings); RoomService = new RoomService(settings); UserService = new UserService(settings); UserInOrgService = new UserInOrgService(settings); RoomInOrgService = new RoomInOrgService(settings); BookingRoomService = new BookingRoomService(settings); AllowedEmail = new List <string>(); this.env = env; } catch (Exception e) { throw new ServiceStartUpException(e.Message); } }
private static void ConfigureDb() { var conventionPack = new ConventionPack { new CamelCaseElementNameConvention() }; ConventionRegistry.Register("camelCase", conventionPack, type => true); BsonClassMap.RegisterClassMap <NamespaceDto>(); BsonClassMap.RegisterClassMap <EnvironmentDto>(); BsonClassMap.RegisterClassMap <FeatureGroupDto>(); BsonClassMap.RegisterClassMap <FeatureToggleDto>(); BsonClassMap.RegisterClassMap <FeatureToggleRuleDto>(); BsonSerializer.RegisterIdGenerator( typeof(Guid), GuidGenerator.Instance ); }
//Constructors public FrassetMongoContext() { //set all Id guids to use COMB generator BsonSerializer.RegisterIdGenerator(typeof(Guid), CombGuidGenerator.Instance); //set db connection var url = MongoUrl.Create(ConfigurationManager.ConnectionStrings[Constants.FrassetDbConnectionKey].ConnectionString); if (url.DatabaseName == null) { throw new Frasset.Objects.Exceptions.ConfigurationException(@"Database name was not specified in connection string, e.g. http:\\localhost:27017\Frasset"); } var client = new MongoClient(url); var server = client.GetServer(); this.db = server.GetDatabase(url.DatabaseName); InitialiseRepositories(); }
public MongoDbRepository(string connectionString) { if (DB == null) { lock (_sync) { if (DB == null) { Guard.Instance.ArgumentNotNullOrWhiteSpace(() => connectionString, connectionString); BsonSerializer.RegisterSerializer(typeof(Identity), new IdentitySerializer()); BsonSerializer.RegisterIdGenerator(typeof(Identity?), new IdentityGenerator()); var server = MongoServer.Create(connectionString); var uri = new Uri(connectionString); var dbName = uri.Segments[uri.Segments.Length - 1]; DB = server.GetDatabase(dbName); } } } }
public MongoRepository(string connectionString) { if (Db != null) { return; } lock (Sync) { if (Db != null) { return; } BsonSerializer.RegisterSerializer(typeof(ObjectId), new IdentitySerializer()); BsonSerializer.RegisterIdGenerator(typeof(string), new IdentityGenerator()); var server = new MongoClient(connectionString).GetServer(); var uri = new Uri(connectionString); var dbName = uri.Segments[uri.Segments.Length - 1]; Db = server.GetDatabase(dbName); } }
private DBContext(IConfiguration config) { // mongo use string for id BsonSerializer.RegisterIdGenerator(typeof(string), new StringObjectIdGenerator()); Settings.customConfiguration = config; string databaseName = Settings.Instance.DatabaseName; if (databaseName == null) { throw new AppException("Configuration error DatabaseName"); } string connectionString = Settings.Instance.ConnectionString(databaseName); if (connectionString == null) { throw new AppException(string.Format("Configuration error connectionString for databaseName={0}", databaseName)); } var client = new MongoClient(connectionString); Database = client.GetDatabase(databaseName); }
private void RegisterIdGenerator() { BsonSerializer.RegisterIdGenerator(typeof(string), StringObjectIdGenerator.Instance); BsonSerializer.RegisterSerializer(typeof(DateTime), DateTimeStringSerializer.Instance); BsonClassMap.RegisterClassMap <NodeBase>(entity => { entity.AutoMap(); //entity.UnmapProperty(c => c.ChangeSetId); entity.UnmapProperty(c => c.Srid); entity.UnmapProperty(c => c.User); entity.UnmapProperty(c => c.UserId); entity.UnmapProperty(c => c.Visible); //entity.UnmapProperty(c => c.TimeStamp); }); BsonClassMap.RegisterClassMap <Node>(entity => { entity.AutoMap(); entity.UnmapProperty(c => c.Latitude); entity.UnmapProperty(c => c.Longtitude); }); }
public static void Setup() { BsonSerializer.RegisterIdGenerator(typeof(string), new StringObjectIdGenerator()); BsonClassMap.RegisterClassMap <AccessControlPolicy>(p => { p.MapMember(c => c.Id).SetElementName("policy_id"); p.MapMember(c => c.CollectionName).SetElementName("collection_name"); p.MapMember(c => c.Description).SetElementName("description"); p.MapMember(c => c.RuleCombining).SetElementName("rule_combining"); p.MapMember(c => c.IsAttributeResourceRequired).SetElementName("isAttributeResourceRequired"); p.MapMember(c => c.Action).SetElementName("action"); p.MapMember(c => c.Target).SetElementName("target"); p.MapMember(c => c.Rules).SetElementName("rules"); p.SetIgnoreExtraElements(true); }); BsonClassMap.RegisterClassMap <PrivacyPolicy>(p => { //p.MapMember(c => c.Id).SetElementName("_id").SetSerializer(new StringSerializer(BsonType.ObjectId)); p.MapMember(c => c.CollectionName).SetElementName("collection_name"); p.MapMember(c => c.Description).SetElementName("description"); p.MapMember(c => c.IsAttributeResourceRequired).SetElementName("is_attribute_resource_required"); p.MapMember(c => c.Target).SetElementName("target"); p.MapMember(c => c.Rules).SetElementName("rules"); p.SetIgnoreExtraElements(true); }); BsonClassMap.RegisterClassMap <AccessControlRule>(p => { p.MapMember(c => c.Id).SetElementName("_id"); p.MapMember(c => c.Effect).SetElementName("effect"); p.MapMember(c => c.Condition).SetElementName("condition"); p.SetIgnoreExtraElements(true); }); BsonClassMap.RegisterClassMap <Function>(p => { p.MapMember(c => c.FunctionName).SetElementName("function_name"); p.MapMember(c => c.Parameters).SetElementName("parameters"); p.MapMember(c => c.Value).SetElementName("value"); p.MapMember(c => c.ResourceID).SetElementName("resource_id"); p.SetIgnoreExtraElements(true); }); BsonClassMap.RegisterClassMap <FieldRule>(p => { p.MapMember(c => c.FieldEffects).SetElementName("field_effects"); p.MapMember(c => c.Condition).SetElementName("condition"); p.MapMember(c => c.Identifer).SetElementName("identifier"); p.SetIgnoreExtraElements(true); }); BsonClassMap.RegisterClassMap <FieldEffect>(p => { p.MapMember(c => c.Name).SetElementName("name"); p.MapMember(c => c.FunctionApply).SetElementName("effect_function"); p.SetIgnoreExtraElements(true); }); BsonClassMap.RegisterClassMap <PrivacyDomain>(p => { //p.MapMember(c => c.Id).SetElementName("_id").SetSerializer(new StringSerializer(BsonType.ObjectId)); p.MapMember(c => c.DomainName).SetElementName("domain_name"); p.MapMember(c => c.IsArrayFieldDomain).SetElementName("is_sub_policy"); p.MapMember(c => c.Fields).SetElementName("fields"); p.MapMember(c => c.Functions).SetElementName("hierarchy"); p.SetIgnoreExtraElements(true); }); BsonClassMap.RegisterClassMap <PriorityFunction>(p => { p.MapMember(c => c.Name).SetElementName("name"); p.MapMember(c => c.Priority).SetElementName("priority"); p.SetIgnoreExtraElements(true); }); }
/// <summary> /// Registers SequentialGuidGenerator with the Mongo BsonSerializer for all Guid types /// </summary> /// <param name="generator"></param> public static void RegisterMongoIdGenerator(this SequentialGuidGenerator generator) => BsonSerializer.RegisterIdGenerator(typeof(Guid), generator);
public virtual void FixtureSetUp() { connectionString = "mongodb://localhost:" + this.port + "/" + MongoDbConstants.DBName; #region Launchs MongoDB service in a local process. var id = WindowsIdentity.GetCurrent(); Assert.IsNotNull(id); var principal = new WindowsPrincipal(id); Assert.IsTrue(principal.IsInRole(WindowsBuiltInRole.Administrator), "Process must run as administrator"); mongoDir = Path.Combine(Environment.CurrentDirectory, "MongoDb"); var fileName = "mongod.exe"; var fileNamePath = Path.Combine(mongoDir, fileName); // Kill previous process var previous = Process.GetProcessesByName("mongod"); var current = previous .Where(p => p.MainWindowTitle == fileNamePath) .FirstOrDefault(); if (current != null) { current.Kill(); Thread.Sleep(1000); } // Create local folder if (Directory.Exists(mongoDir)) { Directory.Delete(mongoDir, true); } Directory.CreateDirectory(mongoDir); // deploy mongod.exe file var resourceFileName = Utils.Is64BitOperatingSystem() ? "mongod_64.exe" : "mongod_32.exe"; using (var resource = typeof(MongoDbBaseFixture).Assembly.GetManifestResourceStream("DataAccess.Tests." + resourceFileName)) { using (var file = File.Create(fileNamePath)) { const int size = 16384; var buffer = new byte[size]; var bytesRead = resource.Read(buffer, 0, size); while (bytesRead > 0) { file.Write(buffer, 0, bytesRead); bytesRead = resource.Read(buffer, 0, size); } } } // Creates mongo process var info = new ProcessStartInfo { Arguments = "--dbpath \"" + mongoDir + "\" --port " + port, CreateNoWindow = false, FileName = fileNamePath, WorkingDirectory = mongoDir, UseShellExecute = true, Verb = "runas" }; mongoProcess = Process.Start(info); #endregion BsonSerializer.RegisterSerializer(typeof(Identity), new IdentitySerializer()); BsonSerializer.RegisterIdGenerator(typeof(Identity?), new IdentityGenerator()); // Connects to mongo mongoServer = MongoServer.Create(connectionString); mongoDb = mongoServer.GetDatabase(MongoDbConstants.DBName); // Validates that mongo is working var col = mongoDb.GetCollection("ping"); col.Save(new BsonDocument("ping", new BsonInt32(1))); }
static DocumentId() { BsonSerializer.RegisterSerializer(typeof(DocumentId <T>), DocumentIdSerializer <T> .Instance); BsonSerializer.RegisterIdGenerator(typeof(DocumentId <T>), DocumentIdGenerator <T> .Instance); }
public static void Register() { BsonSerializer.RegisterIdGenerator(typeof(MongoObjectId), instance); }
static void Main(string[] args) { BsonSerializer.RegisterIdGenerator(typeof(string), new StringObjectIdGenerator()); namesList = new List <string>(); const string PATH = @"C:\Users\Tyeth\Documents\REPOS\C#\facialrecognition\FaceRecProOV\bin\Debug\TrainedFaces"; Console.WriteLine($"Searching {PATH}!"); List <FacialCroppedMatch> list = new List <FacialCroppedMatch>(); Console.ForegroundColor = ConsoleColor.White; Console.Write("loading "); Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("TrainedLabels.txt"); LoadTrainedLabels(PATH + "\\TrainedLabels.txt"); for (int i = 0; i < namesList.Count; i++) { string file = PATH + "\\face" + (i + 1) + ".bmp"; var imgMatch = new FacialCroppedMatch() { Name = file, Person = namesList[i] }; //var imgGrey = new Image<Gray, byte>(file); var fileBytes = File.ReadAllBytes(file); MemoryStream ms = new MemoryStream(fileBytes.Length); ms.Write(fileBytes, 0, fileBytes.Length); //ms.FlushAsync(); //imgGrey.Bitmap.Save(ms, ImageFormat.Bmp); //ms.Seek(0, SeekOrigin.Begin); imgMatch.ImageBytes = ms.ToArray(); list.Add(imgMatch); } var dbClient = new MongoClient(); //defaults to using admin database on localhost. var db = dbClient.GetDatabase("faces"); var collection = db.GetCollection <FacialCroppedMatch>("trustedGrey", new MongoCollectionSettings() { AssignIdOnInsert = true, ReadPreference = ReadPreference.Primary, ReadConcern = ReadConcern.Default }); var list2 = new FacialCroppedMatch[list.Count]; list.CopyTo(list2); foreach (var facialCroppedMatch in list2) { var filename = facialCroppedMatch.Name.Split('\\').Last(); if (collection.Count(x => x.Name == facialCroppedMatch.Name && x.Person == facialCroppedMatch.Person && x.ImageBytes == facialCroppedMatch.ImageBytes) > 0) { list.Remove(facialCroppedMatch); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Skipped duplicate (name: {facialCroppedMatch.Person} file:{filename})"); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Adding to mongodb collection (name: {facialCroppedMatch.Person} file:{filename})"); } } if (list.Count > 0) { collection.InsertMany(list); } Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(string.Format("Test {0} images found for Tyeth of {1} in mongodb collection.\n", collection.Count(x => x.Person == "Tyeth"), collection.Count(x => true))); Console.BackgroundColor = ConsoleColor.DarkBlue; Console.WriteLine(""); Console.WriteLine("Press a key to continue"); Console.WriteLine(""); Console.ReadKey(); }