diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/VirtualizationForPrivateCloud/VirtualizationServerControllerForPrivateCloud.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/VirtualizationForPrivateCloud/VirtualizationServerControllerForPrivateCloud.cs
index 913e3eef..0742287c 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/VirtualizationForPrivateCloud/VirtualizationServerControllerForPrivateCloud.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/VirtualizationForPrivateCloud/VirtualizationServerControllerForPrivateCloud.cs
@@ -2700,7 +2700,7 @@ namespace WebsitePanel.EnterpriseServer
public static NetworkAdapterDetails GetExternalNetworkAdapterDetails(int itemId)
{
// load service item
- VirtualMachine vm = (VirtualMachine)PackageController.GetPackageItem(itemId);
+ VMInfo vm = (VMInfo)PackageController.GetPackageItem(itemId);
if (vm == null)
return null;
diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/VirtualMachinesHelper.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/VirtualMachinesHelper.cs
index 594c8785..0be00d79 100644
--- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/VirtualMachinesHelper.cs
+++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/VirtualMachinesHelper.cs
@@ -29,9 +29,54 @@
using WebsitePanel.EnterpriseServer;
using WebsitePanel.Providers.Virtualization;
using System.Web;
+using System;
namespace WebsitePanel.Portal
{
+ // TODO: Move this extension to a separate file later.
+ public static class VirtualMachinesExtensions
+ {
+ #region Privates with specific purposes (eq. caching, usability, performance and etc)
+ ///
+ /// This method supports the Portal internal infrastructure and is not intended to be used directly from your code. Gets a cached copy of virtual machine object of the specified type or retrieves it for the first time and then caches it.
+ ///
+ /// Type of virtual machine to be retrieved (possible types are VirtualMachine|VMInfo)
+ /// Virtual machine item id
+ /// Function to retrieve the virtual machine data from Enterprise Server
+ /// An instance of the specified virtual machine
+ internal static T GetCachedVirtualMachine(object cacheIdentityKey, Func getVmFunc)
+ {
+ // TODO: Make this method private when all dependents will be consolidated in the extension.
+ string cacheKey = "CachedVirtualMachine_" + cacheIdentityKey;
+ if (HttpContext.Current.Items[cacheKey] != null)
+ return (T)HttpContext.Current.Items[cacheKey];
+
+ // load virtual machine
+ T virtualMachine = getVmFunc();
+
+ // place to cache
+ if (virtualMachine != null)
+ HttpContext.Current.Items[cacheKey] = virtualMachine;
+
+ return virtualMachine;
+ }
+ #endregion
+
+ #region Extension methods
+ ///
+ /// Gets a cached copy of virtual machine object of the specified type or retrieves it for the first time and then caches it.
+ ///
+ ///
+ /// Virtual machine id
+ /// An instance of the virtual machine speficied
+ public static VMInfo GetCachedVirtualMachine(this esVirtualizationServerForPrivateCloud client, int itemId)
+ {
+ return GetCachedVirtualMachine(
+ itemId, () => ES.Services.VPSPC.GetVirtualMachineItem(itemId));
+ }
+ #endregion
+ }
+
public class VirtualMachinesHelper
{
public static bool IsVirtualMachineManagementAllowed(int packageId)
@@ -57,20 +102,11 @@ namespace WebsitePanel.Portal
return manageAllowed;
}
+ // TODO: Move this method to the corresponding extension later.
public static VirtualMachine GetCachedVirtualMachine(int itemId)
{
- string key = "CachedVirtualMachine" + itemId;
- if (HttpContext.Current.Items[key] != null)
- return (VirtualMachine)HttpContext.Current.Items[key];
-
- // load virtual machine
- VirtualMachine vm = ES.Services.VPS.GetVirtualMachineItem(itemId);
-
- // place to cache
- if (vm != null)
- HttpContext.Current.Items[key] = vm;
-
- return vm;
+ return VirtualMachinesExtensions.GetCachedVirtualMachine(
+ itemId, () => ES.Services.VPS.GetVirtualMachineItem(itemId));
}
#region Virtual Machines
diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPSForPC/RemoteDesktop/Connect.aspx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPSForPC/RemoteDesktop/Connect.aspx.cs
index 5805a371..c4faa3a9 100644
--- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPSForPC/RemoteDesktop/Connect.aspx.cs
+++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/VPSForPC/RemoteDesktop/Connect.aspx.cs
@@ -40,13 +40,14 @@ namespace WebsitePanel.Portal.VPSForPC.RemoteDesktop
resolution.Text = Request["Resolution"];
// load server info
- VirtualMachine vm = VirtualMachinesHelper.GetCachedVirtualMachine(PanelRequest.ItemID);
+ VMInfo vm = ES.Services.VPSPC.GetCachedVirtualMachine(PanelRequest.ItemID);
litServerName.Text = vm.Name + " - ";
username.Text = "Administrator";
- password.Text = vm.AdministratorPassword;
+ // TODO: Review VMInfo class fields and underlying data for correctness
+ password.Text = vm.AdminPassword;
// load external network parameters
- NetworkAdapterDetails nic = ES.Services.VPS.GetExternalNetworkAdapterDetails(PanelRequest.ItemID);
+ NetworkAdapterDetails nic = ES.Services.VPSPC.GetExternalNetworkAdapterDetails(PanelRequest.ItemID);
if (nic.IPAddresses.Length > 0)
{
NetworkAdapterIPAddress ip = nic.IPAddresses[0];