Merge pull request #12 from kc284/vm-copy-credentials_CA-359712

Merge from master
This commit is contained in:
Danilo Del Busso 2021-12-03 10:44:42 +00:00 committed by GitHub
commit 76b20f4874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
113 changed files with 1380 additions and 1542 deletions

View File

@ -182,6 +182,9 @@
<data name="PRODUCT_VERSION_8_2" xml:space="preserve"> <data name="PRODUCT_VERSION_8_2" xml:space="preserve">
<value>8.2</value> <value>8.2</value>
</data> </data>
<data name="PRODUCT_VERSION_8_2_1" xml:space="preserve">
<value>8.2.1</value>
</data>
<data name="PRODUCT_VERSION_POST_8_2" xml:space="preserve"> <data name="PRODUCT_VERSION_POST_8_2" xml:space="preserve">
<value>[BRANDING_PRODUCT_VERSION_TEXT]</value> <value>[BRANDING_PRODUCT_VERSION_TEXT]</value>
</data> </data>

View File

@ -246,11 +246,11 @@ namespace XenAdmin.Actions
} }
// Returns a set of params which relate to the object you have selected in the treeview // Returns a set of params which relate to the object you have selected in the treeview
private List<string> RetrieveParams(IXenObject obj) private IEnumerable<string> RetrieveParams(IXenObject obj)
{ {
IXenConnection connection = obj.Connection; var connection = obj?.Connection;
Host coordinator = connection != null ? Helpers.GetCoordinator(connection) : null; // get coordinator asserts connection is not null var coordinator = connection != null ? Helpers.GetCoordinator(connection) : null; // get coordinator asserts connection is not null
string coordinatorAddress = EmptyParameter; var coordinatorAddress = EmptyParameter;
if (coordinator != null) if (coordinator != null)
{ {
@ -258,9 +258,9 @@ namespace XenAdmin.Actions
WriteTrustedCertificates(coordinator.Connection); WriteTrustedCertificates(coordinator.Connection);
} }
string sessionRef = connection.Session != null ? connection.Session.opaque_ref : EmptyParameter; var sessionRef = connection?.Session != null ? connection.Session.opaque_ref : EmptyParameter;
string objCls = obj != null ? obj.GetType().Name : EmptyParameter; var objCls = obj != null ? obj.GetType().Name : EmptyParameter;
string objUuid = obj != null && connection.Session != null ? Helpers.GetUuid(obj) : EmptyParameter; var objUuid = connection?.Session != null ? Helpers.GetUuid(obj) : EmptyParameter;
return new List<string>(new string[] { coordinatorAddress, sessionRef, objCls, objUuid }); return new List<string>(new string[] { coordinatorAddress, sessionRef, objCls, objUuid });
} }

View File

@ -55,13 +55,8 @@ namespace XenAdmin.Actions.Wlb
public WlbOptimizePoolAction(Pool pool, Dictionary<VM, WlbOptimizationRecommendation> vmOptLst, string optId) public WlbOptimizePoolAction(Pool pool, Dictionary<VM, WlbOptimizationRecommendation> vmOptLst, string optId)
: base(pool.Connection, string.Format(Messages.WLB_OPTIMIZING_POOL, Helpers.GetName(pool).Ellipsise(50))) : base(pool.Connection, string.Format(Messages.WLB_OPTIMIZING_POOL, Helpers.GetName(pool).Ellipsise(50)))
{ {
if (pool == null) Pool = pool;
throw new ArgumentNullException("pool"); vmOptList = vmOptLst ?? throw new ArgumentNullException("vmOptLst");
if (vmOptLst == null)
throw new ArgumentNullException("vmOptLst");
this.Pool = pool;
this.vmOptList = vmOptLst;
this.optId = optId; this.optId = optId;
#region RBAC Dependencies #region RBAC Dependencies

View File

@ -58,7 +58,10 @@ namespace XenAdmin.Commands
protected override void RunCore(SelectedItemCollection selection) protected override void RunCore(SelectedItemCollection selection)
{ {
Host host = selection[0].HostAncestor; var host = selection[0].HostAncestor;
if (host == null)
return;
using (var dlg = new ControlDomainMemoryDialog(host)) using (var dlg = new ControlDomainMemoryDialog(host))
dlg.ShowDialog(Program.MainWindow); dlg.ShowDialog(Program.MainWindow);
} }

View File

@ -92,23 +92,20 @@ namespace XenAdmin.Commands
protected override bool CanRunCore(SelectedItemCollection selection) protected override bool CanRunCore(SelectedItemCollection selection)
{ {
if (!selection.AllItemsAre<VM>())
{
return false;
}
IXenConnection connection = null; IXenConnection connection = null;
bool atLeastOneCanRun = false; var atLeastOneCanRun = false;
foreach (SelectedItem item in selection) foreach (var item in selection)
{ {
VM vm = (VM)item.XenObject; if (!(item.XenObject is VM vm))
return false;
// all VMs must be on the same connection // all VMs must be on the same connection
if (connection != null && vm.Connection != connection) if (connection != null && vm.Connection != connection)
{ {
return false; return false;
} }
connection = vm.Connection;
if (CanRun(item)) if (CanRun(item))
{ {

View File

@ -33,12 +33,11 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using XenAdmin.Controls;
using XenAPI;
using XenAdmin.Core;
using XenAdmin.Actions;
using XenAdmin.Actions.Wlb; using XenAdmin.Actions.Wlb;
using XenAdmin.Controls;
using XenAdmin.Core;
using XenAdmin.Network; using XenAdmin.Network;
using XenAPI;
namespace XenAdmin.Commands namespace XenAdmin.Commands
@ -112,7 +111,7 @@ namespace XenAdmin.Commands
// Adds the migrate wizard button, do this before the enable checks on the other items // Adds the migrate wizard button, do this before the enable checks on the other items
AddAdditionalMenuItems(selection); AddAdditionalMenuItems(selection);
UpdateHostList(); UpdateHostList();
} }
@ -163,11 +162,13 @@ namespace XenAdmin.Commands
if (Helpers.WlbEnabled(connection)) if (Helpers.WlbEnabled(connection))
{ {
var vms = selection.AsXenObjects<VM>(); var vms = selection.AsXenObjects<VM>();
if (vms == null || vms.Count == 0)
return;
var retrieveVmRecommendationsAction = new WlbRetrieveVmRecommendationsAction(connection, vms); var retrieveVmRecommendationsAction = new WlbRetrieveVmRecommendationsAction(connection, vms);
retrieveVmRecommendationsAction.Completed += delegate retrieveVmRecommendationsAction.Completed += delegate
{ {
if (Stopped || retrieveVmRecommendationsAction.Cancelled || if (Stopped || retrieveVmRecommendationsAction.Cancelled || !retrieveVmRecommendationsAction.Succeeded)
!retrieveVmRecommendationsAction.Succeeded)
return; return;
var recommendations = new WlbRecommendations(vms, retrieveVmRecommendationsAction.Recommendations); var recommendations = new WlbRecommendations(vms, retrieveVmRecommendationsAction.Recommendations);
@ -244,7 +245,7 @@ namespace XenAdmin.Commands
var firstItem = DropDownItems[0] as VMOperationToolStripMenuSubItem; var firstItem = DropDownItems[0] as VMOperationToolStripMenuSubItem;
if (firstItem == null) if (firstItem == null)
return; return;
// API calls could happen in CanRun(), which take time to wait. So a Producer-Consumer-Queue with size 25 is used here to : // API calls could happen in CanRun(), which take time to wait. So a Producer-Consumer-Queue with size 25 is used here to :
// 1. Make API calls for different menu items happen in parallel; // 1. Make API calls for different menu items happen in parallel;
// 2. Limit the count of concurrent threads (now it's 25). // 2. Limit the count of concurrent threads (now it's 25).
@ -254,7 +255,7 @@ namespace XenAdmin.Commands
var connection = selection[0].Connection; var connection = selection[0].Connection;
var session = connection.DuplicateSession(); var session = connection.DuplicateSession();
var affinityHost = connection.Resolve(((VM) selection[0].XenObject).affinity); var affinityHost = connection.Resolve(((VM)selection[0].XenObject).affinity);
EnqueueHostMenuItem(this, session, affinityHost, firstItem, true); EnqueueHostMenuItem(this, session, affinityHost, firstItem, true);
@ -279,7 +280,7 @@ namespace XenAdmin.Commands
workerQueueWithoutWlb.EnqueueItem(() => workerQueueWithoutWlb.EnqueueItem(() =>
{ {
var selection = menu.Command.GetSelection(); var selection = menu.Command.GetSelection();
var cmd = isHomeServer var cmd = isHomeServer
? new VMOperationHomeServerCommand(menu.Command.MainWindowCommandInterface, selection, menu._operation, session) ? new VMOperationHomeServerCommand(menu.Command.MainWindowCommandInterface, selection, menu._operation, session)
: new VMOperationHostCommand(menu.Command.MainWindowCommandInterface, selection, delegate { return host; }, host.Name().EscapeAmpersands(), menu._operation, session); : new VMOperationHostCommand(menu.Command.MainWindowCommandInterface, selection, delegate { return host; }, host.Name().EscapeAmpersands(), menu._operation, session);
@ -321,7 +322,7 @@ namespace XenAdmin.Commands
} }
}); });
} }
#endregion #endregion
/// <summary> /// <summary>

View File

@ -54,8 +54,6 @@ namespace XenAdmin.Commands
/// <param name="recommendations"></param> /// <param name="recommendations"></param>
public WlbRecommendations(List<VM> vms, Dictionary<VM, Dictionary<XenRef<Host>, string[]>> recommendations) public WlbRecommendations(List<VM> vms, Dictionary<VM, Dictionary<XenRef<Host>, string[]>> recommendations)
{ {
Util.ThrowIfEnumerableParameterNullOrEmpty(vms, "vms");
_vms = new ReadOnlyCollection<VM>(vms); _vms = new ReadOnlyCollection<VM>(vms);
_recommendations = recommendations; _recommendations = recommendations;
_isError = recommendations == null; _isError = recommendations == null;

View File

@ -140,7 +140,7 @@ namespace XenAdmin.Commands
if(!LiveMigrateAllowedInVersion(targetHost, draggedVM)) if(!LiveMigrateAllowedInVersion(targetHost, draggedVM))
{ {
Pool targetPool = targetHost == null ? null : Helpers.GetPool(targetHost.Connection); Pool targetPool = Helpers.GetPool(targetHost.Connection);
if(targetPool == null) if(targetPool == null)
return false; return false;

View File

@ -111,7 +111,8 @@ namespace XenAdmin.Commands
!pool.current_operations.Values.Contains(pool_allowed_operations.ha_enable) && !pool.current_operations.Values.Contains(pool_allowed_operations.ha_enable) &&
!pool.current_operations.Values.Contains(pool_allowed_operations.ha_disable) && !pool.current_operations.Values.Contains(pool_allowed_operations.ha_disable) &&
!pool.current_operations.Values.Contains(pool_allowed_operations.cluster_create) && !pool.current_operations.Values.Contains(pool_allowed_operations.cluster_create) &&
!pool.current_operations.Values.Contains(pool_allowed_operations.designate_new_master); !pool.current_operations.Values.Contains(pool_allowed_operations.designate_new_master) &&
!pool.RollingUpgrade();
} }
protected override string GetCantRunReasonCore(IXenObject item) protected override string GetCantRunReasonCore(IXenObject item)
@ -134,6 +135,9 @@ namespace XenAdmin.Commands
if (pool.current_operations.Values.Contains(pool_allowed_operations.designate_new_master)) if (pool.current_operations.Values.Contains(pool_allowed_operations.designate_new_master))
return Messages.ENABLE_TLS_VERIFICATION_NEW_COORDINATOR; return Messages.ENABLE_TLS_VERIFICATION_NEW_COORDINATOR;
if (pool.RollingUpgrade())
return Messages.ENABLE_TLS_VERIFICATION_RPU;
} }
return base.GetCantRunReasonCore(item); return base.GetCantRunReasonCore(item);

View File

@ -49,14 +49,14 @@ namespace XenAdmin.Commands
: base(mainWindow, pool) : base(mainWindow, pool)
{ } { }
public override string MenuText { get { return Messages.HOST_MENU_IMPORT_VM_TEXT; } } public override string MenuText => Messages.HOST_MENU_IMPORT_VM_TEXT;
public override string ContextMenuText{get{return Messages.HOST_MENU_IMPORT_VM_TEXT;}} public override string ContextMenuText => Messages.HOST_MENU_IMPORT_VM_TEXT;
protected override void RunCore(SelectedItemCollection selection) protected override void RunCore(SelectedItemCollection selection)
{ {
var con = selection.GetConnectionOfFirstItem(); var con = selection.GetConnectionOfFirstItem();
MainWindowCommandInterface.ShowPerConnectionWizard(con, new ImportWizard(con, selection.FirstAsXenObject, null, false)); MainWindowCommandInterface.ShowPerConnectionWizard(con, new ImportWizard(con, selection.FirstAsXenObject, null));
} }
} }
} }

View File

@ -78,7 +78,10 @@ namespace XenAdmin.Commands
dlg.ShowDialog(Parent); dlg.ShowDialog(Parent);
} }
new RepairSRDialog(srList).Show(Parent); if (srList.Count != 0)
{
new RepairSRDialog(srList).Show(Parent);
}
} }
protected override bool CanRunCore(SelectedItemCollection selection) protected override bool CanRunCore(SelectedItemCollection selection)

View File

@ -1497,7 +1497,7 @@ namespace XenAdmin.ConsoleView
if (this.Size.Height >= (displayBorder ? this.DesktopSize.Height + BORDER_PADDING + BORDER_PADDING : DesktopSize.Height)) if (this.Size.Height >= (displayBorder ? this.DesktopSize.Height + BORDER_PADDING + BORDER_PADDING : DesktopSize.Height))
{ {
this.dy = (this.Size.Height - this.DesktopSize.Height) / 2; this.dy = ((float) this.Size.Height - this.DesktopSize.Height) / 2;
} }
else else
{ {
@ -1515,7 +1515,7 @@ namespace XenAdmin.ConsoleView
if (this.Size.Width >= (displayBorder ? this.DesktopSize.Width + BORDER_PADDING + BORDER_PADDING : DesktopSize.Width)) if (this.Size.Width >= (displayBorder ? this.DesktopSize.Width + BORDER_PADDING + BORDER_PADDING : DesktopSize.Width))
{ {
this.dx = (this.Size.Width - this.DesktopSize.Width) / 2; this.dx = ((float) this.Size.Width - this.DesktopSize.Width) / 2;
} }
else else
{ {

View File

@ -711,18 +711,10 @@ namespace XenAdmin.ConsoleView
} }
else if (source.power_state == vm_power_state.Paused) else if (source.power_state == vm_power_state.Paused)
{ {
if (source.allowed_operations.Contains(vm_operations.unpause)) // CA-12637: Pause/UnPause is not supported in the GUI. Comment out
{ // the EnablePowerStateLabel because it gives the impression that we
//EnablePowerStateLabel(Messages.CONSOLE_POWER_STATE_PAUSED_UNPAUSE); // support unpause via the GUI.
// CA-12637: Pause/UnPause is not supported in the GUI. Comment out DisablePowerStateLabel(Messages.CONSOLE_POWER_STATE_PAUSED);
// the EnablePowerStateLabel because it gives the appearance that we
// support unpause via the GUI.
DisablePowerStateLabel(Messages.CONSOLE_POWER_STATE_PAUSED);
}
else
{
DisablePowerStateLabel(Messages.CONSOLE_POWER_STATE_PAUSED);
}
} }
else if (source.power_state == vm_power_state.Suspended) else if (source.power_state == vm_power_state.Suspended)
{ {

View File

@ -127,6 +127,9 @@ namespace XenAdmin.Controls.Ballooning
private void valueControlDomain_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void valueControlDomain_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
if (host == null)
return;
using (var dlg = new ControlDomainMemoryDialog(host)) using (var dlg = new ControlDomainMemoryDialog(host))
dlg.ShowDialog(Program.MainWindow); dlg.ShowDialog(Program.MainWindow);
} }

View File

@ -310,10 +310,9 @@ namespace XenAdmin.Controls
// find the <VM, VNCView> pair in vncViews and start timer on the vm // find the <VM, VNCView> pair in vncViews and start timer on the vm
var views = vncViews.Where(kvp => kvp.Value == vncView).ToList(); var views = vncViews.Where(kvp => kvp.Value == vncView).ToList();
foreach (var kvp in views) if (views.Count > 0)
{ {
StartCloseVNCTimer(kvp.Key); StartCloseVNCTimer(views.First().Key);
break;
} }
} }

View File

@ -300,11 +300,7 @@ namespace XenAdmin.Controls.CustomDataGraph
{ {
get get
{ {
foreach (DataSet s in Sets.Values) return Sets.Values.Select(s => s.CustomYRange).FirstOrDefault();
{
return s.CustomYRange;
}
return null;
} }
} }

View File

@ -482,19 +482,15 @@ namespace XenAdmin.Controls.CustomDataGraph
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if(!(obj is DataSet)) if (!(obj is DataSet other))
return base.Equals(obj); return false;
DataSet other = (DataSet)obj;
return Id == other.Id; return Id == other.Id;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
if (string.IsNullOrEmpty(Id)) return string.IsNullOrEmpty(Id) ? 0 : Id.GetHashCode();
return base.GetHashCode();
return Id.GetHashCode();
} }
internal void InsertPointCollection(List<DataPoint> list) internal void InsertPointCollection(List<DataPoint> list)

View File

@ -38,8 +38,8 @@ namespace XenAdmin.Controls.CustomGridView
{ {
public class GridRow : IComparable<GridRow> public class GridRow : IComparable<GridRow>
{ {
public readonly Dictionary<String, GridItemBase> Items = new Dictionary<string, GridItemBase>(); public Dictionary<string, GridItemBase> Items = new Dictionary<string, GridItemBase>();
public readonly List<GridRow> Rows = new List<GridRow>(); public List<GridRow> Rows = new List<GridRow>();
public static Image ExpandedImage = Images.StaticImages.expanded_triangle; public static Image ExpandedImage = Images.StaticImages.expanded_triangle;
public static Image ShrunkenImage = Images.StaticImages.contracted_triangle; public static Image ShrunkenImage = Images.StaticImages.contracted_triangle;
@ -678,14 +678,14 @@ namespace XenAdmin.Controls.CustomGridView
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if(!(obj is GridRow)) if (!(obj is GridRow row))
return base.Equals(obj); return false;
return OpaqueRef == ((GridRow)obj).OpaqueRef; return OpaqueRef == row.OpaqueRef;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode(); return (OpaqueRef != null ? OpaqueRef.GetHashCode() : 0);
} }
} }

