예제 #1
0
        public async Task <ICollection <Assembly> > RegisterPluginAssembliesAsync(IPluginAssembliesSource source)
        {
            m_PluginAssembliesSources.Add(source);
            var assemblies = await m_PluginAssemblyStore.LoadPluginAssembliesAsync(source);

            foreach (var assembly in assemblies)
            {
                // PluginAssemblyStore checks if this attribute exists
                var pluginMetadata  = assembly.GetCustomAttribute <PluginMetadataAttribute>();
                var pluginDirectory = PluginHelper.GetWorkingDirectory(m_Runtime, pluginMetadata.Id);

                if (!Directory.Exists(pluginDirectory))
                {
                    Directory.CreateDirectory(pluginDirectory);
                }

                AssemblyHelper.CopyAssemblyResources(assembly, Path.Combine(m_Runtime.WorkingDirectory, "plugins", pluginMetadata.Id));
            }

            foreach (var assembly in assemblies)
            {
                // Auto register services with [Service] and [ServiceImplementation] attributes
                RegisterServicesFromAssembly(assembly);
            }

            m_Assemblies.AddRange(assemblies);
            return(assemblies);
        }
예제 #2
0
        public async Task <ICollection <Assembly> > RegisterPluginAssembliesAsync(IPluginAssembliesSource source)
        {
            m_PluginAssembliesSources.Add(source);
            var assemblies = await m_PluginAssemblyStore.LoadPluginAssembliesAsync(source);

            foreach (var assembly in assemblies)
            {
                // PluginAssemblyStore checks if this attribute exists
                try
                {
                    var pluginMetadata = assembly.GetCustomAttribute <PluginMetadataAttribute>();
                    AssemblyHelper.CopyAssemblyResources(assembly,
                                                         Path.Combine(m_Runtime.WorkingDirectory, "plugins", pluginMetadata.Id));
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex, $"Failed to copy resources from assembly: {assembly}");
                }
            }

            foreach (var assembly in assemblies)
            {
                // Auto register services with [Service] and [ServiceImplementation] attributes
                try
                {
                    RegisterServicesFromAssembly(assembly);
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex, $"Failed to load services from assembly: {assembly}");
                }
            }

            m_Assemblies.AddRange(assemblies);
            return(assemblies);
        }
예제 #3
0
        public async Task <ICollection <Assembly> > RegisterPluginAssembliesAsync(IPluginAssembliesSource source)
        {
            m_PluginAssembliesSources.Add(source);
            var assemblies = await m_PluginAssemblyStore.LoadPluginAssembliesAsync(source);

            foreach (var assembly in assemblies)
            {
                // PluginAssemblyStore checks if this attribute exists
                try
                {
                    var pluginMetadata = assembly.GetCustomAttribute <PluginMetadataAttribute>();
                    AssemblyHelper.CopyAssemblyResources(assembly,
                                                         Path.Combine(m_Runtime.WorkingDirectory, "plugins", pluginMetadata.Id));
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex, $"Failed to copy resources from assembly: {assembly}");
                }
            }

            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(CamelCaseNamingConvention.Instance)
                               .Build();

            foreach (var assembly in assemblies)
            {
                // Install packages specified in packages.yaml
                try
                {
                    var packagesResourceName = assembly.GetManifestResourceNames()
                                               .FirstOrDefault(x => x.EndsWith("packages.yaml"));
                    if (packagesResourceName == null)
                    {
                        continue;
                    }

                    using var stream = assembly.GetManifestResourceStream(packagesResourceName);
                    if (stream == null)
                    {
                        continue;
                    }

                    using var reader = new StreamReader(stream);
                    var packagesContent = await reader.ReadToEndAsync();

                    var deserialized = deserializer.Deserialize <SerializedPackagesFile>(packagesContent).Packages;

                    var packages = deserialized?.Select(d => new PackageIdentity(d.Id,
                                                                                 d.Version.Equals("latest", StringComparison.OrdinalIgnoreCase)
                            ? null
                            : new NuGetVersion(d.Version)))
                                   .ToList();

                    if (packages == null || packages.Count == 0)
                    {
                        continue;
                    }

                    m_Logger.LogInformation($"Found and installing embedded NuGet packages for plugin assembly: {assembly.GetName().Name}");

                    await m_NuGetPackageManager.InstallPackagesAsync(packages);
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex, $"Failed to check/load embedded NuGet packages for assembly: {assembly}");
                }
            }

            foreach (var assembly in assemblies)
            {
                // Auto register services with [Service] and [ServiceImplementation] attributes
                try
                {
                    RegisterServicesFromAssembly(assembly);
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex, $"Failed to load services from assembly: {assembly}");
                }
            }

            m_Assemblies.AddRange(assemblies);
            return(assemblies);
        }