Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Experiments / Attic / ComponentViewer / Castle.Goodies.Viewer / MainForm.cs
blob0532c3a75e001d2b7408ac338f194b47dcb2d821
2 namespace Castle.Goodies.Viewer
4 using System;
5 using System.Drawing;
6 using System.Collections;
7 using System.ComponentModel;
8 using System.IO;
9 using System.Reflection;
10 using System.Windows.Forms;
11 using System.Data;
12 using System.Security.Policy;
14 using Netron.GraphLib;
16 using Castle.Core;
17 using Castle.MicroKernel;
18 using Castle.Windsor;
20 using Castle.Goodies.Viewer.Shapes;
23 public class MainForm : Form
25 private Random rnd = new Random();
27 private System.ComponentModel.Container components = null;
29 private Netron.GraphLib.UI.GraphControl graphControl1;
30 private System.Windows.Forms.StatusBar statusBar1;
31 private System.Windows.Forms.MainMenu mainMenu1;
32 private System.Windows.Forms.MenuItem menuItem1;
33 private System.Windows.Forms.MenuItem menuItem2;
34 private System.Windows.Forms.TabControl tabControl1;
35 private System.Windows.Forms.TabPage tabPage1;
36 private System.Windows.Forms.TabPage tabPage2;
37 private System.Windows.Forms.Panel panel1;
38 private Netron.GraphLib.UI.Stamper stamper1;
39 private System.Windows.Forms.Splitter splitter2;
40 private System.Windows.Forms.PropertyGrid propertyGrid1;
41 private System.Windows.Forms.Splitter splitter1;
43 private String appPath = @"E:\dev\projects\digitalgravity\castle\trunk\Samples\MindDump\bin";
46 public MainForm()
49 // Required for Windows Form Designer support
51 InitializeComponent();
53 AppDomain currentDomain = AppDomain.CurrentDomain;
54 AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
56 AppDomain app = AppDomain.CreateDomain("minddump", new Evidence(currentDomain.Evidence), appPath, null, false);
58 // app.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
60 object remoteInstance = null;
62 try
64 remoteInstance = app.CreateInstanceAndUnwrap(
65 "Castle.Applications.MindDump", "Castle.Applications.MindDump.MindDumpContainer");
67 catch(Exception ex)
69 MessageBox.Show(ex.StackTrace);
72 IKernel kernel = null;
74 if (remoteInstance is IWindsorContainer)
76 kernel = (remoteInstance as IWindsorContainer).Kernel;
78 else
80 kernel = (remoteInstance as IKernel);
83 graphControl1.AddLibrary("BasicShapes.dll");
84 graphControl1.AddLibrary("Castle.Goodies.Viewer.exe");
86 stamper1.GraphControl = graphControl1;
88 graphControl1.AllowAddShape = false;
90 if (kernel == null) return;
92 GraphNode[] nodes = kernel.GraphNodes;
94 Hashtable node2Shape = new Hashtable();
96 foreach(ComponentModel node in nodes)
98 ComponentNode shape = (ComponentNode)
99 graphControl1.AddShape("castle.comp.node", new PointF(80,20));
101 shape.Key = node.Name;
102 shape.Text = GetPossibleNullName(node.Service);
103 shape.Implementation = GetPossibleNullName(node.Implementation);
105 shape.Tag = node;
106 node2Shape[node] = shape;
107 SetShape(shape);
110 foreach(ComponentModel node in nodes)
112 Shape parentShape = node2Shape[node] as Shape;
114 foreach(ComponentModel dep in node.Adjacencies)
116 Shape childShape = node2Shape[dep] as Shape;
117 Connect(parentShape, childShape);
122 private string GetPossibleNullName(Type type)
124 if (type == null)
126 return "<Custom Activator>";
128 return type.Name;
131 private void SetShape(Shape shape)
133 shape.FitSize(false);
134 shape.X = rnd.Next(50,this.graphControl1.Width-100);
135 shape.Y = rnd.Next(50,this.graphControl1.Height-20);
138 private Connection Connect(Shape childShape, Shape parentShape)
140 Connection conn = graphControl1.AddEdge(childShape.Connectors[1], parentShape.Connectors[0]);
142 // conn.From.ConnectorLocation = ConnectorLocations.South;
143 // conn.To.ConnectorLocation = ConnectorLocations.North;
144 conn.LineEnd = ConnectionEnds.RightOpenArrow;
145 return conn;
148 /// <summary>
149 /// Clean up any resources being used.
150 /// </summary>
151 protected override void Dispose( bool disposing )
153 if( disposing )
155 if (components != null)
157 components.Dispose();
160 base.Dispose( disposing );
163 #region Windows Form Designer generated code
164 /// <summary>
165 /// Required method for Designer support - do not modify
166 /// the contents of this method with the code editor.
167 /// </summary>
168 private void InitializeComponent()
170 this.graphControl1 = new Netron.GraphLib.UI.GraphControl();
171 this.statusBar1 = new System.Windows.Forms.StatusBar();
172 this.mainMenu1 = new System.Windows.Forms.MainMenu();
173 this.menuItem1 = new System.Windows.Forms.MenuItem();
174 this.menuItem2 = new System.Windows.Forms.MenuItem();
175 this.tabControl1 = new System.Windows.Forms.TabControl();
176 this.tabPage1 = new System.Windows.Forms.TabPage();
177 this.tabPage2 = new System.Windows.Forms.TabPage();
178 this.panel1 = new System.Windows.Forms.Panel();
179 this.stamper1 = new Netron.GraphLib.UI.Stamper();
180 this.splitter2 = new System.Windows.Forms.Splitter();
181 this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
182 this.splitter1 = new System.Windows.Forms.Splitter();
183 this.tabControl1.SuspendLayout();
184 this.tabPage1.SuspendLayout();
185 this.panel1.SuspendLayout();
186 this.SuspendLayout();
188 // graphControl1
190 this.graphControl1.AllowAddConnection = true;
191 this.graphControl1.AllowAddShape = true;
192 this.graphControl1.AllowDeleteShape = true;
193 this.graphControl1.AllowDrop = true;
194 this.graphControl1.AllowMoveShape = true;
195 this.graphControl1.AutomataPulse = 10;
196 this.graphControl1.AutoScroll = true;
197 this.graphControl1.BackgroundColor = System.Drawing.Color.Gray;
198 this.graphControl1.BackgroundImagePath = null;
199 this.graphControl1.BackgroundType = Netron.GraphLib.CanvasBackgroundTypes.FlatColor;
200 this.graphControl1.DefaultConnectionPath = "Default";
201 this.graphControl1.DefaultLineEnd = Netron.GraphLib.ConnectionEnds.NoEnds;
202 this.graphControl1.Dock = System.Windows.Forms.DockStyle.Fill;
203 this.graphControl1.DoTrack = false;
204 this.graphControl1.EnableContextMenu = false;
205 this.graphControl1.EnableLayout = false;
206 this.graphControl1.FileName = null;
207 this.graphControl1.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
208 this.graphControl1.GradientBottom = System.Drawing.Color.White;
209 this.graphControl1.GradientTop = System.Drawing.Color.LightSteelBlue;
210 this.graphControl1.GraphLayoutAlgorithm = Netron.GraphLib.GraphLayoutAlgorithms.SpringEmbedder;
211 this.graphControl1.GridSize = 20;
212 this.graphControl1.Location = new System.Drawing.Point(0, 0);
213 this.graphControl1.Name = "graphControl1";
214 this.graphControl1.RestrictToCanvas = false;
215 this.graphControl1.ShowGrid = true;
216 this.graphControl1.Size = new System.Drawing.Size(424, 445);
217 this.graphControl1.Snap = false;
218 this.graphControl1.TabIndex = 4;
219 this.graphControl1.Text = "graphControl1";
220 this.graphControl1.Zoom = 1F;
221 this.graphControl1.ShowNodeProperties += new Netron.GraphLib.ShowPropsDelegate(this.graphControl1_ShowNodeProperties);
223 // statusBar1
225 this.statusBar1.Location = new System.Drawing.Point(0, 471);
226 this.statusBar1.Name = "statusBar1";
227 this.statusBar1.Size = new System.Drawing.Size(728, 22);
228 this.statusBar1.TabIndex = 2;
229 this.statusBar1.Text = "statusBar1";
231 // mainMenu1
233 this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
234 this.menuItem1});
236 // menuItem1
238 this.menuItem1.Index = 0;
239 this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
240 this.menuItem2});
241 this.menuItem1.Text = "File";
243 // menuItem2
245 this.menuItem2.Index = 0;
246 this.menuItem2.Text = "Exit";
248 // tabControl1
250 this.tabControl1.Controls.Add(this.tabPage1);
251 this.tabControl1.Controls.Add(this.tabPage2);
252 this.tabControl1.Dock = System.Windows.Forms.DockStyle.Left;
253 this.tabControl1.Location = new System.Drawing.Point(0, 0);
254 this.tabControl1.Name = "tabControl1";
255 this.tabControl1.SelectedIndex = 0;
256 this.tabControl1.Size = new System.Drawing.Size(432, 471);
257 this.tabControl1.TabIndex = 5;
259 // tabPage1
261 this.tabPage1.Controls.Add(this.graphControl1);
262 this.tabPage1.Location = new System.Drawing.Point(4, 22);
263 this.tabPage1.Name = "tabPage1";
264 this.tabPage1.Size = new System.Drawing.Size(424, 445);
265 this.tabPage1.TabIndex = 0;
266 this.tabPage1.Text = "Configuration";
268 // tabPage2
270 this.tabPage2.Location = new System.Drawing.Point(4, 22);
271 this.tabPage2.Name = "tabPage2";
272 this.tabPage2.Size = new System.Drawing.Size(424, 445);
273 this.tabPage2.TabIndex = 1;
274 this.tabPage2.Text = "Facilities";
276 // panel1
278 this.panel1.BackColor = System.Drawing.SystemColors.Control;
279 this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
280 this.panel1.Controls.Add(this.propertyGrid1);
281 this.panel1.Controls.Add(this.splitter2);
282 this.panel1.Controls.Add(this.stamper1);
283 this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
284 this.panel1.Location = new System.Drawing.Point(432, 0);
285 this.panel1.Name = "panel1";
286 this.panel1.Size = new System.Drawing.Size(296, 471);
287 this.panel1.TabIndex = 7;
289 // stamper1
291 this.stamper1.AutoScroll = true;
292 this.stamper1.Dock = System.Windows.Forms.DockStyle.Bottom;
293 this.stamper1.Location = new System.Drawing.Point(0, 259);
294 this.stamper1.Name = "stamper1";
295 this.stamper1.Size = new System.Drawing.Size(292, 208);
296 this.stamper1.TabIndex = 2;
297 this.stamper1.Zoom = 0.2F;
299 // splitter2
301 this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
302 this.splitter2.Location = new System.Drawing.Point(0, 256);
303 this.splitter2.Name = "splitter2";
304 this.splitter2.Size = new System.Drawing.Size(292, 3);
305 this.splitter2.TabIndex = 3;
306 this.splitter2.TabStop = false;
308 // propertyGrid1
310 this.propertyGrid1.CommandsVisibleIfAvailable = true;
311 this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
312 this.propertyGrid1.LargeButtons = false;
313 this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;
314 this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
315 this.propertyGrid1.Name = "propertyGrid1";
316 this.propertyGrid1.Size = new System.Drawing.Size(292, 256);
317 this.propertyGrid1.TabIndex = 4;
318 this.propertyGrid1.Text = "propertyGrid1";
319 this.propertyGrid1.ViewBackColor = System.Drawing.SystemColors.Window;
320 this.propertyGrid1.ViewForeColor = System.Drawing.SystemColors.WindowText;
322 // splitter1
324 this.splitter1.Location = new System.Drawing.Point(432, 0);
325 this.splitter1.Name = "splitter1";
326 this.splitter1.Size = new System.Drawing.Size(3, 471);
327 this.splitter1.TabIndex = 8;
328 this.splitter1.TabStop = false;
330 // Form1
332 this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
333 this.ClientSize = new System.Drawing.Size(728, 493);
334 this.Controls.Add(this.splitter1);
335 this.Controls.Add(this.panel1);
336 this.Controls.Add(this.tabControl1);
337 this.Controls.Add(this.statusBar1);
338 this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
339 this.Menu = this.mainMenu1;
340 this.Name = "Form1";
341 this.Text = "Form1";
342 this.tabControl1.ResumeLayout(false);
343 this.tabPage1.ResumeLayout(false);
344 this.panel1.ResumeLayout(false);
345 this.ResumeLayout(false);
348 #endregion
350 /// <summary>
351 /// The main entry point for the application.
352 /// </summary>
353 [STAThread]
354 static void Main()
356 Application.Run(new MainForm());
359 private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
361 // Is full assemblyName?
363 String name = args.Name;
364 int index = name.IndexOf(',');
366 if (index != -1)
368 name = name.Substring(0, index);
371 name = Path.Combine( appPath, name );
373 String nameVar1 = String.Format( "{0}.dll", name );
374 String nameVar2 = String.Format( "{0}.exe", name );
376 FileInfo info1 = new FileInfo( nameVar1 );
377 FileInfo info2 = new FileInfo( nameVar2 );
379 if (info1.Exists)
381 return Assembly.LoadFile( info1.FullName );
383 else if (info2.Exists)
385 return Assembly.LoadFile( info2.FullName );
388 // Could not find ...
389 return null;
392 private void graphControl1_ShowNodeProperties(object sender, Netron.GraphLib.PropertyBag props)
394 propertyGrid1.SelectedObject = props;