1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Components
.Winforms
.AssemblyResolver
18 using System
.Reflection
;
19 using System
.Windows
.Forms
;
22 internal class LocateAssemblyForm
: Form
24 private System
.Windows
.Forms
.FolderBrowserDialog folderBrowserDialog1
;
25 private System
.Windows
.Forms
.Button browseButton
;
26 private System
.Windows
.Forms
.TextBox location
;
27 private System
.Windows
.Forms
.TextBox assemblyName
;
28 private System
.Windows
.Forms
.Button okButton
;
29 private System
.Windows
.Forms
.Button cancelButton
;
32 /// Required designer variable.
34 private System
.ComponentModel
.Container components
= null;
35 private System
.Windows
.Forms
.GroupBox groupBox1
;
36 private System
.Windows
.Forms
.Label label2
;
37 private System
.Windows
.Forms
.Label label1
;
39 private String _assemblyName
;
40 private Assembly _assembly
;
42 public LocateAssemblyForm(String assemblyName
)
44 _assemblyName
= assemblyName
;
46 InitializeComponent();
48 this.assemblyName
.Text
= assemblyName
;
51 public Assembly AssemblyLoaded
53 get { return _assembly; }
56 public String AssemblyLocation
58 get { return location.Text; }
62 /// Clean up any resources being used.
64 protected override void Dispose( bool disposing
)
68 if(components
!= null)
73 base.Dispose( disposing
);
76 private void browseButton_Click(object sender
, System
.EventArgs e
)
78 folderBrowserDialog1
.SelectedPath
= AppDomain
.CurrentDomain
.BaseDirectory
;
80 if (folderBrowserDialog1
.ShowDialog(this) == DialogResult
.OK
)
82 location
.Text
= folderBrowserDialog1
.SelectedPath
;
86 #region Windows Form Designer generated code
88 /// Required method for Designer support - do not modify
89 /// the contents of this method with the code editor.
91 private void InitializeComponent()
93 this.folderBrowserDialog1
= new System
.Windows
.Forms
.FolderBrowserDialog();
94 this.groupBox1
= new System
.Windows
.Forms
.GroupBox();
95 this.browseButton
= new System
.Windows
.Forms
.Button();
96 this.location
= new System
.Windows
.Forms
.TextBox();
97 this.assemblyName
= new System
.Windows
.Forms
.TextBox();
98 this.label2
= new System
.Windows
.Forms
.Label();
99 this.label1
= new System
.Windows
.Forms
.Label();
100 this.okButton
= new System
.Windows
.Forms
.Button();
101 this.cancelButton
= new System
.Windows
.Forms
.Button();
102 this.groupBox1
.SuspendLayout();
103 this.SuspendLayout();
107 this.groupBox1
.Controls
.Add(this.browseButton
);
108 this.groupBox1
.Controls
.Add(this.location
);
109 this.groupBox1
.Controls
.Add(this.assemblyName
);
110 this.groupBox1
.Controls
.Add(this.label2
);
111 this.groupBox1
.Controls
.Add(this.label1
);
112 this.groupBox1
.Location
= new System
.Drawing
.Point(12, 8);
113 this.groupBox1
.Name
= "groupBox1";
114 this.groupBox1
.Size
= new System
.Drawing
.Size(488, 172);
115 this.groupBox1
.TabIndex
= 5;
116 this.groupBox1
.TabStop
= false;
117 this.groupBox1
.Text
= "Assembly Resolve";
121 this.browseButton
.Location
= new System
.Drawing
.Point(400, 124);
122 this.browseButton
.Name
= "browseButton";
123 this.browseButton
.Size
= new System
.Drawing
.Size(75, 24);
124 this.browseButton
.TabIndex
= 9;
125 this.browseButton
.Text
= "&Browse...";
126 this.browseButton
.Click
+= new System
.EventHandler(this.browseButton_Click
);
130 this.location
.Location
= new System
.Drawing
.Point(16, 124);
131 this.location
.Name
= "location";
132 this.location
.Size
= new System
.Drawing
.Size(376, 21);
133 this.location
.TabIndex
= 8;
134 this.location
.Text
= "";
138 this.assemblyName
.BorderStyle
= System
.Windows
.Forms
.BorderStyle
.None
;
139 this.assemblyName
.Location
= new System
.Drawing
.Point(16, 52);
140 this.assemblyName
.Multiline
= true;
141 this.assemblyName
.Name
= "assemblyName";
142 this.assemblyName
.ReadOnly
= true;
143 this.assemblyName
.Size
= new System
.Drawing
.Size(456, 42);
144 this.assemblyName
.TabIndex
= 6;
145 this.assemblyName
.Text
= "";
149 this.label2
.Location
= new System
.Drawing
.Point(16, 104);
150 this.label2
.Name
= "label2";
151 this.label2
.Size
= new System
.Drawing
.Size(100, 18);
152 this.label2
.TabIndex
= 7;
153 this.label2
.Text
= "Location:";
157 this.label1
.Font
= new System
.Drawing
.Font("Verdana", 8.25F
, System
.Drawing
.FontStyle
.Bold
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
158 this.label1
.Location
= new System
.Drawing
.Point(16, 28);
159 this.label1
.Name
= "label1";
160 this.label1
.Size
= new System
.Drawing
.Size(360, 18);
161 this.label1
.TabIndex
= 5;
162 this.label1
.Text
= "Could not find the following assembly:";
166 this.okButton
.Location
= new System
.Drawing
.Point(420, 188);
167 this.okButton
.Name
= "okButton";
168 this.okButton
.TabIndex
= 6;
169 this.okButton
.Text
= "OK";
170 this.okButton
.Click
+= new System
.EventHandler(this.okButton_Click
);
174 this.cancelButton
.DialogResult
= System
.Windows
.Forms
.DialogResult
.Cancel
;
175 this.cancelButton
.Location
= new System
.Drawing
.Point(336, 188);
176 this.cancelButton
.Name
= "cancelButton";
177 this.cancelButton
.TabIndex
= 7;
178 this.cancelButton
.Text
= "Cancel";
179 this.cancelButton
.Click
+= new System
.EventHandler(this.cancelButton_Click
);
181 // LocateAssemblyForm
183 this.AcceptButton
= this.okButton
;
184 this.AutoScaleBaseSize
= new System
.Drawing
.Size(6, 14);
185 this.CancelButton
= this.cancelButton
;
186 this.ClientSize
= new System
.Drawing
.Size(510, 220);
187 this.Controls
.Add(this.cancelButton
);
188 this.Controls
.Add(this.okButton
);
189 this.Controls
.Add(this.groupBox1
);
190 this.Font
= new System
.Drawing
.Font("Verdana", 8.25F
, System
.Drawing
.FontStyle
.Regular
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
191 this.FormBorderStyle
= System
.Windows
.Forms
.FormBorderStyle
.Fixed3D
;
192 this.Name
= "LocateAssemblyForm";
193 this.StartPosition
= System
.Windows
.Forms
.FormStartPosition
.CenterParent
;
194 this.Text
= "Could not resolve assembly";
195 this.groupBox1
.ResumeLayout(false);
196 this.ResumeLayout(false);
201 private void okButton_Click(object sender
, System
.EventArgs e
)
203 _assembly
= AssemblyUtils
.TryToLoadAssembly(
204 location
.Text
, AssemblyUtils
.Normalize(_assemblyName
) );
206 if (_assembly
== null)
208 MessageBox
.Show("Could not load assembly from the given location", "Error", MessageBoxButtons
.OK
, MessageBoxIcon
.Error
);
212 this.DialogResult
= DialogResult
.OK
;
215 private void cancelButton_Click(object sender
, System
.EventArgs e
)
217 this.DialogResult
= DialogResult
.Cancel
;