Пример #1
0
        public static AddOnEnvironment CreateDebugEnvironment(string assemblyPath)
        {
            if (assemblyPath == null)
            {
                throw new ArgumentNullException(nameof(assemblyPath));
            }

            if (!File.Exists(assemblyPath))
            {
                throw new FileNotFoundException("File does not exist.", nameof(assemblyPath));
            }

            string          directory        = Path.GetDirectoryName(assemblyPath);
            List <Assembly> loadedAssemblies = new List <Assembly>();
            Assembly        primaryAssembly  = null;

            if (AssemblyManager.LoadAssembly(assemblyPath))
            {
                primaryAssembly = Assembly.LoadFile(assemblyPath);
            }

            foreach (string file in Directory.GetFiles(directory))
            {
                Assembly asm = null;
                if (AssemblyManager.LoadAssembly(file))
                {
                    asm = Assembly.LoadFile(file);
                }

                if (asm != null)
                {
                    loadedAssemblies.Add(asm);
                }
            }

            return(new AddOnEnvironment(directory, primaryAssembly, loadedAssemblies,
                                        $"Debug {Path.GetFileName(assemblyPath)}"));
        }
Пример #2
0
        private AddOnEnvironment(string directory)
        {
            AddOnManifest manifest;

            Location = directory;

            string manifestFileName = Path.Combine(directory, "Manifest.xml");

            try
            {
                manifest = new AddOnManifest();
                manifest.LoadXml(manifestFileName);
            }
            catch { manifest = null; }

            if (manifest != null)
            {
                Console.WriteLine("Attempting to load AddOn environment for \"{0}\".", manifest.Name);
                AppDomain.CurrentDomain.AssemblyResolve += Domain_AssemblyResolve;

                string primaryAssemblyFile = Path.Combine(directory, manifest.PrimaryAssemblyFile);

                if (AssemblyManager.LoadAssembly(primaryAssemblyFile))
                {
                    PrimaryAssembly = Assembly.LoadFile(primaryAssemblyFile);
                }

                foreach (string file in manifest)
                {
                    string assemblyFile = Path.Combine(directory, file);
                    if (AssemblyManager.LoadAssembly(assemblyFile))
                    {
                        loadedAssemblies.Add(Assembly.LoadFile(assemblyFile));
                    }
                }
            }
        }