Beispiel #1
0
        public ConfigActor(IInjectorService injector)
        {
            _log = injector.GetService <ILogService>()
                   .GetContextLogger <ConfigActor>();

            _config = injector.GetService <IConfigService>();
            ReceiveAsync <DirectoryWatchConfig>(OnConfig);
        }
Beispiel #2
0
        public ScanActor(IInjectorService injector)
        {
            _log = injector.GetService <ILogService>()
                   .GetContextLogger <ScanActor>();
            _eventService = injector.GetService <IEventService>();

            Receive <ScanDirectory>(OnScanDirectory);
        }
Beispiel #3
0
        public WatchActor(IInjectorService injector, FolderToWatch folder)
        {
            _log = injector.GetService <ILogService>()
                   .GetContextLogger <WatchActor>();
            _eventService = injector.GetService <IEventService>();
            _folder       = folder;

            StartWatcher(folder.FolderPath);
        }
Beispiel #4
0
 public BasePlugin(IInjectorService injector)
 {
     Info     = BuildPluginInfo();
     FullName = $"{Info.Name}[{Info.Id}]";
     Injector = injector;
     Logger   = Injector
                .GetService <ILogService>()
                .GetContextLogger <T>();
     EventService   = Injector.GetService <IEventService>();
     _subscriptions = new List <IDisposable>();
 }
Beispiel #5
0
        private async Task LoadLocalPlugins()
        {
            var _events  = _injector.GetService <IEventService>();
            var _plugins = _injector.GetService <IPluginService>();

            var dir = PathTools.GetStartDirectory().RelativeDirectory("Plugins");

            _plugins.AddPluginsFolder(dir);
            await _plugins.Load();

            _events.Emit("Initial plugins loaded");
        }
Beispiel #6
0
        private IHost BuildHost()
        {
            injector.RegisterService(() => BuildMockHostProps(), LifeCycle.Singleton);
            injector.RegisterService(() => new MopLifeService(new CancellationToken()), LifeCycle.Singleton);
            injector.RegisterService(() => injector, LifeCycle.Singleton);
            injector.RegisterService <IHost, MopHost>(LifeCycle.Singleton);
            injector.RegisterService <ILogService, LogService>(LifeCycle.Singleton);
            injector.RegisterService <IConfigService, ConfigService>(LifeCycle.Singleton);

            if (injector.GetService <IHost>() is MopHost host)
            {
                return(host);
            }

            throw new Exception("Failed to instantiate host");
        }
Beispiel #7
0
        public async Task Load()
        {
            var loader = _injector.GetService <PluginLoader>();

            loader.AddPlugin(_pending);
            _pending.Clear();

            await loader.Load();

            _ready.AddRange(loader.Success);
            _failed.AddRange(loader.Failed);
        }
Beispiel #8
0
        private Assembly?SearchInDirectory(DirectoryInfo info, string?name)
        {
            var loader = _injector.GetService <AssemblyLoader>();
            var files  = info.GetFiles("*.dll", SearchOption.AllDirectories);

            foreach (var f in files)
            {
                var maybe = loader.LoadAssemblyFromFile(f);
                if (maybe.Exists(a => a.FullName == name))
                {
                    return(maybe.ValueOrFailure());
                }
            }

            return(null);
        }
Beispiel #9
0
 private Option <T> Instatiate <T>(Type type) where T : IPlugin
 {
     try
     {
         var instance = _injector.GetService(type);
         if (instance is T valid)
         {
             return(Some(valid));
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex, $"Error instantiating {type.FullName}");
     }
     _logger.Debug($"Cant instantiate type {type.FullName}");
     return(None <T>());
 }
Beispiel #10
0
        private object?Execute(ICall call, ICommand c, IAction a)
        {
            var service = _injector.GetService(c.Target);

            if (service is null)
            {
                throw new NullReferenceException("Can't find service for type " + c.Target.FullName);
            }

            var method = c.Target.GetMethod(a.Name);

            if (method is null)
            {
                throw new NullReferenceException("Can't find service for type " + c.Target.FullName);
            }

            var args = DeserializeArgument(method, call.Argument);

            return(method.Invoke(service, args));
        }
Beispiel #11
0
        public SupervisorActor(IInjectorService injector, DirectoryWatchConfig config)
        {
            _injector    = injector;
            _config      = config;
            _watchActors = new();
            _configActor = CreateConfigActor();
            _scanActor   = CreateScanActor();

            _supportedTypes = new string[]
            { AddWatchDirectory, RemoveWatchDirectory, DirectoryScan };

            _log = injector.GetService <ILogService>()
                   .GetContextLogger <SupervisorActor>();

            foreach (var d in config.Directories)
            {
                StartWatchActor(d);
            }

            Receive <IEvent>(OnEvent);
        }
Beispiel #12
0
 public PingPlugin(IInjectorService injector) : base(injector)
 {
     _log = injector.GetService <ILogService>();
     RegisterRoles("ping");
 }