private AssemblyServiceRepository GetTestRepo(string databaseName) { AssemblyServiceRepository repo = GetAssemblyManagementRepository(GetConsoleLogger(), databaseName); repo.SetDaoNamespace <ProcessRuntimeDescriptor>(); repo.Database.TryEnsureSchema <Dao.AssemblyDescriptor>(); Dao.AssemblyDescriptor.LoadAll(repo.Database).Delete(repo.Database); repo.Creating += (o, a) => { Output("Creating", o, (RepositoryEventArgs)a); }; repo.Created += (o, a) => { Output("Created", o, (RepositoryEventArgs)a); }; repo.Updating += (o, a) => { Output("Updating", o, (RepositoryEventArgs)a); }; repo.Updated += (o, a) => { Output("Updated", o, (RepositoryEventArgs)a); }; return(repo); }
public void SaveDescriptorDoesntDuplicate() { AssemblyServiceRepository repo = GetTestRepo(nameof(SaveDescriptorDoesntDuplicate)); AssemblyDescriptor descriptor = new AssemblyDescriptor(Assembly.GetExecutingAssembly()); AssemblyDescriptor one = repo.Save(descriptor); AssemblyDescriptor two = repo.Save(descriptor); Expect.IsNotNull(one, "first save returned null"); Expect.IsNotNull(two, "second save returned null"); Expect.AreEqual(one.Id, two.Id, "Ids didn't match"); Expect.AreEqual(one.Uuid, two.Uuid, "Uuids didn't match"); Dao.AssemblyDescriptorCollection descriptors = Dao.AssemblyDescriptor .Where(q => q.AssemblyFullName == descriptor.AssemblyFullName && q.FileHash == descriptor.FileHash && q.Name == descriptor.Name, repo.Database); Expect.AreEqual(1, descriptors.Count); }
public void SaveDescriptorSavesReferences() { AssemblyServiceRepository repo = GetAssemblyManagementRepository(GetConsoleLogger(), nameof(SaveDescriptorSavesReferences)); repo.Database.TryEnsureSchema <Dao.AssemblyDescriptor>(); AssemblyDescriptor[] descriptors = AssemblyDescriptor.GetCurrentAppDomainDescriptors().ToArray(); foreach (AssemblyDescriptor descriptor in descriptors) { int?referenceCount = descriptor.AssemblyReferenceDescriptors?.Count; if (referenceCount > 0) { AssemblyDescriptor wrapped = repo.Save(descriptor); AssemblyDescriptor retrieved = repo.Retrieve <AssemblyDescriptor>(wrapped.Id); Expect.AreEqual(referenceCount, retrieved.AssemblyReferenceDescriptors?.Count); Pass(descriptor.AssemblyFullName + " " + referenceCount.ToString()); } else { OutLineFormat("No references: {0}", ConsoleColor.Cyan, descriptor.AssemblyFullName); } } }
// -- public static ServiceRegistry Create() { DataSettings dataSettings = DataSettings.Current; string databasesPath = dataSettings.GetSysDatabaseDirectory().FullName; string userDatabasesPath = Path.Combine(databasesPath, "UserDbs"); AppConf conf = new AppConf(BamConf.Load(ServiceConfig.ContentRoot), ServiceConfig.ProcessName.Or(RegistryName)); UserManager userMgr = conf.UserManagerConfig.Create(); DaoUserResolver userResolver = new DaoUserResolver(); DaoRoleResolver roleResolver = new DaoRoleResolver(); SQLiteDatabaseProvider dbProvider = new SQLiteDatabaseProvider(databasesPath, Log.Default); ApplicationRegistrationRepository coreRepo = new ApplicationRegistrationRepository(); dbProvider.SetDatabases(coreRepo); dbProvider.SetDatabases(userMgr); userMgr.Database.TryEnsureSchema(typeof(UserAccounts.Data.User), Log.Default); userResolver.Database = userMgr.Database; roleResolver.Database = userMgr.Database; ServiceRegistryRepository serviceRegistryRepo = new ServiceRegistryRepository(); serviceRegistryRepo.Database = dataSettings.GetSysDatabaseFor(serviceRegistryRepo); serviceRegistryRepo.EnsureDaoAssemblyAndSchema(); DaoRoleProvider daoRoleProvider = new DaoRoleProvider(userMgr.Database); RoleService coreRoleService = new RoleService(daoRoleProvider, conf); AssemblyServiceRepository assSvcRepo = new AssemblyServiceRepository(); assSvcRepo.Database = dataSettings.GetSysDatabaseFor(assSvcRepo); assSvcRepo.EnsureDaoAssemblyAndSchema(); ConfigurationService configSvc = new ConfigurationService(coreRepo, conf, userDatabasesPath); CompositeRepository compositeRepo = new CompositeRepository(coreRepo); SystemLoggerService loggerSvc = new SystemLoggerService(conf); dbProvider.SetDatabases(loggerSvc); loggerSvc.SetLogger(); ServiceRegistry reg = (ServiceRegistry)(new ServiceRegistry()) .ForCtor <ConfigurationService>("databaseRoot").Use(userDatabasesPath) .ForCtor <ConfigurationService>("conf").Use(conf) .ForCtor <ConfigurationService>("coreRepo").Use(coreRepo) .For <ILogger>().Use(Log.Default) .For <IRepository>().Use(coreRepo) .For <DaoRepository>().Use(coreRepo) .For <ApplicationRegistrationRepository>().Use(coreRepo) .For <AppConf>().Use(conf) .For <IDatabaseProvider>().Use(dbProvider) .For <IUserManager>().Use(userMgr) .For <UserManager>().Use(userMgr) .For <IUserResolver>().Use(userResolver) .For <DaoUserResolver>().Use(userResolver) .For <IRoleResolver>().Use(roleResolver) .For <DaoRoleResolver>().Use(roleResolver) .For <IRoleProvider>().Use(coreRoleService) .For <RoleService>().Use(coreRoleService) .For <EmailComposer>().Use(userMgr.EmailComposer) .For <IApplicationNameProvider>().Use <ApplicationRegistrationService>() .For <ApplicationRegistrationService>().Use <ApplicationRegistrationService>() .For <IApiKeyResolver>().Use <ApplicationRegistrationService>() .For <ISmtpSettingsProvider>().Use(userMgr) .For <UserRegistryService>().Use <UserRegistryService>() .For <ConfigurationService>().Use(configSvc) .For <IStorableTypesProvider>().Use <NamespaceRepositoryStorableTypesProvider>() .For <FileService>().Use <FileService>() .For <IFileService>().Use <FileService>() .For <AssemblyServiceRepository>().Use(assSvcRepo) .For <IAssemblyService>().Use <AssemblyService>() .For <ServiceRegistryRepository>().Use(serviceRegistryRepo) .For <ServiceRegistryService>().Use <ServiceRegistryService>() .For <OAuthService>().Use <OAuthService>() .For <ILog>().Use(loggerSvc) .For <SystemLoggerService>().Use(loggerSvc) .For <DataSettings>().Use(DataSettings.Current) .For <IApplicationNameResolver>().Use <ClientApplicationNameResolver>() .For <ClientApplicationNameResolver>().Use <ClientApplicationNameResolver>() .For <SmtpSettingsProvider>().Use(DataSettingsSmtpSettingsProvider.Default) .For <NotificationService>().Use <NotificationService>() .For <ILogReader>().Use <SystemLogReaderService>() .For <CredentialManagementService>().Use <CredentialManagementService>(); reg.For <ServiceRegistry>().Use(reg) .For <DiagnosticService>().Use <DiagnosticService>(); reg.SetProperties(userMgr); userMgr.ServiceProvider = reg; reg.For <CompositeRepository>().Use(() => { compositeRepo.AddTypes(reg.Get <IStorableTypesProvider>().GetTypes()); return(compositeRepo); }); ServiceProxySystem.UserResolvers.Clear(); ServiceProxySystem.RoleResolvers.Clear(); ServiceProxySystem.UserResolvers.AddResolver(userResolver); ServiceProxySystem.RoleResolvers.AddResolver(roleResolver); reg.Name = RegistryName; return(reg); }