xenadmin/XenModel/ServerDBs/DbProxy.cs

692 lines
26 KiB
C#
Raw Normal View History

/* Copyright (c) Cloud Software Group, Inc.
*
* 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;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using XenAPI;
using XenAdmin.Network;
using XenAdmin.ServerDBs.FakeAPI;
using XenAdmin.Core;
namespace XenAdmin.ServerDBs
{
public class DbProxy : IInvocationHandler
{
private static readonly ClassGenerator generator = new ClassGenerator(typeof(Proxy));
private static readonly Type proxyType = generator.Generate();
public static readonly Proxy_Event dummyEvent = new Proxy_Event();
public static readonly Dictionary<IXenConnection, DbProxy> proxys = new Dictionary<IXenConnection, DbProxy>();
private static readonly object dicLock = new object();
public readonly Db db;
public readonly List<Proxy_Event> eventsList = new List<Proxy_Event>();
public readonly object eventsListLock = new object();
private readonly string url;
public readonly IXenConnection connection;
public volatile bool MarkToDisconnect;
/// Set this delegate to run inside the event loop.
/// Throwing an specific exception type or Failure will simulate the termination
/// of the event loop mid-loop
public Action RunInEventLoop { get; private set; }
private static readonly Dictionary<string, List<string>> callVersions = new Dictionary<string, List<string>>();
public bool IsSuperUser { get; private set; }
public void SetIsSuperUser(bool isSuperUser)
{
IsSuperUser = isSuperUser;
}
public static void RemoveAll()
{
lock (dicLock)
{
foreach (KeyValuePair<IXenConnection, DbProxy> kvp in proxys)
{
kvp.Value.db.Dispose();
kvp.Value.RunInEventLoop = delegate()
{
throw new Failure(Failure.SESSION_INVALID);
};
}
proxys.Clear();
}
}
/// <summary>
/// Initializes the <see cref="DbProxy"/> class.
/// </summary>
static DbProxy()
{
dummyEvent.class_ = "vtpm"; // This will cause XenCenter to ignore the event
}
/// <summary>
/// Generates a Proxy instance which implements <see cref="Proxy"/> for the specified <see cref="IXenConnection"/> and XML document.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="fileName">Name of the file.</param>
/// <returns></returns>
public static Proxy GetProxy(IXenConnection connection, string fileName)
{
return (Proxy)generator.CreateProxyInstance(proxyType, ProxyInstance(connection, fileName));
}
private static IInvocationHandler ProxyInstance(IXenConnection connection, string fileName)
{
lock (dicLock)
{
if (!proxys.ContainsKey(connection))
{
proxys[connection] = new DbProxy(connection, fileName);
}
return proxys[connection];
}
}
/// <summary>
/// Initializes a new instance of the <see cref="DbProxy"/> class.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="url">The http url of filename to the XenServer status report XML document to be used.</param>
public DbProxy(IXenConnection connection, string url)
{
Util.ThrowIfParameterNull(connection, "connection");
Util.ThrowIfStringParameterNullOrEmpty(url, "url");
this.url = url;
this.connection = connection;
db = new Db(connection, url);
}
CP-34231: Remove language with negative connotations (#2860) * CA-34231: Replace negative language with `block list` in code and references Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `stop` in code and references Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `freezing` in code Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run/ran` in code comments Some paramater mentions have been renamed, as they will be renamed in future commits. Excluded mentions in XenAPI/Host.cs and XenAPI/VM.cs since code is autogenerated. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # CFUValidator/CommandLineOptions/CFUCommandLineOptionManager.cs # XenAdmin/Controls/Wlb/WlbOptModeScheduler.cs # XenAdmin/Dialogs/Wlb/WorkloadReports.cs * CA-34231: Replace negative language with `run` in Command.cs Run method Used Resharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/TabPages/GeneralTabPage.cs * CA-34231: Replace negative language with `run` in Command.cs CanRun method Used Resharper rename utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in Command.cs CanRunCore method Used ReSharper rename utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/DRConfigureCommand.cs # XenAdmin/Commands/DRDryrunCommand.cs # XenAdmin/Commands/DRFailbackCommand.cs # XenAdmin/Commands/DRFailoverCommand.cs # XenAdmin/Commands/DisasterRecoveryCommand.cs # XenAdmin/Commands/VMGroupCommand.cs * CA-34231: Replace negative language with `run` in Command.cs RunCore method Used ReSharper rename utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in Command.cs GetCantExecuteReasonCore method Used ReSharper rename utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in Command.cs GetCantRunReasons method Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language with `run` in Command.cs Also applied to related symbols. Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in methods named CanRun Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in methods in CrossPoolMigrateCommand.cs Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/CrossPoolMigrateCommand.cs * CA-34231: Replace negative language with `run` in remaining Run methods Also updated negative language in `DeleteVMCommand` Also updated in comment in `CrossPoolMigrateCommand` Also renamed missed instances of `CanRun` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in `CanRunCore` and `RunCore` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language with `run` in Commands folder Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language with `run` in XenAdmin/Controls folder Used ReSharper renaming utility. Had to rename `WlbReportView.xs:RunReport()` to `WlbReportView.xs:StartRunReport()` to resolve conflict with change from `WlbReportView:ExecuteReport()` to `WlbReportView:RunReport()` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Controls/Wlb/WlbOptModeScheduler.cs # XenAdmin/Dialogs/Wlb/WorkloadReports.cs # XenAdminTests/UnitTests/WlbTests/WlbScheduledTaskTests.cs * CA-34231: Replace all remaining negative language with `run` in code Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/Controls/WlbRecommendations.cs # XenAdminTests/UnitTests/WlbTests/WlbScheduledTaskTests.cs # XenModel/WLB/WlbScheduledTask.cs * CA-34231: Replace negative language with `supporter` or `bond member` in code strings Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `supporter` or `bond member` in Messages string Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/MainWindow.cs # XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs # XenModel/Messages.Designer.cs # XenModel/Messages.resx * CA-34231: Replace remaining negative language with `supporter` in .resx files Used ReSharper renaming utility. FriendlyErrorNames.resx has been excluded. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `supporter` or `bond member` in XenAdmin code Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/NewPoolDialog.cs * CA-34231: Replace negative language with `supporter` or `bond member` in XenModel code Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in CFUValidator code Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # CFUValidator/CFUValidator.cs * CA-34231: Replace negative language with `coordinator` in solution's comments and hardcoded strings Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `Helpers:GetCoordinator` method Used ReSharper renaming utility. also renamed similarly named method in `ObjectChange.cs` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Alerts/Types/HotfixEligibilityAlert.cs # XenAdmin/Controls/CustomDataGraph/ArchiveMaintainer.cs * CA-34231: Replace negative language with `coordinator` in `EvacuateHostDialog.resx` Used ReSharper renaming utility. Excluded jp and zh resources Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/EvacuateHostDialog.resx * CA-34231: Replace negative language with `coordinator` in `EvacuateHostDialog.resx` Used ReSharper renaming utility. Excluded jp and zh resource files. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/NewPoolDialog.resx * CA-34231: Rename missing language references for change to `coordinator` Misc files were not saved before last commits. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `Messages.resx`'s code Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/HACommand.cs # XenAdmin/TabPages/AdPage.cs # XenModel/Actions/Network/CreateBondAction.cs # XenModel/Actions/Network/NetworkAction.cs # XenModel/Messages.Designer.cs # XenModel/Messages.resx * CA-34231: Replace negative language with `coordinator` in `ExternalPluginAction.cs` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `XenAdmin/Commands` Used ReSharper renaming utility. Also replace negative language in missed comment in `ExternalPluginAction.cs` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/AddHostToPoolCommand.cs # XenAdmin/Commands/HACommand.cs * CA-34231: Replace negative language with `coordinator` in `Helpers.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `NetworkingHelper.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `PoolJoinRules.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/NewPoolDialog.cs * CA-34231: Replace negative language with `coordinator` in `XenAdmin/Commands`, `Controls`, and `Core` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/AddHostToPoolCommand.cs * CA-34231: Replace negative language with `coordinator` in `XenAdmin/Diagnostics` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `XenAdmin/Dialogs` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/NewPoolDialog.cs * CA-34231: Replace remaining negative language with `coordinator` in `XenAdmin` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/MainWindow.cs # XenAdmin/TabPages/GeneralTabPage.cs # XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs # XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeExtrasPage.cs # XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizard.cs # XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs # XenAdmin/XenSearch/Columns.cs * CA-34231: Replace remaining negative language with `coordinator` in `XenModel\Actions` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenModel/Actions/Network/CreateBondAction.cs * CA-34231: Replace remaining negative language with `coordinator` in `XenModel` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative strings with `main` in `Messages.resx` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenModel/Messages.Designer.cs # XenModel/Messages.resx * CA-34231: Replace remaining negative string names with `main` in `Messages.resx` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/OptionsPages/SaveAndRestoreOptionsPage.cs # XenModel/Messages.resx * CA-34231: Rename dialogs to replace negative connotations with `main` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `main` in `SaveAndResoreOptionsPage.cs` Also updated its resx file. Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/OptionsPages/SaveAndRestoreOptionsPage.cs * CA-34231: Fix invalid reference in `SaveAndRestoreOptionsPage.Designer.cs` after renaming Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `main` in `EnterMainPasswordDialog.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `main` in `ChangeMainPasswordDialog.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Fix invalid reference not changed after renaming `EnterMainPasswordDialog.cs` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language with `main` in `XenAdmin/Dialogs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Update class names in HelpManager.resx Following renaming of main password dialog. Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `main` in `Metadata.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Remove remaning negative language with `coordinator` from `Messages.resx` Used ReSharper renaming Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Remove remaning negative language with `other pool member` from `Messages.resx` Used ReSharper Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language in solution Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Remove commented out code in VNCGraphicsClient.cs Code has only been improved partially as it's not strictly relevant to the PR Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Amend negative word replacement in XSVNCScreen.cs Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Simplify debug call formatting in NewPoolDialog.cs Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Add code mistakenly removed in MainWindow.cs Removed as part of `f155f9c8` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Revert renaming of constant related to Windows' API Considered external to CH Center Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Amend hotkey for Coordinator field in `NewPoolDialog` Previous ALT+<key> hotkey was conflicting with CreatePool Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Remove unecessary whitespace in EvacuateHostDialog.cs Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Update if block to exclude unecessary else in DRFailoverWizard.cs Not relevant to the PR, but the change is small enought to no need extra testing Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Amend typo in PoolJoinRules.cs supporer -> supporter Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Replace missing negative language with `coordinator` in `XenAPI-Extensions/Pool.cs` Variables and methods XenAPI-Extensions were mistakenly skipped Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Replace negative language in `XenApi-Extensions` with `coordinator/interface` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Replace negative language in `XenApi-Extensions` with `supporter/member` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Replace remaining negative language in `XenServerHealthCheckBugTool.cs` This is only used to format the string Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Change line-endings to CRLF in `Page_CloudConfigParamters.cs` Done in order to fix merge conflict into master Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Amend misc negative language renaming typos `XenServerHealthCheckBugTool` and `XenServerHealthCheckService` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
2021-08-31 12:31:16 +02:00
public object RunMethod(ProxyMethodInfo pmi, object[] args)
{
object obj;
if (pmi.FakeType == typeof(fakeUnknown))
{
obj = new fakeUnknown(pmi.TypeName, this);
}
else
{
obj = Activator.CreateInstance(pmi.FakeType, this);
}
object[] methodArgs = new object[pmi.FakeMethod.GetParameters().Length];
for (int i = 0; i < methodArgs.Length; i++)
{
methodArgs[i] = args[i];
}
switch (pmi.FakeMethodType)
{
case MethodType.Sync:
return pmi.FakeMethod.Invoke(obj, methodArgs);
case MethodType.Async:
Response<string> response = (Response<string>)pmi.FakeMethod.Invoke(obj, methodArgs);
if (response.Status == ResponseTypes.SUCCESS)
{
return new Response<string>(CreateTask(DbProxy.TaskStatus.success, response.Value));
}
else
{
return new Response<string>(CreateTask(DbProxy.TaskStatus.failure, response.ErrorDescription));
}
}
return new Response<String>(true, new String[] { Failure.INTERNAL_ERROR });
}
public event EventHandler<DbProxyInvokingEventArgs> Invoking;
protected virtual void OnInvoking(DbProxyInvokingEventArgs e)
{
var handler = Invoking;
if (handler != null)
{
handler(this, e);
}
}
#region IInvocationHandler Members
public object Invoke(string proxyMethodName, string returnType, params object[] args)
{
VerifyVersion(proxyMethodName);
ProxyMethodInfo pmi = ProxyMethodNameParser.Parse(proxyMethodName);
OnInvoking(new DbProxyInvokingEventArgs(pmi));
if (pmi.FakeType != null)
{
CP-34231: Remove language with negative connotations (#2860) * CA-34231: Replace negative language with `block list` in code and references Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `stop` in code and references Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `freezing` in code Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run/ran` in code comments Some paramater mentions have been renamed, as they will be renamed in future commits. Excluded mentions in XenAPI/Host.cs and XenAPI/VM.cs since code is autogenerated. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # CFUValidator/CommandLineOptions/CFUCommandLineOptionManager.cs # XenAdmin/Controls/Wlb/WlbOptModeScheduler.cs # XenAdmin/Dialogs/Wlb/WorkloadReports.cs * CA-34231: Replace negative language with `run` in Command.cs Run method Used Resharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/TabPages/GeneralTabPage.cs * CA-34231: Replace negative language with `run` in Command.cs CanRun method Used Resharper rename utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in Command.cs CanRunCore method Used ReSharper rename utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/DRConfigureCommand.cs # XenAdmin/Commands/DRDryrunCommand.cs # XenAdmin/Commands/DRFailbackCommand.cs # XenAdmin/Commands/DRFailoverCommand.cs # XenAdmin/Commands/DisasterRecoveryCommand.cs # XenAdmin/Commands/VMGroupCommand.cs * CA-34231: Replace negative language with `run` in Command.cs RunCore method Used ReSharper rename utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in Command.cs GetCantExecuteReasonCore method Used ReSharper rename utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in Command.cs GetCantRunReasons method Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language with `run` in Command.cs Also applied to related symbols. Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in methods named CanRun Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in methods in CrossPoolMigrateCommand.cs Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/CrossPoolMigrateCommand.cs * CA-34231: Replace negative language with `run` in remaining Run methods Also updated negative language in `DeleteVMCommand` Also updated in comment in `CrossPoolMigrateCommand` Also renamed missed instances of `CanRun` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `run` in `CanRunCore` and `RunCore` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language with `run` in Commands folder Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language with `run` in XenAdmin/Controls folder Used ReSharper renaming utility. Had to rename `WlbReportView.xs:RunReport()` to `WlbReportView.xs:StartRunReport()` to resolve conflict with change from `WlbReportView:ExecuteReport()` to `WlbReportView:RunReport()` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Controls/Wlb/WlbOptModeScheduler.cs # XenAdmin/Dialogs/Wlb/WorkloadReports.cs # XenAdminTests/UnitTests/WlbTests/WlbScheduledTaskTests.cs * CA-34231: Replace all remaining negative language with `run` in code Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/Controls/WlbRecommendations.cs # XenAdminTests/UnitTests/WlbTests/WlbScheduledTaskTests.cs # XenModel/WLB/WlbScheduledTask.cs * CA-34231: Replace negative language with `supporter` or `bond member` in code strings Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `supporter` or `bond member` in Messages string Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/MainWindow.cs # XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs # XenModel/Messages.Designer.cs # XenModel/Messages.resx * CA-34231: Replace remaining negative language with `supporter` in .resx files Used ReSharper renaming utility. FriendlyErrorNames.resx has been excluded. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `supporter` or `bond member` in XenAdmin code Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/NewPoolDialog.cs * CA-34231: Replace negative language with `supporter` or `bond member` in XenModel code Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in CFUValidator code Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # CFUValidator/CFUValidator.cs * CA-34231: Replace negative language with `coordinator` in solution's comments and hardcoded strings Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `Helpers:GetCoordinator` method Used ReSharper renaming utility. also renamed similarly named method in `ObjectChange.cs` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Alerts/Types/HotfixEligibilityAlert.cs # XenAdmin/Controls/CustomDataGraph/ArchiveMaintainer.cs * CA-34231: Replace negative language with `coordinator` in `EvacuateHostDialog.resx` Used ReSharper renaming utility. Excluded jp and zh resources Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/EvacuateHostDialog.resx * CA-34231: Replace negative language with `coordinator` in `EvacuateHostDialog.resx` Used ReSharper renaming utility. Excluded jp and zh resource files. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/NewPoolDialog.resx * CA-34231: Rename missing language references for change to `coordinator` Misc files were not saved before last commits. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `Messages.resx`'s code Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/HACommand.cs # XenAdmin/TabPages/AdPage.cs # XenModel/Actions/Network/CreateBondAction.cs # XenModel/Actions/Network/NetworkAction.cs # XenModel/Messages.Designer.cs # XenModel/Messages.resx * CA-34231: Replace negative language with `coordinator` in `ExternalPluginAction.cs` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `XenAdmin/Commands` Used ReSharper renaming utility. Also replace negative language in missed comment in `ExternalPluginAction.cs` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/AddHostToPoolCommand.cs # XenAdmin/Commands/HACommand.cs * CA-34231: Replace negative language with `coordinator` in `Helpers.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `NetworkingHelper.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `PoolJoinRules.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/NewPoolDialog.cs * CA-34231: Replace negative language with `coordinator` in `XenAdmin/Commands`, `Controls`, and `Core` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Commands/AddHostToPoolCommand.cs * CA-34231: Replace negative language with `coordinator` in `XenAdmin/Diagnostics` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `coordinator` in `XenAdmin/Dialogs` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/NewPoolDialog.cs * CA-34231: Replace remaining negative language with `coordinator` in `XenAdmin` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/MainWindow.cs # XenAdmin/TabPages/GeneralTabPage.cs # XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs # XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeExtrasPage.cs # XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizard.cs # XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs # XenAdmin/XenSearch/Columns.cs * CA-34231: Replace remaining negative language with `coordinator` in `XenModel\Actions` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenModel/Actions/Network/CreateBondAction.cs * CA-34231: Replace remaining negative language with `coordinator` in `XenModel` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative strings with `main` in `Messages.resx` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenModel/Messages.Designer.cs # XenModel/Messages.resx * CA-34231: Replace remaining negative string names with `main` in `Messages.resx` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/OptionsPages/SaveAndRestoreOptionsPage.cs # XenModel/Messages.resx * CA-34231: Rename dialogs to replace negative connotations with `main` Used ReSharper renaming utility Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `main` in `SaveAndResoreOptionsPage.cs` Also updated its resx file. Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> # Conflicts: # XenAdmin/Dialogs/OptionsPages/SaveAndRestoreOptionsPage.cs * CA-34231: Fix invalid reference in `SaveAndRestoreOptionsPage.Designer.cs` after renaming Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `main` in `EnterMainPasswordDialog.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `main` in `ChangeMainPasswordDialog.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Fix invalid reference not changed after renaming `EnterMainPasswordDialog.cs` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language with `main` in `XenAdmin/Dialogs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Update class names in HelpManager.resx Following renaming of main password dialog. Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace negative language with `main` in `Metadata.cs` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Remove remaning negative language with `coordinator` from `Messages.resx` Used ReSharper renaming Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Remove remaning negative language with `other pool member` from `Messages.resx` Used ReSharper Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CA-34231: Replace remaining negative language in solution Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Remove commented out code in VNCGraphicsClient.cs Code has only been improved partially as it's not strictly relevant to the PR Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Amend negative word replacement in XSVNCScreen.cs Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Simplify debug call formatting in NewPoolDialog.cs Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Add code mistakenly removed in MainWindow.cs Removed as part of `f155f9c8` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Revert renaming of constant related to Windows' API Considered external to CH Center Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Amend hotkey for Coordinator field in `NewPoolDialog` Previous ALT+<key> hotkey was conflicting with CreatePool Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Remove unecessary whitespace in EvacuateHostDialog.cs Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Update if block to exclude unecessary else in DRFailoverWizard.cs Not relevant to the PR, but the change is small enought to no need extra testing Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Amend typo in PoolJoinRules.cs supporer -> supporter Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Replace missing negative language with `coordinator` in `XenAPI-Extensions/Pool.cs` Variables and methods XenAPI-Extensions were mistakenly skipped Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Replace negative language in `XenApi-Extensions` with `coordinator/interface` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Replace negative language in `XenApi-Extensions` with `supporter/member` Used ReSharper renaming utility. Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Replace remaining negative language in `XenServerHealthCheckBugTool.cs` This is only used to format the string Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Change line-endings to CRLF in `Page_CloudConfigParamters.cs` Done in order to fix merge conflict into master Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com> * CP-34231: Amend misc negative language renaming typos `XenServerHealthCheckBugTool` and `XenServerHealthCheckService` Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
2021-08-31 12:31:16 +02:00
return RunMethod(pmi, args);
}
if (pmi.MethodName.StartsWith("set_"))
{
string fieldname = pmi.MethodName.Substring(4);
// Special case: set_memory_limits is not just editing a "memory_limits" field
if (fieldname == "memory_limits")
{
EditObject(pmi.TypeName, (string)args[1], "memory_static_min", args[2]);
EditObject(pmi.TypeName, (string)args[1], "memory_static_max", args[3]);
EditObject(pmi.TypeName, (string)args[1], "memory_dynamic_min", args[4]);
EditObject(pmi.TypeName, (string)args[1], "memory_dynamic_max", args[5]);
}
else
{
EditObject(pmi.TypeName, (string)args[1], fieldname, args[2]);
}
return new Response<string>("");
}
switch (pmi.MethodName)
{
case "Url":
return url;// "http://XenCenter.Simulator/";
case "get_record":
{
string uuid = (string)args[1];
if (uuid.StartsWith("task")) // tasks are kept track of separately
{
return new Response<Proxy_Task>(task_get_record(uuid));
}
return get_record(pmi.TypeName, uuid, true);
}
case "destroy":
{
string uuid = (string)args[1];
if (uuid.StartsWith("task"))
{
task_destroy(uuid);
return new Response<string>("");
}
break;
}
case "add_to_other_config":
{
string uuid = (string)args[1];
if (!uuid.StartsWith("task")) // ignore other_config for tasks (used to keep track of meddling actions)
{
AddToDictionary(pmi.TypeName, (string)args[1], "other_config", args[2], args[3]);
}
return new Response<string>("");
}
case "remove_from_other_config":
{
string uuid = (string)args[1];
if (!uuid.StartsWith("task")) // ignore other_config for tasks (used to keep track of meddling actions)
{
RemoveFromDictionary(pmi.TypeName, (string)args[1], "other_config", args[2]);
}
return new Response<string>("");
}
case "add_to_gui_config":
AddToDictionary(pmi.TypeName, (string)args[1], "gui_config", args[2], args[3]);
return new Response<string>("");
case "remove_from_gui_config":
RemoveFromDictionary(pmi.TypeName, (string)args[1], "gui_config", args[2]);
return new Response<string>("");
case "add_tags":
AddToArray(pmi.TypeName, (string)args[1], "tags", args[2]);
return new Response<string>("");
case "remove_tags":
RemoveFromArray(pmi.TypeName, (string)args[1], "tags", args[2]);
return new Response<string>("");
case "get_subject_information_from_identifier":
Hashtable subjectInfo = new Hashtable();
if ((string)args[1] == "SID1")
{
subjectInfo["subject-name"] = @"citrix\tu_one";
subjectInfo["subject-displayname"] = "Test User 1";
subjectInfo["subject-is-group"] = "false";
}
else if ((string)args[1] == "SID2")
{
subjectInfo["subject-name"] = @"citrix\tu_two";
subjectInfo["subject-displayname"] = "Test User 2";
subjectInfo["subject-is-group"] = "false";
}
else if ((string)args[1] == "SID3")
{
subjectInfo["subject-name"] = @"citrix\tg";
subjectInfo["subject-displayname"] = "Test Group";
subjectInfo["subject-is-group"] = "true";
}
return new Response<Object>(subjectInfo);
// For VBDEditPage.CalculateDevicePositions()
case "get_allowed_vbd_devices":
return new Response<String[]>(new String[] { "0", "1", "2", "3", "4", "5", "6", "7" });
case "retrieve_wlb_recommendations":
case "retrieve_wlb_evacuate_recommendations":
case "retrieve_wlb_configuration":
Hashtable tbl = new Hashtable();
return new Response<object>(tbl);
case "get_uncooperative_resident_vms":
return new Response<string[]>(new string[0]);
// For HAWizard_Pages.AssignPriorities
case "ha_compute_hypothetical_max_host_failures_to_tolerate":
return new Response<string>("1");
case "get_ha_host_failures_to_tolerate":
return new Response<string>("1");
// For EvacuateHostDialog and RollingUpgradeWizard
case "get_vms_which_prevent_evacuation":
return new Response<object>(new Hashtable());
// For RollingUpgradeWizard
case "get_live":
return new Response<bool>(true);
case "get_allowed_operations":
return new Response<string[]>(new string[0]);
case "get_health_check_config":
string uuid1 = (string)args[1];
return new Response<object>(get_health_check_config(pmi.TypeName, uuid1, true));
}
return new Response<String>(true, new String[] { Failure.INTERNAL_ERROR });
}
#endregion
/// <summary>
/// Determine if the given URL represents a simulator db proxy
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static bool IsSimulatorUrl(string url)
{
return url.EndsWith(".db") || url.EndsWith(".xml") || url.EndsWith(".tmp");
}
#region Code to create fake asynchronous tasks that just return a known value
private static Dictionary<string, Proxy_Task> tasks = new Dictionary<string, Proxy_Task>();
private readonly Random rand = new Random();
public enum TaskStatus { success, failure, pending }
// If success, use the next argument as the result;
// if !success, use all the subsequent arguments as the error_info.
public string CreateTask(TaskStatus status, params string[] result)
{
Proxy_Task task = new Proxy_Task();
task.uuid = String.Format("task{0}", rand.Next());
task.name_label = task.uuid;
task.name_description = "";
task.created = DateTime.Now;
task.status = status.ToString();
if (status != TaskStatus.pending)
{
task.finished = DateTime.Now;
task.progress = 100.0;
if (status == TaskStatus.success)
{
task.result = result[0];
}
else
{
task.error_info = result;
}
}
tasks.Add(task.uuid, task);
return task.uuid;
}
public Proxy_Task GetTask(string opaque_ref)
{
return tasks[opaque_ref];
}
private static Proxy_Task task_get_record(string uuid)
{
Proxy_Task task;
if (tasks.TryGetValue(uuid, out task))
{
return task;
}
return null;
}
private static bool task_destroy(string uuid)
{
return tasks.Remove(uuid);
}
#endregion
public enum EditTypes { Replace, AddToDict, RemoveFromDict, AddToArray, RemoveFromArray }
public void EditObject_(EditTypes editType, string typeName, string opaqueRef, string field, params object[] args)
{
// Edit the XML to have the new value
edit_record(editType, typeName, opaqueRef, field, args);
// Make a Proxy object from the new XML
TypeCache.TryGetProxyType(typeName, out Type proxyT);
object proxy = get_record(typeName, opaqueRef, false);
// Make a Proxy_Event representing this edit, and add it to the events queue
lock (eventsListLock)
{
eventsList.Add(MakeProxyEvent(typeName, opaqueRef, "mod", proxyT, proxy));
}
}
private void EditObject(string typeName, string opaqueRef, string field, object new_value)
{
EditObject_(EditTypes.Replace, typeName, opaqueRef, field, new_value);
}
private void AddToDictionary(string typeName, string opaqueRef, string field, object key, object new_value)
{
EditObject_(EditTypes.AddToDict, typeName, opaqueRef, field, key, new_value);
}
private void RemoveFromDictionary(string typeName, string opaqueRef, string field, object key)
{
EditObject_(EditTypes.RemoveFromDict, typeName, opaqueRef, field, key);
}
private void AddToArray(string typeName, string opaqueRef, string field, object value)
{
EditObject_(EditTypes.AddToArray, typeName, opaqueRef, field, value);
}
private void RemoveFromArray(string typeName, string opaqueRef, string field, object value)
{
EditObject_(EditTypes.RemoveFromArray, typeName, opaqueRef, field, value);
}
public static Proxy_Event MakeProxyEvent(string typeName, string opaqueRef, string operation, Type ProxyT, object proxy)
{
Proxy_Event ev = new Proxy_Event();
ev.class_ = typeName;
ev.opaqueRef = opaqueRef;
ev.operation = operation;
ev.snapshot = ProxyToHashtable(ProxyT, proxy);
return ev;
}
public static Hashtable ProxyToHashtable(Type proxyT, object proxy)
{
Hashtable table = new Hashtable();
FieldInfo[] fields = proxyT.GetFields();
foreach (FieldInfo field in fields)
{
table[field.Name] = field.GetValue(proxy);
}
return table;
}
public Object get_record(String clazz, String opaqueRef, bool makeResponse)
{
Db.Table table = db.Tables[clazz];
Type type = table.XapiType;
if (!table.Rows.ContainsKey(opaqueRef))
{
if (makeResponse)
{
return typeof(Response<>).MakeGenericType(type).GetConstructor(new Type[] { typeof(bool), typeof(String[]) })
.Invoke(new Object[] { true, new String[] { Failure.OBJECT_NO_LONGER_EXISTS, opaqueRef } });
}
throw new Exception(Failure.OBJECT_NO_LONGER_EXISTS);
}
Db.Row row = table.Rows[opaqueRef];
Object result = Activator.CreateInstance(type);
foreach (string propName in row.Props.Keys)
{
FieldInfo info = type.GetField(propName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
info.SetValue(result, row.Props[propName].XapiObjectValue);
}
if (makeResponse)
{
return typeof(Response<>).MakeGenericType(type).GetConstructor(new Type[] { type }).Invoke(new Object[] { result });
}
return result;
}
public Object get_health_check_config(String clazz, String opaqueRef, bool makeResponse)
{
Db.Table table = db.Tables[clazz];
if (!table.Rows.ContainsKey(opaqueRef))
{
if (makeResponse)
return new object();
throw new Exception(Failure.OBJECT_NO_LONGER_EXISTS);
}
return table.Rows[opaqueRef].Props["health_check_config"].XapiObjectValue;
}
private void edit_record(EditTypes editType, string clazz, string opaqueRef, string field, params object[] args)
{
Db.Row row = db.Tables[clazz].Rows[opaqueRef];
Db.Prop prop;
if (row.Props.TryGetValue(field, out prop))
{
prop.XapiObjectValue = NewValue(editType, prop.XapiObjectValue, args);
}
else
{
prop = new Db.Prop(row, field, NewValue(editType, null, args));
row.Props[field] = prop;
}
}
private object NewValue(EditTypes editType, object fieldBefore, object[] args)
{
switch (editType)
{
case EditTypes.Replace:
return args[0];
case EditTypes.AddToDict:
Hashtable ht = fieldBefore == null ? new Hashtable() : (Hashtable)fieldBefore;
ht[args[0]] = args[1];
return ht;
case EditTypes.RemoveFromDict:
if (fieldBefore == null)
{
return new Hashtable();
}
else
{
ht = (Hashtable)fieldBefore;
ht.Remove(args[0]);
return ht;
}
case EditTypes.AddToArray:
// We only support string[] at the moment
string[] arr = fieldBefore == null ? new string[0] : (string[])fieldBefore;
List<string> list = new List<string>(arr);
if (!list.Contains((string)args[0]))
{
list.Add((string)args[0]);
}
return list.ToArray();
case EditTypes.RemoveFromArray:
if (fieldBefore == null)
{
return new string[0];
}
else
{
arr = (string[])fieldBefore;
list = new List<string>(arr);
while (list.Contains((string)args[0]))
{
list.Remove((string)args[0]);
}
return list.ToArray();
}
default:
System.Diagnostics.Trace.Assert(false);
return null;
}
}
public string GetRandomRef(string clazz)
{
string[] refs = new string[db.Tables[clazz].Rows.Keys.Count];
db.Tables[clazz].Rows.Keys.CopyTo(refs, 0);
return refs[rand.Next(0, refs.Length)];
}
public string CopyObject(string clazz, string opaque_ref)
{
if (!db.Tables[clazz].Rows.ContainsKey(opaque_ref))
return Helper.NullOpaqueRef;
Db.Row r = db.Tables[clazz].Rows[opaque_ref].CopyOf();
string new_opaque_ref = CreateOpaqueRef();
r.Props["uuid"].XapiObjectValue = Guid.NewGuid().ToString(); // this object needs a new uuid & ref
if (r.Props.TryGetValue("VBDs", out Db.Prop vbdVal))
{
if (vbdVal.XapiObjectValue is string[] vbds)
r.Props["VBDs"].XapiObjectValue =
vbds.Select(v => $"OpaqueRef:{Guid.NewGuid().ToString()}").ToArray();
}
db.Tables[clazz].Rows.Add(new_opaque_ref, r);
return new_opaque_ref;
}
public void SendCreateObject(string typeName, string opaqueRef)
{
// Make a Proxy object from the new XML
TypeCache.TryGetProxyType(typeName, out Type proxyT);
object proxy = get_record(typeName, opaqueRef, false);
// Make a Proxy_Event representing this edit, and add it to the events queue
lock (eventsListLock)
{
eventsList.Add(MakeProxyEvent(typeName, opaqueRef, "add", proxyT, proxy));
}
}
public void SendDestroyObject(string typeName, string opaqueRef)
{
// Make a Proxy object from the new XML
TypeCache.TryGetProxyType(typeName, out Type proxyT);
// Make a Proxy_Event representing this edit, and add it to the events queue
lock (eventsListLock)
{
eventsList.Add(MakeProxyEvent(typeName, opaqueRef, "del", proxyT, Activator.CreateInstance(proxyT)));
}
}
public void SendModObject(string typeName, string opaqueRef)
{
// Make a Proxy object from the new XML
TypeCache.TryGetProxyType(typeName, out Type proxyT);
object proxy = get_record(typeName, opaqueRef, false);
// Make a Proxy_Event representing this edit, and add it to the events queue
lock (eventsListLock)
{
eventsList.Add(MakeProxyEvent(typeName, opaqueRef, "mod", proxyT, proxy));
}
}
/// <summary>
/// Verifies that the specified call can be made with this version of server.
/// </summary>
private void VerifyVersion(string call)
{
string version = null;
foreach (string key in callVersions.Keys)
{
if (callVersions[key].Contains(call))
{
version = key;
break;
}
}
}
public string CreateOpaqueRef()
{
return string.Format("OpaqueRef:{0}", Guid.NewGuid());
}
}
}