source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/Forms/AboutDialog.cs@ 1180

Last change on this file since 1180 was 1146, checked in by Sam Habiel, 13 years ago

Initial Import of BMX4

File size: 4.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Windows.Forms;
6using System.Reflection;
7using IndianHealthService.BMXNet.Util;
8
9namespace IndianHealthService.BMXNet.WinForm
10{
11 /// <summary>
12 /// Stardardized "About" dialog that displays information from the executable's (RootAssembly) AssemblyInfo:
13 /// <list>
14 /// AssemblyTitle
15 /// AssemblyProduct
16 /// AssemblyVersion
17 /// AssemblyCopyright
18 /// AssemblyCompany
19 /// AssemblyDescription
20 /// </list>
21 /// <para>
22 /// Additionally, a list box showing all non-system .NET assemblies is displayed. Set IncludeRoot=True
23 /// if the RootAssembly should be included in the list.
24 /// </para>
25 /// <example>
26 /// Usage of dialog:
27 /// <code>
28 /// AboutDialog dialog=new AboutDialog();
29 /// dialog.RootAssembly = Assembly.GetExecutingAssembly();
30 /// dialog.IncludeRoot = true;
31 /// dialog.Show(this.Parent);
32 /// </code>
33 /// By default, the RootAssebmly is the Assembly.GetExecutingAssembly();
34 /// </example>
35 /// </summary>
36 public partial class AboutDialog : Form
37 {
38 public AboutDialog()
39 {
40 InitializeComponent();
41
42 // Initialize the AboutBox to display the product information from the assembly information.
43 // Change assembly information settings for your application through either:
44 // - Project->Properties->Application->Assembly Information
45 // - AssemblyInfo.cs
46 this.Text = String.Format("About {0}", EntryAssemblyInfo.AssemblyTitle);
47 this.labelProductName.Text = EntryAssemblyInfo.AssemblyProduct;
48 this.labelVersion.Text = String.Format("Version {0}", EntryAssemblyInfo.AssemblyVersion);
49 this.labelCopyright.Text = EntryAssemblyInfo.AssemblyCopyright;
50 this.labelCompanyName.Text = EntryAssemblyInfo.AssemblyCompany;
51 this.textBoxDescription.Text = EntryAssemblyInfo.AssemblyDescription;
52 }
53
54 private bool _includeRoot = false;
55
56 /// <summary>
57 /// Set to True if the RootAssembly should be included in the list of displayed assemblies. False by default.
58 /// </summary>
59 public bool IncludeRoot
60 {
61 get { return _includeRoot; }
62 set { _includeRoot = value; }
63 }
64
65 private Assembly _rootAssembly = Assembly.GetEntryAssembly();
66
67 /// <summary>
68 /// The assembly that all references are followed from. The EntryAssembly by default.
69 /// </summary>
70 public Assembly RootAssembly
71 {
72 get { return _rootAssembly; }
73 set { _rootAssembly = value; }
74 }
75
76
77
78 private void AboutDialog_Load(object sender, EventArgs e)
79 {
80 this.Icon = this.Owner==null ? null : this.Owner.Icon;
81
82 Dictionary<String, AssemblyName> dependents = new Dictionary<string, AssemblyName>();
83 SortedList<String, String> sortedList = new SortedList<string, string>();
84
85 if (this.IncludeRoot)
86 {
87 sortedList.Add(this.RootAssembly.GetName().Name, this.RootAssembly.GetName().Version.ToString());
88 }
89
90 foreach (AssemblyName each in this.RootAssembly.GetReferencedAssemblies())
91 {
92 this.AddDependents(dependents, each);
93 }
94
95 foreach (AssemblyName each in dependents.Values)
96 {
97 if (!(each.Name.Equals(this.RootAssembly.GetName().Name) || each.Name.Equals(this.RootAssembly.GetName().Name) || (each.Name.StartsWith("Microsoft") || each.Name.StartsWith("System") || each.Name.StartsWith("mscorlib") || each.Name.StartsWith("Accessibility"))))
98 {
99 sortedList.Add(each.Name, each.Version.ToString());
100 }
101 }
102
103 this.textBoxDescription.Clear();
104
105 foreach (String each in sortedList.Keys)
106 {
107 this.textBoxDescription.AppendText(each + " (" + sortedList[each] + ")\r\n");
108 }
109 }
110
111 private void AddDependents(Dictionary<string, AssemblyName> dependents, AssemblyName anAssemblyName)
112 {
113 if (dependents.ContainsKey(anAssemblyName.FullName))
114 return;
115
116 dependents[anAssemblyName.FullName] = anAssemblyName;
117
118 try
119 {
120 foreach (AssemblyName each in Assembly.Load(anAssemblyName).GetReferencedAssemblies())
121 {
122 this.AddDependents(dependents, each);
123 }
124 }
125 catch
126 {
127
128 }
129 }
130
131 private void okButton_Click(object sender, EventArgs e)
132 {
133 this.Close();
134 }
135
136 }
137}
Note: See TracBrowser for help on using the repository browser.