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.Windows.Forms;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Network;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Dialogs
|
|
|
|
|
{
|
|
|
|
|
public partial class NewDiskDialog : XenDialogBase
|
|
|
|
|
{
|
2019-01-13 01:39:12 +01:00
|
|
|
|
private enum DiskSizeUnits { MB, GB }
|
|
|
|
|
|
|
|
|
|
#region Private fields
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private readonly VM TheVM;
|
|
|
|
|
private readonly SR TheSR;
|
|
|
|
|
|
|
|
|
|
private VDI DiskTemplate;
|
|
|
|
|
private bool CanResize;
|
|
|
|
|
private long MinSize;
|
|
|
|
|
private decimal min;
|
|
|
|
|
private decimal max;
|
|
|
|
|
|
|
|
|
|
private bool SelectionNull = true;
|
|
|
|
|
private readonly IEnumerable<VDI> _VDINamesInUse = new List<VDI>();
|
|
|
|
|
|
2019-01-13 01:39:12 +01:00
|
|
|
|
private const int DecimalPlacesGB = 3; // show 3 decimal places for GB (CA-91322)
|
|
|
|
|
private const int DecimalPlacesMB = 0;
|
|
|
|
|
private const int IncrementGB = 1;
|
|
|
|
|
private const int IncrementMB = 256;
|
|
|
|
|
|
|
|
|
|
private const decimal MinimumDiskSizeGB = 0.001m;
|
|
|
|
|
private const int MinimumDiskSizeMB = 1;
|
|
|
|
|
private DiskSizeUnits currentSelectedUnits = DiskSizeUnits.GB;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private NewDiskDialog(IXenConnection connection, IEnumerable<VDI> vdiNamesInUse)
|
|
|
|
|
: base(connection)
|
|
|
|
|
{
|
2019-01-13 01:39:12 +01:00
|
|
|
|
if (connection == null)
|
|
|
|
|
throw new ArgumentNullException("connection");
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2019-01-13 01:39:12 +01:00
|
|
|
|
_VDINamesInUse = vdiNamesInUse;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
SrListBox.Connection = connection;
|
|
|
|
|
NameTextBox.Text = GetDefaultVDIName();
|
|
|
|
|
max = (decimal)Math.Pow(1024, 4);//1 Petabit
|
|
|
|
|
min = 0;
|
|
|
|
|
comboBoxUnits.SelectedItem = comboBoxUnits.Items[0];
|
2015-08-26 18:14:01 +02:00
|
|
|
|
SetNumUpDownIncrementAndDecimals(DiskSizeNumericUpDown, comboBoxUnits.SelectedItem.ToString());
|
2019-01-13 01:39:12 +01:00
|
|
|
|
updateErrorsAndButtons();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NewDiskDialog(IXenConnection connection, SR sr)
|
|
|
|
|
: this(connection, new List<VDI>())
|
|
|
|
|
{
|
|
|
|
|
TheSR = sr;
|
2019-01-13 01:39:12 +01:00
|
|
|
|
SrListBox.Usage = SrPicker.SRPickerType.InstallFromTemplate;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
SrListBox.SetAffinity(null);
|
|
|
|
|
SrListBox.selectSRorNone(TheSR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NewDiskDialog(IXenConnection connection, VM vm)
|
2019-01-13 01:39:12 +01:00
|
|
|
|
: this(connection, vm, SrPicker.SRPickerType.VM, null, vm.Home(), true, 0, new List<VDI>())
|
|
|
|
|
{ }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-01-13 01:39:12 +01:00
|
|
|
|
public NewDiskDialog(IXenConnection connection, VM vm, SrPicker.SRPickerType pickerUsage, VDI diskTemplate,
|
|
|
|
|
Host affinity, bool canResize, long minSize, IEnumerable<VDI> vdiNamesInUse)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: this(connection, vdiNamesInUse)
|
|
|
|
|
{
|
|
|
|
|
TheVM = vm;
|
|
|
|
|
DiskTemplate = diskTemplate;
|
|
|
|
|
CanResize = canResize;
|
|
|
|
|
MinSize = minSize;
|
2019-01-13 01:39:12 +01:00
|
|
|
|
SrListBox.Usage = pickerUsage;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
SrListBox.SetAffinity(affinity);
|
|
|
|
|
|
|
|
|
|
Pool pool_sr = Helpers.GetPoolOfOne(connection);
|
|
|
|
|
if (pool_sr != null)
|
|
|
|
|
{
|
|
|
|
|
SrListBox.DefaultSR = connection.Resolve(pool_sr.default_SR); //if default sr resolves to null the first sr in the list will be selected
|
|
|
|
|
}
|
|
|
|
|
SrListBox.selectDefaultSROrAny();
|
|
|
|
|
|
|
|
|
|
LoadValues();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-13 01:39:12 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void LoadValues()
|
|
|
|
|
{
|
|
|
|
|
if (DiskTemplate == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
NameTextBox.Text = DiskTemplate.Name();
|
|
|
|
|
DescriptionTextBox.Text = DiskTemplate.Description();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
SrListBox.selectSRorDefaultorAny(connection.Resolve(DiskTemplate.SR));
|
|
|
|
|
|
|
|
|
|
// select the appropriate unit, based on size (CA-45905)
|
|
|
|
|
currentSelectedUnits = DiskTemplate.virtual_size >= Util.BINARY_GIGA ? DiskSizeUnits.GB : DiskSizeUnits.MB;
|
|
|
|
|
SelectedUnits = currentSelectedUnits;
|
2015-08-27 11:23:09 +02:00
|
|
|
|
SetNumUpDownIncrementAndDecimals(DiskSizeNumericUpDown, SelectedUnits.ToString());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
decimal newValue = (decimal)Math.Round((double)DiskTemplate.virtual_size / GetUnits(), DiskSizeNumericUpDown.DecimalPlaces);
|
|
|
|
|
DiskSizeNumericUpDown.Value = newValue >= DiskSizeNumericUpDown.Minimum && newValue <= DiskSizeNumericUpDown.Maximum ?
|
|
|
|
|
newValue : DiskSizeNumericUpDown.Maximum;
|
|
|
|
|
|
|
|
|
|
if (MinSize > 0)
|
|
|
|
|
min = (decimal)((double)MinSize / GetUnits());
|
|
|
|
|
DiskSizeNumericUpDown.Enabled = CanResize;
|
|
|
|
|
|
|
|
|
|
Text = Messages.EDIT_DISK;
|
|
|
|
|
OkButton.Text = Messages.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetDefaultVDIName()
|
|
|
|
|
{
|
|
|
|
|
List<string> usedNames = new List<string>();
|
|
|
|
|
foreach (VDI v in connection.Cache.VDIs.Concat(_VDINamesInUse))
|
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
usedNames.Add(v.Name());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
return Helpers.MakeUniqueName(Messages.DEFAULT_VDI_NAME, usedNames);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 16:35:11 +02:00
|
|
|
|
private void SrListBox_SrSelectionChanged(object obj)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-10-08 16:35:11 +02:00
|
|
|
|
SelectionNull = obj == null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-13 01:39:12 +01:00
|
|
|
|
private void srListBox_SelectedIndexChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
updateErrorsAndButtons();
|
2015-06-18 16:03:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void OkButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SrListBox.SR == null || SelectionNull || NameTextBox.Text == "" || !connection.IsConnected)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (DontCreateVDI)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
XenAPI.SR sr = SrListBox.SR;
|
|
|
|
|
if (!sr.shared && TheVM != null && TheVM.HaPriorityIsRestart())
|
|
|
|
|
{
|
2016-06-20 11:49:12 +02:00
|
|
|
|
DialogResult dialogResult;
|
|
|
|
|
using (var dlg = new ThreeButtonDialog(
|
2013-06-24 13:41:48 +02:00
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.NEW_SR_DIALOG_ATTACH_NON_SHARED_DISK_HA, Messages.XENCENTER),
|
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
2016-06-20 11:49:12 +02:00
|
|
|
|
ThreeButtonDialog.ButtonNo))
|
|
|
|
|
{
|
|
|
|
|
dialogResult = dlg.ShowDialog(Program.MainWindow);
|
|
|
|
|
}
|
|
|
|
|
if (dialogResult != DialogResult.Yes)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
new HAUnprotectVMAction(TheVM).RunExternal(TheVM.Connection.Session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VDI vdi = NewDisk();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (TheVM != null)
|
|
|
|
|
{
|
|
|
|
|
var alreadyHasBootableDisk = HasBootableDisk(TheVM);
|
|
|
|
|
|
|
|
|
|
Actions.DelegatedAsyncAction action = new Actions.DelegatedAsyncAction(connection,
|
2017-09-03 04:33:29 +02:00
|
|
|
|
string.Format(Messages.ACTION_DISK_ADDING_TITLE, NameTextBox.Text, sr.NameWithoutHost()),
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Messages.ACTION_DISK_ADDING, Messages.ACTION_DISK_ADDED,
|
|
|
|
|
delegate(XenAPI.Session session)
|
|
|
|
|
{
|
|
|
|
|
// Get legitimate unused userdevice numbers
|
|
|
|
|
string[] uds = XenAPI.VM.get_allowed_VBD_devices(session, TheVM.opaque_ref);
|
|
|
|
|
if (uds.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(FriendlyErrorNames.VBDS_MAX_ALLOWED);
|
|
|
|
|
}
|
|
|
|
|
string ud = uds[0];
|
|
|
|
|
string vdiref = VDI.create(session, vdi);
|
|
|
|
|
XenAPI.VBD vbd = NewDevice();
|
|
|
|
|
vbd.VDI = new XenAPI.XenRef<XenAPI.VDI>(vdiref);
|
|
|
|
|
vbd.VM = new XenAPI.XenRef<XenAPI.VM>(TheVM);
|
|
|
|
|
|
|
|
|
|
// CA-44959: only make bootable if there aren't other bootable VBDs.
|
|
|
|
|
vbd.bootable = ud == "0" && !alreadyHasBootableDisk;
|
|
|
|
|
vbd.userdevice = ud;
|
|
|
|
|
|
|
|
|
|
// Now try to plug the VBD.
|
2017-09-03 04:33:29 +02:00
|
|
|
|
new XenAdmin.Actions.VbdSaveAndPlugAction(TheVM, vbd, vdi.Name(), session, false, ShowMustRebootBoxCD, ShowVBDWarningBox).RunAsync();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
});
|
|
|
|
|
action.VM = TheVM;
|
|
|
|
|
new Dialogs.ActionProgressDialog(action, ProgressBarStyle.Blocks).ShowDialog();
|
|
|
|
|
if (!action.Succeeded)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CreateDiskAction action = new CreateDiskAction(vdi);
|
|
|
|
|
new Dialogs.ActionProgressDialog(action, ProgressBarStyle.Marquee).ShowDialog();
|
|
|
|
|
if (!action.Succeeded)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool HasBootableDisk(VM vm)
|
|
|
|
|
{
|
|
|
|
|
var c = vm.Connection;
|
|
|
|
|
foreach (XenRef<VBD> vbdRef in vm.VBDs)
|
|
|
|
|
{
|
|
|
|
|
var vbd = c.Resolve(vbdRef);
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (vbd != null && !vbd.IsCDROM() && !vbd.IsFloppyDrive() && vbd.bootable)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
VDI vdi = c.Resolve(vbd.VDI);
|
|
|
|
|
|
|
|
|
|
if (vdi != null)
|
|
|
|
|
{
|
|
|
|
|
SR sr = c.Resolve(vdi.SR);
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (sr != null && sr.IsToolsSR())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 18:14:01 +02:00
|
|
|
|
private void SetNumUpDownIncrementAndDecimals(NumericUpDown upDown, string units)
|
|
|
|
|
{
|
2015-08-27 11:23:09 +02:00
|
|
|
|
if (units == Messages.VAL_GIGB)
|
2015-08-26 18:14:01 +02:00
|
|
|
|
{
|
|
|
|
|
upDown.DecimalPlaces = DecimalPlacesGB;
|
|
|
|
|
upDown.Increment = IncrementGB;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
upDown.DecimalPlaces = DecimalPlacesMB;
|
|
|
|
|
upDown.Increment = IncrementMB;
|
2015-06-17 10:59:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public VDI NewDisk()
|
|
|
|
|
{
|
|
|
|
|
VDI vdi = new VDI();
|
|
|
|
|
vdi.Connection = connection;
|
|
|
|
|
vdi.read_only = DiskTemplate != null ? DiskTemplate.read_only : false;
|
|
|
|
|
vdi.SR = new XenAPI.XenRef<XenAPI.SR>(SrListBox.SR);
|
2015-06-17 10:59:21 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
vdi.virtual_size = Convert.ToInt64(DiskSizeNumericUpDown.Value * GetUnits());
|
|
|
|
|
vdi.name_label = NameTextBox.Text;
|
|
|
|
|
vdi.name_description = DescriptionTextBox.Text;
|
|
|
|
|
vdi.sharable = DiskTemplate != null ? DiskTemplate.sharable : false;
|
|
|
|
|
vdi.type = DiskTemplate != null ? DiskTemplate.type : vdi_type.user;
|
2017-09-05 03:15:38 +02:00
|
|
|
|
vdi.SetVmHint(TheVM != null ? TheVM.uuid : "");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return vdi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private long GetUnits()
|
|
|
|
|
{
|
|
|
|
|
return (SelectedUnits == DiskSizeUnits.GB ? Util.BINARY_GIGA : Util.BINARY_MEGA);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VBD NewDevice()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
VBD vbd = new VBD();
|
|
|
|
|
vbd.Connection = connection;
|
|
|
|
|
vbd.device = "";
|
|
|
|
|
vbd.empty = false;
|
|
|
|
|
vbd.type = XenAPI.vbd_type.Disk;
|
|
|
|
|
vbd.mode = XenAPI.vbd_mode.RW;
|
2017-09-05 03:15:38 +02:00
|
|
|
|
vbd.SetIsOwner(true);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
vbd.unpluggable = true;
|
|
|
|
|
return vbd;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NameTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
updateErrorsAndButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DiskSizeUnits SelectedUnits
|
|
|
|
|
{
|
|
|
|
|
get { return comboBoxUnits.SelectedIndex == 0 ? DiskSizeUnits.GB : DiskSizeUnits.MB; }
|
|
|
|
|
set { comboBoxUnits.SelectedIndex = value == DiskSizeUnits.GB ? 0 : 1; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private decimal GetDiskTooSmallMessageMinSize()
|
|
|
|
|
{
|
|
|
|
|
return min == 0 ? SelectedUnits == DiskSizeUnits.GB ? MinimumDiskSizeGB : MinimumDiskSizeMB : min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateErrorsAndButtons()
|
|
|
|
|
{
|
|
|
|
|
// Ordering is important here, we want to show the most relevant message
|
|
|
|
|
|
2015-06-18 16:03:25 +02:00
|
|
|
|
if (comboBoxUnits.SelectedItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (!SrListBox.ValidSelectionExists)
|
|
|
|
|
{
|
|
|
|
|
OkButton.Enabled = false;
|
|
|
|
|
setError(Messages.NO_VALID_DISK_LOCATION);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (SelectionNull)
|
|
|
|
|
{
|
|
|
|
|
OkButton.Enabled = false;
|
|
|
|
|
// shouldn't happen I think, previous if block should catch this, just to be safe
|
|
|
|
|
setError(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (DiskSizeNumericUpDown.Text.Trim() == string.Empty)
|
|
|
|
|
{
|
|
|
|
|
OkButton.Enabled = false;
|
|
|
|
|
// too minor for scary error to be displayed, plus it's obvious as they have to
|
|
|
|
|
// delete the default entry and can see the OK button disable as they do so
|
|
|
|
|
setError(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!DiskSizeValidNumber())
|
|
|
|
|
{
|
|
|
|
|
OkButton.Enabled = false;
|
|
|
|
|
setError(Messages.INVALID_NUMBER);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!DiskSizeValid())
|
|
|
|
|
{
|
|
|
|
|
OkButton.Enabled = false;
|
|
|
|
|
setError(string.Format(Messages.DISK_TOO_SMALL, GetDiskTooSmallMessageMinSize(),
|
|
|
|
|
comboBoxUnits.SelectedItem.ToString()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(NameTextBox.Text.Trim()))
|
|
|
|
|
{
|
|
|
|
|
OkButton.Enabled = false;
|
|
|
|
|
// too minor for scary error to be displayed, plus it's obvious as they have to
|
|
|
|
|
// delete the default entry and can see the OK button disable as they do so
|
|
|
|
|
setError(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OkButton.Enabled = true;
|
|
|
|
|
setError(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setError(string error)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(error))
|
2018-10-09 12:03:36 +02:00
|
|
|
|
tableLayoutPanelError.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-09 12:03:36 +02:00
|
|
|
|
tableLayoutPanelError.Visible = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
labelError.Text = error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool DiskSizeValidNumber()
|
|
|
|
|
{
|
|
|
|
|
decimal val;
|
|
|
|
|
return decimal.TryParse(DiskSizeNumericUpDown.Text.Trim(), out val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool DiskSizeValid()
|
|
|
|
|
{
|
|
|
|
|
decimal val;
|
|
|
|
|
if (decimal.TryParse(DiskSizeNumericUpDown.Text.Trim(), out val))
|
|
|
|
|
{
|
|
|
|
|
if (min == 0)
|
|
|
|
|
return val > min && val <= max;
|
|
|
|
|
return val >= min && val <= max;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CloseButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-13 01:39:12 +01:00
|
|
|
|
public bool DontCreateVDI { get; set; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
private void DiskSizeNumericUpDown_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateDiskSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DiskSizeNumericUpDown_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateDiskSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DiskSizeNumericUpDown_KeyUp(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateDiskSize();
|
|
|
|
|
}
|
2018-03-21 11:21:21 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void UpdateDiskSize()
|
|
|
|
|
{
|
|
|
|
|
// Don't use DiskSizeNumericUpDown.Value here, as it will fire the NumericUpDown built-in validation. Use Text property instead. (CA-46028)
|
|
|
|
|
decimal newValue;
|
|
|
|
|
if (decimal.TryParse(DiskSizeNumericUpDown.Text.Trim(), out newValue))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-06-25 12:46:31 +02:00
|
|
|
|
SrListBox.DiskSize = (long)(Math.Round(newValue * GetUnits()));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
catch (OverflowException)
|
|
|
|
|
{
|
|
|
|
|
//CA-71312
|
|
|
|
|
SrListBox.DiskSize = newValue < 0 ? long.MinValue : long.MaxValue;
|
|
|
|
|
}
|
2015-09-18 17:33:25 +02:00
|
|
|
|
SrListBox.UpdateDiskSize();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
RefreshMinSize();
|
|
|
|
|
updateErrorsAndButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshMinSize()
|
|
|
|
|
{
|
|
|
|
|
if (DiskTemplate == null)
|
|
|
|
|
return;
|
|
|
|
|
if (MinSize > 0)
|
|
|
|
|
min = (decimal)((double)MinSize / GetUnits());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboBoxUnits_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Check if the new unit is different than the previous one otherwise discard the change
|
|
|
|
|
if (currentSelectedUnits != SelectedUnits)
|
|
|
|
|
{
|
|
|
|
|
currentSelectedUnits = SelectedUnits;
|
|
|
|
|
//Convert the current value to the new units
|
|
|
|
|
decimal newValue = (decimal)Math.Round(SelectedUnits == DiskSizeUnits.GB ? ((double)DiskSizeNumericUpDown.Value / 1024) : ((double)DiskSizeNumericUpDown.Value * 1024), DiskSizeNumericUpDown.DecimalPlaces);
|
|
|
|
|
DiskSizeNumericUpDown.Value = newValue >= DiskSizeNumericUpDown.Minimum && newValue <= DiskSizeNumericUpDown.Maximum ?
|
|
|
|
|
newValue : DiskSizeNumericUpDown.Maximum;
|
2015-08-26 18:14:01 +02:00
|
|
|
|
SetNumUpDownIncrementAndDecimals(DiskSizeNumericUpDown, comboBoxUnits.SelectedItem.ToString());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
UpdateDiskSize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal override string HelpName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (DiskTemplate != null)
|
|
|
|
|
return "EditNewDiskDialog";
|
|
|
|
|
else
|
|
|
|
|
return "NewDiskDialog";
|
|
|
|
|
}
|
2015-08-26 18:14:01 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public static void ShowVBDWarningBox()
|
|
|
|
|
{
|
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
|
|
|
|
{
|
|
|
|
|
if (!Program.RunInAutomatedTestMode)
|
|
|
|
|
{
|
2016-06-20 11:49:12 +02:00
|
|
|
|
using (var dlg = new ThreeButtonDialog(
|
2013-06-24 13:41:48 +02:00
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Information,
|
2016-06-20 11:49:12 +02:00
|
|
|
|
Messages.NEWDISKWIZARD_MESSAGE,
|
|
|
|
|
Messages.NEWDISKWIZARD_MESSAGE_TITLE)))
|
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog(Program.MainWindow);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ShowMustRebootBoxCD()
|
|
|
|
|
{
|
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
|
|
|
|
{
|
|
|
|
|
if (!Program.RunInAutomatedTestMode)
|
|
|
|
|
{
|
|
|
|
|
new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Information,
|
|
|
|
|
Messages.
|
|
|
|
|
NEW_DVD_DRIVE_REBOOT,
|
|
|
|
|
Messages.
|
|
|
|
|
NEW_DVD_DRIVE_CREATED))
|
2015-05-18 20:25:46 +02:00
|
|
|
|
.ShowDialog(Program.MainWindow);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|