// Print the information associated with an Assembly, such as its dependant // assemblies and the files contained within it. private static void _print_info (AssemblyDependencies ad, String name, ArrayList o, int level) { _indent(level); IAssemblyInfo ai = ad[name]; Console.WriteLine(ai.Name); if (!o.Contains(name)) { o.Add(name); _indent(level); Console.WriteLine(Localization.DEPENDANT_ASSEMBLIES); foreach (AssemblyName s in ai.ReferencedAssemblies) { _print_info(ad, s.FullName, o, level + 2); } _indent(level); Console.WriteLine(Localization.DEPENDANT_FILES); foreach (ModuleInfo m in ai.ReferencedModules) { _indent(level + 2); Console.WriteLine(m.Name); } } }
// Creates a TreeNode for the Assembly given by ``name'' and all of // its dependant assemblies and modules. // // If a dependant assembly hasn't been displayed yet, add a new sub-tree // to the current tree describing the dependancy. // private TreeNode _create_info (AssemblyDependencies ad, String name, ArrayList o) { IAssemblyInfo ai = ad[name]; DependencyNode root = new DependencyNode(ai.Name, ai); if (!o.Contains(name)) { o.Add(name); TreeNode referenced = new TreeNode(Localization.REFERENCED_ASSEMBLIES); TreeNode files = new TreeNode(Localization.CONTAINED_MODULES); root.Nodes.Add(referenced); root.Nodes.Add(files); foreach (AssemblyName s in ai.ReferencedAssemblies) { referenced.Nodes.Add(_create_info(ad, s.FullName, o)); } foreach (ModuleInfo m in ai.ReferencedModules) { DependencyNode d = new DependencyNode(m.Name, ai); files.Nodes.Add(d); } } return(root); }
// Displays the contents of a manifest to the console window. // private static void _print_manifest(String manifest, bool prefix) { AssemblyDependencies ad = null; try { ad = new AssemblyDependencies(manifest, m_lai); } catch (System.ArgumentNullException e) { _error_message(Localization.INVALID_ASSEMBLY_MANIFEST, prefix); Trace.WriteLine("Exception: " + e.ToString()); return; } catch (System.Exception e) { _error_message(e.Message, prefix); Trace.WriteLine("Exception: " + e.ToString()); return; } ArrayList observed = new ArrayList(); _print_info(ad, ad.ManifestName, observed, prefix ? 0 : 1); if (m_config != null && m_config.Length > 0) { AppConfig.SaveConfig(ad, m_config); } ad.Dispose(); }
// Generate an Assemblies XML Element consisting of AssemblyIdentity // elements for all the Assemblies we loaded. private static void _assemblies(XmlDocument d, XmlNode parent, AssemblyDependencies ad) { XmlElement assemblies = d.CreateElement(Localization.ACF_DEPENDENTASSEMBLY); ArrayList l = new ArrayList(ad.Assemblies); object[] asminfo = l.ToArray(); Array.Sort(asminfo, new AsmInfoComparer()); /* * Due to obscurities of the dependency search & store process, * the same assembly may be loaded multiple times. * (This may happen if different AssemblyName's are loaded for * what is, eventually, the same Assembly.) * * We would prefer to minimize duplicate lines, so ``o'' keeps * track of what we've printed out, to keep from displaying * it multiple times. */ ArrayList o = new ArrayList(); foreach (IAssemblyInfo ai in asminfo) { if (!o.Contains(ai.Name)) { Trace.WriteLine("Saving Assembly: ``" + ai.Name + "''"); assemblies.AppendChild(_assembly_identity(d, ai)); o.Add(ai.Name); } } parent.AppendChild(assemblies); }
/** Reload the current file. */ private void _on_view_refresh_click(Object sender, System.EventArgs e) { // use the current window for loading. m_ad = null; TreeView.Nodes.Clear(); // re-populate the tree view. _create_manifest(new string[] { m_file }); }
// Set's the Assembly Dependencies that this window will be displaying // and populates the TreeView with the appropriate elements. private void _set_dependencies(AssemblyDependencies ad) { if (m_ad != null) { throw new Exception( "adepends internal error: only one dependency list per window"); } m_ad = ad; ArrayList observed = new ArrayList(); TreeNode root = _create_info(m_ad, m_ad.ManifestName, observed); root.ExpandAll(); TreeView.Nodes.Add(root); }
// Close the current window. private void _close_window(bool force) { if (m_instances > 1) { // there are other windows open, so just close this one. --m_instances; _close_window(); } else if (m_ad != null && !force) { // this is the last window, so clear the TreeView. m_ad = null; TreeView.Nodes.Clear(); _reset_interface(); } else { // this is the last window; exit the program. _close_window(); Application.Exit(); } }
// Save a configuration file that lists the Assemblies contained in // ``ad'', writing the contents to the file ``file''. public static void SaveConfig(AssemblyDependencies ad, string file) { if (ad == null) { Debug.Assert(false, "Invalid AssemblyDependencies Object"); } if (file == null) { Debug.Assert(false, "Invalid file name"); } XmlDocument d = new XmlDocument(); XmlElement root = d.CreateElement(Localization.ACF_CONFIGURATION); XmlElement runtime = d.CreateElement(Localization.ACF_RUNTIME); root.AppendChild(runtime); XmlElement asmBind = d.CreateElement(Localization.ACF_ASSEMBLYBINDING); asmBind.Attributes.Append(_attribute(d, Localization.ACF_XMLNS, Localization.ACF_XMLURN)); runtime.AppendChild(asmBind); _probing(d, asmBind); _binding_redir(d, asmBind); _assemblies(d, asmBind, ad); d.AppendChild(root); XmlTextWriter w = new XmlTextWriter(file, Encoding.UTF8); w.Formatting = Formatting.Indented; w.WriteStartDocument(); d.Save(w); w.Close(); }
// For the given manifest, build a tree of its dependant assembiles/ // modules, and display them in the TreeView. private void _create_manifest(ICollection manifests) { Trace.WriteLine("Loading up manifests..."); Trace.WriteLine(" LoadAs: " + m_lai.LoadAs().ToString()); Trace.WriteLine(" AppP: " + m_lai.AppPath()); Trace.WriteLine(" RelP: " + m_lai.RelPath()); StringBuilder sb = new StringBuilder(); foreach (String manifest in manifests) { try { Trace.WriteLine(" manifest: " + manifest); AssemblyDependencies ad = new AssemblyDependencies(manifest, m_lai); DependenciesForm f = this; // if this window already contains a dependency list, create // a new window. if (f.m_ad != null) { f = new DependenciesForm(m_lai); f.Size = Size; f._set_assembly_load(f.m_lai.LoadAs()); f.BringToFront(); f.Show(); } f._set_dependencies(ad); f.m_file = manifest; f.m_menu.ViewRefresh.Enabled = true; f.m_menu.FileSaveConfig.Enabled = true; // set the infopanel to the root node. f.TreeView.SelectedNode = f.TreeView.Nodes[0]; } catch (System.ArgumentNullException e) { Trace.WriteLine("_create_manifest: arg null exception: " + e.ToString()); sb.Append(String.Format(Localization.FMT_INVALID_MANIFEST, manifest, Localization.INVALID_ASSEMBLY_MANIFEST)); _reset_interface(); } catch (System.Exception e) { Trace.WriteLine("_create_manifest: exception: " + e.ToString()); sb.Append(String.Format(Localization.FMT_INVALID_MANIFEST, manifest, e.Message)); _reset_interface(); } } if (sb.Length > 0) { // some of the files couldn't be opened; alert the user. MessageBox.Show(this, String.Format(Localization.FMT_INVALID_FILE_LIST, Localization.UNOPENED_FILES, sb.ToString()), Localization.GUI_WINDOW_TITLE, MessageBoxButtons.OK); } }