View File

@ -90,7 +90,9 @@ namespace XenAdmin.Controls.DataGridViewEx
} }
} }
} }
private readonly IXenObject _xenObject;
/// <summary> /// <summary>
/// If the row is either a pool row or else a stanadlone host row /// If the row is either a pool row or else a stanadlone host row
/// </summary> /// </summary>
@ -128,7 +130,7 @@ namespace XenAdmin.Controls.DataGridViewEx
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode(); return _xenObject?.GetHashCode() ?? 0;
} }
public CheckState Checked public CheckState Checked
@ -143,11 +145,10 @@ namespace XenAdmin.Controls.DataGridViewEx
} }
} }
protected PoolHostDataGridViewOneCheckboxRow(){}
protected PoolHostDataGridViewOneCheckboxRow(Pool pool) protected PoolHostDataGridViewOneCheckboxRow(Pool pool)
: base(pool) : base(pool)
{ {
_xenObject = pool;
SetupCells(); SetupCells();
} }
@ -159,6 +160,7 @@ namespace XenAdmin.Controls.DataGridViewEx
protected PoolHostDataGridViewOneCheckboxRow(Host host, bool hasPool) protected PoolHostDataGridViewOneCheckboxRow(Host host, bool hasPool)
: base(host, hasPool) : base(host, hasPool)
{ {
_xenObject = host;
SetupCells(); SetupCells();
} }

View File

@ -32,6 +32,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using XenAdmin.Core; using XenAdmin.Core;
using XenAdmin.Network; using XenAdmin.Network;
@ -119,18 +120,18 @@ namespace XenAdmin.Controls
DeregisterEvents(); DeregisterEvents();
RegisterEvents(); RegisterEvents();
foreach (IXenConnection c in ConnectionsManager.XenConnectionsCopy) foreach (var c in ConnectionsManager.XenConnectionsCopy)
{ {
Pool p = Helpers.GetPool(c); var p = Helpers.GetPool(c);
if (p == null)// Stand alone host if (p == null)// Stand alone host
{ {
foreach (Host h in c.Cache.Hosts) if (c.Cache.Hosts.Length > 0)
{ {
var item = GenerateFilterItem(h, h.uuid); var host = c.Cache.Hosts.First();
item.Checked = HostCheckStates.ContainsKey(h.uuid); var item = GenerateFilterItem(host, host.uuid);
item.Checked = HostCheckStates.ContainsKey(host.uuid);
DropDownItems.Add(item); DropDownItems.Add(item);
break;
} }
} }
else else

View File

@ -33,7 +33,6 @@ using System;
using System.Windows.Forms; using System.Windows.Forms;
using System.Drawing; using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using XenAdmin.Core;
using XenCenterLib; using XenCenterLib;
namespace XenAdmin.Controls namespace XenAdmin.Controls
@ -62,8 +61,8 @@ namespace XenAdmin.Controls
/// The handle of the horizontal scrollbar of this ListBox /// The handle of the horizontal scrollbar of this ListBox
/// </summary> /// </summary>
private IntPtr _hScrollbarHandle = IntPtr.Zero; private IntPtr _hScrollbarHandle = IntPtr.Zero;
public WndProcCancelDelegate CancelWndProc = new WndProcCancelDelegate(delegate(Message msg) { return false; });
public Func<Message, bool> CancelWndProc = msg => false;
protected override void WndProc(ref Message msg) protected override void WndProc(ref Message msg)
{ {
@ -92,7 +91,7 @@ namespace XenAdmin.Controls
base.Invalidate(); base.Invalidate();
} }
if(!CancelWndProc(msg)) if (!CancelWndProc(msg))
base.WndProc(ref msg); base.WndProc(ref msg);
} }
@ -118,18 +117,12 @@ namespace XenAdmin.Controls
base.OnMouseWheel(e); base.OnMouseWheel(e);
} }
private ContextMenuStrip _contextMenuStrip = null; private ContextMenuStrip _contextMenuStrip;
public override ContextMenuStrip ContextMenuStrip public override ContextMenuStrip ContextMenuStrip
{ {
get get => _contextMenuStrip;
{ set => _contextMenuStrip = value;
return _contextMenuStrip;
}
set
{
_contextMenuStrip = value;
}
} }
protected override void OnKeyUp(KeyEventArgs e) protected override void OnKeyUp(KeyEventArgs e)
@ -233,115 +226,6 @@ namespace XenAdmin.Controls
Refresh(); Refresh();
} }
public const int RIGHT_PADDING = 5;
public void WilkieSpecial(Image icon, string text, string extraText, Color extraTextColor, Font extraTextFont, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
WSPaintBG(e, this);
// This is the rect where we want to put the text pair
Rectangle bounds = new Rectangle(e.Bounds.Height, e.Bounds.Y, e.Bounds.Width - e.Bounds.Height - RIGHT_PADDING, e.Bounds.Height);
String display;
Size s = WSDrawTextPair(this, text, extraText, extraTextColor, extraTextFont, e, bounds, true, out display);
WSDrawSelectRect(e, bounds.Height + s.Width);
WSDrawLeftImage(icon, e);
// And the text
Drawing.DrawText(g, display, e.Font,
bounds, e.ForeColor, e.BackColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
}
private static void WSDrawSelectRect(DrawItemEventArgs e, int width)
{
Graphics g = e.Graphics;
Rectangle selectionRectangle = new Rectangle(e.Bounds.Location, e.Bounds.Size);
selectionRectangle.Width = width;
using (SolidBrush backBrush = new SolidBrush(e.BackColor))
{
g.FillRectangle(backBrush, selectionRectangle);
}
}
private static Color GetBackColorFor(Control control)
{
return !control.Enabled ? SystemColors.Control : control.BackColor;
}
private static void WSDrawLeftImage(Image icon, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(icon, e.Bounds.Left + 1, e.Bounds.Top + 1, e.Bounds.Height - 2, e.Bounds.Height - 2);
}
private static Size WSDrawTextPair(Control control, String text, String extraText, Color extraTextColor, Font extraTextFont, DrawItemEventArgs e, Rectangle bounds, bool ShowSelectOnExtraText, out String display)
{
Graphics g = e.Graphics;
g.TextRenderingHint = Drawing.TextRenderingHint;
display = text;
Size s = Drawing.MeasureText(g, display, e.Font,
bounds.Size, TextFormatFlags.Right | TextFormatFlags.VerticalCenter);
if (extraText == null)
return s;
// We're going to have the extra text take precedent over the text,
// so shrink the text and put ellipses on until it measures up
Size t = Drawing.MeasureText(g, extraText, extraTextFont,
bounds.Size, TextFormatFlags.Right | TextFormatFlags.VerticalCenter);
int trim = text.Length;
while (s.Width + t.Width + 10 > bounds.Width && trim > 0)
{
trim--;
display = text.Ellipsise(trim);
s = Drawing.MeasureText(g, display, e.Font,
bounds.Size, TextFormatFlags.Right | TextFormatFlags.VerticalCenter);
}
Color backColor = ShowSelectOnExtraText && control.Focused && e.State == DrawItemState.Selected
? Color.LightGray
: GetBackColorFor(control);
if (ShowSelectOnExtraText)
{
Rectangle greySelectionRectangle = new Rectangle(bounds.Width - t.Width + bounds.X, bounds.Y + 2, t.Width, t.Height);
using (SolidBrush brush = new SolidBrush(backColor))
{
g.FillRectangle(brush, greySelectionRectangle);
}
}
Drawing.DrawText(g, extraText, extraTextFont,
bounds, extraTextColor, backColor, TextFormatFlags.Right | TextFormatFlags.VerticalCenter);
return s;
}
private static void WSPaintBG(DrawItemEventArgs e, Control control)
{
Graphics g = e.Graphics;
Color color = GetBackColorFor(control);
using (SolidBrush backBrush = new SolidBrush(color))
{
g.FillRectangle(backBrush, e.Bounds);
}
}
protected override void OnGotFocus(EventArgs e) protected override void OnGotFocus(EventArgs e)
{ {
base.OnGotFocus(e); base.OnGotFocus(e);
@ -354,6 +238,4 @@ namespace XenAdmin.Controls
this.Refresh(); this.Refresh();
} }
} }
public delegate bool WndProcCancelDelegate(Message msg);
} }

View File

@ -271,7 +271,6 @@ namespace XenAdmin.Controls
cbLUN.Items.Add(new LunComboBoxItem(vdi) { AdditionalConstraints = LunConstraints }); cbLUN.Items.Add(new LunComboBoxItem(vdi) { AdditionalConstraints = LunConstraints });
} }
cbLUN.Items.OfType<LunComboBoxItem>().OrderBy(i=>i.Enabled);
Cells.AddRange(tbVDI, cbLUN, tbSR); Cells.AddRange(tbVDI, cbLUN, tbSR);
Debug.Assert(cbLUN.Items.Count == Sr.VDIs.Count, "Not all combobox items were converted"); Debug.Assert(cbLUN.Items.Count == Sr.VDIs.Count, "Not all combobox items were converted");
} }

View File

@ -305,8 +305,6 @@ namespace XenAdmin.Controls.NetworkingTab
} }
NetworksGridView.Rows.AddRange(vifRowsToAdd.ToArray()); NetworksGridView.Rows.AddRange(vifRowsToAdd.ToArray());
bool selected = true;
if (selectedVIF != null) if (selectedVIF != null)
{ {
foreach (VifRow row in NetworksGridView.Rows) foreach (VifRow row in NetworksGridView.Rows)
@ -319,11 +317,6 @@ namespace XenAdmin.Controls.NetworkingTab
} }
} }
} }
if (!selected && NetworksGridView.Rows.Count > 0)
{
NetworksGridView.Rows[0].Selected = true;
}
} }
else if (XenObject is Host || XenObject is Pool) else if (XenObject is Host || XenObject is Pool)
{ {

View File

@ -300,7 +300,7 @@ namespace XenAdmin.Controls
} }
case VerticalAlignment.Middle: case VerticalAlignment.Middle:
{ {
Y = (this.Height - this.Padding.Vertical) / 2; Y = ((float) this.Height - this.Padding.Vertical) / 2;
break; break;
} }
case VerticalAlignment.Bottom: case VerticalAlignment.Bottom:

View File

@ -336,17 +336,6 @@ namespace XenAdmin.Controls
[DllImport("user32.dll")] [DllImport("user32.dll")]
internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref Win32.POINT pt); internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref Win32.POINT pt);
public override Size GetPreferredSize(Size proposedSize)
{
if (root == null && Parent != null)
{
return DefaultSize;
}
return new Size(root.SubtreeWidth, root.SubtreeHeight);
}
#endregion #endregion
#region Drawing #region Drawing

View File

@ -137,12 +137,8 @@ namespace XenAdmin.Controls
if (_scanCount > 0) if (_scanCount > 0)
return; return;
Program.Invoke(this, () => Program.Invoke(this, () => Rebuild(items, preselectedSR));
{
Invalidate();
Rebuild(items, preselectedSR);
});
}; };
action.RunAsync(); action.RunAsync();
} }
@ -177,6 +173,7 @@ namespace XenAdmin.Controls
private void Rebuild(List<SrPickerItem> items = null, SR preselectedSr = null) private void Rebuild(List<SrPickerItem> items = null, SR preselectedSr = null)
{ {
Program.AssertOnEventThread(); Program.AssertOnEventThread();
Invalidate();
SR selectedSr = preselectedSr ?? SR; SR selectedSr = preselectedSr ?? SR;
var theItems = items ?? GetSrPickerItems(); var theItems = items ?? GetSrPickerItems();
@ -213,12 +210,18 @@ namespace XenAdmin.Controls
private void Server_PropertyChanged(object sender, PropertyChangedEventArgs e) private void Server_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (_scanCount > 0)
return;
if (e.PropertyName == "name_label" || e.PropertyName == "PBDs" || e.PropertyName == "physical_utilisation" || e.PropertyName == "currently_attached" || e.PropertyName == "default_SR") if (e.PropertyName == "name_label" || e.PropertyName == "PBDs" || e.PropertyName == "physical_utilisation" || e.PropertyName == "currently_attached" || e.PropertyName == "default_SR")
Program.Invoke(this, () => Rebuild()); Program.Invoke(this, () => Rebuild());
} }
private void SR_CollectionChanged(object sender, CollectionChangeEventArgs e) private void SR_CollectionChanged(object sender, CollectionChangeEventArgs e)
{ {
if (_scanCount > 0)
return;
Program.Invoke(this, () => Rebuild()); Program.Invoke(this, () => Rebuild());
} }

View File

@ -33,6 +33,7 @@ using System;
using System.Windows.Forms; using System.Windows.Forms;
using XenAdmin.Core; using XenAdmin.Core;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using XenAdmin.Network; using XenAdmin.Network;
using XenAdmin.XenSearch; using XenAdmin.XenSearch;
using XenCenterLib; using XenCenterLib;
@ -157,7 +158,7 @@ namespace XenAdmin.Controls
{ {
VirtualTreeNode.PersistenceInfo info = new VirtualTreeNode.PersistenceInfo(node); VirtualTreeNode.PersistenceInfo info = new VirtualTreeNode.PersistenceInfo(node);
if (!_persistedSelectionInfo.Contains(info)) if (_persistedSelectionInfo != null && !_persistedSelectionInfo.Contains(info))
{ {
// selection is different to old one. So fire an event. // selection is different to old one. So fire an event.
@ -203,11 +204,9 @@ namespace XenAdmin.Controls
if (newSelectedNodes.Count == 0) if (newSelectedNodes.Count == 0)
{ {
foreach (VirtualTreeNode.PersistenceInfo info in _persistedSelectionInfo) if (_persistedSelectionInfo.Count > 0)
{ {
// Finally, just select one of the parents TryToSelectNode(newSelectedNodes, ClosestMatch(_persistedSelectionInfo.First().Path));
TryToSelectNode(newSelectedNodes, ClosestMatch(info.Path));
break;
} }
} }

View File

@ -422,7 +422,7 @@ namespace XenAdmin.Controls.Wlb
/// <param name="e">EventArgs</param> /// <param name="e">EventArgs</param>
private void ButtonApply_Click(object sender, EventArgs e) private void ButtonApply_Click(object sender, EventArgs e)
{ {
if (this._pool == null) if (_pool == null || _vmOptList == null)
return; return;
applyButton.Enabled = false; applyButton.Enabled = false;

View File

@ -1080,7 +1080,7 @@ namespace XenAdmin.Controls.XenSearch
public class ExtraComboEntry public class ExtraComboEntry
{ {
public StringPropertyQuery.PropertyQueryType type; public readonly StringPropertyQuery.PropertyQueryType type;
public ExtraComboEntry(StringPropertyQuery.PropertyQueryType type) public ExtraComboEntry(StringPropertyQuery.PropertyQueryType type)
{ {
this.type = type; this.type = type;
@ -1121,7 +1121,7 @@ namespace XenAdmin.Controls.XenSearch
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode(); return (int) type;
} }
} }
@ -1327,7 +1327,7 @@ namespace XenAdmin.Controls.XenSearch
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode(); return (int) type;
} }
} }
@ -2498,7 +2498,7 @@ namespace XenAdmin.Controls.XenSearch
if (intQuery == null) if (intQuery == null)
return; return;
queryElement.numericUpDown.Value = intQuery.query / multiplier; queryElement.numericUpDown.Value = (decimal) intQuery.query / multiplier;
} }
} }

View File

@ -139,11 +139,8 @@ namespace XenAdmin.Controls.XenSearch
public void Populate(Search search) public void Populate(Search search)
{ {
ClearItems(); ClearItems();
if (search != null && search.Query != null) scope = search?.Query?.QueryScope;
scope = search.Query.QueryScope; search?.PopulateAdapters(this);
else
scope = null;
search.PopulateAdapters(this);
} }
} }
} }

View File

