annotate VBoxFrontend/Display.cs @ 7:a7650e26195f tip

Added support for generating Com Callable Wrappers
author Ivo Smits
date Fri, 06 May 2011 08:12:43 +0200
parents e1ec7bf71313
children
rev   line source
0
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
1 ???using System;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
2 using System.Collections.Generic;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
3 using System.ComponentModel;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
4 using System.Drawing;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
5 using System.Text;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
6 using System.Windows.Forms;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
7 using System.Threading;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
8 using VirtualBox;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
9
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
10 namespace ConsoleApplication1 {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
11 public partial class Display : Form {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
12 public Framebuffer Framebuffer { get; private set; }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
13 public IConsole VMConsole { get; private set; }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
14 private Point MouseLocation = new Point(0, 0);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
15 private VBoxEventListener EventListener = new VBoxEventListener();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
16 private VBoxKeyboardHelper Keyboard;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
17 private Size RequestedClientSize = new Size(0, 0);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
18 private IProgress WaitingForProgress = null;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
19 private Boolean InitialPaused = true;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
20
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
21 public Display(IConsole console, Framebuffer fb) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
22 VMConsole = console;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
23 Framebuffer = fb;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
24 Keyboard = new VBoxKeyboardHelper(VMConsole.Keyboard);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
25 InitializeComponent();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
26 Framebuffer.BufferChanged += Framebuffer_BufferChanged;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
27 Framebuffer.Update += Framebuffer_Update;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
28 DisplayBox.Image = Framebuffer.Bitmap;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
29 EventListener.HandleEvent += EventListener_HandleEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
30 EventListener.RegisterSource(VMConsole.EventSource, VBoxEventType.VBoxEventType_Any);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
31 this.MouseWheel += Display_MouseEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
32 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
33
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
34 private void Display_Load(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
35 ClientSize = RequestedClientSize = new Size(800, 600);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
36 if (ProgramRun.VBoxXPCOM != null) COMEventTimer.Enabled = true;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
37 Framebuffer.WinId = Handle.ToInt64();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
38 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
39
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
40 private void EventListener_HandleEvent(Object sender, VBoxEventArgs ea) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
41 IEvent aEvent = ea.Event;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
42 switch (aEvent.Type) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
43 case VBoxEventType.VBoxEventType_OnCanShowWindow: {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
44 ICanShowWindowEvent e = (ICanShowWindowEvent)aEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
45 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
46 case VBoxEventType.VBoxEventType_OnEventSourceChanged:
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
47 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
48 case VBoxEventType.VBoxEventType_OnStateChanged: {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
49 IStateChangedEvent e = (IStateChangedEvent)aEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
50 Console.WriteLine("New state: {0}", e.State);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
51 switch (e.State) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
52 case MachineState.MachineState_Paused:
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
53 if (InitialPaused) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
54 InitialPaused = false;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
55 ThreadPool.QueueUserWorkItem(delegate(Object state) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
56 VMConsole.Resume();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
57 });
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
58 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
59 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
60 case MachineState.MachineState_Running:
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
61 ThreadPool.QueueUserWorkItem(delegate(Object state) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
62 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
63 if (VMConsole.Mouse.AbsoluteSupported == 0 && VMConsole.Mouse.RelativeSupported != 0) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
64 Console.WriteLine("Reset mouse position to {0}", MouseLocation);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
65 //MouseLocation = new Point(0, 0);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
66 VMConsole.Mouse.PutMouseEvent(-(int)Framebuffer.Width, -(int)Framebuffer.Height, 0, 0, 0);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
67 VMConsole.Mouse.PutMouseEvent(MouseLocation.X, MouseLocation.Y, 0, 0, 0);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
68 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
69 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
70 Console.WriteLine(ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
71 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
72 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
73 VMConsole.Display.InvalidateAndUpdate();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
74 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
75 Console.WriteLine(ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
76 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
77 });
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
78 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
79 case MachineState.MachineState_Aborted:
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
80 case MachineState.MachineState_PoweredOff:
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
81 case MachineState.MachineState_Saved:
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
82 if (IsHandleCreated) Invoke((MethodInvoker)delegate() { Close(); });
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
83 break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
84 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
85 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
86 case VBoxEventType.VBoxEventType_OnShowWindow: {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
87 IShowWindowEvent e = (IShowWindowEvent)aEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
88 e.WinId = Handle.ToInt64();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
89 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
90 case VBoxEventType.VBoxEventType_OnKeyboardLedsChanged: {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
91 IKeyboardLedsChangedEvent e = (IKeyboardLedsChangedEvent)aEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
92 Console.WriteLine("Keyboard leds: Numlock={0} Capslock={1} Scrolllock={2}", e.NumLock, e.CapsLock, e.ScrollLock);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
93 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
94 case VBoxEventType.VBoxEventType_OnMouseCapabilityChanged: {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
95 IMouseCapabilityChangedEvent e = (IMouseCapabilityChangedEvent)aEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
96 Console.WriteLine("MouseCapabilityChanged NeedsHostCursor={0} SupportsAbsolute={1} SupportsRelative={2}", e.NeedsHostCursor, e.SupportsAbsolute, e.SupportsRelative);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
97 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
98 case VBoxEventType.VBoxEventType_OnMousePointerShapeChanged: {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
99 IMousePointerShapeChangedEvent e = (IMousePointerShapeChangedEvent)aEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
100 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
101 case VBoxEventType.VBoxEventType_OnAdditionsStateChanged: {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
102 IAdditionsStateChangedEvent e = (IAdditionsStateChangedEvent)aEvent;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
103 } break;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
104 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
105 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
106
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
107 private void COMEventTimer_Tick(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
108 ProgramRun.VBoxXPCOM.EventQueue.ProcessPendingEvents();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
109 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
110
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
111 private void Display_Resize(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
112 if (RequestedClientSize.Equals(ClientSize)) return;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
113 if (VMConsole.State != MachineState.MachineState_Running) return;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
114 VMConsole.Display.SetVideoModeHint((uint)DisplayBox.Width, (uint)DisplayBox.Height, 0, 0);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
115 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
116
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
117 private void Framebuffer_BufferChanged(Object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
118 DisplayBox.Invoke((MethodInvoker)delegate() {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
119 Framebuffer fb = (Framebuffer)sender;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
120 DisplayBox.Image = fb.Bitmap;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
121 if (fb.Width > Screen.FromControl(this).WorkingArea.Width || fb.Height > Screen.FromControl(this).WorkingArea.Height) return;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
122 ClientSize = RequestedClientSize = new Size((int)fb.Width + ClientSize.Width - DisplayBox.Width, (int)fb.Height + ClientSize.Height - DisplayBox.Height);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
123 });
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
124 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
125
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
126 private void Framebuffer_Update(Object sender, FramebufferUpdateEventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
127 DisplayBox.Invoke((MethodInvoker)delegate() {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
128 DisplayBox.Invalidate(e.Rectangle);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
129 });
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
130 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
131
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
132 private void Display_MouseEvent(object sender, MouseEventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
133 IMouse mouse = VMConsole.Mouse;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
134 MouseButtonState mbs = (MouseButtonState)0;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
135 if ((e.Button & MouseButtons.Left) == MouseButtons.Left) mbs |= MouseButtonState.MouseButtonState_LeftButton;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
136 if ((e.Button & MouseButtons.Right) == MouseButtons.Right) mbs |= MouseButtonState.MouseButtonState_RightButton;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
137 if ((e.Button & MouseButtons.Middle) == MouseButtons.Middle) mbs |= MouseButtonState.MouseButtonState_MiddleButton;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
138 if ((e.Button & MouseButtons.XButton1) == MouseButtons.XButton1) mbs |= MouseButtonState.MouseButtonState_XButton1;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
139 if ((e.Button & MouseButtons.XButton2) == MouseButtons.XButton2) mbs |= MouseButtonState.MouseButtonState_XButton2;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
140 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
141 //Console.WriteLine("Mouse {0} Scroll {1} Buttons {2}", e.Location, e.Delta, mbs);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
142 if (mouse.AbsoluteSupported != 0) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
143 mouse.PutMouseEventAbsolute(e.X + 1, e.Y + 1, -e.Delta / 120, 0, (int)mbs);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
144 } else if (mouse.RelativeSupported != 0) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
145 mouse.PutMouseEvent(e.X - MouseLocation.X, e.Y - MouseLocation.Y, -e.Delta / 120, 0, (int)mbs);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
146 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
147 MouseLocation = e.Location;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
148 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
149 Console.WriteLine("MouseEventHandler Exception: {0}", ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
150 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
151 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
152
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
153 private void Display_KeyDown(object sender, KeyEventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
154 Keyboard.SendKeyCode(e.KeyCode, true);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
155 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
156
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
157 private void Display_KeyUp(object sender, KeyEventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
158 Keyboard.SendKeyCode(e.KeyCode, false);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
159 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
160
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
161 private void pauseToolStripMenuItem_Click(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
162 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
163 VMConsole.Pause();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
164 statusLabel.Text = "Paused";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
165 statusLabel.Visible = true;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
166 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
167 MessageBox.Show(ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
168 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
169 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
170
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
171 private void resumeToolStripMenuItem_Click(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
172 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
173 VMConsole.Resume();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
174 if (statusLabel.Text == "Paused") statusLabel.Visible = false;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
175 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
176 MessageBox.Show(ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
177 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
178 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
179
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
180 private void savestateToolStripMenuItem_Click(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
181 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
182 MonitorUntilCompleted(VMConsole.SaveState());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
183 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
184 MessageBox.Show(ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
185 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
186 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
187
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
188 private void aCPIPowerButtonToolStripMenuItem_Click(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
189 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
190 VMConsole.PowerButton();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
191 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
192 MessageBox.Show(ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
193 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
194 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
195
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
196 private void powerdownToolStripMenuItem_Click(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
197 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
198 MonitorUntilCompleted(VMConsole.PowerDown());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
199 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
200 MessageBox.Show(ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
201 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
202 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
203
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
204 private void resetToolStripMenuItem_Click(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
205 try {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
206 VMConsole.Reset();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
207 } catch (Exception ex) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
208 MessageBox.Show(ex.ToString());
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
209 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
210 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
211
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
212 public void MonitorUntilCompleted(IProgress p) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
213 WaitingForProgress = p;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
214 statusLabel.Visible = true;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
215 statusLabel.Text = "Busy...";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
216 ProgressWatcher.Enabled = true;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
217 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
218
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
219 private void ProgressWatcher_Tick(object sender, EventArgs e) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
220 IProgress p = WaitingForProgress;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
221 if (p == null) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
222 ProgressWatcher.Enabled = false;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
223 statusLabel.Visible = false;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
224 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
225 if (p.Canceled == 0 && p.Completed == 0) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
226 statusLabel.Text = "Busy " + p.Percent + "%...";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
227 } else if (p.Canceled != 0) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
228 WaitingForProgress = null;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
229 statusLabel.Text = "Operation aborted";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
230 } else if (p.Completed != 0) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
231 WaitingForProgress = null;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
232 if (p.ErrorInfo == null || p.ErrorInfo.ResultCode == 0) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
233 statusLabel.Text = "Operation completed";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
234 } else {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
235 statusLabel.Text = "Operation failed";
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
236 MessageBox.Show(p.ErrorInfo.Text, "Operation failed");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
237 if (p.Cancelable != 0) p.Cancel();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
238 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
239 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
240 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
241 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
242 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
243 }