From 4ecb5896ce3b3076646008f83f95ae0d5963ace7 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Tue, 9 Dec 2014 05:27:06 -0800 Subject: [PATCH] Enable/Disable RDS server --- WebsitePanel/Database/update_db.sql | 196 ++++++++++-------- .../Data/DataProvider.cs | 7 +- .../RemoteDesktopServicesController.cs | 4 +- .../RemoteDesktopServices/RdsServer.cs | 1 + .../AssignedRDSServers.ascx.resx | 12 ++ .../WebsitePanel/RDS/AssignedRDSServers.ascx | 14 +- .../RDS/AssignedRDSServers.ascx.cs | 58 ++++-- 7 files changed, 174 insertions(+), 118 deletions(-) diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index 355e1325..644bf947 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -5528,31 +5528,6 @@ WHERE Id = @Id GO -IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'UpdateRDSServer') -DROP PROCEDURE UpdateRDSServer -GO -CREATE PROCEDURE [dbo].[UpdateRDSServer] -( - @Id INT, - @ItemID INT, - @Name NVARCHAR(255), - @FqdName NVARCHAR(255), - @Description NVARCHAR(255), - @RDSCollectionId INT -) -AS - -UPDATE RDSServers -SET - ItemID = @ItemID, - Name = @Name, - FqdName = @FqdName, - Description = @Description, - RDSCollectionId = @RDSCollectionId -WHERE ID = @Id -GO - - IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'AddRDSServerToOrganization') DROP PROCEDURE AddRDSServerToOrganization GO @@ -5707,73 +5682,7 @@ GO -IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetRDSServersPaged') -DROP PROCEDURE GetRDSServersPaged -GO -CREATE PROCEDURE [dbo].[GetRDSServersPaged] -( - @FilterColumn nvarchar(50) = '', - @FilterValue nvarchar(50) = '', - @ItemID int, - @IgnoreItemId bit, - @RdsCollectionId int, - @IgnoreRdsCollectionId bit, - @SortColumn nvarchar(50), - @StartRow int, - @MaximumRows int -) -AS --- build query and run it to the temporary table -DECLARE @sql nvarchar(2000) -SET @sql = ' - -DECLARE @EndRow int -SET @EndRow = @StartRow + @MaximumRows - -DECLARE @RDSServer TABLE -( - ItemPosition int IDENTITY(0,1), - RDSServerId int -) -INSERT INTO @RDSServer (RDSServerId) -SELECT - S.ID -FROM RDSServers AS S -WHERE - ((((@ItemID is Null AND S.ItemID is null) or @IgnoreItemId = 1) - or (@ItemID is not Null AND S.ItemID = @ItemID)) - and - (((@RdsCollectionId is Null AND S.RDSCollectionId is null) or @IgnoreRdsCollectionId = 1) - or (@RdsCollectionId is not Null AND S.RDSCollectionId = @RdsCollectionId)))' - -IF @FilterColumn <> '' AND @FilterValue <> '' -SET @sql = @sql + ' AND ' + @FilterColumn + ' LIKE @FilterValue ' - -IF @SortColumn <> '' AND @SortColumn IS NOT NULL -SET @sql = @sql + ' ORDER BY ' + @SortColumn + ' ' - -SET @sql = @sql + ' SELECT COUNT(RDSServerId) FROM @RDSServer; -SELECT - ST.ID, - ST.ItemID, - ST.Name, - ST.FqdName, - ST.Description, - ST.RdsCollectionId, - SI.ItemName -FROM @RDSServer AS S -INNER JOIN RDSServers AS ST ON S.RDSServerId = ST.ID -LEFT OUTER JOIN ServiceItems AS SI ON SI.ItemId = ST.ItemId -WHERE S.ItemPosition BETWEEN @StartRow AND @EndRow' - -exec sp_executesql @sql, N'@StartRow int, @MaximumRows int, @FilterValue nvarchar(50), @ItemID int, @RdsCollectionId int, @IgnoreItemId bit, @IgnoreRdsCollectionId bit', -@StartRow, @MaximumRows, @FilterValue, @ItemID, @RdsCollectionId, @IgnoreItemId , @IgnoreRdsCollectionId - - -RETURN - -GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON @@ -6082,3 +5991,108 @@ set PropertyValue='%PROGRAMFILES(x86)%\PHP\php.exe' where PropertyName='Php4Path' and ProviderId in(101, 105) GO + +IF NOT EXISTS(SELECT * FROM sys.columns + WHERE [name] = N'ConnectionEnabled' AND [object_id] = OBJECT_ID(N'RDSServers')) +BEGIN + ALTER TABLE [RDSServers] + ADD ConnectionEnabled BIT NOT NULL DEFAULT(1) +END + +GO + + +IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetRDSServersPaged') +DROP PROCEDURE GetRDSServersPaged +GO +CREATE PROCEDURE [dbo].[GetRDSServersPaged] +( + @FilterColumn nvarchar(50) = '', + @FilterValue nvarchar(50) = '', + @ItemID int, + @IgnoreItemId bit, + @RdsCollectionId int, + @IgnoreRdsCollectionId bit, + @SortColumn nvarchar(50), + @StartRow int, + @MaximumRows int +) +AS +-- build query and run it to the temporary table +DECLARE @sql nvarchar(2000) + +SET @sql = ' + +DECLARE @EndRow int +SET @EndRow = @StartRow + @MaximumRows + +DECLARE @RDSServer TABLE +( + ItemPosition int IDENTITY(0,1), + RDSServerId int +) +INSERT INTO @RDSServer (RDSServerId) +SELECT + S.ID +FROM RDSServers AS S +WHERE + ((((@ItemID is Null AND S.ItemID is null) or @IgnoreItemId = 1) + or (@ItemID is not Null AND S.ItemID = @ItemID)) + and + (((@RdsCollectionId is Null AND S.RDSCollectionId is null) or @IgnoreRdsCollectionId = 1) + or (@RdsCollectionId is not Null AND S.RDSCollectionId = @RdsCollectionId)))' + +IF @FilterColumn <> '' AND @FilterValue <> '' +SET @sql = @sql + ' AND ' + @FilterColumn + ' LIKE @FilterValue ' + +IF @SortColumn <> '' AND @SortColumn IS NOT NULL +SET @sql = @sql + ' ORDER BY ' + @SortColumn + ' ' + +SET @sql = @sql + ' SELECT COUNT(RDSServerId) FROM @RDSServer; +SELECT + ST.ID, + ST.ItemID, + ST.Name, + ST.FqdName, + ST.Description, + ST.RdsCollectionId, + SI.ItemName, + ST.ConnectionEnabled +FROM @RDSServer AS S +INNER JOIN RDSServers AS ST ON S.RDSServerId = ST.ID +LEFT OUTER JOIN ServiceItems AS SI ON SI.ItemId = ST.ItemId +WHERE S.ItemPosition BETWEEN @StartRow AND @EndRow' + +exec sp_executesql @sql, N'@StartRow int, @MaximumRows int, @FilterValue nvarchar(50), @ItemID int, @RdsCollectionId int, @IgnoreItemId bit, @IgnoreRdsCollectionId bit', +@StartRow, @MaximumRows, @FilterValue, @ItemID, @RdsCollectionId, @IgnoreItemId , @IgnoreRdsCollectionId + + +RETURN + +GO + +IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'UpdateRDSServer') +DROP PROCEDURE UpdateRDSServer +GO +CREATE PROCEDURE [dbo].[UpdateRDSServer] +( + @Id INT, + @ItemID INT, + @Name NVARCHAR(255), + @FqdName NVARCHAR(255), + @Description NVARCHAR(255), + @RDSCollectionId INT, + @ConnectionEnabled BIT +) +AS + +UPDATE RDSServers +SET + ItemID = @ItemID, + Name = @Name, + FqdName = @FqdName, + Description = @Description, + RDSCollectionId = @RDSCollectionId, + ConnectionEnabled = @ConnectionEnabled +WHERE ID = @Id +GO \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs index 62f9905f..98e2a54d 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs @@ -4625,10 +4625,10 @@ namespace WebsitePanel.EnterpriseServer public static void UpdateRDSServer(RdsServer server) { UpdateRDSServer(server.Id, server.ItemId, server.Name, server.FqdName, server.Description, - server.RdsCollectionId); + server.RdsCollectionId, server.ConnectionEnabled); } - public static void UpdateRDSServer(int id, int? itemId, string name, string fqdName, string description, int? rdsCollectionId) + public static void UpdateRDSServer(int id, int? itemId, string name, string fqdName, string description, int? rdsCollectionId, bool connectionEnabled) { SqlHelper.ExecuteNonQuery( ConnectionString, @@ -4639,7 +4639,8 @@ namespace WebsitePanel.EnterpriseServer new SqlParameter("@Name", name), new SqlParameter("@FqdName", fqdName), new SqlParameter("@Description", description), - new SqlParameter("@RDSCollectionId", rdsCollectionId) + new SqlParameter("@RDSCollectionId", rdsCollectionId), + new SqlParameter("@ConnectionEnabled", connectionEnabled) ); } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs index 41db1b4d..c3c154a7 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs @@ -478,7 +478,7 @@ namespace WebsitePanel.EnterpriseServer var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); - var rdsServer = GetRdsServer(rdsSeverId); + var rdsServer = GetRdsServer(rdsSeverId); if (rdsServer == null) { @@ -488,6 +488,8 @@ namespace WebsitePanel.EnterpriseServer } rds.SetRDServerNewConnectionAllowed(newConnectionAllowed, rdsServer); + rdsServer.ConnectionEnabled = newConnectionAllowed; + DataProvider.UpdateRDSServer(rdsServer); } catch (Exception ex) { diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServer.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServer.cs index 5d44984f..de1760a1 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServer.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServer.cs @@ -18,5 +18,6 @@ namespace WebsitePanel.Providers.RemoteDesktopServices public string Address { get; set; } public string ItemName { get; set; } public int? RdsCollectionId { get; set; } + public bool ConnectionEnabled { get; set; } } } \ No newline at end of file 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 56d959f7..33277c17 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 @@ -147,4 +147,16 @@ Total RDS Servers Allocated: + + Disable + + + Enable + + + Disable + + + Enable + \ 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 c1956968..0ce2a538 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx @@ -1,4 +1,5 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AssignedRDSServers.ascx.cs" Inherits="WebsitePanel.Portal.RDS.AssignedRDSServers" %> +<%@ Import Namespace="WebsitePanel.Portal" %> <%@ Register Src="../UserControls/SimpleMessageBox.ascx" TagName="SimpleMessageBox" TagPrefix="wsp" %> <%@ Register Src="../UserControls/QuotaViewer.ascx" TagName="QuotaViewer" TagPrefix="wsp" %> <%@ Register Src="../UserControls/EnableAsyncTasksSupport.ascx" TagName="EnableAsyncTasksSupport" TagPrefix="wsp" %> @@ -46,15 +47,24 @@ DataSourceID="odsRDSAssignedServersPaged" PageSize="20"> - + <%# Eval("Name") %> - + + + + + + + + diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx.cs index 906f8182..025f24fd 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/AssignedRDSServers.ascx.cs @@ -61,35 +61,31 @@ namespace WebsitePanel.Portal.RDS protected void gvRDSAssignedServers_RowCommand(object sender, GridViewCommandEventArgs e) { - if (e.CommandName == "DeleteItem") - { - // delete RDS Server - int rdsServerId = int.Parse(e.CommandArgument.ToString()); + int rdsServerId = int.Parse(e.CommandArgument.ToString()); - try - { - RdsServer rdsServer = ES.Services.RDS.GetRdsServer(rdsServerId); + + RdsServer rdsServer = ES.Services.RDS.GetRdsServer(rdsServerId); + + switch (e.CommandName) + { + case "DeleteItem": if (rdsServer.RdsCollectionId != null) { messageBox.ShowErrorMessage("RDS_UNASSIGN_SERVER_FROM_ORG_SERVER_IS_IN_COLLECTION"); return; } - ResultObject result = ES.Services.RDS.RemoveRdsServerFromOrganization(rdsServerId); - if (!result.IsSuccess) - { - messageBox.ShowMessage(result, "REMOTE_DESKTOP_SERVICES_UNASSIGN_SERVER_FROM_ORG", "RDS"); - return; - } - - gvRDSAssignedServers.DataBind(); - - } - catch (Exception ex) - { - ShowErrorMessage("REMOTE_DESKTOP_SERVICES_UNASSIGN_SERVER_FROM_ORG", ex); - } + DeleteItem(rdsServerId); + break; + case "EnableItem": + ChangeConnectionState(true, rdsServer); + break; + case "DisableItem": + ChangeConnectionState(false, rdsServer); + break; } + + gvRDSAssignedServers.DataBind(); } protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) @@ -97,6 +93,26 @@ namespace WebsitePanel.Portal.RDS gvRDSAssignedServers.PageSize = Convert.ToInt16(ddlPageSize.SelectedValue); gvRDSAssignedServers.DataBind(); + } + + #region Methods + + private void DeleteItem(int rdsServerId) + { + ResultObject result = ES.Services.RDS.RemoveRdsServerFromOrganization(rdsServerId); + + if (!result.IsSuccess) + { + messageBox.ShowMessage(result, "REMOTE_DESKTOP_SERVICES_UNASSIGN_SERVER_FROM_ORG", "RDS"); + return; + } } + + private void ChangeConnectionState(bool enabled, RdsServer rdsServer) + { + ES.Services.RDS.SetRDServerNewConnectionAllowed(rdsServer.ItemId.Value, enabled, rdsServer.Id); + } + + #endregion } } \ No newline at end of file