void LoadModule(MethodInfo adder_method, AssemblyBuilder assemblyBuilder, ModuleAdder adder, string module, ref int errors)
        {
            System.Reflection.Module m;
            string total_log = "";

            try {
                try {
                    m = (System.Reflection.Module)adder_method.Invoke(assemblyBuilder, new object[] { module });
                } catch (TargetInvocationException ex) {
                    throw ex.InnerException;
                }
                adder(m);
            } catch (FileNotFoundException) {
                foreach (string dir in PathsToSearchForLibraries)
                {
                    string full_path = Path.Combine(dir, module);
                    if (!module.EndsWith(".netmodule", StringComparison.Ordinal))
                    {
                        full_path += ".netmodule";
                    }

                    try {
                        try {
                            m = (System.Reflection.Module)adder_method.Invoke(assemblyBuilder, new object[] { full_path });
                        } catch (TargetInvocationException ex) {
                            throw ex.InnerException;
                        }
                        adder(m);
                        return;
                    } catch (FileNotFoundException ff) {
                        total_log += ff.FusionLog;
                        continue;
                    }
                }
                Context.ReportError(6, "Cannot find module `" + module + "'");
                WriteLine("Log: \n" + total_log);
            } catch (BadImageFormatException f) {
                Context.ReportError(6, "Cannot load module (bad file format)" + f.FusionLog);
            } catch (FileLoadException f) {
                Context.ReportError(6, "Cannot load module " + f.FusionLog);
            } catch (ArgumentNullException) {
                Context.ReportError(6, "Cannot load module (null argument)");
            }
            errors++;
        }
        public bool LoadAddedNetModules(AssemblyBuilder assemblyBuilder, ModuleAdder adder)
        {
            int errors = 0;

            if (NetModulesToAdd.Count > 0)
            {
                StartTime("Loading added netmodules");

                MethodInfo adder_method = typeof(AssemblyBuilder).GetMethod("AddModule", BindingFlags.Instance | BindingFlags.NonPublic);
                if (adder_method == null)
                {
                    UnsupportedFeatureOnthisRuntime("/addmodule");
                }

                foreach (string module in NetModulesToAdd)
                {
                    LoadModule(adder_method, assemblyBuilder, adder, module, ref errors);
                }

                ShowTime("   Done");
            }

            return(errors == 0);
        }
		public bool LoadAddedNetModules(AssemblyBuilder assemblyBuilder, ModuleAdder adder)
		{
			int errors = 0;
			
			if (NetModulesToAdd.Count > 0) {
				StartTime("Loading added netmodules");

				MethodInfo adder_method = typeof (AssemblyBuilder).GetMethod ("AddModule", BindingFlags.Instance|BindingFlags.NonPublic);
				if (adder_method == null)
					UnsupportedFeatureOnthisRuntime("/addmodule");

				foreach (string module in NetModulesToAdd)
					LoadModule (adder_method, assemblyBuilder, adder, module, ref errors);
					
				ShowTime("   Done");
			}
			
			return errors == 0;
		}
Exemple #4
0
 public AddModuleCommand(ModuleAdder moduleAdder)
 {
     ModuleAdder = moduleAdder;
     Logger      = NullLogger <AddModuleCommand> .Instance;
 }
		private void LoadModule (MethodInfo adder_method, AssemblyBuilder assemblyBuilder, ModuleAdder adder, string module, ref int errors)
		{
			System.Reflection.Module m;
			string total_log = "";

			try {
				try {
					m = (System.Reflection.Module)adder_method.Invoke (assemblyBuilder, new object [] { module });
				}
				catch (TargetInvocationException ex) {
					throw ex.InnerException;
				}
				adder(m);
			} 
			catch (FileNotFoundException) {
				foreach (string dir in PathsToSearchForLibraries)	{
					string full_path = Path.Combine (dir, module);
					if (!module.EndsWith (".netmodule"))
						full_path += ".netmodule";

					try {
						try {
							m = (System.Reflection.Module) adder_method.Invoke (assemblyBuilder, new object [] { full_path });
						}
						catch (TargetInvocationException ex) {
							throw ex.InnerException;
						}
						adder(m);
						return;
					}
					catch (FileNotFoundException ff) {
						total_log += ff.FusionLog;
						continue;
					}
				}
				ReportError (6, "Cannot find module `" + module + "'" );
				Console.WriteLine ("Log: \n" + total_log);
			}
			catch (BadImageFormatException f) {
				ReportError (6, "Cannot load module (bad file format)" + f.FusionLog);
			}
			catch (FileLoadException f)	{
				ReportError (6, "Cannot load module " + f.FusionLog);
			}
			catch (ArgumentNullException) {
				ReportError (6, "Cannot load module (null argument)");
			}
			errors++;
		}