@ -59,7 +59,10 @@ namespace XenAdmin.Core
internal static string GetDetails(this ActionBase action) internal static string GetDetails(this ActionBase action)
{ {
var sb = new StringBuilder(GetTitle(action)); var sb = new StringBuilder(GetTitle(action));
sb.Append("\n").Append(GetDescription(action));
var description = GetDescription(action);
if (!string.IsNullOrEmpty(description))
sb.Append("\n").Append(description);
string timeString = GetTimeElapsed(action); string timeString = GetTimeElapsed(action);
if (!string.IsNullOrEmpty(timeString)) if (!string.IsNullOrEmpty(timeString))

View File

@ -43,41 +43,30 @@ namespace XenAdmin.Diagnostics.Checks
class PVGuestsCheck : HostPostLivenessCheck class PVGuestsCheck : HostPostLivenessCheck
{ {
private readonly Pool _pool; private readonly Pool _pool;
private readonly bool _upgrade;
private readonly bool _manualUpgrade; private readonly bool _manualUpgrade;
private readonly Dictionary<string, string> _installMethodConfig; private readonly Dictionary<string, string> _installMethodConfig;
public PVGuestsCheck(Host coordinator, bool upgrade, bool manualUpgrade = false, Dictionary<string, string> installMethodConfig = null) public PVGuestsCheck(Host coordinator, bool manualUpgrade = false, Dictionary<string, string> installMethodConfig = null)
: base(coordinator) : base(coordinator)
{ {
_pool = Helpers.GetPoolOfOne(Host?.Connection); _pool = Helpers.GetPoolOfOne(Host?.Connection);
_upgrade = upgrade;
_manualUpgrade = manualUpgrade; _manualUpgrade = manualUpgrade;
_installMethodConfig = installMethodConfig; _installMethodConfig = installMethodConfig;
} }
public override bool CanRun() public override bool CanRun()
{ {
if (Helpers.QuebecOrGreater(Host)) if (Helpers.YangtzeOrGreater(Host))
return false; return false;
if (_pool == null || !_pool.Connection.Cache.VMs.Any(vm => vm.IsPvVm())) if (_pool == null || !_pool.Connection.Cache.VMs.Any(vm => vm.IsPvVm()))
return false; return false;
if (!_upgrade && !Helpers.NaplesOrGreater(Host))
return false;
return true; return true;
} }
protected override Problem RunHostCheck() protected override Problem RunHostCheck()
{ {
//update case
if (!_upgrade)
return new PoolHasPVGuestWarningUrl(this, _pool);
//upgrade case
if (!_manualUpgrade) if (!_manualUpgrade)
{ {
var hotfix = HotfixFactory.Hotfix(Host); var hotfix = HotfixFactory.Hotfix(Host);
@ -95,6 +84,9 @@ namespace XenAdmin.Diagnostics.Checks
if (string.IsNullOrEmpty(upgradePlatformVersion)) if (string.IsNullOrEmpty(upgradePlatformVersion))
return new PoolHasPVGuestWarningUrl(this, _pool); return new PoolHasPVGuestWarningUrl(this, _pool);
if (Helpers.YangtzeOrGreater(upgradePlatformVersion))
return new PoolHasPVGuestProblem(this, _pool);
if (Helpers.QuebecOrGreater(upgradePlatformVersion)) if (Helpers.QuebecOrGreater(upgradePlatformVersion))
return new PoolHasPVGuestWarningUrl(this, _pool); return new PoolHasPVGuestWarningUrl(this, _pool);

View File

@ -57,4 +57,27 @@ namespace XenAdmin.Diagnostics.Problems.PoolProblem
public override string HelpMessage => LinkText; public override string HelpMessage => LinkText;
public override string LinkText => Messages.LEARN_MORE; public override string LinkText => Messages.LEARN_MORE;
} }
class PoolHasPVGuestProblem : ProblemWithInformationUrl
{
private readonly Pool _pool;
public PoolHasPVGuestProblem(Check check, Pool pool)
: base(check)
{
_pool = pool;
}
private string PVGuestCheckUrl => string.Format(InvisibleMessages.PV_GUESTS_CHECK_URL);
public override Uri UriToLaunch => new Uri(PVGuestCheckUrl);
public override string Title => Description;
public override string Description =>
string.Format(Messages.POOL_HAS_PV_GUEST_WARNING, _pool.Name(),
string.Format(Messages.STRING_SPACE_STRING, BrandManager.ProductBrand, BrandManager.ProductVersion81));
public override string HelpMessage => LinkText;
public override string LinkText => Messages.LEARN_MORE;
}
} }

View File

@ -124,7 +124,9 @@ namespace XenAdmin.Dialogs
var multipleAction = action as MultipleAction; var multipleAction = action as MultipleAction;
labelSubActionStatus.Visible = multipleAction != null && multipleAction.ShowSubActionsDetails; labelSubActionStatus.Visible = multipleAction != null && multipleAction.ShowSubActionsDetails;
if (labelSubActionStatus.Visible) if (labelSubActionStatus.Visible)
UpdateLabel(labelSubActionStatus, multipleAction.SubActionDescription, multipleAction.SubActionTitle); {
UpdateLabel(labelSubActionStatus, multipleAction?.SubActionDescription, multipleAction?.SubActionTitle);
}
} }
private void action_Completed(ActionBase sender) private void action_Completed(ActionBase sender)

View File

@ -137,7 +137,9 @@ namespace XenAdmin.Dialogs
ServerNameComboBox.Enabled = true; ServerNameComboBox.Enabled = true;
AddButton.Text = Messages.ADD; AddButton.Text = Messages.ADD;
} }
if (_changedPass && connection.Password == null) else if (!_changedPass)
return;
else if (connection.Password == null)
{ {
Text = Messages.CONNECT_TO_SERVER; Text = Messages.CONNECT_TO_SERVER;
labelInstructions.Text = Messages.CONNECT_TO_SERVER_BLURB; labelInstructions.Text = Messages.CONNECT_TO_SERVER_BLURB;
@ -145,7 +147,7 @@ namespace XenAdmin.Dialogs
ServerNameComboBox.Enabled = false; ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.CONNECT; AddButton.Text = Messages.CONNECT;
} }
else if (_changedPass && connection.ExpectPasswordIsCorrect) else if (connection.ExpectPasswordIsCorrect)
{ {
// This situation should be rare, it normally comes from logging in a new session after an existing one has been made // This situation should be rare, it normally comes from logging in a new session after an existing one has been made
// We now use duplicate sessions instead most of the time which don't log in again. // We now use duplicate sessions instead most of the time which don't log in again.
@ -155,7 +157,7 @@ namespace XenAdmin.Dialogs
ServerNameComboBox.Enabled = false; ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.OK; AddButton.Text = Messages.OK;
} }
else if (_changedPass) // the password probably hasnt actually changed but we do know the user has typed it in wrong else // the password probably hasn't actually changed but we do know the user has typed it in wrong
{ {
Text = Messages.CONNECT_TO_SERVER; Text = Messages.CONNECT_TO_SERVER;
labelInstructions.Text = string.Format(Messages.ERROR_CONNECTING_BLURB, BrandManager.BrandConsole); labelInstructions.Text = string.Format(Messages.ERROR_CONNECTING_BLURB, BrandManager.BrandConsole);
@ -163,6 +165,7 @@ namespace XenAdmin.Dialogs
ServerNameComboBox.Enabled = false; ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.CONNECT; AddButton.Text = Messages.CONNECT;
} }
} }
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
@ -200,7 +203,7 @@ namespace XenAdmin.Dialogs
{ {
if (conn == null) if (conn == null)
{ {
conn = new XenConnection {fromDialog = true}; conn = new XenConnection { fromDialog = true };
conn.CachePopulated += conn_CachePopulated; conn.CachePopulated += conn_CachePopulated;
} }
else if (!_changedPass) else if (!_changedPass)

View File

@ -50,8 +50,6 @@ namespace XenAdmin.Dialogs
public ControlDomainMemoryDialog(Host host) public ControlDomainMemoryDialog(Host host)
: base(host.Connection) : base(host.Connection)
{ {
if (host == null) throw new ArgumentNullException("host");
InitializeComponent(); InitializeComponent();
this.host = host; this.host = host;
this.host.PropertyChanged += Server_PropertyChanged; this.host.PropertyChanged += Server_PropertyChanged;

View File

@ -207,15 +207,15 @@ namespace XenAdmin.Dialogs
if (freeCount == 0 || freeCount < xenObject.Connection.Cache.Hosts.Length) if (freeCount == 0 || freeCount < xenObject.Connection.Cache.Hosts.Length)
return false; return false;
var expiryGroups = from Host h in xenObject.Connection.Cache.Hosts var expiryGroups = (from Host h in xenObject.Connection.Cache.Hosts
let exp = h.LicenseExpiryUTC() let exp = h.LicenseExpiryUTC()
group h by exp group h by exp
into g into g
select new { ExpiryDate = g.Key, Hosts = g }; select new { ExpiryDate = g.Key, Hosts = g }).ToList();
if(expiryGroups.Count() > 1) if (expiryGroups.Count > 1)
{ {
expiryGroups.OrderBy(g => g.ExpiryDate); expiryGroups = expiryGroups.OrderBy(g => g.ExpiryDate).ToList();
if ((expiryGroups.ElementAt(1).ExpiryDate - expiryGroups.ElementAt(0).ExpiryDate).TotalDays > 30) if ((expiryGroups.ElementAt(1).ExpiryDate - expiryGroups.ElementAt(0).ExpiryDate).TotalDays > 30)
return true; return true;
} }

View File

@ -120,7 +120,7 @@ namespace XenAdmin.Dialogs.OptionsPages
log.Warn("Could not unprotect internet proxy password.", e); log.Warn("Could not unprotect internet proxy password.", e);
} }
ConnectionTimeoutNud.Value = Properties.Settings.Default.ConnectionTimeout / 1000; ConnectionTimeoutNud.Value = (decimal) Properties.Settings.Default.ConnectionTimeout / 1000;
eventsDisabled = false; eventsDisabled = false;
} }

View File

