/// <summary>
        /// Loads a new assembly!
        /// </summary>
        /// <param name="assembly"></param>
        /// <returns></returns>
        public async Task LoadAssembly(Assembly assembly)
        {
            var asmBytes    = AssemblyUtils.GetAssemblyBinary(assembly);
            var asmVersion  = AssemblyUtils.GetAssemblyVersion(assembly);
            var asmFullname = assembly.FullName;

            await LoadAssembly(asmFullname, asmVersion, asmBytes);
        }
Esempio n. 2
0
        public async Task ExecuteMethodFromAssemblyTest(int a)
        {
            var asmPath = Path.Combine(Directory.GetCurrentDirectory(), "TestAssembly.dll");
            await _executiveGrain.LoadAssembly(asmPath, AssemblyUtils.GetAssemblyVersion(asmPath), asmPath);

            var ret = await _executiveGrain.Execute <double>(nameof(TestAssembly.TestClass), nameof(TestAssembly.TestClass.Pow2), a);

            Assert.AreEqual(ret, TestAssembly.TestStaticClass.Pow2(a));
        }
Esempio n. 3
0
        public bool TryGetAssembly(string name, NuGetFramework targetFramework, out string path, out NuGetVersion version)
        {
            path    = null;
            version = null;

            // Rewrite DNX framework names.
            // DNX versions match 1:1 with .NET Framework versions
            if (string.Equals(targetFramework.Framework, FrameworkConstants.FrameworkIdentifiers.Dnx))
            {
                targetFramework = new NuGetFramework(
                    FrameworkConstants.FrameworkIdentifiers.Net,
                    targetFramework.Version);
            }

            var information = _cache.GetOrAdd(targetFramework, GetFrameworkInformation);

            if (information == null || !information.Exists)
            {
                Log.LogWarning($"No framework information found for {targetFramework}");
                return(false);
            }

            lock (information.Assemblies)
            {
                AssemblyEntry entry;
                if (information.Assemblies.TryGetValue(name, out entry))
                {
                    if (string.IsNullOrEmpty(entry.Path))
                    {
                        entry.Path = GetAssemblyPath(information.Path, name);
                    }

                    if (!string.IsNullOrEmpty(entry.Path) && entry.Version == null)
                    {
                        // This code path should only run on mono
                        entry.Version = AssemblyUtils.GetAssemblyVersion(entry.Path);
                    }

                    path    = entry.Path;
                    version = new NuGetVersion(entry.Version);

                    if (Log.IsEnabled(LogLevel.Verbose))
                    {
                        // Trim back the path
                        Log.LogVerbose($"Resolved {name} {version} to {path.Substring(information.Path.Length + 1)}");
                    }
                }
            }

            return(!string.IsNullOrEmpty(path));
        }
Esempio n. 4
0
        private void AddPlugin(string dllPath)
        {
            // Create a new assembly from the plugin file we're adding..
            Assembly pluginAssembly = Assembly.LoadFrom(dllPath);

            var guid = AssemblyUtils.Guid(pluginAssembly);

            foreach (var plugin in _repository.PluginsByType)
            {
                if (plugin.AssemblyInfo.Guid == guid)
                {
                    return; // avoid loading duplicated plugin.dll file
                }
            }

            var machineName = Path.GetFileNameWithoutExtension(dllPath) ?? pluginAssembly.GetName().Name ?? "";

            machineName = Regex.Replace(machineName, "Plugin$", "", RegexOptions.IgnoreCase);
            var configFileName = machineName + ".config.json";
            var configFilePath = Path.Combine(_directoryLocator.PluginConfigDir, machineName, configFileName);

            var disabledGuids = _preferenceManager.Preferences.Plugins.DisabledPluginGuids;

            // Next we'll loop through all the Types found in the assembly
            foreach (Type pluginType in pluginAssembly.GetTypes().Where(IsValidPlugin))
            {
                // Create a new instance and store the instance in the collection for later use
                // We could change this later on to not load an instance.. we have 2 options
                // 1- Make one instance, and use it whenever we need it.. it's always there
                // 2- Don't make an instance, and instead make an instance whenever we use it, then close it
                // For now we'll just make an instance of all the plugins
                var newPlugin = (IPlugin)_kernel.Get(pluginType);

                // TODO: Store this in preferences file
                newPlugin.Enabled = !disabledGuids.Contains(guid);

                var assemblyInfo = new PluginAssemblyInfo(dllPath,
                                                          AssemblyUtils.GetAssemblyVersion(pluginAssembly),
                                                          AssemblyUtils.GetLinkerTimestamp(pluginAssembly),
                                                          guid,
                                                          configFilePath);

                // Initialize the plugin
                newPlugin.LoadPlugin(_repository, assemblyInfo);

                // Add the new plugin to our collection here
                _repository.Add(newPlugin);
            }
        }
        /// <summary>
        /// Loads a new assembly!
        /// </summary>
        /// <param name="targetType"></param>
        /// <returns></returns>
        public async Task LoadAssembly(Type targetType, bool loadReferences = true)
        {
            var asmVersion  = AssemblyUtils.GetAssemblyVersion(targetType);
            var asmFullname = AssemblyUtils.GetAssemblyName(targetType);
            var asmBytes    = AssemblyUtils.GetAssemblyBinary(targetType);

            await LoadAssembly(asmFullname, asmVersion, asmBytes);

            if (loadReferences)
            {
                var references = AssemblyUtils.GetNonSystemReferencedAssemblies(asmFullname, 0, 3);
                foreach (var @ref in references)
                {
                    var asm = Assembly.Load(@ref);
                    await LoadAssembly(asm);
                }
            }
        }
Esempio n. 6
0
 private static void ShowVersion()
 {
     Console.Error.WriteLine("{0} v{1} - compiled {2}", AssemblyUtils.GetAssemblyName(), AssemblyUtils.GetAssemblyVersion(), AssemblyUtils.GetLinkerTimestamp());
 }