Enable/Disable RDS server

This commit is contained in:
vfedosevich 2014-12-09 05:27:06 -08:00
parent f4c248637e
commit 4ecb5896ce
7 changed files with 174 additions and 118 deletions

View file

@ -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

View file

@ -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)
);
}

View file

@ -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)
{

View file

@ -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; }
}
}

View file

@ -147,4 +147,16 @@
<data name="locQuota.Text" xml:space="preserve">
<value>Total RDS Servers Allocated:</value>
</data>
<data name="cmdDisable.Text" xml:space="preserve">
<value>Disable</value>
</data>
<data name="cmdEnable.Text" xml:space="preserve">
<value>Enable</value>
</data>
<data name="cmdDisable.ToolTip" xml:space="preserve">
<value>Disable</value>
</data>
<data name="cmdEnable.ToolTip" xml:space="preserve">
<value>Enable</value>
</data>
</root>

View file

@ -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">
<Columns>
<asp:TemplateField HeaderText="gvRDSServerName" SortExpression="Name">
<ItemStyle Width="90%"></ItemStyle>
<ItemStyle Width="80%"></ItemStyle>
<ItemTemplate>
<asp:Label id="litRDSServerName" runat="server">
<%# Eval("Name") %>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<asp:TemplateField>
<ItemStyle Width="10%"></ItemStyle>
<ItemTemplate>
<asp:ImageButton ID="EnableLinkButton" ImageUrl='<%# PortalUtils.GetThemedImage("Exchange/bullet.gif")%>' runat="server" Visible='<%# Eval("RdsCollectionId") != null && !Convert.ToBoolean(Eval("ConnectionEnabled")) %>'
CommandName="EnableItem" CommandArgument='<%# Eval("Id") %>' meta:resourcekey="cmdEnable"></asp:ImageButton>
<asp:ImageButton ID="DisableLinkButton" ImageUrl='<%# PortalUtils.GetThemedImage("Exchange/bullet_hover.gif")%>' runat="server" Visible='<%# Eval("RdsCollectionId") != null && Convert.ToBoolean(Eval("ConnectionEnabled")) %>'
CommandName="DisableItem" CommandArgument='<%# Eval("Id") %>' meta:resourcekey="cmdDisable"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="imgRemove1" runat="server" Text="Remove" Visible='<%# Eval("RdsCollectionId") == null %>'
CommandName="DeleteItem" CommandArgument='<%# Eval("Id") %>'
meta:resourcekey="cmdDelete" OnClientClick="return confirm('Are you sure you want to remove selected server?')"></asp:LinkButton>

View file

@ -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
}
}