@ -75,7 +75,6 @@ namespace XenAdmin.Dialogs
/// <param name="runAction"></param> /// <param name="runAction"></param>
public RepairSRDialog(IEnumerable<SR> srs, bool runAction = true) public RepairSRDialog(IEnumerable<SR> srs, bool runAction = true)
{ {
Util.ThrowIfEnumerableParameterNullOrEmpty(srs, "srs");
this.runAction = runAction; this.runAction = runAction;
BoldFont = new Font(Font, FontStyle.Bold); BoldFont = new Font(Font, FontStyle.Bold);
List<SR> srList = new List<SR>(srs); List<SR> srList = new List<SR>(srs);

View File

@ -78,7 +78,7 @@ namespace XenAdmin.Dialogs.VMDialogs
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
{ {
var action = new VMMoveAction(vm, srPicker1.SR, vm.GetStorageHost(false), vm.Name()); var action = new VMMoveAction(vm, srPicker1.SR, vm.GetStorageHost(false));
action.RunAsync(); action.RunAsync();
Close(); Close();
} }

View File

@ -378,8 +378,8 @@ namespace XenAdmin.Dialogs.Wlb
Dictionary<string, string> rps = new Dictionary<string, string>(); Dictionary<string, string> rps = new Dictionary<string, string>();
foreach(string key in this._rpParams.Keys) foreach(string key in this._rpParams.Keys)
{ {
if (String.Compare(key, WlbReportSubscription.REPORT_NAME, true) == 0) if (String.Compare(key, WlbReportSubscription.REPORT_NAME_KEY, true) == 0)
_subscription.ReportName = this._rpParams[WlbReportSubscription.REPORT_NAME]; _subscription.ReportName = this._rpParams[WlbReportSubscription.REPORT_NAME_KEY];
else else
{ {
//Get start date range //Get start date range

View File

@ -37,7 +37,7 @@ namespace XenAdmin
{ {
internal Grouping Grouping; internal Grouping Grouping;
internal object Parent; internal object Parent;
internal object Group; internal readonly object Group;
/// <summary></summary> /// <summary></summary>
/// <param name="grouping"></param> /// <param name="grouping"></param>
@ -55,8 +55,7 @@ namespace XenAdmin
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
GroupingTag other = obj as GroupingTag; return obj is GroupingTag other && Grouping.Equals(other.Grouping) && Group.Equals(other.Group);
return other != null && Grouping.Equals(other.Grouping) && Group.Equals(other.Group);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@ -2706,7 +2706,7 @@ namespace XenAdmin
{ {
HelpersGUI.BringFormToFront(this); HelpersGUI.BringFormToFront(this);
Host hostAncestor = SelectionManager.Selection.Count == 1 ? SelectionManager.Selection[0].HostAncestor : null; Host hostAncestor = SelectionManager.Selection.Count == 1 ? SelectionManager.Selection[0].HostAncestor : null;
new ImportWizard(SelectionManager.Selection.GetConnectionOfFirstItem(), hostAncestor, param, false).Show(); new ImportWizard(SelectionManager.Selection.GetConnectionOfFirstItem(), hostAncestor, param).Show();
} }
#region XenSearch #region XenSearch

View File

@ -85,8 +85,9 @@ namespace XenAdmin.Plugins
ContextMenu = Helpers.GetEnumXmlAttribute(node, ATT_CONTEXT_MENU, GetContextMenuFromMenu(Menu)); ContextMenu = Helpers.GetEnumXmlAttribute(node, ATT_CONTEXT_MENU, GetContextMenuFromMenu(Menu));
Serialized = Helpers.GetEnumXmlAttribute(node, ATT_SERIALIZED, PluginSerializationLevel.none); Serialized = Helpers.GetEnumXmlAttribute(node, ATT_SERIALIZED, PluginSerializationLevel.none);
foreach (XmlNode child in node.ChildNodes) if (node.ChildNodes.Count > 0)
{ {
var child = node.ChildNodes[0];
switch (child.Name) switch (child.Name)
{ {
case TYPE_SHELL: case TYPE_SHELL:
@ -99,7 +100,6 @@ namespace XenAdmin.Plugins
ShellCmd = new XenServerPowershellCmd(child, paramsFromXML(child)); ShellCmd = new XenServerPowershellCmd(child, paramsFromXML(child));
break; break;
} }
return;
} }
} }

View File

@ -230,7 +230,7 @@ namespace XenAdmin.SettingsPanels
Host host = (Host)_XenObject; Host host = (Host)_XenObject;
Host_metrics metrics = host.Connection.Resolve(host.metrics); Host_metrics metrics = host.Connection.Resolve(host.metrics);
if (metrics != null) if (metrics != null)
nudMemoryUsage.Maximum = metrics.memory_total / (1024 * 1024); nudMemoryUsage.Maximum = (decimal) metrics.memory_total / (1024 * 1024);
} }
Repopulate(); Repopulate();

View File

@ -231,17 +231,17 @@ namespace XenAdmin.TabPages
{ {
vm.PropertyChanged -= VmPropertyChanged; vm.PropertyChanged -= VmPropertyChanged;
vm.PropertyChanged += VmPropertyChanged; vm.PropertyChanged += VmPropertyChanged;
if (pvsProxy != null)
{ if (pvsProxy == null)
pvsProxy.PropertyChanged -= PvsProxyPropertyChanged; return;
pvsProxy.PropertyChanged += PvsProxyPropertyChanged; pvsProxy.PropertyChanged -= PvsProxyPropertyChanged;
PVS_site pvsSite = pvsProxy == null ? null : Connection.Resolve(pvsProxy.site); pvsProxy.PropertyChanged += PvsProxyPropertyChanged;
if (pvsSite != null)
{ var pvsSite = Connection.Resolve(pvsProxy.site);
pvsSite.PropertyChanged -= PvsSitePropertyChanged; if (pvsSite == null)
pvsSite.PropertyChanged += PvsSitePropertyChanged; return;
} pvsSite.PropertyChanged -= PvsSitePropertyChanged;
} pvsSite.PropertyChanged += PvsSitePropertyChanged;
} }
private void UnregisterVmEventHandlers() private void UnregisterVmEventHandlers()

View File

@ -1,161 +0,0 @@
/* 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.Collections.Generic;
using System.Windows.Forms;
namespace DotNetVnc
{
public class KeySet : IEquatable<KeySet>
{
List<Keys> keys;
public IList<Keys> Keys
{
get
{
return keys.AsReadOnly();
}
}
public KeySet()
{
this.keys = new List<Keys>();
}
public KeySet(List<Keys> keys)
{
this.keys = new List<Keys>();
foreach (Keys key in keys)
{
if (!this.keys.Contains(key))
{
this.keys.Add(key);
}
}
this.keys.Sort();
}
public KeySet(params Keys[] keys)
{
this.keys = new List<Keys>();
foreach (Keys key in keys)
{
if (!this.keys.Contains(key))
{
this.keys.Add(key);
}
}
this.keys.Sort();
}
public KeySet Add(Keys _key)
{
List<Keys> newKeys = new List<Keys>();
foreach(Keys key in this.keys)
{
newKeys.Add(key);
}
if (!newKeys.Contains(_key))
newKeys.Add(_key);
return new KeySet(newKeys);
}
public KeySet Remove(Keys _key)
{
List<Keys> newKeys = new List<Keys>();
foreach (Keys key in this.keys)
{
if (key != _key)
{
newKeys.Add(key);
}
}
return new KeySet(newKeys);
}
public bool Equals(KeySet keySet)
{
foreach (Keys key in keySet.Keys)
{
if (!keys.Contains(key))
{
return false;
}
}
foreach (Keys key in this.keys)
{
if (!keySet.Keys.Contains(key))
{
return false;
}
}
return true;
}
public override int GetHashCode()
{
if (this.keys.Count > 0)
{
return (int)this.keys[0];
}
else
{
return 0;
}
}
public override String ToString()
{
String result = "";
foreach (Keys key in this.keys)
{
result += key;
result += " ";
}
return result;
}
}
}

View File

@ -38,6 +38,7 @@ using XenAdmin.Controls.Common;
using XenAdmin.Core; using XenAdmin.Core;
using XenAdmin.Dialogs; using XenAdmin.Dialogs;
using XenCenterLib; using XenCenterLib;
using XenModel;
using Registry = XenAdmin.Core.Registry; using Registry = XenAdmin.Core.Registry;
@ -206,9 +207,9 @@ namespace XenAdmin.Wizards.BugToolWizardFiles
if (String.IsNullOrEmpty(name)) if (String.IsNullOrEmpty(name))
return false; return false;
if (!PathValidator.IsFileNameValid(name)) if (!PathValidator.IsFileNameValid(name, out string invalidNameMsg))
{ {
error = Messages.BUGTOOL_PAGE_DESTINATION_INVALID_NAME; error = $"{Messages.BUGTOOL_PAGE_DESTINATION_INVALID_NAME} {invalidNameMsg}";
return false; return false;
} }
@ -217,9 +218,9 @@ namespace XenAdmin.Wizards.BugToolWizardFiles
string path = String.Format("{0}\\{1}", folder, name); string path = String.Format("{0}\\{1}", folder, name);
if (!PathValidator.IsPathValid(path)) if (!PathValidator.IsPathValid(path, out string invalidPathMsg))
{ {
error = Messages.BUGTOOL_PAGE_DESTINATION_INVALID_FOLDER; error = $"{Messages.BUGTOOL_PAGE_DESTINATION_INVALID_FOLDER} {invalidPathMsg}";
return false; return false;
} }

View File

@ -32,6 +32,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using XenAdmin.Controls; using XenAdmin.Controls;
using XenAdmin.Core; using XenAdmin.Core;
@ -121,11 +122,11 @@ namespace XenAdmin.Wizards.BugToolWizardFiles
node.State = CheckState.Checked; node.State = CheckState.Checked;
} }
var checkedItems = HostListTreeView.CheckedItems();
//focus on first checked item so the user can find it in a long list //focus on first checked item so the user can find it in a long list
foreach (var node in HostListTreeView.CheckedItems()) if (checkedItems.Count > 0)
{ {
HostListTreeView.SelectedItems.Add(node); HostListTreeView.SelectedItems.Add(checkedItems.First());
break;
} }
HostListTreeView.EndUpdate(); HostListTreeView.EndUpdate();

View File

@ -599,8 +599,8 @@ namespace XenAdmin.Wizards.DRWizards
private class PreCheckItemRow : PreCheckGridRow private class PreCheckItemRow : PreCheckGridRow
{ {
private Problem _problem = null; private readonly Problem _problem;
private Check _check = null; private readonly Check _check;
public PreCheckItemRow(Problem problem) public PreCheckItemRow(Problem problem)
{ {
_problem = problem; _problem = problem;

View File

@ -179,8 +179,8 @@ namespace XenAdmin.Wizards.DRWizards
var vdis = sr.Connection.ResolveAll(sr.VDIs); var vdis = sr.Connection.ResolveAll(sr.VDIs);
bool poolMetadataDetected = vdis.Any(vdi => vdi.type == vdi_type.metadata); bool poolMetadataDetected = vdis.Any(vdi => vdi.type == vdi_type.metadata);
SrRow row; var row = dataGridViewSRs.Rows.Cast<SrRow>().FirstOrDefault(r => r.SrUuid == sr.uuid);
if (!FindRowByUuid(sr.uuid, out row)) if (row != null)
{ {
row = new SrRow(sr, poolMetadataDetected, SelectedSRsUuids.Contains(sr.uuid)); row = new SrRow(sr, poolMetadataDetected, SelectedSRsUuids.Contains(sr.uuid));
dataGridViewSRs.Rows.Add(row); dataGridViewSRs.Rows.Add(row);
@ -192,8 +192,8 @@ namespace XenAdmin.Wizards.DRWizards
{ {
foreach (var srInfo in scannedDevice.SRList) foreach (var srInfo in scannedDevice.SRList)
{ {
SrRow row; var row = dataGridViewSRs.Rows.Cast<SrRow>().FirstOrDefault(r => r.SrUuid == srInfo.UUID);
if (!FindRowByUuid(srInfo.UUID, out row)) if (row != null)
{ {
row = new SrRow(srInfo, scannedDevice.Type, srInfo.PoolMetadataDetected, row = new SrRow(srInfo, scannedDevice.Type, srInfo.PoolMetadataDetected,
SelectedSRsUuids.Contains(srInfo.UUID)); SelectedSRsUuids.Contains(srInfo.UUID));
@ -356,8 +356,9 @@ namespace XenAdmin.Wizards.DRWizards
foreach (SR.SRInfo srInfo in metadataSrs) foreach (SR.SRInfo srInfo in metadataSrs)
{ {
SrRow row; var row = dataGridViewSRs.Rows.Cast<SrRow>().FirstOrDefault(r => r.SrUuid == srInfo.UUID);
if (!FindRowByUuid(srInfo.UUID, out row))
if (row != null)
{ {
row = new SrRow(srInfo, type, srInfo.PoolMetadataDetected, srInfo.PoolMetadataDetected); row = new SrRow(srInfo, type, srInfo.PoolMetadataDetected, srInfo.PoolMetadataDetected);
dataGridViewSRs.Rows.Add(row); dataGridViewSRs.Rows.Add(row);
@ -618,17 +619,6 @@ namespace XenAdmin.Wizards.DRWizards
OnPageUpdated(); OnPageUpdated();
} }
private bool FindRowByUuid(string uuid, out SrRow row)
{
row = null;
foreach (var srRow in dataGridViewSRs.Rows.Cast<SrRow>().Where(srRow => srRow.SrUuid == uuid))
{
row = srRow;
return true;
}
return false;
}
private void buttonSelectAll_Click(object sender, EventArgs e) private void buttonSelectAll_Click(object sender, EventArgs e)
{ {
SelectAllRows(true); SelectAllRows(true);

View File

@ -36,6 +36,7 @@ using XenAdmin.Controls;
using XenAdmin.Controls.Common; using XenAdmin.Controls.Common;
using XenAdmin.Wizards.ExportWizard.ApplianceChecks; using XenAdmin.Wizards.ExportWizard.ApplianceChecks;
using XenCenterLib; using XenCenterLib;
using XenModel;
namespace XenAdmin.Wizards.ExportWizard namespace XenAdmin.Wizards.ExportWizard
{ {
@ -166,9 +167,9 @@ namespace XenAdmin.Wizards.ExportWizard
if (String.IsNullOrEmpty(ApplianceFileName)) if (String.IsNullOrEmpty(ApplianceFileName))
return false; return false;
if (!PathValidator.IsFileNameValid(ApplianceFileName)) if (!PathValidator.IsFileNameValid(ApplianceFileName, out string invalidNameMsg))
{ {
error = Messages.EXPORT_APPLIANCE_PAGE_ERROR_INALID_APP; error = string.Join(" ", new []{ Messages.EXPORT_APPLIANCE_PAGE_ERROR_INALID_APP , invalidNameMsg});
return false; return false;
} }
@ -177,9 +178,9 @@ namespace XenAdmin.Wizards.ExportWizard
string path = String.Format("{0}\\{1}", ApplianceDirectory, ApplianceFileName); string path = String.Format("{0}\\{1}", ApplianceDirectory, ApplianceFileName);
if (!PathValidator.IsPathValid(path)) if (!PathValidator.IsPathValid(path, out string invalidPathMsg))
{ {
error = Messages.EXPORT_APPLIANCE_PAGE_ERROR_INVALID_DIR; error = string.Join(" ", new[] { Messages.EXPORT_APPLIANCE_PAGE_ERROR_INVALID_DIR, invalidPathMsg });
return false; return false;
} }

View File

@ -35,18 +35,18 @@ using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Windows.Forms; using System.Windows.Forms;
using XenCenterLib;
using XenOvf; using XenOvf;
using XenAdmin.Controls; using XenAdmin.Controls;
using XenModel;
namespace XenAdmin.Wizards.ExportWizard namespace XenAdmin.Wizards.ExportWizard
{ {
/// <summary> /// <summary>
/// Class representing the page of the ExportAppliance wizard where the user specifies /// Class representing the page of the ExportAppliance wizard where the user specifies
/// whether to create a manifest, sign the appliance or encrypt files and whether to /// whether to create a manifest, sign the appliance or encrypt files and whether to
/// create an OVA package or compress the OVF files /// create an OVA package or compress the OVF files
/// </summary> /// </summary>
internal partial class ExportOptionsPage : XenTabPage internal partial class ExportOptionsPage : XenTabPage
{ {
private const int MIN_PASSWORD_STRENGTH = 1; private const int MIN_PASSWORD_STRENGTH = 1;
private int m_passwordStrength; private int m_passwordStrength;
@ -285,9 +285,9 @@ namespace XenAdmin.Wizards.ExportWizard
{ {
error = string.Empty; error = string.Empty;
if (!PathValidator.IsPathValid(m_textBoxCertificate.Text))//includes null check if (!PathValidator.IsPathValid(m_textBoxCertificate.Text, out string invalidPathMsg))//includes null check
{ {
error = Messages.EXPORT_SECURITY_PAGE_ERROR_INVALID_CERT; error = string.Join(" ", new[] { Messages.EXPORT_SECURITY_PAGE_ERROR_INVALID_CERT, invalidPathMsg });
return false; return false;
} }

View File

@ -413,16 +413,17 @@ namespace XenAdmin.Wizards.GenericPages
{ {
if (hasPoolSharedStorage) if (hasPoolSharedStorage)
{ {
foreach (var pool in target.Item.Connection.Cache.Pools) //there exists one pool per connection
var pools = target.Item.Connection.Cache.Pools;
if (pools.Length > 0)
{ {
var pool = pools.First();
var item = new NoTargetServerPoolItem(pool); var item = new NoTargetServerPoolItem(pool);
cb.Items.Add(item); cb.Items.Add(item);
if ((m_selectedObject != null && m_selectedObject.opaque_ref == pool.opaque_ref) || if ((m_selectedObject != null && m_selectedObject.opaque_ref == pool.opaque_ref) ||
(target.Item.opaque_ref == pool.opaque_ref)) (target.Item.opaque_ref == pool.opaque_ref))
cb.Value = item; cb.Value = item;
break; //there exists one pool per connection
} }
} }

View File

@ -32,7 +32,7 @@
using System; using System;
using XenAdmin.Controls; using XenAdmin.Controls;
using XenCenterLib; using XenCenterLib;
using XenModel;
namespace XenAdmin.Wizards.ImportWizard namespace XenAdmin.Wizards.ImportWizard
{ {
@ -55,17 +55,17 @@ namespace XenAdmin.Wizards.ImportWizard
/// <summary> /// <summary>
/// Gets the page's title (headline) /// Gets the page's title (headline)
/// </summary> /// </summary>
public override string PageTitle { get { return Messages.IMAGE_DEFINITION_PAGE_TITLE; } } public override string PageTitle => Messages.IMAGE_DEFINITION_PAGE_TITLE;
/// <summary> /// <summary>
/// Gets the page's label in the (left hand side) wizard progress panel /// Gets the page's label in the (left hand side) wizard progress panel
/// </summary> /// </summary>
public override string Text { get { return Messages.IMAGE_DEFINITION_PAGE_TEXT; } } public override string Text => Messages.IMAGE_DEFINITION_PAGE_TEXT;
/// <summary> /// <summary>
/// Gets the value by which the help files section for this page is identified /// Gets the value by which the help files section for this page is identified
/// </summary> /// </summary>
public override string HelpID { get { return "VMConfig"; } } public override string HelpID => "VMConfig";
protected override bool ImplementsIsDirty() protected override bool ImplementsIsDirty()
{ {
@ -97,16 +97,16 @@ namespace XenAdmin.Wizards.ImportWizard
#region Accessors #region Accessors
public bool IsWim { private get; set; } public bool IsWim { internal get; set; }
public string VmName { get { return m_textBoxVMName.Text; } } public string VmName => m_textBoxVMName.Text;
public ulong CpuCount { get { return (ulong)m_upDownCpuCount.Value; } } public ulong CpuCount => (ulong)m_upDownCpuCount.Value;
public ulong Memory { get { return (ulong)m_upDownMemory.Value; } } public ulong Memory => (ulong)m_upDownMemory.Value;
public ulong AdditionalSpace => m_groupBoxAddSpace.Visible && m_groupBoxAddSpace.Enabled ? (ulong)m_upDownAddSpace.Value * GB : 0;
public ulong AdditionalSpace { get { return m_groupBoxAddSpace.Enabled ? (ulong)m_upDownAddSpace.Value * GB : 0; } }
#endregion #endregion
#region Private Methods #region Private Methods
@ -118,9 +118,10 @@ namespace XenAdmin.Wizards.ImportWizard
if (String.IsNullOrEmpty(name)) if (String.IsNullOrEmpty(name))
return false; return false;
if (!PathValidator.IsFileNameValid(name))
if (!PathValidator.IsFileNameValid(name, out string invalidNameMsg))
{ {
error = Messages.IMPORT_SELECT_APPLIANCE_PAGE_ERROR_INVALID_PATH; error = invalidNameMsg;
return false; return false;
} }
return true; return true;

View File

@ -50,7 +50,7 @@ using XenCenterLib.Archive;
using XenOvf; using XenOvf;
using XenOvf.Definitions.VMC; using XenOvf.Definitions.VMC;
using XenOvf.Utilities; using XenOvf.Utilities;
using XenModel;
namespace XenAdmin.Wizards.ImportWizard namespace XenAdmin.Wizards.ImportWizard
{ {
@ -370,21 +370,20 @@ namespace XenAdmin.Wizards.ImportWizard
/// </summary> /// </summary>
private bool CheckPathValid(out string error) private bool CheckPathValid(out string error)
{ {
error = string.Empty; error = string.Empty;
if (String.IsNullOrEmpty(FilePath)) if (String.IsNullOrEmpty(FilePath))
return false; return false;
if (IsUri()) if (IsUri())
return CheckDownloadFromUri(out error); return CheckDownloadFromUri(out error);
if (!PathValidator.IsPathValid(FilePath)) if (!PathValidator.IsPathValid(FilePath, out string invalidNameMsg))
{ {
error = Messages.IMPORT_SELECT_APPLIANCE_PAGE_ERROR_INVALID_PATH; error = invalidNameMsg;
return false; return false;
} }
return true; return true;
} }
/// <summary> /// <summary>

File diff suppressed because it is too large Load Diff

View File

@ -49,9 +49,6 @@ namespace XenAdmin.Wizards.ImportWizard
#region Private fields #region Private fields
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private IXenConnection m_selectedConnection;
private Host m_selectedAffinity;
private VM m_vm;
private bool m_buttonNextEnabled; private bool m_buttonNextEnabled;
#endregion #endregion
@ -108,6 +105,15 @@ namespace XenAdmin.Wizards.ImportWizard
#region Accessors #region Accessors
/// <summary>
/// Should be set before the Affinity is set.
/// </summary>
internal IXenConnection SelectedConnection { get; set; }
internal Host SelectedAffinity { get; set; }
internal VM VM { get; set; }
public List<VIF> VIFs public List<VIF> VIFs
{ {
get get
@ -136,24 +142,6 @@ namespace XenAdmin.Wizards.ImportWizard
#endregion #endregion
public void SetAffinity(Host host)
{
m_selectedAffinity = host;
}
public void SetVm(VM vm)
{
m_vm = vm;
}
/// <summary>
/// Should be called before the Affinity is set.
/// </summary>
public void SetConnection(IXenConnection con)
{
m_selectedConnection = con;
}
#region Private methods #region Private methods
private void UpdateControlsEnabledState(bool enabled) private void UpdateControlsEnabledState(bool enabled)
@ -167,7 +155,7 @@ namespace XenAdmin.Wizards.ImportWizard
{ {
NetworkNetworkColumn.Items.Clear(); NetworkNetworkColumn.Items.Clear();
var networks = m_selectedConnection.Cache.Networks.Where(ShowNetwork); var networks = SelectedConnection.Cache.Networks.Where(ShowNetwork);
foreach (XenAPI.Network network in networks) foreach (XenAPI.Network network in networks)
{ {
@ -186,18 +174,18 @@ namespace XenAdmin.Wizards.ImportWizard
m_networkGridView.SuspendLayout(); m_networkGridView.SuspendLayout();
m_networkGridView.Rows.Clear(); m_networkGridView.Rows.Clear();
if (m_vm.is_a_template && m_vm.VIFs.Count < 1) if (VM.is_a_template && VM.VIFs.Count < 1)
{ {
// We need to automatically generate VIFs for Networks marked AutoPlug=true // We need to automatically generate VIFs for Networks marked AutoPlug=true
var networks = m_selectedConnection.Cache.Networks; var networks = SelectedConnection.Cache.Networks;
foreach (XenAPI.Network network in networks) foreach (XenAPI.Network network in networks)
{ {
if (m_networkGridView.Rows.Count < m_vm.MaxVIFsAllowed() && ShowNetwork(network) && network.GetAutoPlug()) if (m_networkGridView.Rows.Count < VM.MaxVIFsAllowed() && ShowNetwork(network) && network.GetAutoPlug())
{ {
AddVIFRow(new VIF AddVIFRow(new VIF
{ {
Connection = m_selectedConnection, Connection = SelectedConnection,
device = m_networkGridView.Rows.Count.ToString(), device = m_networkGridView.Rows.Count.ToString(),
network = new XenRef<XenAPI.Network>(network.opaque_ref), network = new XenRef<XenAPI.Network>(network.opaque_ref),
MAC = Messages.MAC_AUTOGENERATE MAC = Messages.MAC_AUTOGENERATE
@ -205,16 +193,16 @@ namespace XenAdmin.Wizards.ImportWizard
} }
} }
} }
else if (m_vm.is_a_template) else if (VM.is_a_template)
{ {
// We need to create off the _vmTemplate // We need to create off the _vmTemplate
var vifs = m_selectedConnection.ResolveAll(m_vm.VIFs); var vifs = SelectedConnection.ResolveAll(VM.VIFs);
foreach (VIF vif in vifs) foreach (VIF vif in vifs)
{ {
AddVIFRow(new VIF AddVIFRow(new VIF
{ {
Connection = m_selectedConnection, Connection = SelectedConnection,
device = vif.device, device = vif.device,
network = vif.network, network = vif.network,
MAC = Messages.MAC_AUTOGENERATE MAC = Messages.MAC_AUTOGENERATE
@ -224,7 +212,7 @@ namespace XenAdmin.Wizards.ImportWizard
else else
{ {
//We need to recreate off vm //We need to recreate off vm
var vifs = m_selectedConnection.ResolveAll(m_vm.VIFs); var vifs = SelectedConnection.ResolveAll(VM.VIFs);
foreach (VIF vif in vifs) foreach (VIF vif in vifs)
AddVIFRow(vif); AddVIFRow(vif);
} }
@ -240,7 +228,7 @@ namespace XenAdmin.Wizards.ImportWizard
private XenAPI.Network GetDefaultNetwork() private XenAPI.Network GetDefaultNetwork()
{ {
foreach (XenAPI.Network network in m_selectedConnection.Cache.Networks) foreach (XenAPI.Network network in SelectedConnection.Cache.Networks)
if (ShowNetwork(network)) if (ShowNetwork(network))
return network; return network;
@ -261,13 +249,13 @@ namespace XenAdmin.Wizards.ImportWizard
if (network.IsMember()) if (network.IsMember())
return false; return false;
if (m_selectedAffinity != null && !m_selectedAffinity.CanSeeNetwork(network)) if (SelectedAffinity != null && !SelectedAffinity.CanSeeNetwork(network))
return false; return false;
if (m_selectedAffinity == null && !network.AllHostsCanSeeNetwork()) if (SelectedAffinity == null && !network.AllHostsCanSeeNetwork())
return false; return false;
if (network.IsSriov() && !m_vm.HasSriovRecommendation()) if (network.IsSriov() && !VM.HasSriovRecommendation())
return false; return false;
return true; return true;
@ -276,7 +264,7 @@ namespace XenAdmin.Wizards.ImportWizard
private void AddVIFRow(VIF vif) private void AddVIFRow(VIF vif)
{ {
var row = new VifRow(vif); var row = new VifRow(vif);
XenAPI.Network network = m_selectedConnection.Resolve(vif.network); XenAPI.Network network = SelectedConnection.Resolve(vif.network);
bool isGuestInstallerNetwork = network != null && network.IsGuestInstallerNetwork(); bool isGuestInstallerNetwork = network != null && network.IsGuestInstallerNetwork();
ToStringWrapper<XenAPI.Network> comboBoxEntry = FindComboBoxEntryForNetwork(network); ToStringWrapper<XenAPI.Network> comboBoxEntry = FindComboBoxEntryForNetwork(network);
@ -344,7 +332,7 @@ namespace XenAdmin.Wizards.ImportWizard
private void m_buttonAddNetwork_Click(object sender, EventArgs e) private void m_buttonAddNetwork_Click(object sender, EventArgs e)
{ {
if (m_networkGridView.Rows.Count >= m_vm.MaxVIFsAllowed()) if (m_networkGridView.Rows.Count >= VM.MaxVIFsAllowed())
{ {
using (var dlg = new ErrorDialog(FriendlyErrorNames.VIFS_MAX_ALLOWED) using (var dlg = new ErrorDialog(FriendlyErrorNames.VIFS_MAX_ALLOWED)
{WindowTitle = FriendlyErrorNames.VIFS_MAX_ALLOWED_TITLE}) {WindowTitle = FriendlyErrorNames.VIFS_MAX_ALLOWED_TITLE})
@ -354,7 +342,7 @@ namespace XenAdmin.Wizards.ImportWizard
return; return;
} }
VIF vif = new VIF {Connection = m_selectedConnection}; VIF vif = new VIF {Connection = SelectedConnection};
int i = 0; int i = 0;
while (true) while (true)

View File

@ -45,8 +45,6 @@ namespace XenAdmin.Wizards.ImportWizard
public partial class StoragePickerPage : XenTabPage public partial class StoragePickerPage : XenTabPage
{ {
#region Private fields #region Private fields
private Host m_targetHost;
private IXenConnection m_targetConnection;
private volatile Task m_importTask; private volatile Task m_importTask;
private bool m_alreadyFoundVM; private bool m_alreadyFoundVM;
private ActionProgressDialog m_actionDialog; private ActionProgressDialog m_actionDialog;
@ -98,8 +96,8 @@ namespace XenAdmin.Wizards.ImportWizard
SetButtonNextEnabled(false); SetButtonNextEnabled(false);
m_buttonPreviousEnabled = false; m_buttonPreviousEnabled = false;
OnPageUpdated(); OnPageUpdated();
ImportXvaAction = new ImportVmAction(m_targetHost == null ? m_targetConnection : m_targetHost.Connection, ImportXvaAction = new ImportVmAction(TargetHost == null ? TargetConnection : TargetHost.Connection,
m_targetHost, FilePath, SR, TargetHost, FilePath, SR,
VMOperationCommand.WarningDialogHAInvalidConfig, VMOperationCommand.StartDiagnosisForm); VMOperationCommand.WarningDialogHAInvalidConfig, VMOperationCommand.StartDiagnosisForm);
ImportXvaAction.Completed += m_importXvaAction_Completed; ImportXvaAction.Completed += m_importXvaAction_Completed;
@ -119,7 +117,7 @@ namespace XenAdmin.Wizards.ImportWizard
public override void PopulatePage() public override void PopulatePage()
{ {
SetButtonNextEnabled(false); SetButtonNextEnabled(false);
m_srPicker.PopulateAsync(SrPicker.SRPickerType.VM, m_targetConnection, m_targetHost, null, null); m_srPicker.PopulateAsync(SrPicker.SRPickerType.VM, TargetConnection, TargetHost, null, null);
IsDirty = true; IsDirty = true;
} }
@ -137,6 +135,10 @@ namespace XenAdmin.Wizards.ImportWizard
#region Accessors #region Accessors
internal IXenConnection TargetConnection { get; set; }
internal Host TargetHost { get; set; }
public ImportVmAction ImportXvaAction { get; private set; } public ImportVmAction ImportXvaAction { get; private set; }
public string FilePath { private get; set; } public string FilePath { private get; set; }
@ -147,19 +149,6 @@ namespace XenAdmin.Wizards.ImportWizard
#endregion #endregion
/// <summary>
/// Should be called before the Affinity is set.
/// </summary>
public void SetConnection(IXenConnection con)
{
m_targetConnection = con;
}
public void SetTargetHost(Host host)
{
m_targetHost = host;
}
#region Private methods #region Private methods
private void SetButtonNextEnabled(bool enabled) private void SetButtonNextEnabled(bool enabled)
@ -196,12 +185,12 @@ namespace XenAdmin.Wizards.ImportWizard
while (ImportXvaAction.RelatedTask == null) while (ImportXvaAction.RelatedTask == null)
Thread.Sleep(100); Thread.Sleep(100);
while ((m_importTask = m_targetConnection.Resolve(ImportXvaAction.RelatedTask)) == null) while ((m_importTask = TargetConnection.Resolve(ImportXvaAction.RelatedTask)) == null)
Thread.Sleep(100); Thread.Sleep(100);
// We register a XenObjectsUpdated event handler where we check that the import task has the object creation phase marked as "complete"; // We register a XenObjectsUpdated event handler where we check that the import task has the object creation phase marked as "complete";
// Once the object creation is complete, we look for the vm; When we found the vm we unregister this event handler; // Once the object creation is complete, we look for the vm; When we found the vm we unregister this event handler;
m_targetConnection.XenObjectsUpdated += targetConnection_XenObjectsUpdated; TargetConnection.XenObjectsUpdated += targetConnection_XenObjectsUpdated;
Program.Invoke(this, CheckTask); Program.Invoke(this, CheckTask);
} }
@ -233,11 +222,11 @@ namespace XenAdmin.Wizards.ImportWizard
{ {
// Should never get here (as we unregister XenObjectsUpdated event handler after we find the vm) but just in case, // Should never get here (as we unregister XenObjectsUpdated event handler after we find the vm) but just in case,
// unregister XenObjectsUpdated event handler // unregister XenObjectsUpdated event handler
m_targetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated; TargetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
return; return;
} }
foreach (VM vm in m_targetConnection.Cache.VMs) foreach (VM vm in TargetConnection.Cache.VMs)
{ {
if (!vm.other_config.ContainsKey(ImportVmAction.IMPORT_TASK)) if (!vm.other_config.ContainsKey(ImportVmAction.IMPORT_TASK))
continue; continue;
@ -250,7 +239,7 @@ namespace XenAdmin.Wizards.ImportWizard
ImportedVm = vm; ImportedVm = vm;
// We found the VM, unregister XenObjectsUpdated event handler // We found the VM, unregister XenObjectsUpdated event handler
m_targetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated; TargetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
// And close the dialog, flick to next page. // And close the dialog, flick to next page.
m_actionDialog.Close(); m_actionDialog.Close();
@ -279,7 +268,7 @@ namespace XenAdmin.Wizards.ImportWizard
if (!(ImportXvaAction.Succeeded) || ImportXvaAction.Cancelled) if (!(ImportXvaAction.Succeeded) || ImportXvaAction.Cancelled)
{ {
// task failed or has been cancelled, unregister XenObjectsUpdated event handler // task failed or has been cancelled, unregister XenObjectsUpdated event handler
m_targetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated; TargetConnection.XenObjectsUpdated -= targetConnection_XenObjectsUpdated;
// Give the user a chance to correct any errors // Give the user a chance to correct any errors
m_actionDialog = null; m_actionDialog = null;

View File

@ -614,8 +614,8 @@ namespace XenAdmin.Wizards.PatchingWizard
private class PreCheckHostRow : PreCheckGridRow private class PreCheckHostRow : PreCheckGridRow
{ {
private Problem _problem = null; private readonly Problem _problem = null;
private Check _check = null; private readonly Check _check = null;
public PreCheckHostRow(Problem problem) public PreCheckHostRow(Problem problem)
: base(new DataGridViewTextBoxCell()) : base(new DataGridViewTextBoxCell())
{ {

View File

@ -49,7 +49,7 @@ namespace XenAdmin.Wizards.PatchingWizard
} }
#region Accessors #region Accessors
public readonly List<HostUpdateMapping> PatchMappings = new List<HostUpdateMapping>(); public List<HostUpdateMapping> PatchMappings { get; } = new List<HostUpdateMapping>();
public UpdateType SelectedUpdateType { private get; set; } public UpdateType SelectedUpdateType { private get; set; }
public string SelectedPatchFilePath { get; set; } public string SelectedPatchFilePath { get; set; }

View File

@ -39,7 +39,8 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
public abstract class RebootPlanAction : HostPlanAction public abstract class RebootPlanAction : HostPlanAction
{ {
private bool _cancelled; private bool _cancelled;
private bool lostConnection; private bool _lostConnection;
private readonly object _lockObj = new object();
protected RebootPlanAction(Host host) protected RebootPlanAction(Host host)
: base(host) : base(host)
@ -50,9 +51,9 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
{ {
_cancelled = true; _cancelled = true;
lock (this) lock (_lockObj)
{ {
Monitor.PulseAll(this); Monitor.PulseAll(_lockObj);
} }
} }
@ -98,7 +99,7 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
{ {
bool isCoordinator = GetResolvedHost().IsCoordinator(); bool isCoordinator = GetResolvedHost().IsCoordinator();
lostConnection = false; _lostConnection = false;
_cancelled = false; _cancelled = false;
double metric = metricDelegate(session, HostXenRef.opaque_ref); double metric = metricDelegate(session, HostXenRef.opaque_ref);
@ -134,7 +135,7 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
Connection.SuppressErrors = true; Connection.SuppressErrors = true;
// //
// Wait for a dissconnection // Wait for a disconnection
// //
WaitForDisconnection(); WaitForDisconnection();
@ -165,11 +166,11 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
{ {
log.DebugFormat("{0}._WaitForReboot waiting for connection to go away...", GetType().Name); log.DebugFormat("{0}._WaitForReboot waiting for connection to go away...", GetType().Name);
lock (this) lock (_lockObj)
{ {
while (!lostConnection && !_cancelled) while (!_lostConnection && !_cancelled)
{ {
Monitor.Wait(this); Monitor.Wait(_lockObj);
} }
} }
@ -274,10 +275,10 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
private void connection_ConnectionLost(IXenConnection conn) private void connection_ConnectionLost(IXenConnection conn)
{ {
lock (this) lock (_lockObj)
{ {
lostConnection = true; _lostConnection = true;
Monitor.PulseAll(this); Monitor.PulseAll(_lockObj);
} }
} }
} }

View File

@ -42,8 +42,8 @@ namespace XenAdmin.Wizards.PatchingWizard
public List<HostPlan> HostPlans { get; private set; } public List<HostPlan> HostPlans { get; private set; }
public List<PlanAction> FinalActions { get; private set; } public List<PlanAction> FinalActions { get; private set; }
public List<PlanAction> CleanupActions { get; private set; } public List<PlanAction> CleanupActions { get; private set; }
public readonly List<PlanAction> DoneActions = new List<PlanAction>(); public List<PlanAction> DoneActions { get; } = new List<PlanAction>();
public readonly List<PlanAction> InProgressActions = new List<PlanAction>(); public List<PlanAction> InProgressActions { get; } = new List<PlanAction>();
public Pool Pool { get; private set; } public Pool Pool { get; private set; }
public string Name { get; private set; } public string Name { get; private set; }

View File

@ -240,7 +240,7 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
//Checking PV guests - for hosts that have any PV guests and warn the user before the upgrade. //Checking PV guests - for hosts that have any PV guests and warn the user before the upgrade.
var pvChecks = (from Host server in SelectedCoordinators var pvChecks = (from Host server in SelectedCoordinators
let check = new PVGuestsCheck(server, true, ManualUpgrade, InstallMethodConfig) let check = new PVGuestsCheck(server, ManualUpgrade, InstallMethodConfig)
where check.CanRun() where check.CanRun()
select check as Check).ToList(); select check as Check).ToList();

View File

@ -744,7 +744,6 @@
<Compile Include="VNC\KeyMap.Designer.cs"> <Compile Include="VNC\KeyMap.Designer.cs">
<DependentUpon>KeyMap.cs</DependentUpon> <DependentUpon>KeyMap.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="VNC\KeySet.cs" />
<Compile Include="VNC\MyStream.cs" /> <Compile Include="VNC\MyStream.cs" />
<Compile Include="VNC\VNCException.cs" /> <Compile Include="VNC\VNCException.cs" />
<Compile Include="VNC\VNCStream.cs" /> <Compile Include="VNC\VNCStream.cs" />

View File

@ -1,100 +0,0 @@
/* 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.IO;
namespace XenCenterLib
{
public class PathValidator
{
private static readonly char[] m_invalidFileCharList = Path.GetInvalidFileNameChars();
private static readonly string[] m_deviceNames = {
"CON", "PRN", "AUX", "NUL",
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
};
public static bool IsFileNameValid(string filename)
{
if (filename.IndexOfAny(m_invalidFileCharList) > -1)
return false;
foreach (var name in m_deviceNames)
{
if (name == filename.ToUpper())
return false;
}
return true;
}
public static bool IsPathValid(string path)
{
if (string.IsNullOrEmpty(path))
return false;
try
{
if (Path.IsPathRooted(path))
{
path = path[0] == '\\' && path.Length == 1
? path.Substring(1)
: path.Substring(2);
}
}
catch(ArgumentException)
{
//path contains a character from Path.GetInvalidPathChars()
return false;
}
string[] parts = path.Split(new[] {'\\'});
if (parts.Length > 0)
{
foreach (var part in parts)
{
if (part.IndexOfAny(m_invalidFileCharList) > -1)
return false;
foreach (var name in m_deviceNames)
{
if (name == part.ToUpper())
return false;
}
}
}
return true;
}
}
}

View File

@ -79,7 +79,6 @@
<Compile Include="LockFreeQueue.cs" /> <Compile Include="LockFreeQueue.cs" />
<Compile Include="NamedPipes.cs" /> <Compile Include="NamedPipes.cs" />
<Compile Include="PartialIP.cs" /> <Compile Include="PartialIP.cs" />
<Compile Include="PathValidator.cs" />
<Compile Include="Processes.cs" /> <Compile Include="Processes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Set.cs" /> <Compile Include="Set.cs" />

View File

@ -378,10 +378,9 @@ namespace XenAdmin.Actions
doc.LoadXml(task.result); doc.LoadXml(task.result);
var nodes = doc.GetElementsByTagName("value"); var nodes = doc.GetElementsByTagName("value");
foreach (XmlNode node in nodes) if (nodes.Count > 0)
{ {
Result = node.InnerText; Result = nodes[0].InnerText;
break;
} }
} }
catch //CA-352946 catch //CA-352946

View File

@ -84,7 +84,6 @@ namespace XenAdmin.Actions.DR
internal static void DestroyVM(Session session, VM vm) internal static void DestroyVM(Session session, VM vm)
{ {
Exception caught = null;
log.DebugFormat("Destroying VM '{0}'", vm.Name()); log.DebugFormat("Destroying VM '{0}'", vm.Name());
if (vm.snapshots.Count > 0) if (vm.snapshots.Count > 0)
@ -143,9 +142,6 @@ namespace XenAdmin.Actions.DR
} }
log.DebugFormat("VM '{0}' destroyed", vm.Name()); log.DebugFormat("VM '{0}' destroyed", vm.Name());
if (caught != null)
throw caught;
} }
} }
} }

View File

@ -31,6 +31,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using XenAdmin.Core; using XenAdmin.Core;
using XenAdmin.Network; using XenAdmin.Network;
using XenAPI; using XenAPI;
@ -91,25 +92,21 @@ namespace XenAdmin.Actions.DR
MetadataSession = Session.get_record(Session, MetadataSessionRef); MetadataSession = Session.get_record(Session, MetadataSessionRef);
#region FIND POOL #region FIND POOL
Dictionary<XenRef<XenAPI.Pool>, XenAPI.Pool> pools = XenAPI.Pool.get_all_records(MetadataSession); var pools = Pool.get_all_records(MetadataSession);
foreach (var pool in pools.Values) var poolValues = pools.Values;
if (poolValues.Count > 0)
{ {
_poolMetadata.Pool = pool; var pool = poolValues.First();
string poolName = String.IsNullOrEmpty(pool.name_label) && pool.master != null var poolName = string.IsNullOrEmpty(pool.name_label) && pool.master != null
? XenAPI.Host.get_name_label(MetadataSession, pool.master.opaque_ref) ? Host.get_name_label(MetadataSession, pool.master.opaque_ref)
: pool.name_label; : pool.name_label;
_poolMetadata.Pool.name_label = poolName; _poolMetadata.Pool.name_label = poolName;
log.DebugFormat("Found metadata of pool '{0}' (UUID={1})", _poolMetadata.Pool.Name(), log.DebugFormat("Found metadata of pool '{0}' (UUID={1})", _poolMetadata.Pool.Name(),
_poolMetadata.Pool.uuid); _poolMetadata.Pool.uuid);
break;
} }
#endregion #endregion
/*if (_poolMetadata.Pool.uuid == Pool.uuid) // metadata of current pool
{
return;
}*/
_poolMetadata.VmAppliances = VM_appliance.get_all_records(MetadataSession); _poolMetadata.VmAppliances = VM_appliance.get_all_records(MetadataSession);
foreach (var vmAppRef in _poolMetadata.VmAppliances.Keys) foreach (var vmAppRef in _poolMetadata.VmAppliances.Keys)
{ {

View File

@ -64,9 +64,11 @@ namespace XenAdmin.Actions
public ApplyLicenseEditionAction(IEnumerable<IXenObject> xos, Host.Edition edition, string licenseServerAddress, string licenseServerPort, Action<List<LicenseFailure>, string> doOnLicensingFailure = null) public ApplyLicenseEditionAction(IEnumerable<IXenObject> xos, Host.Edition edition, string licenseServerAddress, string licenseServerPort, Action<List<LicenseFailure>, string> doOnLicensingFailure = null)
: base(null, Messages.LICENSE_UPDATING_LICENSES) : base(null, Messages.LICENSE_UPDATING_LICENSES)
{ {
LicenseFailures = new List<LicenseFailure>(); if (xos == null || !xos.Any())
Util.ThrowIfEnumerableParameterNullOrEmpty(xos, "xenobjects"); throw new ArgumentException(@"Parameter cannot be null or empty", nameof(xos));
LicenseFailures = new List<LicenseFailure>();
_edition = edition; _edition = edition;
this.xos = xos; this.xos = xos;
_licenseServerAddress = licenseServerAddress; _licenseServerAddress = licenseServerAddress;

View File

@ -42,12 +42,10 @@ namespace XenAdmin.Actions
private readonly bool _resumeVMs; private readonly bool _resumeVMs;
public EnableHostAction(Host host, bool resumeVMs,Func<Pool, Host, long, long, bool> acceptNTolChangesOnEnable) public EnableHostAction(Host host, bool resumeVMs,Func<Pool, Host, long, long, bool> acceptNTolChangesOnEnable)
: base(host.Connection, Messages.HOST_ENABLE, Messages.WAITING, null, acceptNTolChangesOnEnable) : base(host?.Connection, Messages.HOST_ENABLE, Messages.WAITING, null, acceptNTolChangesOnEnable)
{ {
if (host == null) Host = host ?? throw new ArgumentNullException("host");
throw new ArgumentNullException("host");
_resumeVMs = resumeVMs; _resumeVMs = resumeVMs;
this.Host = host;
AddCommonAPIMethodsToRoleCheck(); AddCommonAPIMethodsToRoleCheck();
ApiMethodsToRoleCheck.Add("pool.ha_compute_hypothetical_max_host_failures_to_tolerate"); ApiMethodsToRoleCheck.Add("pool.ha_compute_hypothetical_max_host_failures_to_tolerate");
ApiMethodsToRoleCheck.Add("pool.set_ha_host_failures_to_tolerate"); ApiMethodsToRoleCheck.Add("pool.set_ha_host_failures_to_tolerate");

View File

@ -60,8 +60,6 @@ namespace XenAdmin.Actions
public EvacuateHostAction(Host host, Host newCoordinator, Dictionary<XenRef<VM>, String[]> hostRecommendations, Func<HostAbstractAction, Pool, long, long, bool> acceptNTolChanges, Func<Pool, Host, long, long, bool> acceptNTolChangesOnEnable) public EvacuateHostAction(Host host, Host newCoordinator, Dictionary<XenRef<VM>, String[]> hostRecommendations, Func<HostAbstractAction, Pool, long, long, bool> acceptNTolChanges, Func<Pool, Host, long, long, bool> acceptNTolChangesOnEnable)
: base(host.Connection, null, Messages.HOST_EVACUATE, acceptNTolChanges, acceptNTolChangesOnEnable) : base(host.Connection, null, Messages.HOST_EVACUATE, acceptNTolChanges, acceptNTolChangesOnEnable)
{ {
if (host == null)
throw new ArgumentNullException("host");
Host = host; Host = host;
_newCoordinator = newCoordinator; _newCoordinator = newCoordinator;
_hostRecommendations = hostRecommendations; _hostRecommendations = hostRecommendations;

View File

@ -50,9 +50,7 @@ namespace XenAdmin.Actions
public RebootHostAction(Host host, Func<HostAbstractAction, Pool, long, long, bool> acceptNTolChanges) public RebootHostAction(Host host, Func<HostAbstractAction, Pool, long, long, bool> acceptNTolChanges)
: base(host.Connection, Messages.HOST_REBOOTING, Messages.WAITING, acceptNTolChanges, null) : base(host.Connection, Messages.HOST_REBOOTING, Messages.WAITING, acceptNTolChanges, null)
{ {
if (host == null) Host = host;
throw new ArgumentNullException("host");
this.Host = host;
AddCommonAPIMethodsToRoleCheck(); AddCommonAPIMethodsToRoleCheck();
ApiMethodsToRoleCheck.Add("pool.ha_compute_hypothetical_max_host_failures_to_tolerate"); ApiMethodsToRoleCheck.Add("pool.ha_compute_hypothetical_max_host_failures_to_tolerate");
ApiMethodsToRoleCheck.Add("pool.set_ha_host_failures_to_tolerate"); ApiMethodsToRoleCheck.Add("pool.set_ha_host_failures_to_tolerate");

View File

@ -44,8 +44,6 @@ namespace XenAdmin.Actions
public ShutdownHostAction(Host host, Func<HostAbstractAction, Pool, long, long, bool> acceptNTolChanges) public ShutdownHostAction(Host host, Func<HostAbstractAction, Pool, long, long, bool> acceptNTolChanges)
: base(host.Connection, Messages.HOST_SHUTDOWN, Messages.WAITING, acceptNTolChanges, null) : base(host.Connection, Messages.HOST_SHUTDOWN, Messages.WAITING, acceptNTolChanges, null)
{ {
if (host == null)
throw new ArgumentNullException("host");
Host = host; Host = host;
ApiMethodsToRoleCheck.Add("pool.ha_compute_hypothetical_max_host_failures_to_tolerate"); ApiMethodsToRoleCheck.Add("pool.ha_compute_hypothetical_max_host_failures_to_tolerate");
ApiMethodsToRoleCheck.Add("pool.set_ha_host_failures_to_tolerate"); ApiMethodsToRoleCheck.Add("pool.set_ha_host_failures_to_tolerate");

View File

@ -49,12 +49,10 @@ namespace XenAdmin.Actions
public EnableHAAction(Pool pool, Dictionary<VM, VMStartupOptions> startupOptions, List<SR> heartbeatSRs, long failuresToTolerate) public EnableHAAction(Pool pool, Dictionary<VM, VMStartupOptions> startupOptions, List<SR> heartbeatSRs, long failuresToTolerate)
: base(pool.Connection, string.Format(Messages.ENABLING_HA_ON, Helpers.GetName(pool).Ellipsise(50)), Messages.ENABLING_HA, false) : base(pool.Connection, string.Format(Messages.ENABLING_HA_ON, Helpers.GetName(pool).Ellipsise(50)), Messages.ENABLING_HA, false)
{ {
if (pool == null)
throw new ArgumentNullException("pool");
if (heartbeatSRs.Count == 0) if (heartbeatSRs.Count == 0)
throw new ArgumentException("You must specify at least 1 heartbeat SR"); throw new ArgumentException("You must specify at least 1 heartbeat SR");
this.Pool = pool; Pool = pool;
this.startupOptions = startupOptions; this.startupOptions = startupOptions;
this.heartbeatSRs = heartbeatSRs.ToArray(); this.heartbeatSRs = heartbeatSRs.ToArray();
this.failuresToTolerate = failuresToTolerate; this.failuresToTolerate = failuresToTolerate;
@ -69,7 +67,7 @@ namespace XenAdmin.Actions
{ {
if (startupOptions != null) if (startupOptions != null)
{ {
double increment = 10 / Math.Max(startupOptions.Count, 1); double increment = 10.0 / Math.Max(startupOptions.Count, 1);
int i = 0; int i = 0;
// First set any VM restart priorities supplied // First set any VM restart priorities supplied
foreach (VM vm in startupOptions.Keys) foreach (VM vm in startupOptions.Keys)

View File

@ -57,8 +57,6 @@ namespace XenAdmin.Actions
public CheckDiskSpaceForPatchUploadAction(Host host, string fileName, long size, bool suppressHistory) public CheckDiskSpaceForPatchUploadAction(Host host, string fileName, long size, bool suppressHistory)
: base(host.Connection, Messages.ACTION_CHECK_DISK_SPACE_TITLE, "", suppressHistory) : base(host.Connection, Messages.ACTION_CHECK_DISK_SPACE_TITLE, "", suppressHistory)
{ {
if (host == null)
throw new ArgumentNullException("host");
Host = host; Host = host;
this.fileName = fileName; this.fileName = fileName;
fileSize = size; fileSize = size;

View File

@ -45,8 +45,6 @@ namespace XenAdmin.Actions
public CleanupDiskSpaceAction(Host host, Pool_patch excludedPatch, bool suppressHistory) public CleanupDiskSpaceAction(Host host, Pool_patch excludedPatch, bool suppressHistory)
: base(host.Connection, Messages.ACTION_CLEANUP_DISK_SPACE_TITLE, "", suppressHistory) : base(host.Connection, Messages.ACTION_CLEANUP_DISK_SPACE_TITLE, "", suppressHistory)
{ {
if (host == null)
throw new ArgumentNullException("host");
Host = host; Host = host;
this.excludedPatch = excludedPatch; this.excludedPatch = excludedPatch;
} }

View File

@ -81,8 +81,6 @@ namespace XenAdmin.Actions
public GetDiskSpaceRequirementsAction(Host host, string updateName, long size, bool suppressHistory) public GetDiskSpaceRequirementsAction(Host host, string updateName, long size, bool suppressHistory)
: base(host.Connection, Messages.ACTION_GET_DISK_SPACE_REQUIREMENTS_TITLE, suppressHistory) : base(host.Connection, Messages.ACTION_GET_DISK_SPACE_REQUIREMENTS_TITLE, suppressHistory)
{ {
if (host == null)
throw new ArgumentNullException("host");
Host = host; Host = host;
this.updateName = updateName; this.updateName = updateName;
updateSize = size; updateSize = size;

View File

@ -43,8 +43,6 @@ namespace XenAdmin.Actions
: base(pool.Connection, string.Format(Messages.UPDATES_WIZARD_REMOVING_UPDATE, patch.Name(), pool.Name()), suppressHistory) : base(pool.Connection, string.Format(Messages.UPDATES_WIZARD_REMOVING_UPDATE, patch.Name(), pool.Name()), suppressHistory)
{ {
this.patch = patch; this.patch = patch;
if (patch == null)
throw new ArgumentNullException("patch");
#region RBAC Dependencies #region RBAC Dependencies
ApiMethodsToRoleCheck.Add("pool_patch.pool_clean"); ApiMethodsToRoleCheck.Add("pool_patch.pool_clean");

View File

@ -55,10 +55,8 @@ namespace XenAdmin.Actions
public SrRepairAction(IXenConnection connection, SR sr,bool isSharedAction) public SrRepairAction(IXenConnection connection, SR sr,bool isSharedAction)
: base(connection, isSharedAction ? string.Format(Messages.ACTION_SR_SHARING, sr.NameWithoutHost()) : string.Format(Messages.ACTION_SR_REPAIRING, sr.NameWithoutHost())) : base(connection, isSharedAction ? string.Format(Messages.ACTION_SR_SHARING, sr.NameWithoutHost()) : string.Format(Messages.ACTION_SR_REPAIRING, sr.NameWithoutHost()))
{ {
if (sr == null)
throw new ArgumentNullException("sr");
this.isSharedAction = isSharedAction; this.isSharedAction = isSharedAction;
this.SR = sr; SR = sr;
#region RBAC Dependencies #region RBAC Dependencies
ApiMethodsToRoleCheck.Add("pbd.plug"); ApiMethodsToRoleCheck.Add("pbd.plug");

View File

@ -44,16 +44,14 @@ namespace XenAdmin.Actions
private readonly VDI vdi; private readonly VDI vdi;
public MigrateVirtualDiskAction(IXenConnection connection, VDI vdi, SR sr) public MigrateVirtualDiskAction(IXenConnection connection, VDI vdi, SR sr)
: base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(sr))) : base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(connection.Resolve(vdi.SR)), Helpers.GetName(sr)))
{ {
Description = Messages.ACTION_PREPARING;
this.vdi = vdi; this.vdi = vdi;
SR = sr; SR = sr;
} }
protected override void Run() protected override void Run()
{ {
Description = string.Format(Messages.ACTION_MOVING_VDI, Helpers.GetName(vdi));
RelatedTask = VDI.async_pool_migrate(Session, vdi.opaque_ref, SR.opaque_ref, new Dictionary<string, string>()); RelatedTask = VDI.async_pool_migrate(Session, vdi.opaque_ref, SR.opaque_ref, new Dictionary<string, string>());
PollToCompletion(); PollToCompletion();
Description = Messages.MOVED; Description = Messages.MOVED;

View File

@ -44,8 +44,8 @@ namespace XenAdmin.Actions
private VDI vdi; private VDI vdi;
public MoveVirtualDiskAction(IXenConnection connection, XenAPI.VDI vdi, SR sr) public MoveVirtualDiskAction(IXenConnection connection, VDI vdi, SR sr)
: base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(sr))) : base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(connection.Resolve(vdi.SR)), Helpers.GetName(sr)))
{ {
this.vdi = vdi; this.vdi = vdi;
SR = sr; SR = sr;
@ -61,7 +61,6 @@ namespace XenAdmin.Actions
protected override void Run() protected override void Run()
{ {
Description = string.Format(Messages.ACTION_MOVING_VDI, Helpers.GetName(vdi));
PercentComplete = 10; PercentComplete = 10;
log.DebugFormat("Moving VDI '{0}'", Helpers.GetName(vdi)); log.DebugFormat("Moving VDI '{0}'", Helpers.GetName(vdi));
RelatedTask = VDI.async_copy(Session, vdi.opaque_ref, SR.opaque_ref); RelatedTask = VDI.async_copy(Session, vdi.opaque_ref, SR.opaque_ref);

View File

@ -72,9 +72,10 @@ namespace XenAdmin.Actions
public ImportVmAction(IXenConnection connection, Host affinity, string filename, SR sr, public ImportVmAction(IXenConnection connection, Host affinity, string filename, SR sr,
Action<VM, bool> warningDelegate, Action<VMStartAbstractAction, Failure> failureDiagnosisDelegate) Action<VM, bool> warningDelegate, Action<VMStartAbstractAction, Failure> failureDiagnosisDelegate)
: base(connection, string.Format(Messages.IMPORTVM_TITLE, filename, Helpers.GetName(connection)), Messages.IMPORTVM_PREP) : base(connection, "")
{ {
Pool = Helpers.GetPoolOfOne(connection); Description = Messages.IMPORTVM_PREP;
Pool = Helpers.GetPoolOfOne(connection);
m_affinity = affinity; m_affinity = affinity;
Host = affinity ?? connection.Resolve(Pool.master); Host = affinity ?? connection.Resolve(Pool.master);
SR = sr; SR = sr;
@ -94,7 +95,9 @@ namespace XenAdmin.Actions
ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList); ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);
#endregion #endregion
}
Title = string.Format(Messages.IMPORTVM_TITLE, filename, Host.NameWithLocation());
}
protected override void Run() protected override void Run()
{ {

View File

@ -37,18 +37,17 @@ namespace XenAdmin.Actions.VMActions
{ {
public class VMCloneAction : AsyncAction public class VMCloneAction : AsyncAction
{ {
private readonly string _cloneName;
private readonly string _cloneDescription;
protected string _cloneName;
protected string _cloneDescription;
public VMCloneAction(VM vm, string name, string description) public VMCloneAction(VM vm, string name, string description)
: base(vm.Connection, string.Format(Messages.CREATEVM_CLONE, name, vm.Name())) : base(vm.Connection, string.Format(Messages.CREATEVM_CLONE, name, vm.NameWithLocation()))
{ {
this.Description = Messages.ACTION_PREPARING; VM = vm;
this.VM = vm; Host = vm.Home();
this.Host = vm.Home(); Pool = Helpers.GetPool(vm.Connection);
this.Pool = Core.Helpers.GetPool(vm.Connection);
if (vm.is_a_template) if (vm.is_a_template)
this.Template = vm; Template = vm;
_cloneName = name; _cloneName = name;
_cloneDescription = description; _cloneDescription = description;
@ -68,17 +67,14 @@ namespace XenAdmin.Actions.VMActions
protected override void Run() protected override void Run()
{ {
this.Description = Messages.ACTION_TEMPLATE_CLONING; RelatedTask = VM.async_clone(Session, VM.opaque_ref, _cloneName);
RelatedTask = XenAPI.VM.async_clone(Session, VM.opaque_ref, _cloneName);
PollToCompletion(); PollToCompletion();
{
VM created = Connection.WaitForCache(new XenRef<VM>(Result)); VM created = Connection.WaitForCache(new XenRef<VM>(Result));
XenAPI.VM.set_name_description(Session, created.opaque_ref, _cloneDescription); VM.set_name_description(Session, created.opaque_ref, _cloneDescription);
Result = created.opaque_ref; Result = created.opaque_ref;
}
this.Description = Messages.ACTION_TEMPLATE_CLONED; Description = Messages.ACTION_TEMPLATE_CLONED;
} }
} }
} }

View File

@ -41,16 +41,15 @@ namespace XenAdmin.Actions.VMActions
private string _namedescription; private string _namedescription;
public VMCopyAction(VM vm, Host host, SR sr, string nameLabel, string description) public VMCopyAction(VM vm, Host host, SR sr, string nameLabel, string description)
: base(vm.Connection, string.Format(Messages.ACTION_VM_COPYING_TITLE, vm.Name(), nameLabel, sr.NameWithoutHost())) : base(vm.Connection, string.Format(Messages.ACTION_VM_COPYING_TITLE, vm.NameWithLocation(), nameLabel, sr.NameWithLocation()))
{ {
this.Description = Messages.ACTION_PREPARING; VM = vm;
this.VM = vm; Host = host;
this.Host = host; Pool = Core.Helpers.GetPool(vm.Connection);
this.Pool = Core.Helpers.GetPool(vm.Connection); SR = sr;
this.SR = sr;
_nameLabel = nameLabel; _nameLabel = nameLabel;
if (vm.is_a_template) if (vm.is_a_template)
this.Template = vm; Template = vm;
_namedescription = description; _namedescription = description;
ApiMethodsToRoleCheck.AddRange(StaticRBACDependencies); ApiMethodsToRoleCheck.AddRange(StaticRBACDependencies);
@ -69,25 +68,21 @@ namespace XenAdmin.Actions.VMActions
protected override void Run() protected override void Run()
{ {
RelatedTask = VM.async_copy(Session, VM.opaque_ref, _nameLabel, SR.opaque_ref);
this.Description = Messages.ACTION_VM_COPYING;
RelatedTask = XenAPI.VM.async_copy(Session, VM.opaque_ref, _nameLabel, this.SR.opaque_ref);
try try
{ {
PollToCompletion(); PollToCompletion();
} }
catch (CancelledException) catch (CancelledException)
{ {
this.Description = string.Format(Messages.COPY_TO_SHARED_CANCELLED, VM.Name()); Description = string.Format(Messages.COPY_TO_SHARED_CANCELLED, VM.NameWithLocation());
throw; throw;
} }
{ {
VM created = Connection.WaitForCache(new XenRef<VM>(Result)); VM created = Connection.WaitForCache(new XenRef<VM>(Result));
XenAPI.VM.set_name_description(Session, created.opaque_ref, _namedescription); VM.set_name_description(Session, created.opaque_ref, _namedescription);
} }
this.Description = Messages.ACTION_VM_COPIED; Description = Messages.ACTION_VM_COPIED;
} }
} }
} }

View File

@ -55,7 +55,6 @@ namespace XenAdmin.Actions.VMActions
: base(vm.Connection, GetTitle(vm, destinationHost, copy)) : base(vm.Connection, GetTitle(vm, destinationHost, copy))
{ {
Session = vm.Connection.Session; Session = vm.Connection.Session;
Description = Messages.ACTION_PREPARING;
VM = vm; VM = vm;
Host = destinationHost; Host = destinationHost;
Pool = Helpers.GetPool(vm.Connection); Pool = Helpers.GetPool(vm.Connection);
@ -80,18 +79,20 @@ namespace XenAdmin.Actions.VMActions
public static string GetTitle(VM vm, Host toHost, bool copy) public static string GetTitle(VM vm, Host toHost, bool copy)
{ {
if (copy) if (copy)
return string.Format(Messages.ACTION_VM_CROSS_POOL_COPY_TITLE, vm.Name(), toHost.Name()); return string.Format(Messages.ACTION_VM_CROSS_POOL_COPY_TITLE,
vm.NameWithLocation(),
Helpers.GetPool(vm.Connection)?.Name() ?? vm.Connection.Name,
toHost.NameWithLocation());
Host residentOn = vm.Connection.Resolve(vm.resident_on); Host residentOn = vm.Connection.Resolve(vm.resident_on);
return residentOn == null return residentOn == null
? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.Name(), toHost.Name()) ? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.NameWithLocation(), toHost.NameWithLocation())
: string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name(), Helpers.GetName(residentOn), toHost.Name()); : string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name(), residentOn.NameWithLocation(), toHost.NameWithLocation());
} }
protected override void Run() protected override void Run()
{ {
Description = copy ? Messages.ACTION_VM_COPYING: Messages.ACTION_VM_MIGRATING;
try try
{ {
PercentComplete = 0; PercentComplete = 0;
@ -114,7 +115,7 @@ namespace XenAdmin.Actions.VMActions
Description = string.Format(copy Description = string.Format(copy
? Messages.ACTION_VM_CROSS_POOL_COPY_CANCELLED ? Messages.ACTION_VM_CROSS_POOL_COPY_CANCELLED
: Messages.ACTION_VM_MIGRATE_CANCELLED, : Messages.ACTION_VM_MIGRATE_CANCELLED,
VM.Name()); VM.NameWithLocation());
throw; throw;
} }
catch (Failure ex) catch (Failure ex)

View File

@ -40,27 +40,22 @@ namespace XenAdmin.Actions.VMActions
{ {
public VMMigrateAction(VM vm, Host destinationHost) public VMMigrateAction(VM vm, Host destinationHost)
: base(vm.Connection, GetTitle(vm, destinationHost)) : base(vm.Connection, "")
{ {
this.Description = Messages.ACTION_PREPARING; VM = vm;
this.VM = vm; Host = destinationHost;
this.Host = destinationHost; Pool = Helpers.GetPool(vm.Connection);
this.Pool = Core.Helpers.GetPool(vm.Connection);
}
private static string GetTitle(VM vm, Host toHost) var residentOn = vm.Connection.Resolve(vm.resident_on);
{
Host residentOn = vm.Connection.Resolve(vm.resident_on); Title = residentOn == null
? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.NameWithLocation(), Host.NameWithLocation())
return residentOn == null : string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name(), residentOn.NameWithLocation(), Host.NameWithLocation());
? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.Name(), toHost.Name())
: string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name(), Helpers.GetName(residentOn), toHost.Name());
} }
protected override void Run() protected override void Run()
{ {
this.Description = Messages.ACTION_VM_MIGRATING; RelatedTask = VM.async_live_migrate(Session, VM.opaque_ref, Host.opaque_ref);
RelatedTask = XenAPI.VM.async_live_migrate(Session, VM.opaque_ref, Host.opaque_ref);
try try
{ {
PollToCompletion(); PollToCompletion();
@ -68,17 +63,15 @@ namespace XenAdmin.Actions.VMActions
catch (Failure f) catch (Failure f)
{ {
if (f.ErrorDescription.Count >= 5 && f.ErrorDescription[0] == "VM_MIGRATE_FAILED" if (f.ErrorDescription.Count >= 5 && f.ErrorDescription[0] == "VM_MIGRATE_FAILED"
&& f.ErrorDescription[4].Contains("VDI_MISSING")) && f.ErrorDescription[4].Contains("VDI_MISSING"))
{ {
throw new Exception(Messages.MIGRATE_EJECT_TOOLS_ON_UPGRADE); throw new Exception(Messages.MIGRATE_EJECT_TOOLS_ON_UPGRADE);
} }
else
{ throw;
throw;
}
} }
this.Description = Messages.ACTION_VM_MIGRATED; Description = Messages.ACTION_VM_MIGRATED;
} }
} }
} }

View File

@ -45,40 +45,44 @@ namespace XenAdmin.Actions.VMActions
private Dictionary<string, SR> _storageMapping; private Dictionary<string, SR> _storageMapping;
public VMMoveAction(VM vm, Dictionary<string, SR> storageMapping, Host host) public VMMoveAction(VM vm, Dictionary<string, SR> storageMapping, Host host)
: base(vm.Connection, string.Format(Messages.ACTION_VM_MOVING, vm.Name())) : base(vm.Connection, "")
{ {
this.VM = vm; VM = vm;
this.Host = host; Host = host;
this.Pool = Helpers.GetPool(vm.Connection); Pool = Helpers.GetPool(vm.Connection);
if (vm.is_a_template) if (vm.is_a_template)
this.Template = vm; Template = vm;
_storageMapping = storageMapping; _storageMapping = storageMapping;
SR = _storageMapping.Values.FirstOrDefault(); SR = _storageMapping.Values.FirstOrDefault();
PopulateApiMethodsToRoleCheck(); PopulateApiMethodsToRoleCheck();
var sourceHost = vm.Home();
if (sourceHost != null && !sourceHost.Equals(host))
Title = string.Format(Messages.ACTION_VM_MOVING_HOST, vm.Name(), sourceHost, host.Name());
else if (storageMapping.Count == 1)
Title = string.Format(Messages.ACTION_VM_MOVING_SR, vm.Name(), storageMapping.Values.ElementAt(0).Name());
else
Title = string.Format(Messages.ACTION_VM_MOVING, vm.Name());
} }
public VMMoveAction(VM vm, SR sr, Host host, string namelabel) public VMMoveAction(VM vm, SR sr, Host host)
: base(vm.Connection, string.Format(Messages.ACTION_VM_MOVING_TITLE, vm.Name(), namelabel, sr.NameWithoutHost())) : this(vm, GetStorageMapping(vm, sr), host)
{ {
this.VM = vm; }
this.Host = host;
this.Pool = Helpers.GetPool(vm.Connection);
this.SR = sr;
if (vm.is_a_template)
this.Template = vm;
// create a storage map where all VDIs are mapped to the same SR private static Dictionary<string, SR> GetStorageMapping(VM vm, SR sr)
_storageMapping = new Dictionary<string, SR>(); {
var storageMapping = new Dictionary<string, SR>();
foreach (var vbdRef in vm.VBDs) foreach (var vbdRef in vm.VBDs)
{ {
var vbd = vm.Connection.Resolve(vbdRef); var vbd = vm.Connection.Resolve(vbdRef);
if (vbd != null) if (vbd != null)
_storageMapping.Add(vbd.VDI.opaque_ref, sr); storageMapping.Add(vbd.VDI.opaque_ref, sr);
} }
return storageMapping;
PopulateApiMethodsToRoleCheck();
} }
#region RBAC Dependencies #region RBAC Dependencies
@ -96,8 +100,6 @@ namespace XenAdmin.Actions.VMActions
protected override void Run() protected override void Run()
{ {
Description = Messages.ACTION_PREPARING;
// move the progress bar above 0, it's more reassuring to see than a blank bar as we copy the first disk // move the progress bar above 0, it's more reassuring to see than a blank bar as we copy the first disk
PercentComplete += 10; PercentComplete += 10;
int halfstep = 90 / (VM.VBDs.Count * 2); int halfstep = 90 / (VM.VBDs.Count * 2);
@ -126,7 +128,7 @@ namespace XenAdmin.Actions.VMActions
continue; continue;
Description = string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Description = string.Format(Messages.ACTION_MOVING_VDI_TO_SR,
Helpers.GetName(curVdi), Helpers.GetName(sr)); Helpers.GetName(curVdi), Helpers.GetName(Connection.Resolve(curVdi.SR)), Helpers.GetName(sr));
RelatedTask = VDI.async_copy(Session, oldVBD.VDI.opaque_ref, sr.opaque_ref); RelatedTask = VDI.async_copy(Session, oldVBD.VDI.opaque_ref, sr.opaque_ref);
PollToCompletion(PercentComplete, PercentComplete + halfstep); PollToCompletion(PercentComplete, PercentComplete + halfstep);
@ -160,11 +162,13 @@ namespace XenAdmin.Actions.VMActions
PercentComplete += halfstep; PercentComplete += halfstep;
} }
Description = string.Empty;
if (SR != null) if (SR != null)
VM.set_suspend_SR(Session, VM.opaque_ref, SR.opaque_ref); VM.set_suspend_SR(Session, VM.opaque_ref, SR.opaque_ref);
if (exceptions.Count > 0) if (exceptions.Count > 0)
throw new Exception(Messages.ACTION_VM_MOVING_VDI_DESTROY_FAILURE); throw new Exception(string.Format(Messages.ACTION_VM_MOVING_VDI_DESTROY_FAILURE, VM.NameWithLocation()));
Description = Messages.MOVED; Description = Messages.MOVED;
} }

View File

@ -287,24 +287,20 @@ namespace XenAdmin.Alerts
public static PerfmonDefinition[] GetPerfmonDefinitions(IXenObject xo) public static PerfmonDefinition[] GetPerfmonDefinitions(IXenObject xo)
{ {
if (!(xo is VM) && !(xo is Host) && !(xo is SR)) if (!(xo is VM) && !(xo is Host) && !(xo is SR))
return new PerfmonDefinition[0]; return Array.Empty<PerfmonDefinition>();
Dictionary<string, string> other_config = Helpers.GetOtherConfig(xo); var other_config = Helpers.GetOtherConfig(xo);
if (other_config == null) if (other_config == null)
return new PerfmonDefinition[0]; return Array.Empty<PerfmonDefinition>();
if (!other_config.ContainsKey(PERFMON_KEY_NAME)) if (!other_config.ContainsKey(PERFMON_KEY_NAME))
return new PerfmonDefinition[0]; return Array.Empty<PerfmonDefinition>();
string perfmonConfigXML = other_config[PERFMON_KEY_NAME]; var perfmonConfigXML = other_config[PERFMON_KEY_NAME];
if (perfmonConfigXML == null) if (perfmonConfigXML == null)
return new PerfmonDefinition[0]; return Array.Empty<PerfmonDefinition>();
perfmonConfigXML.Trim(); return string.IsNullOrWhiteSpace(perfmonConfigXML) ? Array.Empty<PerfmonDefinition>() : GetPerfmonDefinitions(perfmonConfigXML);
if (String.IsNullOrEmpty(perfmonConfigXML))
return new PerfmonDefinition[0];
return GetPerfmonDefinitions(perfmonConfigXML);
} }
/// <summary> /// <summary>

View File

@ -213,74 +213,53 @@ namespace XenAdmin.Alerts
public static string GetMailDestination(IXenConnection connection) public static string GetMailDestination(IXenConnection connection)
{ {
Pool pool = Helpers.GetPoolOfOne(connection); var pool = Helpers.GetPoolOfOne(connection);
if (pool == null) if (pool == null)
return null; return null;
Dictionary<String, String> other_config = Helpers.GetOtherConfig(pool); var otherConfig = Helpers.GetOtherConfig(pool);
if (other_config == null) if (otherConfig == null)
return null; return null;
if (!other_config.ContainsKey(MAIL_DESTINATION_KEY_NAME)) if (!otherConfig.ContainsKey(MAIL_DESTINATION_KEY_NAME))
return null; return null;
String mailAddress = other_config[MAIL_DESTINATION_KEY_NAME]; var mailAddress = otherConfig[MAIL_DESTINATION_KEY_NAME]?.Trim();
if (mailAddress == null) return string.IsNullOrEmpty(mailAddress) ? null : mailAddress;
return null;
mailAddress.Trim();
if (String.IsNullOrEmpty(mailAddress))
return null;
return mailAddress;
} }
public static string GetSmtpMailHub(IXenConnection connection) public static string GetSmtpMailHub(IXenConnection connection)
{ {
Pool pool = Helpers.GetPoolOfOne(connection); var pool = Helpers.GetPoolOfOne(connection);
if (pool == null) if (pool == null)
return null; return null;
Dictionary<String, String> other_config = Helpers.GetOtherConfig(pool); var otherConfig = Helpers.GetOtherConfig(pool);
if (other_config == null) if (otherConfig == null)
return null; return null;
if (!other_config.ContainsKey(SMTP_MAILHUB_KEY_NAME)) if (!otherConfig.ContainsKey(SMTP_MAILHUB_KEY_NAME))
return null; return null;
String mailHub = other_config[SMTP_MAILHUB_KEY_NAME]; var mailHub = otherConfig[SMTP_MAILHUB_KEY_NAME]?.Trim();
if (mailHub == null) return string.IsNullOrEmpty(mailHub) ? null : mailHub;
return null;
mailHub.Trim();
if (String.IsNullOrEmpty(mailHub))
return null;
return mailHub;
} }
public static string GetMailLanguageCode(IXenConnection connection) public static string GetMailLanguageCode(IXenConnection connection)
{ {
Pool pool = Helpers.GetPoolOfOne(connection); var pool = Helpers.GetPoolOfOne(connection);
if (pool == null) if (pool == null)
return null; return null;
Dictionary<String, String> other_config = Helpers.GetOtherConfig(pool); var otherConfig = Helpers.GetOtherConfig(pool);
if (other_config == null) if (otherConfig == null)
return null; return null;
if (!other_config.ContainsKey(MAIL_LANGUAGE_KEY_NAME)) if (!otherConfig.ContainsKey(MAIL_LANGUAGE_KEY_NAME))
return null; return null;
String mailLanguageCode = other_config[MAIL_LANGUAGE_KEY_NAME]; var mailLanguageCode = otherConfig[MAIL_LANGUAGE_KEY_NAME]?.Trim();
if (mailLanguageCode == null) return string.IsNullOrEmpty(mailLanguageCode) ? null : mailLanguageCode;
return null;
mailLanguageCode.Trim();
if (String.IsNullOrEmpty(mailLanguageCode))
return null;
return mailLanguageCode;
} }
public static String MailLanguageNameFromCode(String code) public static String MailLanguageNameFromCode(String code)

View File

@ -82,6 +82,8 @@ namespace XenAdmin.Core
public static readonly string ProductVersion82 = Get("PRODUCT_VERSION_8_2"); public static readonly string ProductVersion82 = Get("PRODUCT_VERSION_8_2");
public static readonly string ProductVersion821 = Get("PRODUCT_VERSION_8_2_1");
public static readonly string ProductVersionPost82 = Get("PRODUCT_VERSION_POST_8_2"); public static readonly string ProductVersionPost82 = Get("PRODUCT_VERSION_POST_8_2");
public static readonly string ProductVersionText = Get("PRODUCT_VERSION_TEXT"); public static readonly string ProductVersionText = Get("PRODUCT_VERSION_TEXT");

View File

@ -68,36 +68,25 @@ namespace XenAdmin.CustomFields
private static List<CustomFieldDefinition> GetCustomFieldsFromGuiConfig(IXenConnection connection) private static List<CustomFieldDefinition> GetCustomFieldsFromGuiConfig(IXenConnection connection)
{ {
Pool pool = Helpers.GetPoolOfOne(connection); var pool = Helpers.GetPoolOfOne(connection);
if (pool == null) if (pool == null)
{ {
return new List<CustomFieldDefinition>(); return new List<CustomFieldDefinition>();
} }
Dictionary<String, String> other_config = Helpers.GetGuiConfig(pool); var otherConfig = Helpers.GetGuiConfig(pool);
if (other_config == null) if (otherConfig == null)
{ {
return new List<CustomFieldDefinition>(); return new List<CustomFieldDefinition>();
} }
if (!other_config.ContainsKey(CustomFieldsManager.CUSTOM_FIELD_BASE_KEY)) if (!otherConfig.ContainsKey(CustomFieldsManager.CUSTOM_FIELD_BASE_KEY))
{ {
return new List<CustomFieldDefinition>(); return new List<CustomFieldDefinition>();
} }
String customFields = other_config[CustomFieldsManager.CUSTOM_FIELD_BASE_KEY]; var customFields = otherConfig[CustomFieldsManager.CUSTOM_FIELD_BASE_KEY]?.Trim();
if (customFields == null) return string.IsNullOrEmpty(customFields) ? new List<CustomFieldDefinition>() : GetCustomFieldDefinitions(customFields);
{
return new List<CustomFieldDefinition>();
}
customFields.Trim();
if (String.IsNullOrEmpty(customFields))
{
return new List<CustomFieldDefinition>();
}
return GetCustomFieldDefinitions(customFields);
} }
public List<CustomFieldDefinition> GetCustomFields() public List<CustomFieldDefinition> GetCustomFields()

View File

@ -44,6 +44,11 @@ namespace XenAdmin.Mappings
} }
public string VmNameLabel { get; set; } public string VmNameLabel { get; set; }
public ulong Capacity { get; set; }
public ulong CpuCount { get; set; }
public ulong Memory { get; set; }
public string BootParams { get; set; }
public string PlatformSettings { get; set; }
/// <summary> /// <summary>
/// OpaqueRef of the target pool or host /// OpaqueRef of the target pool or host
@ -66,5 +71,26 @@ namespace XenAdmin.Mappings
/// Keyed on the id in the ovf file /// Keyed on the id in the ovf file
/// </summary> /// </summary>
public Dictionary<string, XenAPI.Network> Networks { get; set; } public Dictionary<string, XenAPI.Network> Networks { get; set; }
}
public override bool Equals(object obj)
{
return obj is VmMapping other &&
VmNameLabel == other.VmNameLabel &&
Capacity == other.Capacity &&
CpuCount == other.CpuCount &&
Memory == other.Memory &&
BootParams == other.BootParams &&
PlatformSettings == other.PlatformSettings &&
XenRef == other.XenRef &&
TargetName == other.TargetName &&
Storage == other.Storage &&
StorageToAttach == other.StorageToAttach &&
Networks == other.Networks;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
} }

View File

@ -1593,16 +1593,7 @@ namespace XenAdmin {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Moving virtual disk &apos;{0}&apos;.... /// Looks up a localized string similar to Moving Virtual Disk &apos;{0}&apos; from SR &apos;{1}&apos; to SR &apos;{2}&apos;.
/// </summary>
public static string ACTION_MOVING_VDI {
get {
return ResourceManager.GetString("ACTION_MOVING_VDI", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Moving Virtual Disk &apos;{0}&apos; to SR &apos;{1}&apos;.
/// </summary> /// </summary>
public static string ACTION_MOVING_VDI_TO_SR { public static string ACTION_MOVING_VDI_TO_SR {
get { get {
@ -2663,15 +2654,6 @@ namespace XenAdmin {
} }
} }
/// <summary>
/// Looks up a localized string similar to Duplicating.
/// </summary>
public static string ACTION_TEMPLATE_CLONING {
get {
return ResourceManager.GetString("ACTION_TEMPLATE_CLONING", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Restart toolstack on &apos;{0}&apos;. /// Looks up a localized string similar to Restart toolstack on &apos;{0}&apos;.
/// </summary> /// </summary>
@ -3114,7 +3096,7 @@ namespace XenAdmin {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Copying VM &apos;{0}&apos; to &apos;{1}&apos;. /// Looks up a localized string similar to Copying VM &apos;{0}&apos; from &apos;{1}&apos; to &apos;{2}&apos;.
/// </summary> /// </summary>
public static string ACTION_VM_CROSS_POOL_COPY_TITLE { public static string ACTION_VM_CROSS_POOL_COPY_TITLE {
get { get {
@ -3231,11 +3213,20 @@ namespace XenAdmin {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Moving VM &apos;{0}&apos; to &apos;{1}&apos; on SR &apos;{2}&apos;. /// Looks up a localized string similar to Moving VM &apos;{0}&apos; from server &apos;{1}&apos; to server &apos;{2}&apos;.
/// </summary> /// </summary>
public static string ACTION_VM_MOVING_TITLE { public static string ACTION_VM_MOVING_HOST {
get { get {
return ResourceManager.GetString("ACTION_VM_MOVING_TITLE", resourceCulture); return ResourceManager.GetString("ACTION_VM_MOVING_HOST", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Moving VM &apos;{0}&apos; to SR &apos;{1}&apos;.
/// </summary>
public static string ACTION_VM_MOVING_SR {
get {
return ResourceManager.GetString("ACTION_VM_MOVING_SR", resourceCulture);
} }
} }
@ -15294,6 +15285,15 @@ namespace XenAdmin {
} }
} }
/// <summary>
/// Looks up a localized string similar to You cannot enable certificate verification while a rolling pool upgrade is in progress..
/// </summary>
public static string ENABLE_TLS_VERIFICATION_RPU {
get {
return ResourceManager.GetString("ENABLE_TLS_VERIFICATION_RPU", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Res&amp;ume. /// Looks up a localized string similar to Res&amp;ume.
/// </summary> /// </summary>
@ -16978,6 +16978,24 @@ namespace XenAdmin {
} }
} }
/// <summary>
/// Looks up a localized string similar to A file name cannot be a device name..
/// </summary>
public static string FILE_NAME_IS_DEVICE_NAME_ERROR_MESSAGE {
get {
return ResourceManager.GetString("FILE_NAME_IS_DEVICE_NAME_ERROR_MESSAGE", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Path section {0} matches a device name..
/// </summary>
public static string FILE_PATH_DEVICE_NAME_ERROR_MESSAGE {
get {
return ResourceManager.GetString("FILE_PATH_DEVICE_NAME_ERROR_MESSAGE", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Acrobat (PDF) file. /// Looks up a localized string similar to Acrobat (PDF) file.
/// </summary> /// </summary>
@ -20224,6 +20242,15 @@ namespace XenAdmin {
} }
} }
/// <summary>
/// Looks up a localized string similar to The following characters are invalid: {0}.
/// </summary>
public static string ILLEGAL_CHARACTER_ERROR_MESSAGE {
get {
return ResourceManager.GetString("ILLEGAL_CHARACTER_ERROR_MESSAGE", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to It is not possible to connect to the iLO service. Please review your configuration.. /// Looks up a localized string similar to It is not possible to connect to the iLO service. Please review your configuration..
/// </summary> /// </summary>
@ -30178,6 +30205,15 @@ namespace XenAdmin {
} }
} }
/// <summary>
/// Looks up a localized string similar to Path cannot be null or empty..
/// </summary>
public static string PATH_CAN_NOT_BE_NULL_ERROR_MESSAGE {
get {
return ResourceManager.GetString("PATH_CAN_NOT_BE_NULL_ERROR_MESSAGE", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Path does not exist.. /// Looks up a localized string similar to Path does not exist..
/// </summary> /// </summary>

View File

@ -629,11 +629,8 @@ This could be because the data source is not generating any data. Ensure the pre
<data name="ACTION_MIGRATING_X_VDIS_STARTED" xml:space="preserve"> <data name="ACTION_MIGRATING_X_VDIS_STARTED" xml:space="preserve">
<value>Started migrating virtual disks</value> <value>Started migrating virtual disks</value>
</data> </data>
<data name="ACTION_MOVING_VDI" xml:space="preserve">
<value>Moving virtual disk '{0}'...</value>
</data>
<data name="ACTION_MOVING_VDI_TO_SR" xml:space="preserve"> <data name="ACTION_MOVING_VDI_TO_SR" xml:space="preserve">
<value>Moving Virtual Disk '{0}' to SR '{1}'</value> <value>Moving Virtual Disk '{0}' from SR '{1}' to SR '{2}'</value>
</data> </data>
<data name="ACTION_MOVING_X_VDIS" xml:space="preserve"> <data name="ACTION_MOVING_X_VDIS" xml:space="preserve">
<value>Moving {0} virtual disks to {1}</value> <value>Moving {0} virtual disks to {1}</value>
@ -986,9 +983,6 @@ This could be because the data source is not generating any data. Ensure the pre
<data name="ACTION_TEMPLATE_CLONE_NEW_NAME" xml:space="preserve"> <data name="ACTION_TEMPLATE_CLONE_NEW_NAME" xml:space="preserve">
<value>Copy of {0}</value> <value>Copy of {0}</value>
</data> </data>
<data name="ACTION_TEMPLATE_CLONING" xml:space="preserve">
<value>Duplicating</value>
</data>
<data name="ACTION_TOOLSTACK_RESTARTED" xml:space="preserve"> <data name="ACTION_TOOLSTACK_RESTARTED" xml:space="preserve">
<value>Toolstack restarted.</value> <value>Toolstack restarted.</value>
</data> </data>
@ -1158,7 +1152,7 @@ This could be because the data source is not generating any data. Ensure the pre
<value>Copying {0} canceled</value> <value>Copying {0} canceled</value>
</data> </data>
<data name="ACTION_VM_CROSS_POOL_COPY_TITLE" xml:space="preserve"> <data name="ACTION_VM_CROSS_POOL_COPY_TITLE" xml:space="preserve">
<value>Copying VM '{0}' to '{1}'</value> <value>Copying VM '{0}' from '{1}' to '{2}'</value>
</data> </data>
<data name="ACTION_VM_DELETE_SNAPSHOTS_TITLE" xml:space="preserve"> <data name="ACTION_VM_DELETE_SNAPSHOTS_TITLE" xml:space="preserve">
<value>Deleting snapshots</value> <value>Deleting snapshots</value>
@ -1196,8 +1190,11 @@ This could be because the data source is not generating any data. Ensure the pre
<data name="ACTION_VM_MOVING" xml:space="preserve"> <data name="ACTION_VM_MOVING" xml:space="preserve">
<value>Moving VM '{0}' to new storage</value> <value>Moving VM '{0}' to new storage</value>
</data> </data>
<data name="ACTION_VM_MOVING_TITLE" xml:space="preserve"> <data name="ACTION_VM_MOVING_HOST" xml:space="preserve">
<value>Moving VM '{0}' to '{1}' on SR '{2}'</value> <value>Moving VM '{0}' from server '{1}' to server '{2}'</value>
</data>
<data name="ACTION_VM_MOVING_SR" xml:space="preserve">
<value>Moving VM '{0}' to SR '{1}'</value>
</data> </data>
<data name="ACTION_VM_MOVING_VDI_DESTROY_FAILURE" xml:space="preserve"> <data name="ACTION_VM_MOVING_VDI_DESTROY_FAILURE" xml:space="preserve">
<value>Failed to finalize moving VM '{0}' to new storage. Please see logs for details.</value> <value>Failed to finalize moving VM '{0}' to new storage. Please see logs for details.</value>
@ -5382,6 +5379,9 @@ Would you like to eject these ISOs before continuing?</value>
{1}</value> {1}</value>
</data> </data>
<data name="ENABLE_TLS_VERIFICATION_RPU" xml:space="preserve">
<value>You cannot enable certificate verification while a rolling pool upgrade is in progress.</value>
</data>
<data name="ENABLE_WLB_ELLIPSIS" xml:space="preserve"> <data name="ENABLE_WLB_ELLIPSIS" xml:space="preserve">
<value>Res&amp;ume</value> <value>Res&amp;ume</value>
</data> </data>
@ -5938,6 +5938,12 @@ Would you like to eject these ISOs before continuing?</value>
<data name="FILE_ALL" xml:space="preserve"> <data name="FILE_ALL" xml:space="preserve">
<value>All files</value> <value>All files</value>
</data> </data>
<data name="FILE_NAME_IS_DEVICE_NAME_ERROR_MESSAGE" xml:space="preserve">
<value>A file name cannot be a device name.</value>
</data>
<data name="FILE_PATH_DEVICE_NAME_ERROR_MESSAGE" xml:space="preserve">
<value>Path section {0} matches a device name.</value>
</data>
<data name="FILE_PDF" xml:space="preserve"> <data name="FILE_PDF" xml:space="preserve">
<value>Acrobat (PDF) file</value> <value>Acrobat (PDF) file</value>
</data> </data>
@ -7046,6 +7052,9 @@ This might result in failure to migrate VMs to this server during the RPU or to
<data name="IGNORE_BUTTON_LABEL" xml:space="preserve"> <data name="IGNORE_BUTTON_LABEL" xml:space="preserve">
<value>&amp;Ignore</value> <value>&amp;Ignore</value>
</data> </data>
<data name="ILLEGAL_CHARACTER_ERROR_MESSAGE" xml:space="preserve">
<value>The following characters are invalid: {0}</value>
</data>
<data name="ILO_CONNECTION_ERROR" xml:space="preserve"> <data name="ILO_CONNECTION_ERROR" xml:space="preserve">
<value>It is not possible to connect to the iLO service. Please review your configuration.</value> <value>It is not possible to connect to the iLO service. Please review your configuration.</value>
</data> </data>
@ -10465,6 +10474,9 @@ File not found</value>
<data name="PATCH_UPLOADED" xml:space="preserve"> <data name="PATCH_UPLOADED" xml:space="preserve">
<value>Update uploaded to server '{0}' </value> <value>Update uploaded to server '{0}' </value>
</data> </data>
<data name="PATH_CAN_NOT_BE_NULL_ERROR_MESSAGE" xml:space="preserve">
<value>Path cannot be null or empty.</value>
</data>
<data name="PATH_DOES_NOT_EXIST" xml:space="preserve"> <data name="PATH_DOES_NOT_EXIST" xml:space="preserve">
<value>Path does not exist.</value> <value>Path does not exist.</value>
</data> </data>

View File

@ -41,6 +41,7 @@ using XenAdmin.Core;
using XenAPI; using XenAPI;
using XenCenterLib; using XenCenterLib;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Xml.Serialization; using System.Xml.Serialization;
using XenAdmin.ServerDBs; using XenAdmin.ServerDBs;
@ -1757,12 +1758,14 @@ namespace XenAdmin.Network
private Pool getAPool(ICache objects, out string opaqueref) private Pool getAPool(ICache objects, out string opaqueref)
{ {
foreach (Pool pool in objects.Pools) var pools = objects.Pools;
if (pools.Length > 0)
{ {
var pool = pools.First();
opaqueref = pool.opaque_ref; opaqueref = pool.opaque_ref;
return pool; return pool;
} }
System.Diagnostics.Trace.Assert(false); Trace.Assert(false);
opaqueref = null; opaqueref = null;
return null; return null;
} }

135
XenModel/PathValidator.cs Normal file
View File

@ -0,0 +1,135 @@
/* 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.IO;
using System.Linq;
using XenAdmin;
namespace XenModel
{
public class PathValidator
{
private static readonly char[] m_invalidFileCharList = Path.GetInvalidFileNameChars();
private static readonly string[] m_deviceNames = {
"CON", "PRN", "AUX", "NUL",
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
};
private static string IllegalFileCharMsg {
get {
return string.Format(Messages.ILLEGAL_CHARACTER_ERROR_MESSAGE, string.Join(" ", m_invalidFileCharList.Where(c => !char.IsControl(c))));
}
}
private static string IllegalPathCharMsg
{
get
{
return string.Format(Messages.ILLEGAL_CHARACTER_ERROR_MESSAGE, string.Join(" ", m_invalidFileCharList.Where(c => !char.IsControl(c) && c != '\\')));
}
}
public static bool IsFileNameValid(string filename, out string invalidNameMsg)
{
invalidNameMsg = string.Empty;
if (filename.IndexOfAny(m_invalidFileCharList) > -1)
{
invalidNameMsg = IllegalFileCharMsg;
return false;
}
foreach (var name in m_deviceNames)
{
if (name == filename.ToUpper())
{
invalidNameMsg = Messages.FILE_NAME_IS_DEVICE_NAME_ERROR_MESSAGE;
return false;
}
}
return true;
}
public static bool IsPathValid(string path, out string invalidPathMsg)
{
invalidPathMsg = string.Empty;
if (string.IsNullOrEmpty(path))
{
invalidPathMsg = Messages.PATH_CAN_NOT_BE_NULL_ERROR_MESSAGE;
return false;
}
try
{
if (Path.IsPathRooted(path))
{
path = path[0] == '\\' && path.Length == 1
? path.Substring(1)
: path.Substring(2);
}
}
catch (ArgumentException)
{
//path contains some of the characters from Path.GetInvalidPathChars()
invalidPathMsg = IllegalPathCharMsg;
return false;
}
var parts = path.Split('\\');
if (parts.Length > 0)
{
foreach (var part in parts)
{
if (part.IndexOfAny(m_invalidFileCharList) > -1)
{
invalidPathMsg = IllegalPathCharMsg;
return false;
}
foreach (var name in m_deviceNames)
{
if (name == part.ToUpper())
{
invalidPathMsg = string.Format(Messages.FILE_PATH_DEVICE_NAME_ERROR_MESSAGE, name);
return false;
}
}
}
}
return true;
}
}
}

View File

@ -34,6 +34,7 @@ using System.Collections.Generic;
using XenAPI; using XenAPI;
using System.Collections; using System.Collections;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Threading; using System.Threading;
namespace XenAdmin.ServerDBs.FakeAPI namespace XenAdmin.ServerDBs.FakeAPI
@ -107,14 +108,14 @@ namespace XenAdmin.ServerDBs.FakeAPI
public Response<string> reboot(string session, string opaque_ref) public Response<string> reboot(string session, string opaque_ref)
{ {
string metrics_ref = (string)proxy.db.GetValue("host", opaque_ref, "metrics"); var metrics_ref = (string)proxy.db.GetValue("host", opaque_ref, "metrics");
proxy.EditObject_(DbProxy.EditTypes.Replace, "host_metrics", metrics_ref, "live", false); proxy.EditObject_(DbProxy.EditTypes.Replace, "host_metrics", metrics_ref, "live", false);
string coordinator_ref = ""; var coordinator_ref = string.Empty;
foreach (string pool in proxy.db.Tables["pool"].Rows.Keys) var pools = proxy.db.Tables["pool"].Rows.Keys;
if (pools.Count > 0)
{ {
coordinator_ref = (string)proxy.db.GetValue("pool", pool, "master"); coordinator_ref = (string)proxy.db.GetValue("pool", pools.First(), "master");
break;
} }
if (opaque_ref == coordinator_ref) if (opaque_ref == coordinator_ref)

View File

@ -212,13 +212,7 @@ namespace XenAdmin.Core
/// </summary> /// </summary>
public static Pool GetPoolOfOne(IXenConnection connection) public static Pool GetPoolOfOne(IXenConnection connection)
{ {
if (connection == null) return connection?.Cache.Pools.FirstOrDefault();
return null;
foreach (Pool pool in connection.Cache.Pools)
return pool;
return null;
} }
/// <summary> /// <summary>
@ -497,6 +491,12 @@ namespace XenAdmin.Core
return platformVersion != null && productVersionCompare(platformVersion, "3.2.50") >= 0; return platformVersion != null && productVersionCompare(platformVersion, "3.2.50") >= 0;
} }
/// <param name="conn">May be null, in which case true is returned.</param>
public static bool YangtzeOrGreater(IXenConnection conn)
{
return conn == null || YangtzeOrGreater(Helpers.GetCoordinator(conn));
}
/// <param name="host">May be null, in which case true is returned.</param> /// <param name="host">May be null, in which case true is returned.</param>
public static bool YangtzeOrGreater(Host host) public static bool YangtzeOrGreater(Host host)
{ {
@ -1545,11 +1545,9 @@ namespace XenAdmin.Core
public static string HostnameFromLocation(string p) public static string HostnameFromLocation(string p)
{ {
foreach (Match m in HostnameOrIpRegex.Matches(p)) var matches = HostnameOrIpRegex.Matches(p);
{ // we only want the hostname or ip which should be the first match
return m.Value; // we only want the hostname or ip which should be the first match return matches.Count > 0 ? matches[0].Value : string.Empty;
}
return "";
} }
/// <summary> /// <summary>

Some files were not shown because too many files have changed in this diff Show More