Пример #1
0
 public MessageBrokerService(ILoggerFactory loggerFactory,
                             IConfigurationRoot configurationRoot,
                             ApplicationSettings applicationSettings,
                             IPluginManager pluginManager,
                             JSchemaGenerator schemaGenerator)
 {
     _loggerFactory       = loggerFactory;
     _logger              = loggerFactory.CreateLogger <MessageBrokerService>();
     _configurationRoot   = configurationRoot;
     _applicationSettings = applicationSettings;
     _pluginSet           = pluginManager.LoadPlugins();
     _schemaGenerator     = schemaGenerator;
 }
        public PluginSet LoadPlugins()
        {
            try
            {
                var executableLocation = Assembly.GetEntryAssembly().Location;
                _logger.LogDebug($"executable location: {executableLocation}");

                var pluginRootDirectory = Path.GetDirectoryName(executableLocation) ?? throw new InvalidOperationException();
                _logger.LogDebug($"plugin root directory: {executableLocation}");

                var assemblies = Directory
                                 .GetFiles(pluginRootDirectory, "*.dll", SearchOption.AllDirectories)
                                 .Where(f => f.Contains("Emb.TargetProvider") || f.Contains("Emb.DataSourceProvider"))
                                 .Select(AssemblyLoadContext.Default.LoadFromAssemblyPath)
                                 .ToList();
                _logger.LogDebug("found assemblies: " + string.Join(", ", assemblies.Select(assembly => assembly.FullName)));

                var configuration = new ContainerConfiguration()
                                    .WithAssemblies(assemblies);
                using (var container = configuration.CreateContainer())
                {
                    DataSourceProviders = container.GetExports <IDataSourceProvider>();
                    TargetProviders     = container.GetExports <ITargetProvider>();
                }

                var result = new PluginSet()
                {
                    DataSourceProviders = DataSourceProviders.ToList(),
                    TargetProviders     = TargetProviders.ToList(),
                };

                _logger.LogDebug("found data source providers: " + string.Join(", ", result.DataSourceProviders.Select(dataSourceProvider => dataSourceProvider.GetType().Name)));
                _logger.LogDebug("found targets: " + string.Join(", ", result.TargetProviders.Select(dataSourceProvider => dataSourceProvider.GetType().Name)));

                return(result);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "can't load plugins");
                return(new PluginSet());
            }
        }
Пример #3
0
        static QuicState[] ProcessTraceFiles(IEnumerable <string> filePaths)
        {
            var quicStates = new List <QuicState>();

            foreach (var filePath in filePaths)
            {
                //
                // Create our runtime environment, add file, enable cookers, and process.
                //
                PluginSet pluginSet;

                if (string.IsNullOrWhiteSpace(typeof(QuicEtwSource).Assembly.Location))
                {
                    // Single File EXE
                    pluginSet = PluginSet.Load(new[] { Environment.CurrentDirectory }, new SingleFileAssemblyLoader());
                }
                else
                {
                    pluginSet = PluginSet.Load();
                }

                using var dataSources = DataSourceSet.Create(pluginSet);
                dataSources.AddFile(filePath);
                var info = new EngineCreateInfo(dataSources.AsReadOnly());
                using var runtime = Engine.Create(info);
                runtime.EnableCooker(QuicEventCooker.CookerPath);
                //Console.Write("Processing {0}...", filePath);
                var results = runtime.Process();
                //Console.WriteLine("Done.\n");

                //
                // Return our 'cooked' data.
                //
                quicStates.Add(results.QueryOutput <QuicState>(new DataOutputPath(QuicEventCooker.CookerPath, "State")));
            }

            return(quicStates.ToArray());
        }
Пример #4
0
 public void AddPlugin(IPlugin plugin)
 {
     PluginSet.Add(plugin);
 }