2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* 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.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2013-11-14 13:16:35 +01:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Dialogs;
|
2019-10-27 16:52:15 +01:00
|
|
|
|
using XenAdmin.Network;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class MultipleDvdIsoList : UserControl
|
|
|
|
|
{
|
|
|
|
|
bool inRefresh = false;
|
|
|
|
|
|
|
|
|
|
public MultipleDvdIsoList()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 14:13:50 +02:00
|
|
|
|
private VM vm;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public VM VM
|
|
|
|
|
{
|
2013-11-14 13:16:35 +01:00
|
|
|
|
set
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-11-14 13:16:35 +01:00
|
|
|
|
DeregisterEvents();
|
2021-05-19 14:13:50 +02:00
|
|
|
|
cdChanger1.VM = value;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
vm = value;
|
|
|
|
|
if (vm != null)
|
2021-05-19 14:13:50 +02:00
|
|
|
|
vm.PropertyChanged += vm_PropertyChanged;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
refreshDrives();
|
|
|
|
|
}
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-05-19 14:13:50 +02:00
|
|
|
|
return cdChanger1.VM;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 09:55:28 +02:00
|
|
|
|
#region Designer browsable properties
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Category("Appearance")]
|
|
|
|
|
public Color LabelSingleDvdForeColor
|
|
|
|
|
{
|
|
|
|
|
get { return labelSingleDvd.ForeColor; }
|
|
|
|
|
set { labelSingleDvd.ForeColor = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Category("Appearance")]
|
|
|
|
|
public Color LabelNewCdForeColor
|
|
|
|
|
{
|
|
|
|
|
get { return newCDLabel.ForeColor; }
|
|
|
|
|
set { newCDLabel.ForeColor = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Category("Appearance")]
|
|
|
|
|
public Color LinkLabelLinkColor
|
|
|
|
|
{
|
|
|
|
|
get { return linkLabel1.LinkColor; }
|
|
|
|
|
set { linkLabel1.LinkColor = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2017-01-31 15:35:59 +01:00
|
|
|
|
internal virtual void DeregisterEvents()
|
2013-11-14 13:16:35 +01:00
|
|
|
|
{
|
|
|
|
|
if (vm == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// remove VM listeners
|
|
|
|
|
vm.PropertyChanged -= vm_PropertyChanged;
|
|
|
|
|
|
|
|
|
|
// remove cache listener
|
|
|
|
|
vm.Connection.CachePopulated -= CachePopulatedMethod;
|
|
|
|
|
|
|
|
|
|
// remove VBD listeners
|
|
|
|
|
var vbds = vm.Connection.ResolveAll(VM.VBDs);
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
foreach (var vbd in vbds.Where(vbd => vbd.IsCDROM() || vbd.IsFloppyDrive()))
|
2013-11-14 13:16:35 +01:00
|
|
|
|
{
|
|
|
|
|
vbd.PropertyChanged -= vbd_PropertyChanged;
|
|
|
|
|
}
|
2017-01-31 15:35:59 +01:00
|
|
|
|
cdChanger1.DeregisterEvents();
|
2013-11-14 13:16:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
void vm_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.PropertyName == "VBDs")
|
|
|
|
|
refreshDrives();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void refreshDrives()
|
|
|
|
|
{
|
|
|
|
|
VbdCombiItem prevSelection = comboBoxDrive.SelectedItem as VbdCombiItem;
|
|
|
|
|
inRefresh = true;
|
|
|
|
|
|
|
|
|
|
foreach (object o in comboBoxDrive.Items)
|
|
|
|
|
{
|
|
|
|
|
VbdCombiItem v = o as VbdCombiItem;
|
|
|
|
|
v.vbd.PropertyChanged -= new PropertyChangedEventHandler(vbd_PropertyChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comboBoxDrive.Items.Clear();
|
2016-07-05 09:14:13 +02:00
|
|
|
|
if (VM != null && !VM.is_control_domain)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
List<VBD> vbds = VM.Connection.ResolveAll(VM.VBDs);
|
|
|
|
|
if (vbds == null)
|
|
|
|
|
{
|
|
|
|
|
// let's come back when the cache is populated
|
2019-10-27 16:52:15 +01:00
|
|
|
|
VM.Connection.CachePopulated += CachePopulatedMethod;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
vbds.RemoveAll(vbd => !vbd.IsCDROM() && !vbd.IsFloppyDrive());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
vbds.Sort();
|
|
|
|
|
int dvdCount = 0;
|
|
|
|
|
int floppyCount = 0;
|
|
|
|
|
foreach (VBD vbd in vbds)
|
|
|
|
|
{
|
|
|
|
|
vbd.PropertyChanged +=new PropertyChangedEventHandler(vbd_PropertyChanged);
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (vbd.IsCDROM())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
dvdCount++;
|
|
|
|
|
VbdCombiItem i = new VbdCombiItem();
|
|
|
|
|
i.name = string.Format(Messages.DVD_DRIVE_LABEL_NUMBERED, dvdCount);
|
|
|
|
|
i.vbd = vbd;
|
|
|
|
|
comboBoxDrive.Items.Add(i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
floppyCount++;
|
|
|
|
|
VbdCombiItem i = new VbdCombiItem();
|
|
|
|
|
i.name = string.Format(Messages.FLOPPY_DRIVE_LABEL_NUMBERED, floppyCount);
|
|
|
|
|
i.vbd = vbd;
|
|
|
|
|
comboBoxDrive.Items.Add(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxDrive.Items.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
comboBoxDrive.Visible = false;
|
|
|
|
|
cdChanger1.Visible = false;
|
|
|
|
|
labelSingleDvd.Visible = false;
|
|
|
|
|
linkLabel1.Visible = false;
|
|
|
|
|
panel1.Visible = false;
|
|
|
|
|
newCDLabel.Visible = vm != null && !vm.is_control_domain;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (comboBoxDrive.Items.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
comboBoxDrive.Visible = false;
|
|
|
|
|
cdChanger1.Visible = true;
|
|
|
|
|
labelSingleDvd.Text = comboBoxDrive.Items[0].ToString();
|
|
|
|
|
labelSingleDvd.Visible = true;
|
|
|
|
|
tableLayoutPanel1.ColumnStyles[0].Width = labelSingleDvd.Width;
|
|
|
|
|
newCDLabel.Visible = false;
|
|
|
|
|
panel1.Visible = true;
|
|
|
|
|
linkLabel1.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
comboBoxDrive.Visible = true;
|
|
|
|
|
cdChanger1.Visible = true;
|
|
|
|
|
labelSingleDvd.Visible = false;
|
|
|
|
|
panel1.Visible = true;
|
|
|
|
|
newCDLabel.Visible = false;
|
|
|
|
|
linkLabel1.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
inRefresh = false;
|
|
|
|
|
// Restore prev selection or select the top item by default
|
|
|
|
|
if (prevSelection != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (object o in comboBoxDrive.Items)
|
|
|
|
|
{
|
|
|
|
|
VbdCombiItem v = o as VbdCombiItem;
|
|
|
|
|
if (v.vbd.uuid == prevSelection.vbd.uuid)
|
|
|
|
|
{
|
|
|
|
|
comboBoxDrive.SelectedItem = o;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxDrive.Items.Count == 0)
|
|
|
|
|
comboBoxDrive.SelectedItem = null;
|
|
|
|
|
else
|
|
|
|
|
comboBoxDrive.SelectedItem = comboBoxDrive.Items[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vbd_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
refreshDrives();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-27 16:52:15 +01:00
|
|
|
|
private void CachePopulatedMethod(IXenConnection conn)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
VM.Connection.CachePopulated -= CachePopulatedMethod;
|
|
|
|
|
refreshDrives();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class VbdCombiItem
|
|
|
|
|
{
|
|
|
|
|
public string name;
|
|
|
|
|
public VBD vbd;
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboBoxDrive_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (inRefresh)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-05-19 14:13:50 +02:00
|
|
|
|
cdChanger1.Drive = (comboBoxDrive.SelectedItem as VbdCombiItem)?.vbd;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void newCDLabel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (VM != null)
|
|
|
|
|
{
|
2019-08-16 17:03:09 +02:00
|
|
|
|
var createDriveAction = new CreateCdDriveAction(VM);
|
|
|
|
|
createDriveAction.ShowUserInstruction += CreateDriveAction_ShowUserInstruction;
|
|
|
|
|
|
2016-06-20 14:17:42 +02:00
|
|
|
|
using (var dlg = new ActionProgressDialog(createDriveAction, ProgressBarStyle.Marquee))
|
|
|
|
|
dlg.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-16 17:03:09 +02:00
|
|
|
|
private void CreateDriveAction_ShowUserInstruction(string message)
|
|
|
|
|
{
|
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
|
|
|
|
{
|
|
|
|
|
if (!Program.RunInAutomatedTestMode)
|
|
|
|
|
{
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new InformationDialog(message))
|
2019-08-16 17:03:09 +02:00
|
|
|
|
dlg.ShowDialog(Program.MainWindow);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (cdChanger1.Drive != null)
|
|
|
|
|
cdChanger1.ChangeCD(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|