xenadmin/XenAdmin/ConsoleView/VNCView.cs
Gabor Apati-Nagy 7b7bcb0aa5 CP-14379, CP-14461, CP-14462, CP-14463, CP-14464, CP-14465, CP-14467:
Implementing Upgrading VMs to Windows Update

New screen features:
-Create skeleton of the Upgrade VM dialog
-Implement a Go To Console link (just a link that opens a vm console)
-Implement logic to show the right status for a VM (includes rules to
get the states). Includes updating the dialog whenever the status changes.
-Add status texts to Messages, proper text on the UI
-Add stub methods to VM class in XenAPI-Extensions to r/w states from
Guest Agent
-UI: Implement rules what vms to display, checkbox rules, read only vms,
and when to enable the Upgrade button
-Implement Upgrade button (writes state for GA, mounts ISO) + maximum
parallel executions/actions

Signed-off-by: Gabor Apati-Nagy <gabor.apati-nagy@citrix.com>
2015-10-16 12:47:00 +01:00

289 lines
9.6 KiB
C#

/* Copyright (c) Citrix Systems Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using XenAPI;
using XenAdmin.Core;
namespace XenAdmin.ConsoleView
{
public partial class VNCView : UserControl
{
private readonly VM source;
public readonly VNCTabView vncTabView;
public Form undockedForm = null;
public bool isDocked
{
get
{
return this.undockedForm == null || !this.undockedForm.Visible;
}
}
public bool isPaused
{
get
{
return vncTabView.isPaused;
}
}
public void Pause()
{
if (vncTabView != null && isDocked)
vncTabView.Pause();
}
public void Unpause()
{
if(vncTabView != null)
vncTabView.Unpause();
}
public VNCView(VM source, string elevatedUsername, string elevatedPassword)
{
Program.AssertOnEventThread();
this.source = source;
this.vncTabView = new VNCTabView(this, source, elevatedUsername, elevatedPassword);
InitializeComponent();
this.Dock = DockStyle.Fill;
this.Controls.Add(this.vncTabView);
}
private void UnregisterEventListeners()
{
if(source != null)
source.PropertyChanged -= new PropertyChangedEventHandler(Server_PropertyChanged);
}
private Size oldUndockedSize = Size.Empty;
private Point oldUndockedLocation = Point.Empty;
private bool oldScaledSetting = false;
public void ToogleDockUnDock()
{
if (this.isDocked)
UnDockVncView();
else
DockVncView();
}
public void DockVncView()
{
if (!this.isDocked)
{
//save location of undock vnc control
this.oldUndockedLocation = undockedForm.Location;
this.oldUndockedSize = undockedForm.Size;
if (!Properties.Settings.Default.PreserveScaleWhenUndocked)
vncTabView.scaleCheckBox.Checked = oldScaledSetting;
this.reattachConsoleButton.Hide();
this.findConsoleButton.Hide();
undockedForm.Hide();
vncTabView.showHeaderBar(true, false);
undockedForm.Controls.Remove(vncTabView);
this.Controls.Add(vncTabView);
undockedForm.Dispose();
undockedForm = null;
}
vncTabView.UpdateDockButton();
vncTabView.UpdateParentMinimumSize();
//Every time we dock / undock I'm going to force an unpause to make sure we don't ever pause a visible one.
vncTabView.Unpause();
vncTabView.focus_vnc();
}
public void UnDockVncView()
{
if (this.isDocked)
{
if (this.undockedForm == null)
{
undockedForm = new Form();
undockedForm.Text = UndockedWindowTitle(source);
source.PropertyChanged -= Server_PropertyChanged;
source.PropertyChanged += Server_PropertyChanged;
undockedForm.Icon = Program.MainWindow.Icon;
undockedForm.FormClosing += new FormClosingEventHandler(delegate(object sender, FormClosingEventArgs e)
{
this.ToogleDockUnDock();
});
undockedForm.StartPosition = FormStartPosition.CenterScreen;
undockedForm.Resize += new EventHandler(
delegate(Object o, EventArgs a)
{
if (undockedForm.WindowState == FormWindowState.Minimized)
{
vncTabView.Pause();
}
else
{
vncTabView.Unpause();
}
});
}
this.Controls.Remove(vncTabView);
undockedForm.Controls.Add(vncTabView);
oldScaledSetting = vncTabView.scaleCheckBox.Checked;
vncTabView.showHeaderBar(!source.is_control_domain, true);
undockedForm.ClientSize = vncTabView.GrowToFit();
if (oldUndockedSize != Size.Empty
&& oldUndockedLocation != Point.Empty
&& HelpersGUI.WindowIsOnScreen(oldUndockedLocation, oldUndockedSize))
{
undockedForm.Size = oldUndockedSize;
undockedForm.StartPosition = FormStartPosition.Manual;
undockedForm.Location = oldUndockedLocation;
}
undockedForm.HelpButton = true;
//undockedForm.MinimizeBox = false;
//undockedForm.MaximizeBox = false;
undockedForm.HelpButtonClicked += undockedForm_HelpButtonClicked;
undockedForm.HelpRequested += undockedForm_HelpRequested;
undockedForm.Show();
if (Properties.Settings.Default.PreserveScaleWhenUndocked)
vncTabView.scaleCheckBox.Checked = oldScaledSetting;
this.reattachConsoleButton.Show();
this.findConsoleButton.Show();
}
vncTabView.UpdateDockButton();
vncTabView.UpdateParentMinimumSize();
//Every time we dock / undock I'm going to force an unpause to make sure we don't ever pause a visible one.
vncTabView.Unpause();
vncTabView.focus_vnc();
}
private string UndockedWindowTitle(VM source)
{
if (source.is_control_domain)
{
Host host = source.Connection.Resolve(source.resident_on);
return host == null ? source.Name : string.Format(Messages.CONSOLE_HOST, host.Name);
}
else
{
return source.Name;
}
}
private void undockedForm_HelpButtonClicked(object sender, CancelEventArgs e)
{
Help.HelpManager.Launch("TabPageConsole");
e.Cancel = true;
}
private void undockedForm_HelpRequested(object sender, HelpEventArgs hlpevent)
{
Help.HelpManager.Launch("TabPageConsole");
hlpevent.Handled = true;
}
void Server_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "name_label" && undockedForm != null)
{
undockedForm.Text = source.name_label;
}
}
private void findConsoleButton_Click(object sender, EventArgs e)
{
if (!this.isDocked)
undockedForm.BringToFront();
if (undockedForm.WindowState == FormWindowState.Minimized)
undockedForm.WindowState = FormWindowState.Normal;
}
private void reattachConsoleButton_Click(object sender, EventArgs e)
{
ToogleDockUnDock();
}
internal void SendCAD()
{
if (this.vncTabView != null)
this.vncTabView.SendCAD();
}
internal void FocusConsole(bool forceFocus = false)
{
if (this.vncTabView != null)
vncTabView.focus_vnc(forceFocus);
}
internal void SwitchIfRequired()
{
vncTabView.SwitchIfRequired();
}
internal Image Snapshot()
{
return vncTabView.Snapshot();
}
public void refreshIsoList()
{
vncTabView.setupCD();
}
internal bool IsVNC
{
get { return vncTabView.IsVNC; }
}
}
}