xenadmin/XenModel/Actions/DelegatedAsyncAction.cs
Konstantina Chremmou d93e40065a Various fixes on the EvacuateHostDialog (includes CA-292642, CA-284126, CP-34862).
- CP-34862: Do not allow nomination of new master if a pool secret rotation or
  other pool operations are in progress.
- CA-292642: Fixed button enablement after resolving VM problem.
- CA-284126: Added button to rescan running VMs on the server.
- Removed annoying, focus stealing, modal action progress dialog. When scanning
  for VMs show a spinner on the control instead.
- Fixed crash when the host combobox was updated due to cache changes.
- Logging in an elevated session was happening on the UI thread.
- Show the role elevation dialog before launching the host evacuation dialog or
  we end up with showing the user an unpopulated control.
- Stop deriving from animated progress dialog because it makes it difficult to
  get the resizing right when adding more controls.
- Stop using the progress bar for the VM solution actions; rely simply on the
  action's description and the VM's icon in the gridView.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
2020-10-06 11:27:32 +01:00

95 lines
4.0 KiB
C#

/* Copyright (c) Citrix Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
using XenAdmin.Core;
using XenAdmin.Network;
using XenAPI;
namespace XenAdmin.Actions
{
/// <summary>
/// An action which just runs a delegate.
/// It is bad style to use this for more than the very simplest delegate: preferably just a single API call.
/// Anything more complicated should be turned into a proper action of its own.
/// </summary>
public class DelegatedAsyncAction : AsyncAction
{
private readonly Action<Session> invoker;
private readonly Func<Session, object> function;
private readonly string endDescription;
//TODO: this should move to AsyncAction and replace Result really
public object ResultObject { get; private set; }
public DelegatedAsyncAction(IXenConnection connection, string title, string startDescription, string endDescription,
Action<Session> invoker, params string[] rbacMethods)
: this(connection, title, startDescription, endDescription, invoker, false, rbacMethods)
{
}
public DelegatedAsyncAction(IXenConnection connection, string title, string startDescription, string endDescription,
Action<Session> invoker, bool suppressHistory, params string[] rbacMethods)
: base(connection, title, startDescription, suppressHistory)
{
this.endDescription = endDescription;
this.invoker = invoker;
ApiMethodsToRoleCheck = new RbacMethodList(rbacMethods);
}
public DelegatedAsyncAction(IXenConnection connection, string title, string startDescription, string endDescription,
Func<Session, object> function, params string[] rbacMethods)
: this(connection, title, startDescription, endDescription, function, false, rbacMethods)
{
}
public DelegatedAsyncAction(IXenConnection connection, string title, string startDescription, string endDescription,
Func<Session, object> function, bool suppressHistory, params string[] rbacMethods)
: base(connection, title, startDescription, suppressHistory)
{
this.endDescription = endDescription;
this.function = function;
ApiMethodsToRoleCheck = new RbacMethodList(rbacMethods);
}
protected override void Run()
{
if (invoker != null)
invoker(Session);
else if (function != null)
ResultObject = function(Session);
Description = endDescription;
}
}
}