From a1c0b624902194d6da5182f0864045d239ea6722 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Fri, 27 Feb 2015 06:47:53 -0800 Subject: [PATCH] RDS Qoutas fixes --- WebsitePanel/Database/update_db.sql | 18 +++++++- .../RemoteDesktopServicesController.cs | 15 +++++- .../RemoteDesktopServices/RdsUserSession.cs | 2 + .../Windows2012.cs | 20 ++++---- .../AssignedRDSServers.ascx.resx | 2 +- .../RDSCollections.ascx.resx | 3 ++ .../RDSEditCollectionUsers.ascx.resx | 3 ++ .../WebsitePanel/RDS/AssignedRDSServers.ascx | 5 ++ .../RDS/AssignedRDSServers.ascx.cs | 20 ++++++-- .../RDS/AssignedRDSServers.ascx.designer.cs | 46 ++++++++----------- .../WebsitePanel/RDS/RDSCollections.ascx | 5 ++ .../WebsitePanel/RDS/RDSCollections.ascx.cs | 19 +++++++- .../RDS/RDSCollections.ascx.designer.cs | 18 ++++++++ .../RDS/RDSEditCollectionUsers.ascx | 6 +++ .../RDS/RDSEditCollectionUsers.ascx.cs | 18 +++++++- .../RDSEditCollectionUsers.ascx.designer.cs | 18 ++++++++ .../WebsitePanel/RDS/RDSUserSessions.ascx | 3 +- .../WebsitePanel/RDS/RDSUserSessions.ascx.cs | 12 +++++ 18 files changed, 187 insertions(+), 46 deletions(-) diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index 54df0493..27d8a6f9 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -6042,7 +6042,7 @@ CREATE PROCEDURE [dbo].GetOrganizationRdsUsersCount ) AS SELECT - @TotalNumber = Count([RDSCollectionId]) + @TotalNumber = Count(DISTINCT([AccountId])) FROM [dbo].[RDSCollectionUsers] WHERE [RDSCollectionId] in (SELECT [ID] FROM [RDSCollections] where [ItemId] = @ItemId ) RETURN @@ -8192,6 +8192,22 @@ AS INNER JOIN ServiceItems si ON ea.ItemID = si.ItemID INNER JOIN PackagesTreeCache pt ON si.PackageID = pt.PackageID WHERE pt.ParentPackageID = @PackageID AND ea.AccountType = 11) + ELSE IF @QuotaID = 450 + SET @Result = (SELECT COUNT(DISTINCT(RCU.[AccountId])) FROM [dbo].[RDSCollectionUsers] RCU + INNER JOIN ExchangeAccounts EA ON EA.AccountId = RCU.AccountId + INNER JOIN ServiceItems si ON ea.ItemID = si.ItemID + INNER JOIN PackagesTreeCache pt ON si.PackageID = pt.PackageID + WHERE PT.ParentPackageID = @PackageID) + ELSE IF @QuotaID = 451 + SET @Result = (SELECT COUNT(RS.[ID]) FROM [dbo].[RDSServers] RS + INNER JOIN ServiceItems si ON RS.ItemID = si.ItemID + INNER JOIN PackagesTreeCache pt ON si.PackageID = pt.PackageID + WHERE PT.ParentPackageID = @PackageID) + ELSE IF @QuotaID = 491 + SET @Result = (SELECT COUNT(RC.[ID]) FROM [dbo].[RDSCollections] RC + INNER JOIN ServiceItems si ON RC.ItemID = si.ItemID + INNER JOIN PackagesTreeCache pt ON si.PackageID = pt.PackageID + WHERE PT.ParentPackageID = @PackageID) ELSE IF @QuotaName like 'ServiceLevel.%' -- Support Service Level Quota BEGIN DECLARE @LevelID int diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs index c3bd42d7..269add07 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs @@ -760,8 +760,21 @@ namespace WebsitePanel.EnterpriseServer } var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(organization.PackageId)); + var userSessions = rds.GetRdsUserSessions(collection.Name).ToList(); + var organizationUsers = OrganizationController.GetOrganizationUsersPaged(collection.ItemId, null, null, null, 0, Int32.MaxValue).PageUsers; - return rds.GetRdsUserSessions(collection.Name).ToList(); + foreach(var userSession in userSessions) + { + var organizationUser = organizationUsers.FirstOrDefault(o => o.SamAccountName.Equals(userSession.SamAccountName, StringComparison.CurrentCultureIgnoreCase)); + + if (organizationUser != null) + { + userSession.IsVip = organizationUser.IsVIP; + result.Add(userSession); + } + } + + return result; } private static RdsServersPaged GetFreeRdsServersPagedInternal(int itemId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsUserSession.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsUserSession.cs index 8c3e9729..4d6b4e19 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsUserSession.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsUserSession.cs @@ -13,5 +13,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices public string SessionState { get; set; } public string HostServer { get; set; } public string DomainName { get; set; } + public bool IsVip { get; set; } + public string SamAccountName { get; set; } } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs index dea195b8..a0015101 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs @@ -2290,18 +2290,22 @@ namespace WebsitePanel.Providers.RemoteDesktopServices cmd.Parameters.Add("CollectionName", collectionName); cmd.Parameters.Add("ConnectionBroker", ConnectionBroker); var userSessions = ExecuteShellCommand(runSpace, cmd, false, out errors); - var properties = typeof(RdsUserSession).GetProperties(); + var properties = typeof(RdsUserSession).GetProperties(); foreach(var userSession in userSessions) { - var session = new RdsUserSession(); - - foreach(var prop in properties) + var session = new RdsUserSession { - prop.SetValue(session, GetPSObjectProperty(userSession, prop.Name).ToString(), null); - } - - session.UserName = GetUserFullName(session.DomainName, session.UserName, runSpace); + CollectionName = GetPSObjectProperty(userSession, "CollectionName").ToString(), + DomainName = GetPSObjectProperty(userSession, "DomainName").ToString(), + HostServer = GetPSObjectProperty(userSession, "HostServer").ToString(), + SessionState = GetPSObjectProperty(userSession, "SessionState").ToString(), + UnifiedSessionId = GetPSObjectProperty(userSession, "UnifiedSessionId").ToString(), + SamAccountName = GetPSObjectProperty(userSession, "UserName").ToString(), + }; + + session.IsVip = false; + session.UserName = GetUserFullName(session.DomainName, session.SamAccountName, runSpace); result.Add(session); } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/AssignedRDSServers.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/AssignedRDSServers.ascx.resx index 33277c17..e2d6204d 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/AssignedRDSServers.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/AssignedRDSServers.ascx.resx @@ -145,7 +145,7 @@ Assigned RDS Servers - Total RDS Servers Allocated: + Total Remote Desktop Servers Allocated: Disable diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSCollections.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSCollections.ascx.resx index b231aa48..3a2deaac 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSCollections.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSCollections.ascx.resx @@ -147,4 +147,7 @@ RDS Server + + Total Remote Desktop Collections Created: + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSEditCollectionUsers.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSEditCollectionUsers.ascx.resx index b7086125..60f1cf4b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSEditCollectionUsers.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/App_LocalResources/RDSEditCollectionUsers.ascx.resx @@ -144,4 +144,7 @@ RDS Users + + Total RDS Users Assigned: + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx index 6016913e..9ff6017f 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx @@ -72,6 +72,11 @@ +
+ +     + +
// This code was generated by a tool. @@ -139,6 +111,24 @@ namespace WebsitePanel.Portal.RDS { /// protected global::System.Web.UI.WebControls.GridView gvRDSAssignedServers; + /// + /// locQuota control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Localize locQuota; + + /// + /// rdsServersQuota control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::WebsitePanel.Portal.QuotaViewer rdsServersQuota; + /// /// odsRDSAssignedServersPaged control. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCollections.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCollections.ascx index a311aaa3..a5369d97 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCollections.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSCollections.ascx @@ -66,6 +66,11 @@ +
+ +     + +
protected global::System.Web.UI.WebControls.GridView gvRDSCollections; + /// + /// locQuota control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Localize locQuota; + + /// + /// collectionsQuota control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::WebsitePanel.Portal.QuotaViewer collectionsQuota; + /// /// odsRDSCollectionsPaged control. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx index 7f71695d..57a37195 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx @@ -1,6 +1,7 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RDSEditCollectionUsers.ascx.cs" Inherits="WebsitePanel.Portal.RDS.RDSEditCollectionUsers" %> <%@ Register Src="../UserControls/SimpleMessageBox.ascx" TagName="SimpleMessageBox" TagPrefix="wsp" %> <%@ Register Src="../UserControls/EnableAsyncTasksSupport.ascx" TagName="EnableAsyncTasksSupport" TagPrefix="wsp" %> +<%@ Register Src="../UserControls/QuotaViewer.ascx" TagName="QuotaViewer" TagPrefix="wsp" %> <%@ Register Src="UserControls/RDSCollectionUsers.ascx" TagName="CollectionUsers" TagPrefix="wsp"%> <%@ Register Src="UserControls/RDSCollectionTabs.ascx" TagName="CollectionTabs" TagPrefix="wsp" %> <%@ Register TagPrefix="wsp" TagName="CollapsiblePanel" Src="../UserControls/CollapsiblePanel.ascx" %> @@ -34,6 +35,11 @@ +
+ +     + +
diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.cs index beaeed58..767eab4f 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.cs @@ -39,9 +39,10 @@ namespace WebsitePanel.Portal.RDS { protected void Page_Load(object sender, EventArgs e) - { + { if (!IsPostBack) { + BindQuota(); var collectionUsers = ES.Services.RDS.GetRdsCollectionUsers(PanelRequest.CollectionID); var collection = ES.Services.RDS.GetRdsCollection(PanelRequest.CollectionID); @@ -50,6 +51,20 @@ namespace WebsitePanel.Portal.RDS } } + private void BindQuota() + { + PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); + OrganizationStatistics stats = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID); + OrganizationStatistics tenantStats = ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID); + usersQuota.QuotaUsedValue = stats.CreatedRdsUsers; + usersQuota.QuotaValue = stats.AllocatedRdsUsers; + + if (stats.AllocatedUsers != -1) + { + usersQuota.QuotaAvailable = tenantStats.AllocatedRdsUsers - tenantStats.CreatedRdsUsers; + } + } + private bool SaveRdsUsers() { try @@ -73,6 +88,7 @@ namespace WebsitePanel.Portal.RDS } SaveRdsUsers(); + BindQuota(); } protected void btnSaveExit_Click(object sender, EventArgs e) diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.designer.cs index b4cdce32..e584e549 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSEditCollectionUsers.ascx.designer.cs @@ -93,6 +93,24 @@ namespace WebsitePanel.Portal.RDS { /// protected global::WebsitePanel.Portal.RDS.UserControls.RDSCollectionUsers users; + /// + /// locQuota control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Localize locQuota; + + /// + /// usersQuota control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::WebsitePanel.Portal.QuotaViewer usersQuota; + /// /// buttonPanel control. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSUserSessions.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSUserSessions.ascx index 642ed06a..9afc8a5b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSUserSessions.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSUserSessions.ascx @@ -38,10 +38,11 @@ - + + diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSUserSessions.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSUserSessions.ascx.cs index 79e37ea8..9938e16e 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSUserSessions.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/RDSUserSessions.ascx.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using WebsitePanel.EnterpriseServer; +using WebsitePanel.Providers.HostedSolution; using WebsitePanel.Providers.RemoteDesktopServices; namespace WebsitePanel.Portal.RDS @@ -101,5 +103,15 @@ namespace WebsitePanel.Portal.RDS gvRDSUserSessions.DataSource = userSessions; gvRDSUserSessions.DataBind(); } + + public string GetAccountImage(bool vip) + { + if (vip) + { + return GetThemedImage("Exchange/vip_user_16.png"); + } + + return GetThemedImage("Exchange/accounting_mail_16.png"); + } } } \ No newline at end of file