Exemplo n.º 1
0
        public Task <bool> IsValidAssembly(LukeLocationModel lukeLocationModel)
        {
            if (lukeLocationModel == null)
            {
                throw new ParameterRequiredException(nameof(lukeLocationModel));
            }

            bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

            if (isWindows)
            {
                // TODO : create another app domain and see if the assembly is valid
            }

            AssemblyLoader assemblyLoader = new AssemblyLoader(lukeLocationModel.AssemblyLocation);
            Assembly       assembly       = assemblyLoader.Load(lukeLocationModel.AssemblyName);

            if (assembly == null)
            {
                throw new AssemblyNotFoundException();
            }

            bool isValidAssembly = assembly.GetTypes().Any(m => m.IsClass && typeof(LukeJob).IsAssignableFrom(m));

            return(Task.FromResult(isValidAssembly));
        }
Exemplo n.º 2
0
        public Task Load(LukeLocationModel lukeLocationModel)
        {
            if (lukeLocationModel == null)
            {
                throw new ParameterRequiredException(nameof(lukeLocationModel));
            }

            AssemblyLoader assemblyLoader = new AssemblyLoader(lukeLocationModel.AssemblyLocation);

            DirectoryInfo directoryInfo = new DirectoryInfo(lukeLocationModel.AssemblyLocation);

            FileInfo[] files = directoryInfo.GetFiles("*.dll");

            foreach (FileInfo fileInfo in files)
            {
                // TODO : check if assembly already loaded

                // it is loaded in IsValid method
                if (fileInfo.Name != lukeLocationModel.AssemblyName)
                {
                    try
                    {
                        assemblyLoader.Load(fileInfo.Name);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }

            return(Task.CompletedTask);
        }