public JobScheduler( IRuntime runtime, ILogger <JobScheduler> logger, IDataStoreFactory dataStoreFactory, IOptions <JobExecutorOptions> options) { m_Runtime = runtime; m_Logger = logger; m_DataStore = dataStoreFactory.CreateDataStore(new DataStoreCreationParameters { Component = runtime, LogOnChange = true, WorkingDirectory = runtime.WorkingDirectory }); AsyncHelper.RunSync(ReadJobsFileAsync); m_ScheduledJobs = new List <ScheduledJob>(); m_DataStore.AddChangeWatcher(c_DataStoreKey, runtime, () => { m_ScheduledJobs.Clear(); AsyncHelper.RunSync(() => StartAsync(isFromFileChange: true)); }); m_JobExecutors = new List <ITaskExecutor>(); foreach (var provider in options.Value.JobExecutorTypes) { m_JobExecutors.Add( (ITaskExecutor)ActivatorUtilitiesEx.CreateInstance(runtime.LifetimeScope, provider)); } }
/// <summary> /// Construct a <see cref="ChangelogModule"/> /// </summary> /// <param name="dataStoreFactory">The <see cref="IDataStoreFactory{TModule}"/> to create <see cref="dataStore"/> from</param> /// <param name="stringLocalizer">The value of <see cref="stringLocalizer"/></param> /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/></param> /// <param name="gitHubManager">The value of <see cref="gitHubManager"/></param> public ChangelogModule(IDataStoreFactory <ChangelogModule> dataStoreFactory, IStringLocalizer <ChangelogModule> stringLocalizer, IOptions <GeneralConfiguration> generalConfigurationOptions, IGitHubManager gitHubManager) { this.stringLocalizer = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer)); this.gitHubManager = gitHubManager ?? throw new ArgumentNullException(nameof(gitHubManager)); generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); dataStore = dataStoreFactory?.CreateDataStore(this) ?? throw new ArgumentNullException(nameof(dataStoreFactory)); }
// ReSharper disable once SuggestBaseTypeForParameter /* we don't want this because of DI */ public OpenModUnturnedHost( IRuntime runtime, IServiceProvider serviceProvider, ILifetimeScope lifetimeScope, IDataStoreFactory dataStoreFactory, IConsoleActorAccessor consoleActorAccessor, ICommandExecutor commandExecutor, ILogger <OpenModUnturnedHost> logger, UnturnedCommandHandler unturnedCommandHandler) { m_ServiceProvider = serviceProvider; m_ConsoleActorAccessor = consoleActorAccessor; m_CommandExecutor = commandExecutor; m_Logger = logger; m_UnturnedCommandHandler = unturnedCommandHandler; WorkingDirectory = runtime.WorkingDirectory; LifetimeScope = lifetimeScope; DataStore = dataStoreFactory.CreateDataStore("openmod.unturned", WorkingDirectory); Version = VersionHelper.ParseAssemblyVersion(GetType().Assembly); m_Capabilities = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { KnownGameCapabilities.Health, KnownGameCapabilities.Inventory, KnownGameCapabilities.Vehicles }; }
public IDataStore CreateDataStore(DataStoreCreationParameters parameters) { var logger = _loggerFactory.CreateLogger <WebDataStore>(); var configuration = _pluginAccessor.Instance.Configuration; var baseDataStore = _parentDataStoreFactory.CreateDataStore(parameters); return(new WebDataStore(parameters.ComponentId, configuration, baseDataStore, logger)); }
/// <summary> /// Construct a <see cref="ChangelogGeneratorModule"/> /// </summary> /// <param name="dataStoreFactory">The <see cref="IDataStoreFactory{TModule}"/> to create <see cref="dataStore"/> from</param> /// <param name="stringLocalizer">The value of <see cref="stringLocalizer"/></param> /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/></param> /// <param name="ioManager">The value of <see cref="ioManager"/></param> /// <param name="repository">The value of <see cref="repository"/></param> public ChangelogGeneratorModule(IDataStoreFactory <ChangelogGeneratorModule> dataStoreFactory, IStringLocalizer <ChangelogGeneratorModule> stringLocalizer, IOptions <GeneralConfiguration> generalConfigurationOptions, IIOManager ioManager, IRepository repository) { this.stringLocalizer = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer)); this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); this.repository = repository ?? throw new ArgumentNullException(nameof(repository)); generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); dataStore = dataStoreFactory?.CreateDataStore(this) ?? throw new ArgumentNullException(nameof(dataStoreFactory)); }
public KeyValueLite(IDataStoreFactory dsFactory, IKeyValueItemSerializer serializer, ILogger logger) { syncer = new Syncer(logger); this.serializer = serializer; var datastore = dsFactory.CreateDataStore(nameof(KeyValueLite)); db = new KeyValueDbContext(datastore, logger); KeyValueDbContext.InitDb(db); }
public AccountRepository(IConfigurationManager configurationManager, IDataStoreFactory dataStoreFactory) { // In my opinion, reading the app data and creating store should be done by the PaymentService consumer. // Since there is no consumer class,I made the repository class to do this. // Instead of IConfigurationManager and IDataStoreFactory,I would inject only the IDataStore in to this class var dataStoreType = configurationManager.GetAppSettings("DataStoreType"); var dataStore = dataStoreFactory.CreateDataStore(dataStoreType); DataStore = dataStore; }
protected override Task OnLoadAsync() { m_PermissionRegistry.RegisterPermission(this, "immune", "Grants immunity to cooldowns."); CooldownDataStore = m_DataStoreFactory.CreateDataStore(new DataStoreCreationParameters() { ComponentId = OpenModComponentId, WorkingDirectory = Path.Combine(WorkingDirectory, "Records") }); return(Task.CompletedTask); }
public StandaloneHost( IRuntime runtime, ILifetimeScope lifetimeScope, IDataStoreFactory dataStoreFactory, IConsoleActorAccessor consoleActorAccessor, ICommandExecutor commandExecutor) { m_ConsoleActorAccessor = consoleActorAccessor; m_CommandExecutor = commandExecutor; Version = VersionHelper.ParseAssemblyVersion(GetType().Assembly); WorkingDirectory = runtime.WorkingDirectory; LifetimeScope = lifetimeScope; DataStore = dataStoreFactory.CreateDataStore("openmod.standalone", WorkingDirectory); }
protected BaseOpenModRustHost( ILifetimeScope lifetimeScope, IRuntime runtime, IDataStoreFactory dataStoreFactory ) { LifetimeScope = lifetimeScope; WorkingDirectory = runtime.WorkingDirectory; DataStore = dataStoreFactory.CreateDataStore(new DataStoreCreationParameters { ComponentId = OpenModComponentId, Prefix = "openmod.rust", Suffix = null, WorkingDirectory = WorkingDirectory }); }
// ReSharper disable once SuggestBaseTypeForParameter /* we don't want this because of DI */ public OpenModUnturnedHost( IRuntime runtime, IServiceProvider serviceProvider, ILifetimeScope lifetimeScope, IDataStoreFactory dataStoreFactory, IConsoleActorAccessor consoleActorAccessor, ICommandExecutor commandExecutor, ILogger <OpenModUnturnedHost> logger, UnturnedCommandHandler unturnedCommandHandler) { m_ServiceProvider = serviceProvider; m_ConsoleActorAccessor = consoleActorAccessor; m_CommandExecutor = commandExecutor; m_Logger = logger; m_UnturnedCommandHandler = unturnedCommandHandler; WorkingDirectory = runtime.WorkingDirectory; LifetimeScope = lifetimeScope; DataStore = dataStoreFactory.CreateDataStore("openmod.unturned", WorkingDirectory); Version = VersionHelper.ParseAssemblyVersion(GetType().Assembly); }
public CommandCooldownStore( IConfiguration configuration, IRuntime runtime, IDataStoreFactory dataStoreFactory, ILogger <CommandCooldownStore> logger, IPermissionRoleStore permissionRoleStore, IPermissionRolesDataStore permissionRolesDataStore, IPermissionChecker permissionChecker) { m_Configuration = configuration; m_DataStore = dataStoreFactory.CreateDataStore(new DataStoreCreationParameters() { Prefix = "openmod", WorkingDirectory = runtime.WorkingDirectory, LogOnChange = false }); m_Logger = logger; m_PermissionRoleStore = permissionRoleStore; m_PermissionRolesDataStore = permissionRolesDataStore; m_PermissionChecker = permissionChecker; m_Records = new Dictionary <string, List <CooldownRecord> >(); m_LoadedPersistedRecords = false; }
public StandaloneHost( IRuntime runtime, ILifetimeScope lifetimeScope, IDataStoreFactory dataStoreFactory, IConsoleActorAccessor consoleActorAccessor, ICommandExecutor commandExecutor) { m_ConsoleActorAccessor = consoleActorAccessor; m_CommandExecutor = commandExecutor; Version = VersionHelper.ParseAssemblyVersion(GetType().Assembly); WorkingDirectory = runtime.WorkingDirectory; LifetimeScope = lifetimeScope; DataStore = dataStoreFactory.CreateDataStore(new DataStoreCreationParameters { ComponentId = OpenModComponentId, Prefix = "openmod.standalone", Suffix = null, WorkingDirectory = WorkingDirectory }); }
public OpenModUnturnedHost( IRuntime runtime, IHostInformation hostInformation, IServiceProvider serviceProvider, ILifetimeScope lifetimeScope, IDataStoreFactory dataStoreFactory, IConsoleActorAccessor consoleActorAccessor, ILogger <OpenModUnturnedHost> logger, NuGetPackageManager nuGetPackageManager, Lazy <ICommandExecutor> commandExecutor, Lazy <UnturnedCommandHandler> unturnedCommandHandler) { m_Runtime = runtime; m_HostInformation = hostInformation; m_ServiceProvider = serviceProvider; m_ConsoleActorAccessor = consoleActorAccessor; m_CommandExecutor = commandExecutor; m_Logger = logger; m_NuGetPackageManager = nuGetPackageManager; m_UnturnedCommandHandler = unturnedCommandHandler; WorkingDirectory = runtime.WorkingDirectory; LifetimeScope = lifetimeScope; DataStore = dataStoreFactory.CreateDataStore(new DataStoreCreationParameters { Component = this, Prefix = "openmod.unturned", Suffix = null, WorkingDirectory = WorkingDirectory }); m_Capabilities = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { KnownGameCapabilities.Health, KnownGameCapabilities.Inventory, KnownGameCapabilities.Vehicles }; }
// ReSharper disable once SuggestBaseTypeForParameter /* we don't want this because of DI */ public OpenModUnturnedHost( IRuntime runtime, ILifetimeScope lifetimeScope, IDataStoreFactory dataStoreFactory, ILoggerFactory loggerFactory, IConsoleActorAccessor consoleActorAccessor, ICommandExecutor commandExecutor, IHost host, ILogger <OpenModUnturnedHost> logger, UnturnedPlayerEventsHandler unturnedPlayerEventsHandler) { m_Runtime = runtime; m_LoggerFactory = loggerFactory; m_ConsoleActorAccessor = consoleActorAccessor; m_CommandExecutor = commandExecutor; m_Host = host; m_Logger = logger; m_UnturnedPlayerEventsHandler = unturnedPlayerEventsHandler; m_Harmony = new Harmony(c_HarmonyInstanceId); WorkingDirectory = runtime.WorkingDirectory; LifetimeScope = lifetimeScope; DataStore = dataStoreFactory.CreateDataStore("openmod.unturned", WorkingDirectory); Version = VersionHelper.ParseAssemblyVersion(GetType().Assembly); }
public async Task <IOpenModPlugin> TryActivatePluginAsync(Assembly assembly) { if (m_IsDisposing) { throw new ObjectDisposedException(nameof(PluginActivator)); } var pluginMetadata = assembly.GetCustomAttribute <PluginMetadataAttribute>(); if (pluginMetadata == null) { m_Logger.LogError($"Failed to load plugin from assembly {assembly}: couldn't find any plugin metadata"); return(null); } var pluginTypes = assembly.FindTypes <IOpenModPlugin>(false).ToList(); if (pluginTypes.Count == 0) { m_Logger.LogError($"Failed to load plugin from assembly {assembly}: couldn't find any IOpenModPlugin implementation"); return(null); } if (pluginTypes.Count > 1) { m_Logger.LogError($"Failed to load plugin from assembly {assembly}: assembly has multiple IOpenModPlugin instances"); return(null); } var pluginType = pluginTypes.Single(); IOpenModPlugin pluginInstance; try { var serviceProvider = m_LifetimeScope.Resolve <IServiceProvider>(); var lifetimeScope = m_LifetimeScope.BeginLifetimeScope(containerBuilder => { var workingDirectory = PluginHelper.GetWorkingDirectory(m_Runtime, pluginMetadata.Id); var configurationBuilder = new ConfigurationBuilder(); if (Directory.Exists(workingDirectory)) { configurationBuilder .SetBasePath(workingDirectory) .AddYamlFile("config.yaml", optional: true, reloadOnChange: true); } var configuration = configurationBuilder .AddEnvironmentVariables(pluginMetadata.Id.Replace(".", "_") + "_") .Build(); containerBuilder.Register(context => configuration) .As <IConfiguration>() .As <IConfigurationRoot>() .SingleInstance() .OwnedByLifetimeScope(); containerBuilder.RegisterType(pluginType) .As(pluginType) .As <IOpenModPlugin>() .SingleInstance() .ExternallyOwned(); containerBuilder.Register(context => m_DataStoreFactory.CreateDataStore(null, workingDirectory)) .As <IDataStore>() .SingleInstance() .OwnedByLifetimeScope(); var stringLocalizer = m_StringLocalizerFactory.Create("translations", workingDirectory); containerBuilder.Register(context => stringLocalizer) .As <IStringLocalizer>() .SingleInstance() .OwnedByLifetimeScope(); foreach (var type in pluginType.Assembly.FindTypes <IPluginContainerConfigurator>()) { var configurator = (IPluginContainerConfigurator)ActivatorUtilities.CreateInstance(serviceProvider, type); configurator.ConfigureContainer(containerBuilder); } }); pluginInstance = (IOpenModPlugin)lifetimeScope.Resolve(pluginType); } catch (Exception ex) { m_Logger.LogError(ex, $"Failed to load plugin from type: {pluginType.FullName} in assembly: {assembly.FullName}"); return(null); } try { await pluginInstance.LoadAsync(); } catch (Exception ex) { m_Logger.LogError(ex, $"Failed to load plugin: {pluginInstance.DisplayName} v{pluginInstance.Version}"); return(null); } m_ActivatedPlugins.Add(new WeakReference(pluginInstance)); return(pluginInstance); }
public async Task <IOpenModPlugin> TryActivatePluginAsync(Assembly assembly) { try { if (m_IsDisposing) { throw new ObjectDisposedException(nameof(PluginActivator)); } var pluginMetadata = assembly.GetCustomAttribute <PluginMetadataAttribute>(); if (pluginMetadata == null) { m_Logger.LogError( $"Failed to load plugin from assembly {assembly}: couldn't find any plugin metadata"); return(null); } var pluginTypes = assembly.FindTypes <IOpenModPlugin>(false).ToList(); if (pluginTypes.Count == 0) { m_Logger.LogError( $"Failed to load plugin from assembly {assembly}: couldn't find any IOpenModPlugin implementation"); return(null); } if (pluginTypes.Count > 1) { m_Logger.LogError( $"Failed to load plugin from assembly {assembly}: assembly has multiple IOpenModPlugin instances"); return(null); } var pluginType = pluginTypes.Single(); IOpenModPlugin pluginInstance; try { var serviceProvider = m_LifetimeScope.Resolve <IServiceProvider>(); var lifetimeScope = m_LifetimeScope.BeginLifetimeScope(containerBuilder => { var workingDirectory = PluginHelper.GetWorkingDirectory(m_Runtime, pluginMetadata.Id); var configurationBuilder = new ConfigurationBuilder(); if (Directory.Exists(workingDirectory)) { configurationBuilder .SetBasePath(workingDirectory) .AddYamlFile("config.yaml", optional: true, reloadOnChange: true); } var configuration = configurationBuilder .AddEnvironmentVariables(pluginMetadata.Id.Replace(".", "_") + "_") .Build(); containerBuilder.Register(context => configuration) .As <IConfiguration>() .As <IConfigurationRoot>() .SingleInstance() .OwnedByLifetimeScope(); containerBuilder.RegisterType(pluginType) .AsSelf() .As <IOpenModComponent>() .As <IOpenModPlugin>() .SingleInstance() .OwnedByLifetimeScope(); containerBuilder.RegisterType <ScopedPermissionChecker>() .As <IPermissionChecker>() .InstancePerLifetimeScope() .OwnedByLifetimeScope(); containerBuilder.Register(context => m_DataStoreFactory.CreateDataStore(new DataStoreCreationParameters { ComponentId = pluginMetadata.Id, Prefix = null, Suffix = "data", WorkingDirectory = workingDirectory })) .As <IDataStore>() .SingleInstance() .OwnedByLifetimeScope(); var stringLocalizer = Directory.Exists(workingDirectory) ? m_StringLocalizerFactory.Create("translations", workingDirectory) : NullStringLocalizer.Instance; containerBuilder.Register(context => stringLocalizer) .As <IStringLocalizer>() .SingleInstance() .OwnedByLifetimeScope(); var services = ServiceRegistrationHelper.FindFromAssembly <PluginServiceImplementationAttribute>(assembly, m_Logger); var servicesRegistrations = services.OrderBy(d => d.Priority, new PriorityComparer(PriortyComparisonMode.LowestFirst)); foreach (var servicesRegistration in servicesRegistrations) { var implementationType = servicesRegistration.ServiceImplementationType; containerBuilder.RegisterType(implementationType) .As(implementationType) .WithLifetime(servicesRegistration.Lifetime) .OwnedByLifetimeScope(); foreach (var service in servicesRegistration.ServiceTypes) { containerBuilder.Register(c => c.Resolve(implementationType)) .As(service) .WithLifetime(servicesRegistration.Lifetime) .OwnedByLifetimeScope(); } } foreach (var type in pluginType.Assembly.FindTypes <IPluginContainerConfigurator>()) { var configurator = (IPluginContainerConfigurator)ActivatorUtilities.CreateInstance(serviceProvider, type); configurator.ConfigureContainer(new PluginServiceConfigurationContext(m_LifetimeScope, configuration, containerBuilder)); } var configurationEvent = new PluginContainerConfiguringEvent(pluginMetadata, pluginType, configuration, containerBuilder, workingDirectory); AsyncHelper.RunSync(() => m_EventBus.EmitAsync(m_Runtime, this, configurationEvent)); }); pluginInstance = (IOpenModPlugin)lifetimeScope.Resolve(pluginType); var pluginActivateEvent = new PluginActivatingEvent(pluginInstance); await m_EventBus.EmitAsync(m_Runtime, this, pluginActivateEvent); if (pluginActivateEvent.IsCancelled) { await lifetimeScope.DisposeAsync(); return(null); } } catch (Exception ex) { m_Logger.LogError(ex, $"Failed to load plugin from type: {pluginType.FullName} in assembly: {assembly.FullName}"); return(null); } try { await pluginInstance.LoadAsync(); var serviceProvider = pluginInstance.LifetimeScope.Resolve <IServiceProvider>(); var pluginHelpWriter = ActivatorUtilities.CreateInstance <PluginHelpWriter>(serviceProvider); await pluginHelpWriter.WriteHelpFileAsync(); } catch (Exception ex) { m_Logger.LogError(ex, $"Failed to load plugin: {pluginInstance.DisplayName} v{pluginInstance.Version}"); try { await pluginInstance.LifetimeScope.DisposeAsync(); } catch (Exception e) { m_Logger.LogError(e, "Failed to unload plugin: {DisplayName} v{Version}", pluginInstance.DisplayName, pluginInstance.Version); } return(null); } m_ActivatedPlugins.Add(new WeakReference(pluginInstance)); return(pluginInstance); } catch (Exception ex) { m_Logger.LogError(ex, $"Failed to load plugin from assembly: {assembly.FullName}"); return(null); } }
public List <IFolder> GetFolders(ResourceType resourceType) { return(_dataStoreFactory .CreateDataStore(resourceType) .GetFolders()); }
/// <summary> /// Construct a <see cref="GoodBoyPointsModule"/> /// </summary> /// <param name="gitHubManager">The value of <see cref="gitHubManager"/></param> /// <param name="dataStoreFactory">The <see cref="IDataStoreFactory{TModule}"/> for <see cref="dataStore"/></param> /// <param name="stringLocalizer">The value of <see cref="stringLocalizer"/></param> public GoodBoyPointsModule(IGitHubManager gitHubManager, IDataStoreFactory <GoodBoyPointsModule> dataStoreFactory, IStringLocalizer <GoodBoyPointsModule> stringLocalizer) { dataStore = dataStoreFactory?.CreateDataStore(this) ?? throw new ArgumentNullException(nameof(dataStoreFactory)); this.gitHubManager = gitHubManager ?? throw new ArgumentNullException(nameof(gitHubManager)); this.stringLocalizer = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer)); }
public String QueueBatch(BatchDetails batchDetails) { try { // Make sure no other processing running on this file name CheckUniqueRun(batchDetails); // Check that the temp file exists CheckFileExists(batchDetails); // Save new details row in database, generate GUID into batch details Guid processId = PersistQueue(batchDetails); // Add completion callback to batchUploader BackgroundWorker batchUploader = new BackgroundWorker(); batchUploader.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted); batchUploaders.Add(batchDetails.ProcessId, new BatchUploader(batchUploader, batchDetails, dataStoreFactory.CreateDataStore(), documentUploadService)); // NB this starts the background thread return(processId.ToString()); } catch (Exception e) { exceptionHandler.ShieldException(e); return(null); } }
public IDataStore CreateDataStore(LdClientContext context, IDataStoreUpdates dataStoreUpdates) { Context = context; DataStoreUpdates = dataStoreUpdates; return(_factory.CreateDataStore(context, dataStoreUpdates)); }
public AccountService( IDataStoreFactory dataStoreFactory, IAppConfiguration appConfiguration) { _dataStore = dataStoreFactory.CreateDataStore(appConfiguration.DataStoreType); }