diff --git a/WebsitePanel/Database/install_db.sql b/WebsitePanel/Database/install_db.sql
index 5ce2c55b..a0f5162d 100644
--- a/WebsitePanel/Database/install_db.sql
+++ b/WebsitePanel/Database/install_db.sql
@@ -41836,7 +41836,7 @@ INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName]
GO
INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES (65, 4, N'SmarterMail', N'SmarterMail 9.x', N'WebsitePanel.Providers.Mail.SmarterMail9, WebsitePanel.Providers.Mail.SmarterMail9', N'SmarterMail60', NULL)
GO
-INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES (66, 4, N'SmarterMail', N'SmarterMail 10.x +', N'WebsitePanel.Providers.Mail.SmarterMail10, WebsitePanel.Providers.Mail.SmarterMail10', N'SmarterMail60', NULL)
+INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES (66, 4, N'SmarterMail', N'SmarterMail 10.x +', N'WebsitePanel.Providers.Mail.SmarterMail10, WebsitePanel.Providers.Mail.SmarterMail10', N'SmarterMail100', NULL)
GO
INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES (90, 12, N'Exchange2010SP2', N'Hosted Microsoft Exchange Server 2010 SP2', N'WebsitePanel.Providers.HostedSolution.Exchange2010SP2, WebsitePanel.Providers.HostedSolution', N'Exchange', NULL)
GO
diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql
index a2d28ea9..4fd5d931 100644
--- a/WebsitePanel/Database/update_db.sql
+++ b/WebsitePanel/Database/update_db.sql
@@ -1,4 +1,4 @@
-USE [${install.database}]
+USE [${install.database}]
GO
-- update database version
DECLARE @build_version nvarchar(10), @build_date datetime
@@ -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
@@ -8605,6 +8621,138 @@ WHERE
RETURN
GO
+
+
+--Webdav portal users settings
+
+IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE name = 'WebDavPortalUsersSettings')
+CREATE TABLE WebDavPortalUsersSettings
+(
+ ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
+ AccountId INT NOT NULL,
+ Settings NVARCHAR(max)
+)
+GO
+
+IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_WebDavPortalUsersSettings_UserId')
+ALTER TABLE [dbo].[WebDavPortalUsersSettings]
+DROP CONSTRAINT [FK_WebDavPortalUsersSettings_UserId]
+GO
+
+ALTER TABLE [dbo].[WebDavPortalUsersSettings] WITH CHECK ADD CONSTRAINT [FK_WebDavPortalUsersSettings_UserId] FOREIGN KEY([AccountID])
+REFERENCES [dbo].[ExchangeAccounts] ([AccountID])
+ON DELETE CASCADE
+GO
+
+
+
+IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetWebDavPortalUsersSettingsByAccountId')
+DROP PROCEDURE GetWebDavPortalUsersSettingsByAccountId
+GO
+CREATE PROCEDURE [dbo].[GetWebDavPortalUsersSettingsByAccountId]
+(
+ @AccountId INT
+)
+AS
+SELECT TOP 1
+ US.Id,
+ US.AccountId,
+ US.Settings
+ FROM WebDavPortalUsersSettings AS US
+ WHERE AccountId = @AccountId
+GO
+
+
+
+IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'AddWebDavPortalUsersSettings')
+DROP PROCEDURE AddWebDavPortalUsersSettings
+GO
+CREATE PROCEDURE [dbo].[AddWebDavPortalUsersSettings]
+(
+ @WebDavPortalUsersSettingsId INT OUTPUT,
+ @AccountId INT,
+ @Settings NVARCHAR(max)
+)
+AS
+
+INSERT INTO WebDavPortalUsersSettings
+(
+ AccountId,
+ Settings
+)
+VALUES
+(
+ @AccountId,
+ @Settings
+)
+
+SET @WebDavPortalUsersSettingsId = SCOPE_IDENTITY()
+
+RETURN
+GO
+
+
+IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'UpdateWebDavPortalUsersSettings')
+DROP PROCEDURE UpdateWebDavPortalUsersSettings
+GO
+CREATE PROCEDURE [dbo].[UpdateWebDavPortalUsersSettings]
+(
+ @AccountId INT,
+ @Settings NVARCHAR(max)
+)
+AS
+
+UPDATE WebDavPortalUsersSettings
+SET
+ Settings = @Settings
+WHERE AccountId = @AccountId
+GO
+
+IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [DisplayName] = 'SmarterMail 10.x +')
+BEGIN
+INSERT [dbo].[Providers] ([ProviderId], [GroupId], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES(66, 4, N'SmarterMail', N'SmarterMail 10.x +', N'WebsitePanel.Providers.Mail.SmarterMail10, WebsitePanel.Providers.Mail.SmarterMail10', N'SmarterMail100', NULL)
+END
+ELSE
+BEGIN
+UPDATE [dbo].[Providers] SET [EditorControl] = 'SmarterMail100' WHERE [DisplayName] = 'SmarterMail 10.x +'
+END
+GO
+
+
+-- Service items count by name and serviceid
+
+IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetServiceItemsCountByNameAndServiceId')
+DROP PROCEDURE GetServiceItemsCountByNameAndServiceId
+GO
+
+CREATE PROCEDURE [dbo].[GetServiceItemsCountByNameAndServiceId]
+(
+ @ActorID int,
+ @ServiceId int,
+ @ItemName nvarchar(500),
+ @GroupName nvarchar(100) = NULL,
+ @ItemTypeName nvarchar(200)
+)
+AS
+SELECT Count(*)
+FROM ServiceItems AS SI
+INNER JOIN ServiceItemTypes AS SIT ON SI.ItemTypeID = SIT.ItemTypeID
+INNER JOIN ResourceGroups AS RG ON SIT.GroupID = RG.GroupID
+INNER JOIN Services AS S ON SI.ServiceID = S.ServiceID
+WHERE S.ServiceID = @ServiceId
+AND SIT.TypeName = @ItemTypeName
+AND SI.ItemName = @ItemName
+AND ((@GroupName IS NULL) OR (@GroupName IS NOT NULL AND RG.GroupName = @GroupName))
+RETURN
+GO
+
+-- Hyper-V 2012 R2
+IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [ProviderName] = 'HyperV2012R2')
+BEGIN
+INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES (350, 30, N'HyperV2012R2', N'Microsoft Hyper-V 2012 R2', N'WebsitePanel.Providers.Virtualization.HyperV2012R2, WebsitePanel.Providers.Virtualization.HyperV2012R2', N'HyperV', 1)
+END
+GO
+
-- Hyper-V 2012 R2
IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [ProviderName] = 'HyperV2012R2')
BEGIN
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Common/BusinessErrorCodes.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Common/BusinessErrorCodes.cs
index 8e8ed5ff..dc4f432d 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Common/BusinessErrorCodes.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Common/BusinessErrorCodes.cs
@@ -151,6 +151,7 @@ namespace WebsitePanel.EnterpriseServer
public const int ERROR_MAIL_LICENSE_USERS_QUOTA = -724;
public const int ERROR_MAIL_ACCOUNT_MAX_MAILBOX_SIZE_LIMIT = -725;
+ public const int ERROR_MAIL_ACCOUNT_PASSWORD_NOT_COMPLEXITY = -726;
#endregion
#region FTP
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/EnterpriseStorageProxy.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/EnterpriseStorageProxy.cs
index 7300cf58..87682b0f 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/EnterpriseStorageProxy.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/EnterpriseStorageProxy.cs
@@ -69,6 +69,12 @@ namespace WebsitePanel.EnterpriseServer {
private System.Threading.SendOrPostCallback CheckUsersDomainExistsOperationCompleted;
+ private System.Threading.SendOrPostCallback GetWebDavPortalUserSettingsByAccountIdOperationCompleted;
+
+ private System.Threading.SendOrPostCallback UpdateWebDavPortalUserSettingsOperationCompleted;
+
+ private System.Threading.SendOrPostCallback SearchFilesOperationCompleted;
+
private System.Threading.SendOrPostCallback GetDirectoryBrowseEnabledOperationCompleted;
private System.Threading.SendOrPostCallback SetDirectoryBrowseEnabledOperationCompleted;
@@ -145,6 +151,15 @@ namespace WebsitePanel.EnterpriseServer {
///
public event CheckUsersDomainExistsCompletedEventHandler CheckUsersDomainExistsCompleted;
+ ///
+ public event GetWebDavPortalUserSettingsByAccountIdCompletedEventHandler GetWebDavPortalUserSettingsByAccountIdCompleted;
+
+ ///
+ public event UpdateWebDavPortalUserSettingsCompletedEventHandler UpdateWebDavPortalUserSettingsCompleted;
+
+ ///
+ public event SearchFilesCompletedEventHandler SearchFilesCompleted;
+
///
public event GetDirectoryBrowseEnabledCompletedEventHandler GetDirectoryBrowseEnabledCompleted;
@@ -928,6 +943,143 @@ namespace WebsitePanel.EnterpriseServer {
}
}
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetWebDavPortalUserSettingsByAccount" +
+ "Id", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public string GetWebDavPortalUserSettingsByAccountId(int accountId) {
+ object[] results = this.Invoke("GetWebDavPortalUserSettingsByAccountId", new object[] {
+ accountId});
+ return ((string)(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginGetWebDavPortalUserSettingsByAccountId(int accountId, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("GetWebDavPortalUserSettingsByAccountId", new object[] {
+ accountId}, callback, asyncState);
+ }
+
+ ///
+ public string EndGetWebDavPortalUserSettingsByAccountId(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((string)(results[0]));
+ }
+
+ ///
+ public void GetWebDavPortalUserSettingsByAccountIdAsync(int accountId) {
+ this.GetWebDavPortalUserSettingsByAccountIdAsync(accountId, null);
+ }
+
+ ///
+ public void GetWebDavPortalUserSettingsByAccountIdAsync(int accountId, object userState) {
+ if ((this.GetWebDavPortalUserSettingsByAccountIdOperationCompleted == null)) {
+ this.GetWebDavPortalUserSettingsByAccountIdOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetWebDavPortalUserSettingsByAccountIdOperationCompleted);
+ }
+ this.InvokeAsync("GetWebDavPortalUserSettingsByAccountId", new object[] {
+ accountId}, this.GetWebDavPortalUserSettingsByAccountIdOperationCompleted, userState);
+ }
+
+ private void OnGetWebDavPortalUserSettingsByAccountIdOperationCompleted(object arg) {
+ if ((this.GetWebDavPortalUserSettingsByAccountIdCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.GetWebDavPortalUserSettingsByAccountIdCompleted(this, new GetWebDavPortalUserSettingsByAccountIdCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/UpdateWebDavPortalUserSettings", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public void UpdateWebDavPortalUserSettings(int accountId, string settings) {
+ this.Invoke("UpdateWebDavPortalUserSettings", new object[] {
+ accountId,
+ settings});
+ }
+
+ ///
+ public System.IAsyncResult BeginUpdateWebDavPortalUserSettings(int accountId, string settings, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("UpdateWebDavPortalUserSettings", new object[] {
+ accountId,
+ settings}, callback, asyncState);
+ }
+
+ ///
+ public void EndUpdateWebDavPortalUserSettings(System.IAsyncResult asyncResult) {
+ this.EndInvoke(asyncResult);
+ }
+
+ ///
+ public void UpdateWebDavPortalUserSettingsAsync(int accountId, string settings) {
+ this.UpdateWebDavPortalUserSettingsAsync(accountId, settings, null);
+ }
+
+ ///
+ public void UpdateWebDavPortalUserSettingsAsync(int accountId, string settings, object userState) {
+ if ((this.UpdateWebDavPortalUserSettingsOperationCompleted == null)) {
+ this.UpdateWebDavPortalUserSettingsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateWebDavPortalUserSettingsOperationCompleted);
+ }
+ this.InvokeAsync("UpdateWebDavPortalUserSettings", new object[] {
+ accountId,
+ settings}, this.UpdateWebDavPortalUserSettingsOperationCompleted, userState);
+ }
+
+ private void OnUpdateWebDavPortalUserSettingsOperationCompleted(object arg) {
+ if ((this.UpdateWebDavPortalUserSettingsCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.UpdateWebDavPortalUserSettingsCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/SearchFiles", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public SystemFile[] SearchFiles(int itemId, string[] searchPaths, string searchText, string userPrincipalName, bool recursive) {
+ object[] results = this.Invoke("SearchFiles", new object[] {
+ itemId,
+ searchPaths,
+ searchText,
+ userPrincipalName,
+ recursive});
+ return ((SystemFile[])(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginSearchFiles(int itemId, string[] searchPaths, string searchText, string userPrincipalName, bool recursive, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("SearchFiles", new object[] {
+ itemId,
+ searchPaths,
+ searchText,
+ userPrincipalName,
+ recursive}, callback, asyncState);
+ }
+
+ ///
+ public SystemFile[] EndSearchFiles(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((SystemFile[])(results[0]));
+ }
+
+ ///
+ public void SearchFilesAsync(int itemId, string[] searchPaths, string searchText, string userPrincipalName, bool recursive) {
+ this.SearchFilesAsync(itemId, searchPaths, searchText, userPrincipalName, recursive, null);
+ }
+
+ ///
+ public void SearchFilesAsync(int itemId, string[] searchPaths, string searchText, string userPrincipalName, bool recursive, object userState) {
+ if ((this.SearchFilesOperationCompleted == null)) {
+ this.SearchFilesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSearchFilesOperationCompleted);
+ }
+ this.InvokeAsync("SearchFiles", new object[] {
+ itemId,
+ searchPaths,
+ searchText,
+ userPrincipalName,
+ recursive}, this.SearchFilesOperationCompleted, userState);
+ }
+
+ private void OnSearchFilesOperationCompleted(object arg) {
+ if ((this.SearchFilesCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.SearchFilesCompleted(this, new SearchFilesCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetDirectoryBrowseEnabled", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool GetDirectoryBrowseEnabled(int itemId, string site) {
@@ -1811,6 +1963,62 @@ namespace WebsitePanel.EnterpriseServer {
}
}
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void GetWebDavPortalUserSettingsByAccountIdCompletedEventHandler(object sender, GetWebDavPortalUserSettingsByAccountIdCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class GetWebDavPortalUserSettingsByAccountIdCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal GetWebDavPortalUserSettingsByAccountIdCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public string Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((string)(this.results[0]));
+ }
+ }
+ }
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void UpdateWebDavPortalUserSettingsCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void SearchFilesCompletedEventHandler(object sender, SearchFilesCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class SearchFilesCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal SearchFilesCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public SystemFile[] Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((SystemFile[])(this.results[0]));
+ }
+ }
+ }
+
///
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
public delegate void GetDirectoryBrowseEnabledCompletedEventHandler(object sender, GetDirectoryBrowseEnabledCompletedEventArgs e);
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs
index bf847f10..3214d80d 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs
@@ -106,6 +106,20 @@ namespace WebsitePanel.EnterpriseServer {
private System.Threading.SendOrPostCallback GetRdsCollectionSessionHostsOperationCompleted;
+ private System.Threading.SendOrPostCallback GetRdsServerInfoOperationCompleted;
+
+ private System.Threading.SendOrPostCallback GetRdsServerStatusOperationCompleted;
+
+ private System.Threading.SendOrPostCallback ShutDownRdsServerOperationCompleted;
+
+ private System.Threading.SendOrPostCallback RestartRdsServerOperationCompleted;
+
+ private System.Threading.SendOrPostCallback GetRdsCollectionLocalAdminsOperationCompleted;
+
+ private System.Threading.SendOrPostCallback SaveRdsCollectionLocalAdminsOperationCompleted;
+
+ private System.Threading.SendOrPostCallback InstallSessionHostsCertificateOperationCompleted;
+
///
public esRemoteDesktopServices() {
this.Url = "http://localhost:9002/esRemoteDesktopServices.asmx";
@@ -225,6 +239,27 @@ namespace WebsitePanel.EnterpriseServer {
///
public event GetRdsCollectionSessionHostsCompletedEventHandler GetRdsCollectionSessionHostsCompleted;
+ ///
+ public event GetRdsServerInfoCompletedEventHandler GetRdsServerInfoCompleted;
+
+ ///
+ public event GetRdsServerStatusCompletedEventHandler GetRdsServerStatusCompleted;
+
+ ///
+ public event ShutDownRdsServerCompletedEventHandler ShutDownRdsServerCompleted;
+
+ ///
+ public event RestartRdsServerCompletedEventHandler RestartRdsServerCompleted;
+
+ ///
+ public event GetRdsCollectionLocalAdminsCompletedEventHandler GetRdsCollectionLocalAdminsCompleted;
+
+ ///
+ public event SaveRdsCollectionLocalAdminsCompletedEventHandler SaveRdsCollectionLocalAdminsCompleted;
+
+ ///
+ public event InstallSessionHostsCertificateCompletedEventHandler InstallSessionHostsCertificateCompleted;
+
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsCollection", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public RdsCollection GetRdsCollection(int collectionId) {
@@ -1196,15 +1231,17 @@ namespace WebsitePanel.EnterpriseServer {
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/RemoveRdsServerFromOrganization", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
- public ResultObject RemoveRdsServerFromOrganization(int rdsServerId) {
+ public ResultObject RemoveRdsServerFromOrganization(int itemId, int rdsServerId) {
object[] results = this.Invoke("RemoveRdsServerFromOrganization", new object[] {
+ itemId,
rdsServerId});
return ((ResultObject)(results[0]));
}
///
- public System.IAsyncResult BeginRemoveRdsServerFromOrganization(int rdsServerId, System.AsyncCallback callback, object asyncState) {
+ public System.IAsyncResult BeginRemoveRdsServerFromOrganization(int itemId, int rdsServerId, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("RemoveRdsServerFromOrganization", new object[] {
+ itemId,
rdsServerId}, callback, asyncState);
}
@@ -1215,16 +1252,17 @@ namespace WebsitePanel.EnterpriseServer {
}
///
- public void RemoveRdsServerFromOrganizationAsync(int rdsServerId) {
- this.RemoveRdsServerFromOrganizationAsync(rdsServerId, null);
+ public void RemoveRdsServerFromOrganizationAsync(int itemId, int rdsServerId) {
+ this.RemoveRdsServerFromOrganizationAsync(itemId, rdsServerId, null);
}
///
- public void RemoveRdsServerFromOrganizationAsync(int rdsServerId, object userState) {
+ public void RemoveRdsServerFromOrganizationAsync(int itemId, int rdsServerId, object userState) {
if ((this.RemoveRdsServerFromOrganizationOperationCompleted == null)) {
this.RemoveRdsServerFromOrganizationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRemoveRdsServerFromOrganizationOperationCompleted);
}
this.InvokeAsync("RemoveRdsServerFromOrganization", new object[] {
+ itemId,
rdsServerId}, this.RemoveRdsServerFromOrganizationOperationCompleted, userState);
}
@@ -1944,6 +1982,314 @@ namespace WebsitePanel.EnterpriseServer {
}
}
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsServerInfo", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public RdsServerInfo GetRdsServerInfo(int itemId, string fqdnName) {
+ object[] results = this.Invoke("GetRdsServerInfo", new object[] {
+ itemId,
+ fqdnName});
+ return ((RdsServerInfo)(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginGetRdsServerInfo(int itemId, string fqdnName, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("GetRdsServerInfo", new object[] {
+ itemId,
+ fqdnName}, callback, asyncState);
+ }
+
+ ///
+ public RdsServerInfo EndGetRdsServerInfo(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((RdsServerInfo)(results[0]));
+ }
+
+ ///
+ public void GetRdsServerInfoAsync(int itemId, string fqdnName) {
+ this.GetRdsServerInfoAsync(itemId, fqdnName, null);
+ }
+
+ ///
+ public void GetRdsServerInfoAsync(int itemId, string fqdnName, object userState) {
+ if ((this.GetRdsServerInfoOperationCompleted == null)) {
+ this.GetRdsServerInfoOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsServerInfoOperationCompleted);
+ }
+ this.InvokeAsync("GetRdsServerInfo", new object[] {
+ itemId,
+ fqdnName}, this.GetRdsServerInfoOperationCompleted, userState);
+ }
+
+ private void OnGetRdsServerInfoOperationCompleted(object arg) {
+ if ((this.GetRdsServerInfoCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.GetRdsServerInfoCompleted(this, new GetRdsServerInfoCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsServerStatus", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public string GetRdsServerStatus(int itemId, string fqdnName) {
+ object[] results = this.Invoke("GetRdsServerStatus", new object[] {
+ itemId,
+ fqdnName});
+ return ((string)(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginGetRdsServerStatus(int itemId, string fqdnName, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("GetRdsServerStatus", new object[] {
+ itemId,
+ fqdnName}, callback, asyncState);
+ }
+
+ ///
+ public string EndGetRdsServerStatus(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((string)(results[0]));
+ }
+
+ ///
+ public void GetRdsServerStatusAsync(int itemId, string fqdnName) {
+ this.GetRdsServerStatusAsync(itemId, fqdnName, null);
+ }
+
+ ///
+ public void GetRdsServerStatusAsync(int itemId, string fqdnName, object userState) {
+ if ((this.GetRdsServerStatusOperationCompleted == null)) {
+ this.GetRdsServerStatusOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsServerStatusOperationCompleted);
+ }
+ this.InvokeAsync("GetRdsServerStatus", new object[] {
+ itemId,
+ fqdnName}, this.GetRdsServerStatusOperationCompleted, userState);
+ }
+
+ private void OnGetRdsServerStatusOperationCompleted(object arg) {
+ if ((this.GetRdsServerStatusCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.GetRdsServerStatusCompleted(this, new GetRdsServerStatusCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/ShutDownRdsServer", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public ResultObject ShutDownRdsServer(int itemId, string fqdnName) {
+ object[] results = this.Invoke("ShutDownRdsServer", new object[] {
+ itemId,
+ fqdnName});
+ return ((ResultObject)(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginShutDownRdsServer(int itemId, string fqdnName, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("ShutDownRdsServer", new object[] {
+ itemId,
+ fqdnName}, callback, asyncState);
+ }
+
+ ///
+ public ResultObject EndShutDownRdsServer(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((ResultObject)(results[0]));
+ }
+
+ ///
+ public void ShutDownRdsServerAsync(int itemId, string fqdnName) {
+ this.ShutDownRdsServerAsync(itemId, fqdnName, null);
+ }
+
+ ///
+ public void ShutDownRdsServerAsync(int itemId, string fqdnName, object userState) {
+ if ((this.ShutDownRdsServerOperationCompleted == null)) {
+ this.ShutDownRdsServerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnShutDownRdsServerOperationCompleted);
+ }
+ this.InvokeAsync("ShutDownRdsServer", new object[] {
+ itemId,
+ fqdnName}, this.ShutDownRdsServerOperationCompleted, userState);
+ }
+
+ private void OnShutDownRdsServerOperationCompleted(object arg) {
+ if ((this.ShutDownRdsServerCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.ShutDownRdsServerCompleted(this, new ShutDownRdsServerCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/RestartRdsServer", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public ResultObject RestartRdsServer(int itemId, string fqdnName) {
+ object[] results = this.Invoke("RestartRdsServer", new object[] {
+ itemId,
+ fqdnName});
+ return ((ResultObject)(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginRestartRdsServer(int itemId, string fqdnName, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("RestartRdsServer", new object[] {
+ itemId,
+ fqdnName}, callback, asyncState);
+ }
+
+ ///
+ public ResultObject EndRestartRdsServer(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((ResultObject)(results[0]));
+ }
+
+ ///
+ public void RestartRdsServerAsync(int itemId, string fqdnName) {
+ this.RestartRdsServerAsync(itemId, fqdnName, null);
+ }
+
+ ///
+ public void RestartRdsServerAsync(int itemId, string fqdnName, object userState) {
+ if ((this.RestartRdsServerOperationCompleted == null)) {
+ this.RestartRdsServerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRestartRdsServerOperationCompleted);
+ }
+ this.InvokeAsync("RestartRdsServer", new object[] {
+ itemId,
+ fqdnName}, this.RestartRdsServerOperationCompleted, userState);
+ }
+
+ private void OnRestartRdsServerOperationCompleted(object arg) {
+ if ((this.RestartRdsServerCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.RestartRdsServerCompleted(this, new RestartRdsServerCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsCollectionLocalAdmins", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public OrganizationUser[] GetRdsCollectionLocalAdmins(int collectionId) {
+ object[] results = this.Invoke("GetRdsCollectionLocalAdmins", new object[] {
+ collectionId});
+ return ((OrganizationUser[])(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginGetRdsCollectionLocalAdmins(int collectionId, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("GetRdsCollectionLocalAdmins", new object[] {
+ collectionId}, callback, asyncState);
+ }
+
+ ///
+ public OrganizationUser[] EndGetRdsCollectionLocalAdmins(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((OrganizationUser[])(results[0]));
+ }
+
+ ///
+ public void GetRdsCollectionLocalAdminsAsync(int collectionId) {
+ this.GetRdsCollectionLocalAdminsAsync(collectionId, null);
+ }
+
+ ///
+ public void GetRdsCollectionLocalAdminsAsync(int collectionId, object userState) {
+ if ((this.GetRdsCollectionLocalAdminsOperationCompleted == null)) {
+ this.GetRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCollectionLocalAdminsOperationCompleted);
+ }
+ this.InvokeAsync("GetRdsCollectionLocalAdmins", new object[] {
+ collectionId}, this.GetRdsCollectionLocalAdminsOperationCompleted, userState);
+ }
+
+ private void OnGetRdsCollectionLocalAdminsOperationCompleted(object arg) {
+ if ((this.GetRdsCollectionLocalAdminsCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.GetRdsCollectionLocalAdminsCompleted(this, new GetRdsCollectionLocalAdminsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/SaveRdsCollectionLocalAdmins", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public ResultObject SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int collectionId) {
+ object[] results = this.Invoke("SaveRdsCollectionLocalAdmins", new object[] {
+ users,
+ collectionId});
+ return ((ResultObject)(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginSaveRdsCollectionLocalAdmins(OrganizationUser[] users, int collectionId, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("SaveRdsCollectionLocalAdmins", new object[] {
+ users,
+ collectionId}, callback, asyncState);
+ }
+
+ ///
+ public ResultObject EndSaveRdsCollectionLocalAdmins(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((ResultObject)(results[0]));
+ }
+
+ ///
+ public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, int collectionId) {
+ this.SaveRdsCollectionLocalAdminsAsync(users, collectionId, null);
+ }
+
+ ///
+ public void SaveRdsCollectionLocalAdminsAsync(OrganizationUser[] users, int collectionId, object userState) {
+ if ((this.SaveRdsCollectionLocalAdminsOperationCompleted == null)) {
+ this.SaveRdsCollectionLocalAdminsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSaveRdsCollectionLocalAdminsOperationCompleted);
+ }
+ this.InvokeAsync("SaveRdsCollectionLocalAdmins", new object[] {
+ users,
+ collectionId}, this.SaveRdsCollectionLocalAdminsOperationCompleted, userState);
+ }
+
+ private void OnSaveRdsCollectionLocalAdminsOperationCompleted(object arg) {
+ if ((this.SaveRdsCollectionLocalAdminsCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.SaveRdsCollectionLocalAdminsCompleted(this, new SaveRdsCollectionLocalAdminsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
+ ///
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/InstallSessionHostsCertificate", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public ResultObject InstallSessionHostsCertificate(int collectionId, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] certificate, string password) {
+ object[] results = this.Invoke("InstallSessionHostsCertificate", new object[] {
+ collectionId,
+ certificate,
+ password});
+ return ((ResultObject)(results[0]));
+ }
+
+ ///
+ public System.IAsyncResult BeginInstallSessionHostsCertificate(int collectionId, byte[] certificate, string password, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("InstallSessionHostsCertificate", new object[] {
+ collectionId,
+ certificate,
+ password}, callback, asyncState);
+ }
+
+ ///
+ public ResultObject EndInstallSessionHostsCertificate(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((ResultObject)(results[0]));
+ }
+
+ ///
+ public void InstallSessionHostsCertificateAsync(int collectionId, byte[] certificate, string password) {
+ this.InstallSessionHostsCertificateAsync(collectionId, certificate, password, null);
+ }
+
+ ///
+ public void InstallSessionHostsCertificateAsync(int collectionId, byte[] certificate, string password, object userState) {
+ if ((this.InstallSessionHostsCertificateOperationCompleted == null)) {
+ this.InstallSessionHostsCertificateOperationCompleted = new System.Threading.SendOrPostCallback(this.OnInstallSessionHostsCertificateOperationCompleted);
+ }
+ this.InvokeAsync("InstallSessionHostsCertificate", new object[] {
+ collectionId,
+ certificate,
+ password}, this.InstallSessionHostsCertificateOperationCompleted, userState);
+ }
+
+ private void OnInstallSessionHostsCertificateOperationCompleted(object arg) {
+ if ((this.InstallSessionHostsCertificateCompleted != null)) {
+ System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
+ this.InstallSessionHostsCertificateCompleted(this, new InstallSessionHostsCertificateCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
+ }
+ }
+
///
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
@@ -2937,4 +3283,186 @@ namespace WebsitePanel.EnterpriseServer {
}
}
}
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void GetRdsServerInfoCompletedEventHandler(object sender, GetRdsServerInfoCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class GetRdsServerInfoCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal GetRdsServerInfoCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public RdsServerInfo Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((RdsServerInfo)(this.results[0]));
+ }
+ }
+ }
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void GetRdsServerStatusCompletedEventHandler(object sender, GetRdsServerStatusCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class GetRdsServerStatusCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal GetRdsServerStatusCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public string Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((string)(this.results[0]));
+ }
+ }
+ }
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void ShutDownRdsServerCompletedEventHandler(object sender, ShutDownRdsServerCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class ShutDownRdsServerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal ShutDownRdsServerCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public ResultObject Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((ResultObject)(this.results[0]));
+ }
+ }
+ }
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void RestartRdsServerCompletedEventHandler(object sender, RestartRdsServerCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class RestartRdsServerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal RestartRdsServerCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public ResultObject Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((ResultObject)(this.results[0]));
+ }
+ }
+ }
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void GetRdsCollectionLocalAdminsCompletedEventHandler(object sender, GetRdsCollectionLocalAdminsCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class GetRdsCollectionLocalAdminsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal GetRdsCollectionLocalAdminsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public OrganizationUser[] Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((OrganizationUser[])(this.results[0]));
+ }
+ }
+ }
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void SaveRdsCollectionLocalAdminsCompletedEventHandler(object sender, SaveRdsCollectionLocalAdminsCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class SaveRdsCollectionLocalAdminsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal SaveRdsCollectionLocalAdminsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public ResultObject Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((ResultObject)(this.results[0]));
+ }
+ }
+ }
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ public delegate void InstallSessionHostsCertificateCompletedEventHandler(object sender, InstallSessionHostsCertificateCompletedEventArgs e);
+
+ ///
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.ComponentModel.DesignerCategoryAttribute("code")]
+ public partial class InstallSessionHostsCertificateCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
+
+ private object[] results;
+
+ internal InstallSessionHostsCertificateCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState) {
+ this.results = results;
+ }
+
+ ///
+ public ResultObject Result {
+ get {
+ this.RaiseExceptionIfNecessary();
+ return ((ResultObject)(this.results[0]));
+ }
+ }
+ }
}
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs
index 1ef34bd0..1d903a9c 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs
@@ -1197,6 +1197,24 @@ namespace WebsitePanel.EnterpriseServer
new SqlParameter("@itemName", itemName));
}
+ public static int GetServiceItemsCountByNameAndServiceId(int actorId, int serviceId, string groupName,
+ string itemName, string itemTypeName)
+ {
+ int res = 0;
+
+ object obj = SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure,
+ ObjectQualifier + "GetServiceItemsCountByNameAndServiceId",
+ new SqlParameter("@ActorID", actorId),
+ new SqlParameter("@ServiceId", serviceId),
+ new SqlParameter("@ItemName", itemName),
+ new SqlParameter("@GroupName", groupName),
+ new SqlParameter("@ItemTypeName", itemTypeName));
+
+ if (!int.TryParse(obj.ToString(), out res)) return -1;
+
+ return res;
+ }
+
public static int AddServiceItem(int actorId, int serviceId, int packageId, string itemName,
string itemTypeName, string xmlProperties)
{
@@ -4486,6 +4504,45 @@ namespace WebsitePanel.EnterpriseServer
);
}
+ public static IDataReader GetWebDavPortalUserSettingsByAccountId(int accountId)
+ {
+ return SqlHelper.ExecuteReader(
+ ConnectionString,
+ CommandType.StoredProcedure,
+ "GetWebDavPortalUsersSettingsByAccountId",
+ new SqlParameter("@AccountId", accountId)
+ );
+ }
+
+ public static int AddWebDavPortalUsersSettings(int accountId, string settings)
+ {
+ SqlParameter settingsId = new SqlParameter("@WebDavPortalUsersSettingsId", SqlDbType.Int);
+ settingsId.Direction = ParameterDirection.Output;
+
+ SqlHelper.ExecuteNonQuery(
+ ConnectionString,
+ CommandType.StoredProcedure,
+ "AddWebDavPortalUsersSettings",
+ settingsId,
+ new SqlParameter("@AccountId", accountId),
+ new SqlParameter("@Settings", settings)
+ );
+
+ // read identity
+ return Convert.ToInt32(settingsId.Value);
+ }
+
+ public static void UpdateWebDavPortalUsersSettings(int accountId, string settings)
+ {
+ SqlHelper.ExecuteNonQuery(
+ ConnectionString,
+ CommandType.StoredProcedure,
+ "UpdateWebDavPortalUsersSettings",
+ new SqlParameter("@AccountId", accountId),
+ new SqlParameter("@Settings", settings)
+ );
+ }
+
#endregion
#region Support Service Levels
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/DatabaseServers/DatabaseServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/DatabaseServers/DatabaseServerController.cs
index 246b6155..afbb2652 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/DatabaseServers/DatabaseServerController.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/DatabaseServers/DatabaseServerController.cs
@@ -125,8 +125,8 @@ namespace WebsitePanel.EnterpriseServer
if (serviceId == 0)
return BusinessErrorCodes.ERROR_MSSQL_RESOURCE_UNAVAILABLE;
- // check package items
- if (PackageController.GetPackageItemByName(item.PackageId, groupName, item.Name, typeof(SqlDatabase)) != null)
+ // check service items
+ if (PackageController.GetServiceItemsCountByNameAndServiceId(serviceId, groupName, item.Name, typeof(SqlDatabase)) > 0)
return BusinessErrorCodes.ERROR_MSSQL_DATABASES_PACKAGE_ITEM_EXISTS;
// place log record
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/EnterpriseStorage/EnterpriseStorageController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/EnterpriseStorage/EnterpriseStorageController.cs
index 21cd276d..d7fbc832 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/EnterpriseStorage/EnterpriseStorageController.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/EnterpriseStorage/EnterpriseStorageController.cs
@@ -172,6 +172,34 @@ namespace WebsitePanel.EnterpriseServer
return ObjectUtils.FillObjectFromDataReader(DataProvider.GetWebDavAccessTokenByAccessToken(accessToken));
}
+ public static SystemFile[] SearchFiles(int itemId, string[] searchPaths, string searchText, string userPrincipalName, bool recursive)
+ {
+ try
+ {
+ // load organization
+ Organization org = OrganizationController.GetOrganization(itemId);
+ if (org == null)
+ {
+ return new SystemFile[0];
+ }
+
+ int serviceId = GetEnterpriseStorageServiceID(org.PackageId);
+
+ if (serviceId == 0)
+ {
+ return new SystemFile[0];
+ }
+
+ EnterpriseStorage es = GetEnterpriseStorage(serviceId);
+
+ return es.Search(org.OrganizationId, searchPaths, searchText, userPrincipalName, recursive);
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ }
+
#region Directory Browsing
public static bool GetDirectoryBrowseEnabled(int itemId, string siteId)
@@ -202,6 +230,33 @@ namespace WebsitePanel.EnterpriseServer
#endregion
+ private static IEnumerable GetRootFolders(string userPrincipalName)
+ {
+ var rootFolders = new List();
+
+ var account = ExchangeServerController.GetAccountByAccountName(userPrincipalName);
+
+ var userGroups = OrganizationController.GetSecurityGroupsByMember(account.ItemId, account.AccountId);
+
+ foreach (var folder in GetFolders(account.ItemId))
+ {
+ var permissions = GetFolderPermission(account.ItemId, folder.Name);
+
+ foreach (var permission in permissions)
+ {
+ if ((!permission.IsGroup
+ && (permission.DisplayName == account.UserPrincipalName || permission.DisplayName == account.DisplayName))
+ || (permission.IsGroup && userGroups.Any(x => x.DisplayName == permission.DisplayName)))
+ {
+ rootFolders.Add(folder);
+ break;
+ }
+ }
+ }
+
+ return rootFolders;
+ }
+
protected static void StartESBackgroundTaskInternal(string taskName, int itemId, SystemFile folder, ESPermission[] permissions, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
{
// load organization
@@ -1210,6 +1265,37 @@ namespace WebsitePanel.EnterpriseServer
return null;
}
+ #region WebDav portal
+
+ public static string GetWebDavPortalUserSettingsByAccountId(int accountId)
+ {
+ var dataReader = DataProvider.GetWebDavPortalUserSettingsByAccountId(accountId);
+
+ while (dataReader.Read())
+ {
+ return (string)dataReader["Settings"];
+ }
+
+ return null;
+ }
+
+ public static void UpdateUserSettings(int accountId, string settings)
+ {
+ var oldSettings = GetWebDavPortalUserSettingsByAccountId(accountId);
+
+ if (string.IsNullOrEmpty(oldSettings))
+ {
+ DataProvider.AddWebDavPortalUsersSettings(accountId, settings);
+ }
+ else
+ {
+ DataProvider.UpdateWebDavPortalUsersSettings(accountId, settings);
+ }
+ }
+
+ #endregion
+
+
#region Statistics
public static OrganizationStatistics GetStatistics(int itemId)
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/MailServers/MailServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/MailServers/MailServerController.cs
index 82b7e117..5bfb9ea7 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/MailServers/MailServerController.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/MailServers/MailServerController.cs
@@ -137,7 +137,6 @@ namespace WebsitePanel.EnterpriseServer
return domainResult;
// create service item
- item.Enabled = true;
item.MaxMailboxSize = GetMaxMailBoxSize(item.PackageId, item);
// add service item
@@ -159,7 +158,11 @@ namespace WebsitePanel.EnterpriseServer
{
return BusinessErrorCodes.ERROR_MAIL_LICENSE_DOMAIN_QUOTA;
}
- if (ex.Message != null && ex.Message.Contains("The maximum number of users for the server has been reached"))
+ if (ex.Message.Contains("Password doesn't meet complexity"))
+ {
+ return BusinessErrorCodes.ERROR_MAIL_ACCOUNT_PASSWORD_NOT_COMPLEXITY;
+ }
+ if (ex.Message.Contains("The maximum number of users for the server has been reached"))
{
return BusinessErrorCodes.ERROR_MAIL_LICENSE_USERS_QUOTA;
}
@@ -203,7 +206,6 @@ namespace WebsitePanel.EnterpriseServer
MailServer mail = new MailServer();
ServiceProviderProxy.Init(mail, origItem.ServiceId);
item.Name = origItem.Name;
- item.Enabled = true;
item.MaxMailboxSize = GetMaxMailBoxSize(origItem.PackageId, item);
@@ -224,6 +226,11 @@ namespace WebsitePanel.EnterpriseServer
}
catch (Exception ex)
{
+ if (ex.Message.Contains("Password doesn't meet complexity"))
+ {
+ return BusinessErrorCodes.ERROR_MAIL_ACCOUNT_PASSWORD_NOT_COMPLEXITY;
+ }
+
throw TaskManager.WriteError(ex);
}
finally
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Packages/PackageController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Packages/PackageController.cs
index 19508ce5..292abb2a 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Packages/PackageController.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Packages/PackageController.cs
@@ -1380,6 +1380,14 @@ namespace WebsitePanel.EnterpriseServer
return CreateServiceItem(dvItem[0], dsItem.Tables[1].DefaultView);
}
+ public static int GetServiceItemsCountByNameAndServiceId(int serviceId, string groupName, string itemName, Type itemType)
+ {
+ string itemTypeName = ObjectUtils.GetTypeFullName(itemType);
+
+ return DataProvider.GetServiceItemsCountByNameAndServiceId(SecurityContext.User.UserId,
+ serviceId, groupName, itemName, itemTypeName);
+ }
+
public static bool CheckServiceItemExists(string itemName, Type itemType)
{
return CheckServiceItemExists(itemName, null, itemType);
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs
index 09b99f2c..269add07 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs
@@ -168,9 +168,9 @@ namespace WebsitePanel.EnterpriseServer
return RemoveRdsServerFromCollectionInternal(itemId, rdsServer, rdsCollection);
}
- public static ResultObject RemoveRdsServerFromOrganization(int rdsServerId)
+ public static ResultObject RemoveRdsServerFromOrganization(int itemId, int rdsServerId)
{
- return RemoveRdsServerFromOrganizationInternal(rdsServerId);
+ return RemoveRdsServerFromOrganizationInternal(itemId, rdsServerId);
}
public static ResultObject UpdateRdsServer(RdsServer rdsServer)
@@ -248,6 +248,81 @@ namespace WebsitePanel.EnterpriseServer
return GetRdsCollectionSessionHostsInternal(collectionId);
}
+ public static RdsServerInfo GetRdsServerInfo(int itemId, string fqdnName)
+ {
+ return GetRdsServerInfoInternal(itemId, fqdnName);
+ }
+
+ public static string GetRdsServerStatus(int itemId, string fqdnName)
+ {
+ return GetRdsServerStatusInternal(itemId, fqdnName);
+ }
+
+ public static ResultObject ShutDownRdsServer(int itemId, string fqdnName)
+ {
+ return ShutDownRdsServerInternal(itemId, fqdnName);
+ }
+
+ public static ResultObject RestartRdsServer(int itemId, string fqdnName)
+ {
+ return RestartRdsServerInternal(itemId, fqdnName);
+ }
+
+ public static List GetRdsCollectionLocalAdmins(int collectionId)
+ {
+ return GetRdsCollectionLocalAdminsInternal(collectionId);
+ }
+
+ public static ResultObject SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int collectionId)
+ {
+ return SaveRdsCollectionLocalAdminsInternal(users, collectionId);
+ }
+
+ public static ResultObject InstallSessionHostsCertificate(int collectionId, byte[] certificate, string password)
+ {
+ return InstallSessionHostsCertificateInternal(collectionId, certificate, password);
+ }
+
+ private static ResultObject InstallSessionHostsCertificateInternal(int collectionId, byte[] certificate, string password)
+ {
+ var result = TaskManager.StartResultTask("REMOTE_DESKTOP_SERVICES", "INSTALL_CERTIFICATE");
+
+ try
+ {
+ var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId));
+ Organization org = OrganizationController.GetOrganization(collection.ItemId);
+
+ if (org == null)
+ {
+ result.IsSuccess = false;
+ result.AddError("", new NullReferenceException("Organization not found"));
+ return result;
+ }
+
+ var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
+ var servers = ObjectUtils.CreateListFromDataReader(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList();
+
+ rds.InstallCertificate(certificate, password, servers.Select(s => s.FqdName).ToArray());
+ }
+ catch (Exception ex)
+ {
+ throw TaskManager.WriteError(ex);
+ }
+ finally
+ {
+ if (!result.IsSuccess)
+ {
+ TaskManager.CompleteResultTask(result);
+ }
+ else
+ {
+ TaskManager.CompleteResultTask();
+ }
+ }
+
+ return result;
+ }
+
private static RdsCollection GetRdsCollectionInternal(int collectionId)
{
var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId));
@@ -280,11 +355,87 @@ namespace WebsitePanel.EnterpriseServer
return collection;
}
+ private static List GetRdsCollectionLocalAdminsInternal(int collectionId)
+ {
+ var result = new List();
+ var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId));
+ var servers = ObjectUtils.CreateListFromDataReader(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList();
+ Organization org = OrganizationController.GetOrganization(collection.ItemId);
+
+ if (org == null)
+ {
+ return result;
+ }
+
+ var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
+
+ var organizationUsers = OrganizationController.GetOrganizationUsersPaged(collection.ItemId, null, null, null, 0, Int32.MaxValue).PageUsers;
+ var organizationAdmins = rds.GetRdsCollectionLocalAdmins(servers.First().FqdName);
+
+ return organizationUsers.Where(o => organizationAdmins.Select(a => a.ToLower()).Contains(o.DomainUserName.ToLower())).ToList();
+ }
+
+ private static ResultObject SaveRdsCollectionLocalAdminsInternal(OrganizationUser[] users, int collectionId)
+ {
+ var result = TaskManager.StartResultTask("REMOTE_DESKTOP_SERVICES", "SAVE_LOCAL_ADMINS");
+
+ try
+ {
+ var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId));
+ Organization org = OrganizationController.GetOrganization(collection.ItemId);
+
+ if (org == null)
+ {
+ result.IsSuccess = false;
+ result.AddError("", new NullReferenceException("Organization not found"));
+ return result;
+ }
+
+ var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
+ var servers = ObjectUtils.CreateListFromDataReader(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList();
+
+ rds.SaveRdsCollectionLocalAdmins(users, servers.Select(s => s.FqdName).ToArray());
+ }
+ catch (Exception ex)
+ {
+ throw TaskManager.WriteError(ex);
+ }
+ finally
+ {
+ if (!result.IsSuccess)
+ {
+ TaskManager.CompleteResultTask(result);
+ }
+ else
+ {
+ TaskManager.CompleteResultTask();
+ }
+ }
+
+ return result;
+ }
+
private static RdsCollectionSettings GetRdsCollectionSettingsInternal(int collectionId)
{
- var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId));
-
- return ObjectUtils.FillObjectFromDataReader(DataProvider.GetRdsCollectionSettingsByCollectionId(collectionId));
+ var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId));
+ var settings = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRdsCollectionSettingsByCollectionId(collectionId));
+
+ if (settings.SecurityLayer == null)
+ {
+ settings.SecurityLayer = SecurityLayerValues.Negotiate.ToString();
+ }
+
+ if (settings.EncryptionLevel == null)
+ {
+ settings.EncryptionLevel = EncryptionLevel.ClientCompatible.ToString();
+ }
+
+ if (settings.AuthenticateUsingNLA == null)
+ {
+ settings.AuthenticateUsingNLA = true;
+ }
+
+ return settings;
}
private static List GetOrganizationRdsCollectionsInternal(int itemId)
@@ -336,7 +487,10 @@ namespace WebsitePanel.EnterpriseServer
ClientPrinterRedirected = true,
ClientPrinterAsDefault = true,
RDEasyPrintDriverEnabled = true,
- MaxRedirectedMonitors = 16
+ MaxRedirectedMonitors = 16,
+ EncryptionLevel = EncryptionLevel.ClientCompatible.ToString(),
+ SecurityLayer = SecurityLayerValues.Negotiate.ToString(),
+ AuthenticateUsingNLA = true
};
rds.CreateCollection(org.OrganizationId, collection);
@@ -509,8 +663,8 @@ namespace WebsitePanel.EnterpriseServer
}
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
-
- rds.RemoveCollection(org.OrganizationId, collection.Name);
+ var servers = ObjectUtils.CreateListFromDataReader(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToArray();
+ rds.RemoveCollection(org.OrganizationId, collection.Name, servers);
DataProvider.DeleteRDSCollection(collection.Id);
}
@@ -586,7 +740,7 @@ namespace WebsitePanel.EnterpriseServer
foreach (var tmpServer in tmpServers)
{
- FillRdsServerData(tmpServer);
+ FillRdsServerData(tmpServer);
}
result.Servers = tmpServers.ToArray();
@@ -606,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)
@@ -940,11 +1107,12 @@ namespace WebsitePanel.EnterpriseServer
rds.AddSessionHostFeatureToServer(rdsServer.FqdName);
}
+ rds.MoveRdsServerToTenantOU(rdsServer.FqdName, org.OrganizationId);
DataProvider.AddRDSServerToOrganization(itemId, serverId);
}
catch (Exception ex)
{
- result.AddError("REMOTE_DESKTOP_SERVICES_ADD_RDS_SERVER_TO_ORGANIZATION", ex);
+ throw TaskManager.WriteError(ex);
}
finally
{
@@ -961,17 +1129,29 @@ namespace WebsitePanel.EnterpriseServer
return result;
}
- private static ResultObject RemoveRdsServerFromOrganizationInternal(int rdsServerId)
+ private static ResultObject RemoveRdsServerFromOrganizationInternal(int itemId, int rdsServerId)
{
- var result = TaskManager.StartResultTask("REMOTE_DESKTOP_SERVICES", "REMOVE_RDS_SERVER_FROM_ORGANIZATION");
+ var result = TaskManager.StartResultTask("REMOTE_DESKTOP_SERVICES", "REMOVE_RDS_SERVER_FROM_ORGANIZATION");
try
{
+ Organization org = OrganizationController.GetOrganization(itemId);
+
+ if (org == null)
+ {
+ result.IsSuccess = false;
+ result.AddError("", new NullReferenceException("Organization not found"));
+ return result;
+ }
+
+ var rdsServer = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSServerById(rdsServerId));
+ var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
+ rds.RemoveRdsServerFromTenantOU(rdsServer.FqdName, org.OrganizationId);
DataProvider.RemoveRDSServerFromOrganization(rdsServerId);
}
catch (Exception ex)
{
- result.AddError("REMOTE_DESKTOP_SERVICES_REMOVE_RDS_SERVER_FROM_ORGANIZATION", ex);
+ throw TaskManager.WriteError(ex);
}
finally
{
@@ -1235,6 +1415,118 @@ namespace WebsitePanel.EnterpriseServer
return result;
}
+ private static RdsServerInfo GetRdsServerInfoInternal(int itemId, string fqdnName)
+ {
+ Organization org = OrganizationController.GetOrganization(itemId);
+
+ if (org == null)
+ {
+ return new RdsServerInfo();
+ }
+
+ var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
+ var result = rds.GetRdsServerInfo(fqdnName);
+
+ return result;
+ }
+
+ private static string GetRdsServerStatusInternal(int itemId, string fqdnName)
+ {
+ Organization org = OrganizationController.GetOrganization(itemId);
+ var result = "Unavailable";
+
+ if (org == null)
+ {
+ return result;
+ }
+
+ var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
+
+ try
+ {
+ result = rds.GetRdsServerStatus(fqdnName);
+ }
+ catch
+ {
+ }
+
+ return result;
+ }
+
+ private static ResultObject ShutDownRdsServerInternal(int itemId, string fqdnName)
+ {
+ var result = TaskManager.StartResultTask("REMOTE_DESKTOP_SERVICES", "SHUTDOWN_RDS_SERVER");
+
+ try
+ {
+ Organization org = OrganizationController.GetOrganization(itemId);
+
+ if (org == null)
+ {
+ result.IsSuccess = false;
+ result.AddError("", new NullReferenceException("Organization not found"));
+ return result;
+ }
+
+ var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
+ rds.ShutDownRdsServer(fqdnName);
+ }
+ catch (Exception ex)
+ {
+ result.AddError("REMOTE_DESKTOP_SERVICES_SHUTDOWN_RDS_SERVER", ex);
+ }
+ finally
+ {
+ if (!result.IsSuccess)
+ {
+ TaskManager.CompleteResultTask(result);
+ }
+ else
+ {
+ TaskManager.CompleteResultTask();
+ }
+ }
+
+ return result;
+ }
+
+ private static ResultObject RestartRdsServerInternal(int itemId, string fqdnName)
+ {
+ var result = TaskManager.StartResultTask("REMOTE_DESKTOP_SERVICES", "RESTART_RDS_SERVER");
+
+ try
+ {
+ Organization org = OrganizationController.GetOrganization(itemId);
+
+ if (org == null)
+ {
+ result.IsSuccess = false;
+ result.AddError("", new NullReferenceException("Organization not found"));
+ return result;
+ }
+
+ var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
+ rds.RestartRdsServer(fqdnName);
+ }
+ catch (Exception ex)
+ {
+ result.AddError("REMOTE_DESKTOP_SERVICES_RESTART_RDS_SERVER", ex);
+ }
+ finally
+ {
+ if (!result.IsSuccess)
+ {
+ TaskManager.CompleteResultTask(result);
+ }
+ else
+ {
+ TaskManager.CompleteResultTask();
+ }
+ }
+
+ return result;
+ }
+
private static List GetCollectionRemoteApplicationsInternal(int itemId, string collectionName)
{
var result = new List();
@@ -1410,7 +1702,7 @@ namespace WebsitePanel.EnterpriseServer
foreach (var server in servers)
{
- RemoveRdsServerFromOrganization(server.Id);
+ RemoveRdsServerFromOrganization(itemId, server.Id);
}
}
catch (Exception ex)
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization/VirtualizationServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization/VirtualizationServerController.cs
index 75ea31ef..fb69ef50 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization/VirtualizationServerController.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization/VirtualizationServerController.cs
@@ -1074,10 +1074,14 @@ namespace WebsitePanel.EnterpriseServer
}
}
- private static void CheckNumericQuota(PackageContext cntx, List errors, string quotaName, int currentVal, int val, string messageKey)
+ private static void CheckNumericQuota(PackageContext cntx, List errors, string quotaName, long currentVal, long val, string messageKey)
{
CheckQuotaValue(cntx, errors, quotaName, currentVal, val, messageKey);
}
+ private static void CheckNumericQuota(PackageContext cntx, List errors, string quotaName, int currentVal, int val, string messageKey)
+ {
+ CheckQuotaValue(cntx, errors, quotaName, Convert.ToInt64(currentVal), Convert.ToInt64(val), messageKey);
+ }
private static void CheckNumericQuota(PackageContext cntx, List errors, string quotaName, int val, string messageKey)
{
@@ -1094,7 +1098,7 @@ namespace WebsitePanel.EnterpriseServer
CheckQuotaValue(cntx, errors, quotaName, 0, -1, messageKey);
}
- private static void CheckQuotaValue(PackageContext cntx, List errors, string quotaName, int currentVal, int val, string messageKey)
+ private static void CheckQuotaValue(PackageContext cntx, List errors, string quotaName, long currentVal, long val, string messageKey)
{
if (!cntx.Quotas.ContainsKey(quotaName))
return;
@@ -1111,7 +1115,7 @@ namespace WebsitePanel.EnterpriseServer
errors.Add(messageKey);
else if (quota.QuotaTypeId == 2)
{
- int maxValue = quota.QuotaAllocatedValue - quota.QuotaUsedValue + currentVal;
+ long maxValue = quota.QuotaAllocatedValue - quota.QuotaUsedValue + currentVal;
if(val > maxValue)
errors.Add(messageKey + ":" + maxValue);
}
@@ -1795,8 +1799,9 @@ namespace WebsitePanel.EnterpriseServer
else if (state == VirtualMachineRequestedState.Reboot)
{
// shutdown first
- ResultObject shutdownResult = ChangeVirtualMachineState(itemId, VirtualMachineRequestedState.ShutDown);
- if(!shutdownResult.IsSuccess)
+ ResultObject shutdownResult = ChangeVirtualMachineState(itemId,
+ VirtualMachineRequestedState.ShutDown);
+ if (!shutdownResult.IsSuccess)
{
TaskManager.CompleteResultTask(res);
return shutdownResult;
@@ -1817,20 +1822,29 @@ namespace WebsitePanel.EnterpriseServer
JobResult result = vps.ChangeVirtualMachineState(machine.VirtualMachineId, state);
- // check return
- if (result.ReturnValue != ReturnCode.JobStarted)
+ if (result.Job.JobState == ConcreteJobState.Completed)
{
LogReturnValueResult(res, result);
- TaskManager.CompleteResultTask(res);
+ TaskManager.CompleteTask();
return res;
}
-
- // wait for completion
- if (!JobCompleted(vps, result.Job))
+ else
{
- LogJobResult(res, result.Job);
- TaskManager.CompleteResultTask(res);
- return res;
+ // check return
+ if (result.ReturnValue != ReturnCode.JobStarted)
+ {
+ LogReturnValueResult(res, result);
+ TaskManager.CompleteResultTask(res);
+ return res;
+ }
+
+ // wait for completion
+ if (!JobCompleted(vps, result.Job))
+ {
+ LogJobResult(res, result.Job);
+ TaskManager.CompleteResultTask(res);
+ return res;
+ }
}
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esEnterpriseStorage.asmx.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esEnterpriseStorage.asmx.cs
index deb4f45a..6668b40b 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esEnterpriseStorage.asmx.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esEnterpriseStorage.asmx.cs
@@ -158,6 +158,24 @@ namespace WebsitePanel.EnterpriseServer
return EnterpriseStorageController.CheckUsersDomainExists(itemId);
}
+ [WebMethod]
+ public string GetWebDavPortalUserSettingsByAccountId(int accountId)
+ {
+ return EnterpriseStorageController.GetWebDavPortalUserSettingsByAccountId(accountId);
+ }
+
+ [WebMethod]
+ public void UpdateWebDavPortalUserSettings(int accountId, string settings)
+ {
+ EnterpriseStorageController.UpdateUserSettings(accountId,settings);
+ }
+
+ [WebMethod]
+ public SystemFile[] SearchFiles(int itemId, string[] searchPaths, string searchText, string userPrincipalName, bool recursive)
+ {
+ return EnterpriseStorageController.SearchFiles(itemId, searchPaths, searchText, userPrincipalName, recursive);
+ }
+
#region Directory Browsing
[WebMethod]
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs
index 82127d09..8cd3ecdb 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs
@@ -189,9 +189,9 @@ namespace WebsitePanel.EnterpriseServer
}
[WebMethod]
- public ResultObject RemoveRdsServerFromOrganization(int rdsServerId)
+ public ResultObject RemoveRdsServerFromOrganization(int itemId, int rdsServerId)
{
- return RemoteDesktopServicesController.RemoveRdsServerFromOrganization(rdsServerId);
+ return RemoteDesktopServicesController.RemoveRdsServerFromOrganization(itemId, rdsServerId);
}
[WebMethod]
@@ -289,5 +289,47 @@ namespace WebsitePanel.EnterpriseServer
{
return RemoteDesktopServicesController.GetRdsCollectionSessionHosts(collectionId);
}
+
+ [WebMethod]
+ public RdsServerInfo GetRdsServerInfo(int itemId, string fqdnName)
+ {
+ return RemoteDesktopServicesController.GetRdsServerInfo(itemId, fqdnName);
+ }
+
+ [WebMethod]
+ public string GetRdsServerStatus(int itemId, string fqdnName)
+ {
+ return RemoteDesktopServicesController.GetRdsServerStatus(itemId, fqdnName);
+ }
+
+ [WebMethod]
+ public ResultObject ShutDownRdsServer(int itemId, string fqdnName)
+ {
+ return RemoteDesktopServicesController.ShutDownRdsServer(itemId, fqdnName);
+ }
+
+ [WebMethod]
+ public ResultObject RestartRdsServer(int itemId, string fqdnName)
+ {
+ return RemoteDesktopServicesController.RestartRdsServer(itemId, fqdnName);
+ }
+
+ [WebMethod]
+ public List GetRdsCollectionLocalAdmins(int collectionId)
+ {
+ return RemoteDesktopServicesController.GetRdsCollectionLocalAdmins(collectionId);
+ }
+
+ [WebMethod]
+ public ResultObject SaveRdsCollectionLocalAdmins(OrganizationUser[] users, int collectionId)
+ {
+ return RemoteDesktopServicesController.SaveRdsCollectionLocalAdmins(users, collectionId);
+ }
+
+ [WebMethod]
+ public ResultObject InstallSessionHostsCertificate(int collectionId, byte[] certificate, string password)
+ {
+ return RemoteDesktopServicesController.InstallSessionHostsCertificate(collectionId, certificate, password);
+ }
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/EnterpriseStorage/IEnterpriseStorage.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/EnterpriseStorage/IEnterpriseStorage.cs
index 5693ea5e..892864a9 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/EnterpriseStorage/IEnterpriseStorage.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/EnterpriseStorage/IEnterpriseStorage.cs
@@ -46,6 +46,6 @@ namespace WebsitePanel.Providers.EnterpriseStorage
bool SetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting, WebDavFolderRule[] rules);
WebDavFolderRule[] GetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting);
bool CheckFileServicesInstallation();
-
+ SystemFile[] Search(string organizationId, string[] searchPaths, string searchText, string userPrincipalName, bool recursive);
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Mail/MailAccount.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Mail/MailAccount.cs
index 3fbba76b..3dedd942 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Mail/MailAccount.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Mail/MailAccount.cs
@@ -33,7 +33,7 @@ namespace WebsitePanel.Providers.Mail
[Serializable]
public class MailAccount : ServiceProviderItem
{
- private bool enabled;
+ private bool enabled = true;
private string password;
private string replyTo;
private bool responderEnabled;
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/OS/SystemFile.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/OS/SystemFile.cs
index 27478af4..830bccab 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/OS/SystemFile.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/OS/SystemFile.cs
@@ -144,6 +144,8 @@ namespace WebsitePanel.Providers.OS
set { this.url = value; }
}
+ public string RelativeUrl { get; set; }
+
public string DriveLetter
{
get { return this.driveLetter; }
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs
index e434048d..a176c00f 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs
@@ -31,6 +31,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
+using WebsitePanel.Providers.HostedSolution;
namespace WebsitePanel.Providers.RemoteDesktopServices
{
@@ -42,7 +43,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
bool CreateCollection(string organizationId, RdsCollection collection);
bool AddRdsServersToDeployment(RdsServer[] servers);
RdsCollection GetCollection(string collectionName);
- bool RemoveCollection(string organizationId, string collectionName);
+ bool RemoveCollection(string organizationId, string collectionName, List servers);
bool SetUsersInCollection(string organizationId, string collectionName, List users);
void AddSessionHostServerToCollection(string organizationId, string collectionName, RdsServer server);
void AddSessionHostServersToCollection(string organizationId, string collectionName, List servers);
@@ -69,5 +70,14 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
List GetRdsUserSessions(string collectionName);
void LogOffRdsUser(string unifiedSessionId, string hostServer);
List GetRdsCollectionSessionHosts(string collectionName);
+ RdsServerInfo GetRdsServerInfo(string serverName);
+ string GetRdsServerStatus(string serverName);
+ void ShutDownRdsServer(string serverName);
+ void RestartRdsServer(string serverName);
+ void SaveRdsCollectionLocalAdmins(List users, List hosts);
+ List GetRdsCollectionLocalAdmins(string hostName);
+ void MoveRdsServerToTenantOU(string hostName, string organizationId);
+ void RemoveRdsServerFromTenantOU(string hostName, string organizationId);
+ void InstallCertificate(byte[] certificate, string password, List hostNames);
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsCollectionSettings.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsCollectionSettings.cs
index 5827ecc6..2ccae36a 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsCollectionSettings.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsCollectionSettings.cs
@@ -21,6 +21,9 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
public bool ClientPrinterRedirected { get; set; }
public bool ClientPrinterAsDefault { get; set; }
public bool RDEasyPrintDriverEnabled { get; set; }
- public int MaxRedirectedMonitors { get; set; }
+ public int MaxRedirectedMonitors { get; set; }
+ public string SecurityLayer { get; set; }
+ public string EncryptionLevel { get; set; }
+ public bool AuthenticateUsingNLA { get; set; }
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServer.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServer.cs
index 1f89e9b8..aa181ba7 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServer.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServer.cs
@@ -47,5 +47,6 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
public string ItemName { get; set; }
public int? RdsCollectionId { get; set; }
public bool ConnectionEnabled { get; set; }
+ public string Status { get; set; }
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServerDriveInfo.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServerDriveInfo.cs
new file mode 100644
index 00000000..1b29f46f
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServerDriveInfo.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace WebsitePanel.Providers.RemoteDesktopServices
+{
+ public class RdsServerDriveInfo
+ {
+ public string DeviceId { get; set; }
+ public string VolumeName { get; set; }
+ public double SizeMb { get; set; }
+ public double FreeSpaceMb { get; set; }
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServerInfo.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServerInfo.cs
new file mode 100644
index 00000000..55056203
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RdsServerInfo.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace WebsitePanel.Providers.RemoteDesktopServices
+{
+ public class RdsServerInfo
+ {
+ public string Status { get; set; }
+ public int NumberOfCores { get; set; }
+ public int MaxClockSpeed { get; set; }
+ public int LoadPercentage { get; set; }
+ public double MemoryAllocatedMb { get; set; }
+ public double FreeMemoryMb { get; set; }
+ public RdsServerDriveInfo[] Drives { get; set; }
+ }
+}
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.Base/RemoteDesktopServices/RemoteApplication.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RemoteApplication.cs
index 300f8b47..b0bda452 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RemoteApplication.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/RemoteApplication.cs
@@ -36,5 +36,6 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
public string FileVirtualPath { get; set; }
public bool ShowInWebAccess { get; set; }
public string RequiredCommandLine { get; set; }
+ public string[] Users { get; set; }
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/ConcreteJobState.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/ConcreteJobState.cs
index 468136e8..b316ef8f 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/ConcreteJobState.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/ConcreteJobState.cs
@@ -42,6 +42,9 @@ namespace WebsitePanel.Providers.Virtualization
Completed = 7,
Terminated = 8,
Killed = 9,
- Exception = 10
+ Exception = 10,
+
+ NotStarted = 11,
+ Failed = 12,
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/DvdDriveInfo.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/DvdDriveInfo.cs
new file mode 100644
index 00000000..df548b0b
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/DvdDriveInfo.cs
@@ -0,0 +1,43 @@
+// Copyright (c) 2014, Outercurve Foundation.
+// All rights reserved.
+//
+// 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.
+//
+// - Neither the name of the Outercurve Foundation nor the names of its
+// contributors may be used to endorse or promote products derived from this
+// software without specific prior written permission.
+//
+// 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.Generic;
+using System.Text;
+
+namespace WebsitePanel.Providers.Virtualization
+{
+ public class DvdDriveInfo
+ {
+ public ControllerType ControllerType { get; set; }
+ public int ControllerNumber { get; set; }
+ public int ControllerLocation { get; set; }
+ public string Name { get; set; }
+ public string Id { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/MemoryInfo.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/MemoryInfo.cs
index 0fe02369..7e79088a 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/MemoryInfo.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/MemoryInfo.cs
@@ -35,9 +35,9 @@ namespace WebsitePanel.Providers.Virtualization
public class MemoryInfo
{
public bool DynamicMemoryEnabled { get; set; }
- public Int32 Startup { get; set; }
- public Int32 Minimum { get; set; }
- public Int32 Maximum { get; set; }
+ public Int64 Startup { get; set; }
+ public Int64 Minimum { get; set; }
+ public Int64 Maximum { get; set; }
public int Buffer { get; set; }
public int Priority { get; set; }
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/OperationalStatus.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/OperationalStatus.cs
index 808ff0dc..c10ebc26 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/OperationalStatus.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/OperationalStatus.cs
@@ -35,9 +35,10 @@ namespace WebsitePanel.Providers.Virtualization
public enum OperationalStatus
{
None = 0,
- OK = 2,
+ Ok = 2,
Error = 6,
NoContact = 12,
- LostCommunication = 13
+ LostCommunication = 13,
+ Paused = 15
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualHardDiskInfo.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualHardDiskInfo.cs
index 36c9a29e..e327767f 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualHardDiskInfo.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualHardDiskInfo.cs
@@ -41,8 +41,8 @@ namespace WebsitePanel.Providers.Virtualization
public string ParentPath { get; set; }
public VirtualHardDiskType DiskType { get; set; }
public bool SupportPersistentReservations { get; set; }
- public long MaximumIOPS { get; set; }
- public long MinimumIOPS { get; set; }
+ public ulong MaximumIOPS { get; set; }
+ public ulong MinimumIOPS { get; set; }
public ControllerType VHDControllerType { get; set; }
public int ControllerNumber { get; set; }
public int ControllerLocation { get; set; }
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualMachine.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualMachine.cs
index 763abf86..5f5847a8 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualMachine.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualMachine.cs
@@ -69,8 +69,8 @@ namespace WebsitePanel.Providers.Virtualization
public int CpuUsage { get; set; }
[Persistent]
- public int RamSize { get; set; }
- public int RamUsage { get; set; }
+ public long RamSize { get; set; }
+ public long RamUsage { get; set; }
[Persistent]
public int HddSize { get; set; }
public LogicalDisk[] HddLogicalDisks { get; set; }
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualMachineNetworkAdapter.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualMachineNetworkAdapter.cs
index fe2646d3..d1209d10 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualMachineNetworkAdapter.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/VirtualMachineNetworkAdapter.cs
@@ -36,5 +36,6 @@ namespace WebsitePanel.Providers.Virtualization
{
public string Name { get; set; }
public string MacAddress { get; set; }
+ public string SwitchName { get; set; }
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj
index 64efc261..f60340ee 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj
@@ -135,6 +135,8 @@
+
+
@@ -307,6 +309,7 @@
+
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs
index fbd7b157..e5ff425c 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs
@@ -27,9 +27,12 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
+using System.Data.OleDb;
using System.IO;
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
+using System.Security.Principal;
using System.Text;
using Microsoft.Win32;
@@ -62,6 +65,7 @@ namespace WebsitePanel.Providers.EnterpriseStorage
#endregion
#region Folders
+
public SystemFile[] GetFolders(string organizationId, WebDavSetting[] settings)
{
ArrayList items = new ArrayList();
@@ -70,7 +74,8 @@ namespace WebsitePanel.Providers.EnterpriseStorage
foreach (var setting in webDavSettings)
{
- string rootPath = string.Format("{0}:\\{1}\\{2}", setting.LocationDrive, setting.HomeFolder, organizationId);
+ string rootPath = string.Format("{0}:\\{1}\\{2}", setting.LocationDrive, setting.HomeFolder,
+ organizationId);
var windows = new WebsitePanel.Providers.OS.Windows2012();
@@ -114,16 +119,17 @@ namespace WebsitePanel.Providers.EnterpriseStorage
}
}
- return (SystemFile[])items.ToArray(typeof(SystemFile));
+ return (SystemFile[]) items.ToArray(typeof (SystemFile));
}
public SystemFile GetFolder(string organizationId, string folderName, WebDavSetting setting)
{
var webDavSetting = GetWebDavSetting(setting);
- string fullName = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder, organizationId, folderName);
+ string fullName = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder,
+ organizationId, folderName);
SystemFile folder = null;
-
+
var windows = new WebsitePanel.Providers.OS.Windows2012();
if (Directory.Exists(fullName))
@@ -151,7 +157,7 @@ namespace WebsitePanel.Providers.EnterpriseStorage
folder.FRSMQuotaGB = windows.ConvertMegaBytesToGB(folder.FRSMQuotaMB);
folder.FsrmQuotaType = quota.QuotaType;
}
-
+
return folder;
}
@@ -159,17 +165,21 @@ namespace WebsitePanel.Providers.EnterpriseStorage
{
var webDavSetting = GetWebDavSetting(setting);
- FileUtils.CreateDirectory(string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder, organizationId, folder));
+ FileUtils.CreateDirectory(string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive,
+ webDavSetting.HomeFolder, organizationId, folder));
}
- public SystemFile RenameFolder(string organizationId, string originalFolder, string newFolder, WebDavSetting setting)
+ public SystemFile RenameFolder(string organizationId, string originalFolder, string newFolder,
+ WebDavSetting setting)
{
var webDavSetting = GetWebDavSetting(setting);
- var oldPath = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder, organizationId, originalFolder);
- var newPath = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder, organizationId, newFolder);
+ var oldPath = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder,
+ organizationId, originalFolder);
+ var newPath = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder,
+ organizationId, newFolder);
- FileUtils.MoveFile(oldPath,newPath);
+ FileUtils.MoveFile(oldPath, newPath);
IWebDav webdav = new WebDav(webDavSetting);
@@ -183,17 +193,20 @@ namespace WebsitePanel.Providers.EnterpriseStorage
{
var webDavSetting = GetWebDavSetting(setting);
- string rootPath = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder, organizationId, folder);
+ string rootPath = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder,
+ organizationId, folder);
DirectoryInfo treeRoot = new DirectoryInfo(rootPath);
-
+
if (treeRoot.Exists)
{
DirectoryInfo[] dirs = treeRoot.GetDirectories();
while (dirs.Length > 0)
{
foreach (DirectoryInfo dir in dirs)
- DeleteFolder(organizationId, folder != string.Empty ? string.Format("{0}\\{1}", folder, dir.Name) : dir.Name, webDavSetting);
+ DeleteFolder(organizationId,
+ folder != string.Empty ? string.Format("{0}\\{1}", folder, dir.Name) : dir.Name,
+ webDavSetting);
dirs = treeRoot.GetDirectories();
}
@@ -207,14 +220,15 @@ namespace WebsitePanel.Providers.EnterpriseStorage
}
IWebDav webdav = new WebDav(webDavSetting);
-
+
webdav.DeleteAllWebDavRules(organizationId, folder);
-
+
Directory.Delete(treeRoot.FullName, true);
}
}
- public bool SetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting, WebDavFolderRule[] rules)
+ public bool SetFolderWebDavRules(string organizationId, string folder, WebDavSetting setting,
+ WebDavFolderRule[] rules)
{
var users = new List();
@@ -243,14 +257,15 @@ namespace WebsitePanel.Providers.EnterpriseStorage
var webDavSetting = GetWebDavSetting(setting);
- string path = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder, organizationId, folder);
+ string path = string.Format("{0}:\\{1}\\{2}\\{3}", webDavSetting.LocationDrive, webDavSetting.HomeFolder,
+ organizationId, folder);
SecurityUtils.ResetNtfsPermissions(path);
SecurityUtils.GrantGroupNtfsPermissions(path, users.ToArray(), false, new RemoteServerSettings(), null, null);
IWebDav webdav = new WebDav(webDavSetting);
-
+
return webdav.SetFolderWebDavRules(organizationId, folder, rules);
}
@@ -270,6 +285,73 @@ namespace WebsitePanel.Providers.EnterpriseStorage
#endregion
+ public SystemFile[] Search(string organizationId, string[] searchPaths, string searchText, string userPrincipalName, bool recursive)
+ {
+ var settings = GetWebDavSetting(null);
+ var result = new List();
+ var isRootSearch = false;
+
+ if (searchPaths.Any(string.IsNullOrEmpty))
+ {
+ isRootSearch = true;
+ searchPaths = searchPaths.Where(x => !string.IsNullOrEmpty(x)).ToArray();
+ }
+
+ //using (new WindowsIdentity(userPrincipalName).Impersonate())
+ {
+ using (var conn = new OleDbConnection("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"))
+ {
+ var rootFolder = Path.Combine(settings.LocationDrive + ":\\", settings.HomeFolder);
+ rootFolder = Path.Combine(rootFolder, organizationId);
+
+ var wsSql = string.Format(@"SELECT System.FileName, System.DateModified, System.Size, System.Kind, System.ItemPathDisplay, System.ItemType FROM SYSTEMINDEX WHERE System.FileName LIKE '%{0}%' AND ({1})",
+ searchText, string.Join(" OR ", searchPaths.Select(x => string.Format("{0} = '{1}'", recursive ? "SCOPE" : "DIRECTORY", Path.Combine(rootFolder, x))).ToArray()));
+
+ conn.Open();
+
+ var cmd = new OleDbCommand(wsSql, conn);
+
+ using (OleDbDataReader reader = cmd.ExecuteReader())
+ {
+ while (reader!= null && reader.Read())
+ {
+ var file = new SystemFile {Name = reader[0] as string};
+
+ file.Changed = file.CreatedDate = reader[1] is DateTime ? (DateTime)reader[1] : new DateTime();
+ file.Size = reader[2] is long ? (long) reader[2] : 0;
+
+ var kind = reader[3] is IEnumerable ? ((IEnumerable)reader[3]).Cast().ToList() : null;
+ var itemType = reader[5] as string ?? string.Empty;
+
+ if (kind != null && kind.Any() && itemType.ToLowerInvariant() != ".zip")
+ {
+ file.IsDirectory = kind.Any(x => x == "folder");
+ }
+
+ file.FullName = (reader[4] as string ?? string.Empty);
+
+ if (isRootSearch)
+ {
+ file.RelativeUrl = file.FullName.Replace(rootFolder, "").Trim('\\');
+ }
+ else
+ {
+ foreach (var searchPath in searchPaths)
+ {
+ file.RelativeUrl = file.FullName.Replace(Path.Combine(rootFolder, searchPath), "").Trim('\\');
+ }
+ }
+
+ result.Add(file);
+ }
+ }
+ }
+ }
+
+ return result.ToArray();
+ }
+
+
#region HostingServiceProvider methods
public override string[] Install()
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Mail.SmarterMail10/SmarterMail10.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Mail.SmarterMail10/SmarterMail10.cs
index a4b1f28f..4c4f965a 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Mail.SmarterMail10/SmarterMail10.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Mail.SmarterMail10/SmarterMail10.cs
@@ -1171,8 +1171,13 @@ namespace WebsitePanel.Providers.Mail
mailbox.IsDomainAdmin // domain admin is false
);
- if (!result.Result)
- throw new Exception(result.Message);
+ if (!result.Result)
+ {
+ if (result.ResultCode == -21)
+ throw new Exception("Password doesn't meet complexity", new Exception(result.Message));
+
+ throw new Exception(result.Message);
+ }
// set forwarding settings
result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword,
@@ -1232,10 +1237,15 @@ namespace WebsitePanel.Providers.Mail
GenericResult result = users.UpdateUser(
AdminUsername, AdminPassword, mailbox.Name, strPassword, mailbox.FirstName, mailbox.LastName, mailbox.IsDomainAdmin);
- if (!result.Result)
- throw new Exception(result.Message);
+ if (!result.Result)
+ {
+ if (result.ResultCode == -21)
+ throw new Exception("Password doesn't meet complexity", new Exception(result.Message));
+
+ throw new Exception(result.Message);
+ }
- // set forwarding settings
+ // set forwarding settings
result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword,
mailbox.Name, mailbox.DeleteOnForward,
(mailbox.ForwardingAddresses != null ? String.Join(", ", mailbox.ForwardingAddresses) : ""));
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs
index e6e8dba2..a0015101 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs
@@ -47,6 +47,9 @@ using System.Management;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
+using System.DirectoryServices;
+using System.Security.Cryptography.X509Certificates;
+using System.Collections;
namespace WebsitePanel.Providers.RemoteDesktopServices
@@ -64,6 +67,13 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
private const string RdsGroupFormat = "rds-{0}-{1}";
private const string RdsModuleName = "RemoteDesktopServices";
private const string AddNpsString = "netsh nps add np name=\"\"{0}\"\" policysource=\"1\" processingorder=\"{1}\" conditionid=\"0x3d\" conditiondata=\"^5$\" conditionid=\"0x1fb5\" conditiondata=\"{2}\" conditionid=\"0x1e\" conditiondata=\"UserAuthType:(PW|CA)\" profileid=\"0x1005\" profiledata=\"TRUE\" profileid=\"0x100f\" profiledata=\"TRUE\" profileid=\"0x1009\" profiledata=\"0x7\" profileid=\"0x1fe6\" profiledata=\"0x40000000\"";
+ private const string WspAdministratorsGroupName = "WSP-Org-Administrators";
+ private const string WspAdministratorsGroupDescription = "WSP Org Administrators";
+ private const string RdsServersOU = "RDSServers";
+ private const string RDSHelpDeskComputerGroup = "Websitepanel-RDSHelpDesk-Computer";
+ private const string RDSHelpDeskGroup = "WSP-HelpDeskAdministrators";
+ private const string RDSHelpDeskGroupDescription = "WSP Help Desk Administrators";
+
#endregion
#region Properties
@@ -300,6 +310,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
//ActiveDirectoryUtils.AddObjectToGroup(GetComputerPath(ConnectionBroker), GetComputerGroupPath(organizationId, collection.Name));
}
+ CheckOrCreateHelpDeskComputerGroup();
+
if (!ActiveDirectoryUtils.AdObjectExists(GetUsersGroupPath(organizationId, collection.Name)))
{
//Create user group
@@ -329,7 +341,13 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
//add session servers to group
foreach (var rdsServer in collection.Servers)
- {
+ {
+ if (!CheckLocalAdminsGroupExists(rdsServer.FqdName, runSpace))
+ {
+ CreateLocalAdministratorsGroup(rdsServer.FqdName, runSpace);
+ }
+
+ AddHelpDeskAdminsGroupToLocalAdmins(runSpace, rdsServer.FqdName);
AddComputerToCollectionAdComputerGroup(organizationId, collection.Name, rdsServer);
}
}
@@ -458,7 +476,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return collection;
}
- public bool RemoveCollection(string organizationId, string collectionName)
+ public bool RemoveCollection(string organizationId, string collectionName, List servers)
{
var result = true;
@@ -493,11 +511,13 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
RemoveNpsPolicy(runSpace, CentralNpsHost, capPolicyName);
}
- //Remove security group
+ foreach(var server in servers)
+ {
+ RemoveComputerFromCollectionAdComputerGroup(organizationId, collectionName, server);
+ }
ActiveDirectoryUtils.DeleteADObject(GetComputerGroupPath(organizationId, collectionName));
-
- ActiveDirectoryUtils.DeleteADObject(GetUsersGroupPath(organizationId, collectionName));
+ ActiveDirectoryUtils.DeleteADObject(GetUsersGroupPath(organizationId, collectionName));
}
catch (Exception e)
{
@@ -553,6 +573,14 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
ExecuteShellCommand(runSpace, cmd, false);
+ CheckOrCreateHelpDeskComputerGroup();
+
+ if (!CheckLocalAdminsGroupExists(server.FqdName, runSpace))
+ {
+ CreateLocalAdministratorsGroup(server.FqdName, runSpace);
+ }
+
+ AddHelpDeskAdminsGroupToLocalAdmins(runSpace, server.FqdName);
AddComputerToCollectionAdComputerGroup(organizationId, collectionName, server);
}
catch (Exception e)
@@ -948,6 +976,351 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
#endregion
+ #region Local Admins
+
+ public void SaveRdsCollectionLocalAdmins(List users, List hosts)
+ {
+ Runspace runspace = null;
+
+ try
+ {
+ runspace = OpenRunspace();
+ var index = ServerSettings.ADRootDomain.LastIndexOf(".");
+ var domainName = ServerSettings.ADRootDomain;
+
+ if (index > 0)
+ {
+ domainName = ServerSettings.ADRootDomain.Substring(0, index);
+ }
+
+ foreach (var hostName in hosts)
+ {
+ if (!CheckLocalAdminsGroupExists(hostName, runspace))
+ {
+ var errors = CreateLocalAdministratorsGroup(hostName, runspace);
+
+ if (errors.Any())
+ {
+ Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ throw new Exception(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ }
+ }
+
+ var existingAdmins = GetExistingLocalAdmins(hostName, runspace).Select(e => e.ToLower());
+ var formUsers = users.Select(u => string.Format("{0}\\{1}", domainName, u.SamAccountName).ToLower());
+ var newUsers = users.Where(u => !existingAdmins.Contains(string.Format("{0}\\{1}", domainName, u.SamAccountName).ToLower()));
+ var removedUsers = existingAdmins.Where(e => !formUsers.Contains(e));
+
+ foreach (var user in newUsers)
+ {
+ AddNewLocalAdmin(hostName, user.SamAccountName, runspace);
+ }
+
+ foreach (var user in removedUsers)
+ {
+ RemoveLocalAdmin(hostName, user, runspace);
+ }
+
+ AddHelpDeskAdminsGroupToLocalAdmins(runspace, hostName);
+ }
+ }
+ finally
+ {
+ CloseRunspace(runspace);
+ }
+ }
+
+ public List GetRdsCollectionLocalAdmins(string hostName)
+ {
+ Runspace runspace = null;
+ var result = new List();
+
+ try
+ {
+ runspace = OpenRunspace();
+
+ if (CheckLocalAdminsGroupExists(hostName, runspace))
+ {
+ result = GetExistingLocalAdmins(hostName, runspace);
+ }
+ }
+ finally
+ {
+ CloseRunspace(runspace);
+ }
+
+ return result;
+ }
+
+ private bool CheckLocalAdminsGroupExists(string hostName, Runspace runspace)
+ {
+ var scripts = new List
+ {
+ string.Format("net localgroup {0}", WspAdministratorsGroupName)
+ };
+
+ object[] errors = null;
+ var result = ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
+
+ if (!errors.Any())
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private object[] CreateLocalAdministratorsGroup(string hostName, Runspace runspace)
+ {
+ var scripts = new List
+ {
+ string.Format("$cn = [ADSI]\"WinNT://{0}\"", hostName),
+ string.Format("$group = $cn.Create(\"Group\", \"{0}\")", WspAdministratorsGroupName),
+ "$group.setinfo()",
+ string.Format("$group.description = \"{0}\"", WspAdministratorsGroupDescription),
+ "$group.setinfo()"
+ };
+
+ object[] errors = null;
+ ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
+
+ if (!errors.Any())
+ {
+ scripts = new List
+ {
+ string.Format("$GroupObj = [ADSI]\"WinNT://{0}/Administrators\"", hostName),
+ string.Format("$GroupObj.Add(\"WinNT://{0}/{1}\")", hostName.ToLower().Replace(string.Format(".{0}", ServerSettings.ADRootDomain.ToLower()), ""), WspAdministratorsGroupName)
+ };
+
+ errors = null;
+ ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
+ }
+
+ return errors;
+ }
+
+ private List GetExistingLocalAdmins(string hostName, Runspace runspace)
+ {
+ var result = new List();
+
+ var scripts = new List
+ {
+ string.Format("net localgroup {0} | select -skip 6", WspAdministratorsGroupName)
+ };
+
+ object[] errors = null;
+ var exitingAdmins = ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
+
+ if (!errors.Any())
+ {
+ foreach(var user in exitingAdmins.Take(exitingAdmins.Count - 2))
+ {
+ result.Add(user.ToString());
+ }
+ }
+
+ return result;
+ }
+
+ private object[] AddNewLocalAdmin(string hostName, string samAccountName, Runspace runspace)
+ {
+ var scripts = new List
+ {
+ string.Format("$GroupObj = [ADSI]\"WinNT://{0}/{1}\"", hostName, WspAdministratorsGroupName),
+ string.Format("$GroupObj.Add(\"WinNT://{0}/{1}\")", ServerSettings.ADRootDomain, samAccountName)
+ };
+
+ object[] errors = null;
+ ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
+
+ return errors;
+ }
+
+ private object[] RemoveLocalAdmin(string hostName, string user, Runspace runspace)
+ {
+ var userObject = user.Split('\\');
+
+ var scripts = new List
+ {
+ string.Format("$GroupObj = [ADSI]\"WinNT://{0}/{1}\"", hostName, WspAdministratorsGroupName),
+ string.Format("$GroupObj.Remove(\"WinNT://{0}/{1}\")", userObject[0], userObject[1])
+ };
+
+ object[] errors = null;
+ ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
+
+ return errors;
+ }
+
+ #endregion
+
+ #region RDS Help Desk
+
+ private string GetHelpDeskGroupPath(string groupName)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ AppendProtocol(sb);
+ AppendDomainController(sb);
+ AppendCNPath(sb, groupName);
+ AppendOUPath(sb, RootOU);
+ AppendDomainPath(sb, RootDomain);
+
+ return sb.ToString();
+ }
+
+ private void CheckOrCreateHelpDeskComputerGroup()
+ {
+ if (!ActiveDirectoryUtils.AdObjectExists(GetHelpDeskGroupPath(RDSHelpDeskComputerGroup)))
+ {
+ ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskComputerGroup);
+ }
+ }
+
+ private void AddHelpDeskAdminsGroupToLocalAdmins(Runspace runspace, string hostName)
+ {
+ var helpDeskAdminsGroupPath = GetHelpDeskGroupPath(RDSHelpDeskGroup);
+ DirectoryEntry groupEntry = null;
+
+ if (!ActiveDirectoryUtils.AdObjectExists(helpDeskAdminsGroupPath))
+ {
+ ActiveDirectoryUtils.CreateGroup(GetRootOUPath(), RDSHelpDeskGroup);
+ groupEntry = ActiveDirectoryUtils.GetADObject(helpDeskAdminsGroupPath);
+
+ if (groupEntry.Properties.Contains("Description"))
+ {
+ groupEntry.Properties["Description"][0] = RDSHelpDeskGroupDescription;
+ }
+ else
+ {
+ groupEntry.Properties["Description"].Add(RDSHelpDeskGroupDescription);
+ }
+
+ groupEntry.CommitChanges();
+ }
+
+ if (groupEntry == null)
+ {
+ groupEntry = ActiveDirectoryUtils.GetADObject(helpDeskAdminsGroupPath);
+ }
+
+ var samAccountName = ActiveDirectoryUtils.GetADObjectProperty(groupEntry, "sAMAccountName");
+
+ var scripts = new List
+ {
+ string.Format("$GroupObj = [ADSI]\"WinNT://{0}/{1}\"", hostName, WspAdministratorsGroupName),
+ string.Format("$GroupObj.Add(\"WinNT://{0}/{1}\")", ServerSettings.ADRootDomain, samAccountName)
+ };
+
+ object[] errors = null;
+ ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
+ }
+
+ #endregion
+
+ #region SSL
+
+ public void InstallCertificate(byte[] certificate, string password, List hostNames)
+ {
+ Runspace runspace = null;
+
+ try
+ {
+ var guid = Guid.NewGuid();
+ var x509Cert = new X509Certificate2(certificate, password, X509KeyStorageFlags.Exportable);
+ //var content = x509Cert.Export(X509ContentType.Pfx);
+ var filePath = SaveCertificate(certificate, guid);
+ runspace = OpenRunspace();
+
+ foreach (var hostName in hostNames)
+ {
+ var destinationPath = string.Format("\\\\{0}\\c$\\{1}.pfx", hostName, guid);
+ var errors = CopyCertificateFile(runspace, filePath, destinationPath);
+
+ if (!errors.Any())
+ {
+ errors = ImportCertificate(runspace, hostName, password, string.Format("c:\\{0}.pfx", guid), x509Cert.Thumbprint);
+ }
+
+ DeleteCertificateFile(destinationPath, runspace);
+
+ if (errors.Any())
+ {
+ Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ throw new Exception(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ }
+ }
+
+ if (File.Exists(filePath))
+ {
+ File.Delete(filePath);
+ }
+ }
+ finally
+ {
+ CloseRunspace(runspace);
+ }
+ }
+
+ private object[] ImportCertificate(Runspace runspace, string hostName, string password, string certificatePath, string thumbprint)
+ {
+ var scripts = new List
+ {
+ string.Format("$mypwd = ConvertTo-SecureString -String {0} -Force –AsPlainText", password),
+ string.Format("Import-PfxCertificate –FilePath \"{0}\" cert:\\localMachine\\my -Password $mypwd", certificatePath),
+ string.Format("$cert = Get-Item cert:\\LocalMachine\\My\\{0}", thumbprint),
+ string.Format("$path = (Get-WmiObject -class \"Win32_TSGeneralSetting\" -Namespace root\\cimv2\\terminalservices -Filter \"TerminalName='RDP-tcp'\").__path"),
+ string.Format("Set-WmiInstance -Path $path -argument @{0}", string.Format("{{SSLCertificateSHA1Hash=\"{0}\"}}", thumbprint))
+ };
+
+ object[] errors = null;
+ ExecuteRemoteShellCommand(runspace, hostName, scripts, out errors);
+
+ return errors;
+ }
+
+ private string SaveCertificate(byte[] certificate, Guid guid)
+ {
+ var filePath = string.Format("{0}{1}.pfx", Path.GetTempPath(), guid);
+
+ if (File.Exists(filePath))
+ {
+ File.Delete(filePath);
+ }
+
+ File.WriteAllBytes(filePath, certificate);
+
+ return filePath;
+ }
+
+ private object[] CopyCertificateFile(Runspace runspace, string filePath, string destinationPath)
+ {
+ var scripts = new List
+ {
+ string.Format("Copy-Item \"{0}\" -Destination \"{1}\" -Force", filePath, destinationPath)
+ };
+
+ object[] errors = null;
+ ExecuteShellCommand(runspace, scripts, out errors);
+
+ return errors;
+ }
+
+ private object[] DeleteCertificateFile(string destinationPath, Runspace runspace)
+ {
+ var scripts = new List
+ {
+ string.Format("Remove-Item -Path \"{0}\" -Force", destinationPath)
+ };
+
+ object[] errors = null;
+ ExecuteShellCommand(runspace, scripts, out errors);
+
+ return errors;
+ }
+
+ #endregion
+
private void AddRdsServerToDeployment(Runspace runSpace, RdsServer server)
{
Command cmd = new Command("Add-RDserver");
@@ -956,9 +1329,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
cmd.Parameters.Add("ConnectionBroker", ConnectionBroker);
ExecuteShellCommand(runSpace, cmd, false);
- }
-
-
+ }
private bool ExistRdsServerInDeployment(Runspace runSpace, RdsServer server)
{
@@ -1028,7 +1399,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
}
return users;
- }
+ }
private void AddUserGroupsToCollection(Runspace runSpace, string collectionName, List groups)
{
@@ -1043,7 +1414,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
private void AddComputerToCollectionAdComputerGroup(string organizationId, string collectionName, RdsServer server)
{
var computerPath = GetComputerPath(server.Name, false);
- var computerGroupName = GetComputersGroupName( collectionName);
+ var computerGroupName = GetComputersGroupName( collectionName);
if (!ActiveDirectoryUtils.AdObjectExists(computerPath))
{
@@ -1059,6 +1430,11 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
{
ActiveDirectoryUtils.AddObjectToGroup(computerPath, GetComputerGroupPath(organizationId, collectionName));
}
+
+ if (!ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup))
+ {
+ ActiveDirectoryUtils.AddObjectToGroup(computerPath, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup));
+ }
}
SetRDServerNewConnectionAllowed(false, server);
@@ -1083,6 +1459,14 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
{
ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetComputerGroupPath(organizationId, collectionName));
}
+
+ if (ActiveDirectoryUtils.AdObjectExists(GetHelpDeskGroupPath(RDSHelpDeskComputerGroup)))
+ {
+ if (ActiveDirectoryUtils.IsComputerInGroup(samName, RDSHelpDeskComputerGroup))
+ {
+ ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, GetHelpDeskGroupPath(RDSHelpDeskComputerGroup));
+ }
+ }
}
}
@@ -1105,6 +1489,63 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return installationResult;
}
+ public void MoveRdsServerToTenantOU(string hostName, string organizationId)
+ {
+ var tenantComputerGroupPath = GetTenantComputerGroupPath(organizationId);
+
+ if (!ActiveDirectoryUtils.AdObjectExists(tenantComputerGroupPath))
+ {
+ ActiveDirectoryUtils.CreateGroup(GetOrganizationPath(organizationId), RdsServersOU);
+ }
+
+ hostName = hostName.ToLower().Replace(string.Format(".{0}", ServerSettings.ADRootDomain.ToLower()), "");
+ var computerPath = GetComputerPath(hostName, true);
+
+ if(!ActiveDirectoryUtils.AdObjectExists(computerPath))
+ {
+ computerPath = GetComputerPath(hostName, false);
+ }
+
+ if (ActiveDirectoryUtils.AdObjectExists(computerPath))
+ {
+ var computerObject = ActiveDirectoryUtils.GetADObject(computerPath);
+ var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(computerObject, "sAMAccountName");
+
+ if (!ActiveDirectoryUtils.IsComputerInGroup(samName, RdsServersOU))
+ {
+ DirectoryEntry group = new DirectoryEntry(tenantComputerGroupPath);
+ group.Invoke("Add", computerObject.Path);
+
+ group.CommitChanges();
+ }
+ }
+ }
+
+ public void RemoveRdsServerFromTenantOU(string hostName, string organizationId)
+ {
+ var tenantComputerGroupPath = GetTenantComputerGroupPath(organizationId);
+ hostName = hostName.ToLower().Replace(string.Format(".{0}", ServerSettings.ADRootDomain.ToLower()), "");
+ var tenantComputerPath = GetTenantComputerPath(hostName, organizationId);
+
+ var computerPath = GetComputerPath(hostName, true);
+
+ if (!ActiveDirectoryUtils.AdObjectExists(computerPath))
+ {
+ computerPath = GetComputerPath(hostName, false);
+ }
+
+ if (ActiveDirectoryUtils.AdObjectExists(computerPath))
+ {
+ var computerObject = ActiveDirectoryUtils.GetADObject(computerPath);
+ var samName = (string)ActiveDirectoryUtils.GetADObjectProperty(computerObject, "sAMAccountName");
+
+ if (ActiveDirectoryUtils.IsComputerInGroup(samName, RdsServersOU))
+ {
+ ActiveDirectoryUtils.RemoveObjectFromGroup(computerPath, tenantComputerGroupPath);
+ }
+ }
+ }
+
public bool CheckSessionHostFeatureInstallation(string hostName)
{
bool isInstalled = false;
@@ -1216,11 +1657,18 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
DisplayName = Convert.ToString(GetPSObjectProperty(psObject, "DisplayName")),
FilePath = Convert.ToString(GetPSObjectProperty(psObject, "FilePath")),
Alias = Convert.ToString(GetPSObjectProperty(psObject, "Alias")),
- ShowInWebAccess = Convert.ToBoolean(GetPSObjectProperty(psObject, "ShowInWebAccess"))
+ ShowInWebAccess = Convert.ToBoolean(GetPSObjectProperty(psObject, "ShowInWebAccess")),
+ Users = null
};
var requiredCommandLine = GetPSObjectProperty(psObject, "RequiredCommandLine");
remoteApp.RequiredCommandLine = requiredCommandLine == null ? null : requiredCommandLine.ToString();
+ var users = (string[])(GetPSObjectProperty(psObject, "UserGroups"));
+
+ if (users != null && users.Any())
+ {
+ remoteApp.Users = users;
+ }
return remoteApp;
}
@@ -1293,7 +1741,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
internal string GetComputerGroupPath(string organizationId, string collection)
{
StringBuilder sb = new StringBuilder();
- // append provider
+
AppendProtocol(sb);
AppendDomainController(sb);
AppendCNPath(sb, GetComputersGroupName(collection));
@@ -1302,16 +1750,16 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
AppendDomainPath(sb, RootDomain);
return sb.ToString();
- }
+ }
internal string GetUsersGroupPath(string organizationId, string collection)
{
StringBuilder sb = new StringBuilder();
- // append provider
+
AppendProtocol(sb);
AppendDomainController(sb);
AppendCNPath(sb, GetUsersGroupName(collection));
- AppendOUPath(sb, organizationId);
+ AppendOUPath(sb, organizationId);
AppendOUPath(sb, RootOU);
AppendDomainPath(sb, RootDomain);
@@ -1332,6 +1780,18 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return sb.ToString();
}
+ private string GetRootOUPath()
+ {
+ StringBuilder sb = new StringBuilder();
+ // append provider
+ AppendProtocol(sb);
+ AppendDomainController(sb);
+ AppendOUPath(sb, RootOU);
+ AppendDomainPath(sb, RootDomain);
+
+ return sb.ToString();
+ }
+
private string GetOrganizationPath(string organizationId)
{
StringBuilder sb = new StringBuilder();
@@ -1350,7 +1810,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
StringBuilder sb = new StringBuilder();
// append provider
AppendProtocol(sb);
- AppendDomainController(sb);
+ AppendDomainController(sb);
AppendCNPath(sb, objName);
if (domainController)
{
@@ -1366,6 +1826,35 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return sb.ToString();
}
+ private string GetTenantComputerPath(string objName, string organizationId)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ AppendProtocol(sb);
+ AppendDomainController(sb);
+ AppendCNPath(sb, objName);
+ AppendCNPath(sb, RdsServersOU);
+ AppendOUPath(sb, organizationId);
+ AppendOUPath(sb, RootOU);
+ AppendDomainPath(sb, RootDomain);
+
+ return sb.ToString();
+ }
+
+ internal string GetTenantComputerGroupPath(string organizationId)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ AppendProtocol(sb);
+ AppendDomainController(sb);
+ AppendCNPath(sb, RdsServersOU);
+ AppendOUPath(sb, organizationId);
+ AppendOUPath(sb, RootOU);
+ AppendDomainPath(sb, RootDomain);
+
+ return sb.ToString();
+ }
+
private static void AppendCNPath(StringBuilder sb, string organizationId)
{
if (string.IsNullOrEmpty(organizationId))
@@ -1550,7 +2039,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return ExecuteShellCommand(runSpace, invokeCommand, false, out errors);
}
- internal Collection ExecuteRemoteShellCommand(Runspace runSpace, string hostName, List scripts, params string[] moduleImports)
+ internal Collection ExecuteRemoteShellCommand(Runspace runSpace, string hostName, List scripts, out object[] errors, params string[] moduleImports)
{
Command invokeCommand = new Command("Invoke-Command");
invokeCommand.Parameters.Add("ComputerName", hostName);
@@ -1564,7 +2053,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
invokeCommand.Parameters.Add("ScriptBlock", sb);
- return ExecuteShellCommand(runSpace, invokeCommand, false);
+ return ExecuteShellCommand(runSpace, invokeCommand, false, out errors);
}
internal Collection ExecuteShellCommand(Runspace runSpace, Command cmd)
@@ -1801,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);
}
@@ -1835,6 +2328,238 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
}
#endregion
+
+ #region Server Info
+
+ public RdsServerInfo GetRdsServerInfo(string serverName)
+ {
+ var result = new RdsServerInfo();
+ Runspace runspace = null;
+
+ try
+ {
+ runspace = OpenRunspace();
+ result = GetServerInfo(runspace, serverName);
+ result.Status = GetRdsServerStatus(runspace, serverName);
+
+ }
+ finally
+ {
+ CloseRunspace(runspace);
+ }
+
+ return result;
+ }
+
+ public string GetRdsServerStatus(string serverName)
+ {
+ string result = "";
+ Runspace runspace = null;
+
+ try
+ {
+ runspace = OpenRunspace();
+ result = GetRdsServerStatus(runspace, serverName);
+
+ }
+ finally
+ {
+ CloseRunspace(runspace);
+ }
+
+ return result;
+ }
+
+ public void ShutDownRdsServer(string serverName)
+ {
+ Runspace runspace = null;
+
+ try
+ {
+ runspace = OpenRunspace();
+ var command = new Command("Stop-Computer");
+ command.Parameters.Add("ComputerName", serverName);
+ command.Parameters.Add("Force", true);
+ object[] errors = null;
+
+ ExecuteShellCommand(runspace, command, false, out errors);
+
+ if (errors.Any())
+ {
+ Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ throw new Exception(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ }
+ }
+ finally
+ {
+ CloseRunspace(runspace);
+ }
+ }
+
+ public void RestartRdsServer(string serverName)
+ {
+ Runspace runspace = null;
+
+ try
+ {
+ runspace = OpenRunspace();
+ var command = new Command("Restart-Computer");
+ command.Parameters.Add("ComputerName", serverName);
+ command.Parameters.Add("Force", true);
+ object[] errors = null;
+
+ ExecuteShellCommand(runspace, command, false, out errors);
+
+ if (errors.Any())
+ {
+ Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ throw new Exception(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ }
+ }
+ finally
+ {
+ CloseRunspace(runspace);
+ }
+ }
+
+ private RdsServerInfo GetServerInfo(Runspace runspace, string serverName)
+ {
+ var result = new RdsServerInfo();
+ Command cmd = new Command("Get-WmiObject");
+ cmd.Parameters.Add("Class", "Win32_Processor");
+ cmd.Parameters.Add("ComputerName", serverName);
+
+ object[] errors = null;
+ var psProcInfo = ExecuteShellCommand(runspace, cmd, false, out errors).First();
+
+ if (errors.Any())
+ {
+ Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ return result;
+ }
+
+ cmd = new Command("Get-WmiObject");
+ cmd.Parameters.Add("Class", "Win32_OperatingSystem");
+ cmd.Parameters.Add("ComputerName", serverName);
+
+ var psMemoryInfo = ExecuteShellCommand(runspace, cmd, false, out errors).First();
+
+ if (errors.Any())
+ {
+ Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ return result;
+ }
+
+ result.NumberOfCores = Convert.ToInt32(GetPSObjectProperty(psProcInfo, "NumberOfCores"));
+ result.MaxClockSpeed = Convert.ToInt32(GetPSObjectProperty(psProcInfo, "MaxClockSpeed"));
+ result.LoadPercentage = Convert.ToInt32(GetPSObjectProperty(psProcInfo, "LoadPercentage"));
+ result.MemoryAllocatedMb = Math.Round(Convert.ToDouble(GetPSObjectProperty(psMemoryInfo, "TotalVisibleMemorySize")) / 1024, 1);
+ result.FreeMemoryMb = Math.Round(Convert.ToDouble(GetPSObjectProperty(psMemoryInfo, "FreePhysicalMemory")) / 1024, 1);
+ result.Drives = GetRdsServerDriveInfo(runspace, serverName).ToArray();
+
+ return result;
+ }
+
+ private string GetRdsServerStatus (Runspace runspace, string serverName)
+ {
+ if (CheckServerAvailability(serverName))
+ {
+ if (CheckPendingReboot(runspace, serverName))
+ {
+ return "Online - Pending Reboot";
+ }
+
+ return "Online";
+ }
+ else
+ {
+ return "Unavailable";
+ }
+ }
+
+ private List GetRdsServerDriveInfo(Runspace runspace, string serverName)
+ {
+ var result = new List();
+ Command cmd = new Command("Get-WmiObject");
+ cmd.Parameters.Add("Class", "Win32_LogicalDisk");
+ cmd.Parameters.Add("Filter", "DriveType=3");
+ cmd.Parameters.Add("ComputerName", serverName);
+ object[] errors = null;
+ var psDrives = ExecuteShellCommand(runspace, cmd, false, out errors);
+
+ if (errors.Any())
+ {
+ Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
+ return result;
+ }
+
+ foreach (var psDrive in psDrives)
+ {
+ var driveInfo = new RdsServerDriveInfo()
+ {
+ VolumeName = GetPSObjectProperty(psDrive, "VolumeName").ToString(),
+ DeviceId = GetPSObjectProperty(psDrive, "DeviceId").ToString(),
+ SizeMb = Math.Round(Convert.ToDouble(GetPSObjectProperty(psDrive, "Size"))/1024/1024, 1),
+ FreeSpaceMb = Math.Round(Convert.ToDouble(GetPSObjectProperty(psDrive, "FreeSpace"))/1024/1024, 1)
+ };
+
+ result.Add(driveInfo);
+ }
+
+ return result;
+ }
+
+ private bool CheckRDSServerAvaliability(string serverName)
+ {
+ var ping = new Ping();
+ var reply = ping.Send(serverName, 1000);
+
+ if (reply.Status == IPStatus.Success)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private bool CheckPendingReboot(Runspace runspace, string serverName)
+ {
+ if (CheckPendingReboot(runspace, serverName, @"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing", "RebootPending"))
+ {
+ return true;
+ }
+
+ if (CheckPendingReboot(runspace, serverName, @"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "RebootRequired"))
+ {
+ return true;
+ }
+
+ if (CheckPendingReboot(runspace, serverName, @"HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager", "PendingFileRenameOperations"))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private bool CheckPendingReboot(Runspace runspace, string serverName, string registryPath, string registryKey)
+ {
+ Command cmd = new Command("Get-ItemProperty");
+ cmd.Parameters.Add("Path", registryPath);
+ cmd.Parameters.Add("Name", registryKey);
+ cmd.Parameters.Add("ErrorAction", "SilentlyContinue");
+
+ var feature = ExecuteRemoteShellCommand(runspace, serverName, cmd).FirstOrDefault();
+
+ if (feature != null)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ #endregion
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Extensions/PSObjectExtension.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Extensions/PSObjectExtension.cs
new file mode 100644
index 00000000..e1a50bfa
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Extensions/PSObjectExtension.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management.Automation;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebsitePanel.Providers.Virtualization
+{
+ static class PSObjectExtension
+ {
+ public static object GetProperty(this PSObject obj, string name)
+ {
+ return obj.Members[name].Value;
+ }
+ public static T GetProperty(this PSObject obj, string name)
+ {
+ return (T)obj.Members[name].Value;
+ }
+ public static T GetEnum(this PSObject obj, string name) where T : struct
+ {
+ return (T)Enum.Parse(typeof(T), GetProperty(obj, name).ToString());
+ }
+ public static int GetInt(this PSObject obj, string name)
+ {
+ return Convert.ToInt32(obj.Members[name].Value);
+ }
+ public static long GetLong(this PSObject obj, string name)
+ {
+ return Convert.ToInt64(obj.Members[name].Value);
+ }
+ public static string GetString(this PSObject obj, string name)
+ {
+ return obj.Members[name].Value == null ? "" : obj.Members[name].Value.ToString();
+ }
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/DvdDriveHelper.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/DvdDriveHelper.cs
new file mode 100644
index 00000000..871e8fa3
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/DvdDriveHelper.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Management.Automation;
+using System.Management.Automation.Runspaces;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebsitePanel.Providers.Virtualization
+{
+ public static class DvdDriveHelper
+ {
+ public static DvdDriveInfo Get(PowerShellManager powerShell, string vmName)
+ {
+ DvdDriveInfo info = new DvdDriveInfo();
+
+ Command cmd = new Command("Get-VMDvdDrive");
+
+ cmd.Parameters.Add("VMName", vmName);
+
+ Collection result = powerShell.Execute(cmd, false);
+
+ if (result != null && result.Count > 0)
+ {
+ info.Id = result[0].GetString("Id");
+ info.Name = result[0].GetString("Name");
+ info.ControllerType = result[0].GetEnum("ControllerType");
+ info.ControllerNumber = result[0].GetInt("ControllerNumber");
+ info.ControllerLocation = result[0].GetInt("ControllerLocation");
+ }
+ return info;
+ }
+
+ public static void Set(PowerShellManager powerShell, string vmName, string path)
+ {
+ var dvd = Get(powerShell, vmName);
+
+ Command cmd = new Command("Set-VMDvdDrive");
+
+ cmd.Parameters.Add("VMName", vmName);
+ cmd.Parameters.Add("Path", path);
+ cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber);
+ cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation);
+
+ powerShell.Execute(cmd, false);
+ }
+
+ public static void Update(PowerShellManager powerShell, VirtualMachine vm, bool dvdDriveShouldBeInstalled)
+ {
+ if (!vm.DvdDriveInstalled && dvdDriveShouldBeInstalled)
+ Add(powerShell, vm.Name);
+ else if (vm.DvdDriveInstalled && !dvdDriveShouldBeInstalled)
+ Remove(powerShell, vm.Name);
+ }
+
+ public static void Add(PowerShellManager powerShell, string vmName)
+ {
+ var dvd = Get(powerShell, vmName);
+
+ Command cmd = new Command("Add-VMDvdDrive");
+
+ cmd.Parameters.Add("VMName", vmName);
+ cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber);
+ cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation);
+
+ powerShell.Execute(cmd, false);
+ }
+
+ public static void Remove(PowerShellManager powerShell, string vmName)
+ {
+ var dvd = Get(powerShell, vmName);
+
+ Command cmd = new Command("Remove-VMDvdDrive");
+
+ cmd.Parameters.Add("VMName", vmName);
+ cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber);
+ cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation);
+
+ powerShell.Execute(cmd, false);
+ }
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/NetworkAdapterHelper.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/NetworkAdapterHelper.cs
new file mode 100644
index 00000000..c00ff956
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/NetworkAdapterHelper.cs
@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Management.Automation;
+using System.Management.Automation.Runspaces;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebsitePanel.Providers.Virtualization
+{
+ public static class NetworkAdapterHelper
+ {
+ #region Constants
+
+ private const string EXTERNAL_NETWORK_ADAPTER_NAME = "External Network Adapter";
+ private const string PRIVATE_NETWORK_ADAPTER_NAME = "Private Network Adapter";
+ private const string MANAGEMENT_NETWORK_ADAPTER_NAME = "Management Network Adapter";
+
+ #endregion
+
+ public static VirtualMachineNetworkAdapter[] Get(PowerShellManager powerShell, string vmName)
+ {
+ List adapters = new List();
+
+ Command cmd = new Command("Get-VMNetworkAdapter");
+ if (!string.IsNullOrEmpty(vmName)) cmd.Parameters.Add("VMName", vmName);
+
+ Collection result = powerShell.Execute(cmd, false);
+ if (result != null && result.Count > 0)
+ {
+ foreach (PSObject psAdapter in result)
+ {
+ VirtualMachineNetworkAdapter adapter = new VirtualMachineNetworkAdapter();
+
+ adapter.Name = psAdapter.GetString("Name");
+ adapter.MacAddress = psAdapter.GetString("MacAddress");
+ adapter.SwitchName = psAdapter.GetString("SwitchName");
+
+ adapters.Add(adapter);
+ }
+ }
+ return adapters.ToArray();
+ }
+
+ public static VirtualMachineNetworkAdapter Get(PowerShellManager powerShell, string vmName, string macAddress)
+ {
+ var adapters = Get(powerShell, vmName);
+ return adapters.FirstOrDefault(a => a.MacAddress == macAddress);
+ }
+
+ public static void Update(PowerShellManager powerShell, VirtualMachine vm, string switchId, string portName, string macAddress, string adapterName, bool legacyAdapter)
+ {
+ // External NIC
+ if (!vm.ExternalNetworkEnabled && !String.IsNullOrEmpty(vm.ExternalNicMacAddress))
+ {
+ // delete adapter
+ Delete(powerShell, vm.Name, vm.ExternalNicMacAddress);
+ vm.ExternalNicMacAddress = null; // reset MAC
+ }
+ else if (vm.ExternalNetworkEnabled && !String.IsNullOrEmpty(vm.ExternalNicMacAddress))
+ {
+ // add external adapter
+ Add(powerShell, vm.Name, vm.ExternalSwitchId, vm.ExternalNicMacAddress, EXTERNAL_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
+ }
+
+ // Private NIC
+ if (!vm.PrivateNetworkEnabled && !String.IsNullOrEmpty(vm.PrivateNicMacAddress))
+ {
+ Delete(powerShell, vm.Name, vm.PrivateNicMacAddress);
+ vm.PrivateNicMacAddress = null; // reset MAC
+ }
+ else if (vm.PrivateNetworkEnabled && !String.IsNullOrEmpty(vm.PrivateNicMacAddress))
+ {
+ Add(powerShell, vm.Name, vm.ExternalSwitchId, vm.ExternalNicMacAddress, PRIVATE_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
+ }
+ }
+
+ public static void Add(PowerShellManager powerShell, string vmName, string switchId, string macAddress, string adapterName, bool legacyAdapter)
+ {
+ //var dvd = Get(powerShell, vmName);
+
+ //Command cmd = new Command("Add-VMDvdDrive");
+
+ //cmd.Parameters.Add("VMName", vmName);
+ //cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber);
+ //cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation);
+
+ //powerShell.Execute(cmd, false);
+ }
+ public static void Delete(PowerShellManager powerShell, string vmName, string macAddress)
+ {
+ //var dvd = Get(powerShell, vmName);
+
+ //Command cmd = new Command("Add-VMDvdDrive");
+
+ //cmd.Parameters.Add("VMName", vmName);
+ //cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber);
+ //cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation);
+
+ //powerShell.Execute(cmd, false);
+ }
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/VirtualMachineHelper.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/VirtualMachineHelper.cs
new file mode 100644
index 00000000..66958337
--- /dev/null
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/Helpers/VirtualMachineHelper.cs
@@ -0,0 +1,195 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Management.Automation;
+using System.Management.Automation.Runspaces;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebsitePanel.Providers.Virtualization
+{
+ public static class VirtualMachineHelper
+ {
+ #region Constants
+
+ private const Int64 Size1G = 0x40000000;
+ private const Int64 Size1M = 0x100000;
+
+ #endregion
+
+ public static OperationalStatus GetVMHeartBeatStatus(PowerShellManager powerShell, string name)
+ {
+
+ OperationalStatus status = OperationalStatus.None;
+
+ Command cmd = new Command("Get-VMIntegrationService");
+
+ cmd.Parameters.Add("VMName", name);
+ cmd.Parameters.Add("Name", "HeartBeat");
+
+ Collection result = powerShell.Execute(cmd, false);
+ if (result != null && result.Count > 0)
+ {
+ var statusString = result[0].GetProperty("PrimaryOperationalStatus");
+
+ if (statusString != null)
+ status = (OperationalStatus)Enum.Parse(typeof(OperationalStatus), statusString.ToString());
+ }
+ return status;
+ }
+
+
+ public static int GetVMProcessors(PowerShellManager powerShell, string name)
+ {
+
+ int procs = 0;
+
+ Command cmd = new Command("Get-VMProcessor");
+
+ cmd.Parameters.Add("VMName", name);
+
+ Collection result = powerShell.Execute(cmd, false);
+ if (result != null && result.Count > 0)
+ {
+ procs = Convert.ToInt32(result[0].GetProperty("Count"));
+
+ }
+ return procs;
+ }
+
+ public static MemoryInfo GetVMMemory(PowerShellManager powerShell, string name)
+ {
+ MemoryInfo info = new MemoryInfo();
+
+ Command cmd = new Command("Get-VMMemory");
+
+ cmd.Parameters.Add("VMName", name);
+
+ Collection result = powerShell.Execute(cmd, false);
+ if (result != null && result.Count > 0)
+ {
+ info.DynamicMemoryEnabled = Convert.ToBoolean(result[0].GetProperty("DynamicMemoryEnabled"));
+ info.Startup = Convert.ToInt64(result[0].GetProperty("Startup"));
+ info.Minimum = Convert.ToInt64(result[0].GetProperty("Minimum"));
+ info.Maximum = Convert.ToInt64(result[0].GetProperty("Maximum"));
+ info.Buffer = Convert.ToInt32(result[0].GetProperty("Buffer"));
+ info.Priority = Convert.ToInt32(result[0].GetProperty("Priority"));
+ }
+ return info;
+ }
+
+ public static BiosInfo GetVMBios(PowerShellManager powerShell, string name)
+ {
+ BiosInfo info = new BiosInfo();
+
+ Command cmd = new Command("Get-VMBios");
+
+ cmd.Parameters.Add("VMName", name);
+
+ Collection result = powerShell.Execute(cmd, false);
+ if (result != null && result.Count > 0)
+ {
+ info.NumLockEnabled = Convert.ToBoolean(result[0].GetProperty("NumLockEnabled"));
+
+ List startupOrders = new List();
+
+ foreach (var item in (IEnumerable)result[0].GetProperty("StartupOrder"))
+ startupOrders.Add(item.ToString());
+
+ info.StartupOrder = startupOrders.ToArray();
+ }
+ return info;
+ }
+
+ public static VirtualHardDiskInfo[] GetVirtualHardDisks(PowerShellManager powerShell, string name)
+ {
+
+ List disks = new List();
+
+ Command cmd = new Command("Get-VMHardDiskDrive");
+ cmd.Parameters.Add("VMName", name);
+
+ Collection result = powerShell.Execute(cmd, false);
+ if (result != null && result.Count > 0)
+ {
+ foreach (PSObject d in result)
+ {
+ VirtualHardDiskInfo disk = new VirtualHardDiskInfo();
+
+ disk.SupportPersistentReservations = Convert.ToBoolean(d.GetProperty("SupportPersistentReservations"));
+ disk.MaximumIOPS = Convert.ToUInt64(d.GetProperty("MaximumIOPS"));
+ disk.MinimumIOPS = Convert.ToUInt64(d.GetProperty("MinimumIOPS"));
+ disk.VHDControllerType = d.GetEnum("ControllerType");
+ disk.ControllerNumber = Convert.ToInt32(d.GetProperty("ControllerNumber"));
+ disk.ControllerLocation = Convert.ToInt32(d.GetProperty("ControllerLocation"));
+ disk.Path = d.GetProperty("Path").ToString();
+ disk.Name = d.GetProperty("Name").ToString();
+
+ GetVirtualHardDiskDetail(powerShell, disk.Path, ref disk);
+
+ disks.Add(disk);
+ }
+ }
+ return disks.ToArray();
+ }
+
+ public static void GetVirtualHardDiskDetail(PowerShellManager powerShell, string path, ref VirtualHardDiskInfo disk)
+ {
+ if (!string.IsNullOrEmpty(path))
+ {
+ Command cmd = new Command("Get-VHD");
+ cmd.Parameters.Add("Path", path);
+ Collection result = powerShell.Execute(cmd, false);
+ if (result != null && result.Count > 0)
+ {
+ disk.DiskFormat = result[0].GetEnum("VhdFormat");
+ disk.DiskType = result[0].GetEnum("VhdType");
+ disk.ParentPath = result[0].GetProperty("ParentPath");
+ disk.MaxInternalSize = Convert.ToInt64(result[0].GetProperty("Size")) / Size1G;
+ disk.FileSize = Convert.ToInt64(result[0].GetProperty("FileSize")) / Size1G;
+ disk.Attached = Convert.ToBoolean(result[0].GetProperty("Attached"));
+ }
+ }
+ }
+
+
+
+
+ public static void UpdateBios(PowerShellManager powerShell, VirtualMachine vm, bool bootFromCD, bool numLockEnabled)
+ {
+ Command cmd = new Command("Set-VMBios");
+
+ cmd.Parameters.Add("VMName", vm.Name);
+ cmd.Parameters.Add(numLockEnabled ? "EnableNumLock" : "DisableNumLock");
+ var bootOrder = bootFromCD
+ ? new[] { "CD", "IDE", "LegacyNetworkAdapter", "Floppy" }
+ : new[] { "IDE", "CD", "LegacyNetworkAdapter", "Floppy" };
+ cmd.Parameters.Add("StartupOrder", bootOrder);
+
+ powerShell.Execute(cmd, false);
+ }
+ public static void UpdateProcessors(PowerShellManager powerShell, VirtualMachine vm, int cpuCores, int cpuLimitSettings, int cpuReserveSettings, int cpuWeightSettings)
+ {
+ Command cmd = new Command("Set-VMProcessor");
+
+ cmd.Parameters.Add("VMName", vm.Name);
+ cmd.Parameters.Add("Count", cpuCores);
+ cmd.Parameters.Add("Maximum", Convert.ToInt64(cpuLimitSettings * 1000));
+ cmd.Parameters.Add("Reserve", Convert.ToInt64(cpuReserveSettings * 1000));
+ cmd.Parameters.Add("RelativeWeight", cpuWeightSettings);
+
+ powerShell.Execute(cmd, false);
+ }
+ public static void UpdateMemory(PowerShellManager powerShell, VirtualMachine vm, long ramMB)
+ {
+ Command cmd = new Command("Set-VMMemory");
+
+ cmd.Parameters.Add("VMName", vm.Name);
+ cmd.Parameters.Add("StartupBytes", ramMB);
+
+ powerShell.Execute(cmd, false);
+ }
+ }
+}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs
index 6aa31177..2247adf7 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs
@@ -51,6 +51,7 @@ using WebsitePanel.Server.Utils;
using Vds = Microsoft.Storage.Vds;
using System.Configuration;
+using System.Linq;
namespace WebsitePanel.Providers.Virtualization
{
@@ -69,8 +70,6 @@ namespace WebsitePanel.Providers.Virtualization
private const string KVP_RAM_SUMMARY_KEY = "VM-RAM-Summary";
private const string KVP_HDD_SUMMARY_KEY = "VM-HDD-Summary";
- private const Int64 Size1G = 0x40000000;
- private const Int64 Size1M = 0x100000;
#endregion
@@ -140,72 +139,73 @@ namespace WebsitePanel.Providers.Virtualization
public VirtualMachine GetVirtualMachine(string vmId)
{
- return GetVirtualMachineInternal( vmId, false);
+ return GetVirtualMachineInternal(vmId, false);
}
- public VirtualMachine GetVirtualMachineInternal(string vmId, bool extendedInfo)
+ public VirtualMachine GetVirtualMachineEx(string vmId)
{
+ return GetVirtualMachineInternal(vmId, true);
+ }
+ protected VirtualMachine GetVirtualMachineInternal(string vmId, bool extendedInfo)
+ {
HostedSolutionLog.LogStart("GetVirtualMachine");
HostedSolutionLog.DebugInfo("Virtual Machine: {0}", vmId);
- Runspace runSpace = null;
VirtualMachine vm = new VirtualMachine();
try
{
- runSpace = OpenRunspace();
Command cmd = new Command("Get-VM");
cmd.Parameters.Add("Id", vmId);
-
- Collection result = ExecuteShellCommand(runSpace, cmd, false);
+
+ Collection result = PowerShell.Execute(cmd, false);
if (result != null && result.Count > 0)
{
- vm.Name = GetPSObjectProperty(result[0], "Name").ToString();
- vm.State = (VirtualMachineState)Enum.Parse(typeof(VirtualMachineState), GetPSObjectProperty(result[0], "State").ToString());
- vm.CpuUsage = ConvertNullableToInt32((UInt32?)GetPSObjectProperty(result[0], "CpuUsage"));
- vm.RamUsage = ConvertNullableToInt32((UInt32?)GetPSObjectProperty(result[0], "MemoryAssigned"));
- vm.Uptime = TimeSpan.Parse(GetPSObjectProperty(result[0], "Uptime").ToString()).Ticks;
- vm.Status = GetPSObjectProperty(result[0], "Status").ToString();
- vm.ReplicationState = GetPSObjectProperty(result[0], "ReplicationState").ToString();
-
- vm.Heartbeat = GetVMHeartBeatStatus(runSpace, vm.Name);
+ vm.Name = result[0].GetProperty("Name").ToString();
+ vm.State = result[0].GetEnum("State");
+ vm.CpuUsage = ConvertNullableToInt32(result[0].GetProperty("CpuUsage"));
+ vm.RamUsage = ConvertNullableToInt64(result[0].GetProperty("MemoryAssigned"));
+ vm.Uptime = Convert.ToInt64(result[0].GetProperty("UpTime").TotalMilliseconds);
+ vm.Status = result[0].GetProperty("Status").ToString();
+ vm.ReplicationState = result[0].GetProperty("ReplicationState").ToString();
+
+ vm.Heartbeat = VirtualMachineHelper.GetVMHeartBeatStatus(PowerShell, vm.Name);
vm.CreatedDate = DateTime.Now;
if (extendedInfo)
{
- vm.CpuCores = GetVMProcessors(runSpace, vm.Name);
+ vm.CpuCores = VirtualMachineHelper.GetVMProcessors(PowerShell, vm.Name);
- MemoryInfo memoryInfo = GetVMMemory(runSpace, vm.Name);
+ MemoryInfo memoryInfo = VirtualMachineHelper.GetVMMemory(PowerShell, vm.Name);
vm.RamSize = memoryInfo.Startup;
- BiosInfo biosInfo = GetVMBios(runSpace, vm.Name);
+ // BIOS
+ BiosInfo biosInfo = VirtualMachineHelper.GetVMBios(PowerShell, vm.Name);
vm.NumLockEnabled = biosInfo.NumLockEnabled;
vm.BootFromCD = false;
if ((biosInfo.StartupOrder != null) && (biosInfo.StartupOrder.Length > 0))
vm.BootFromCD = (biosInfo.StartupOrder[0] == "CD");
- cmd = new Command("Get-VMDvdDrive");
- cmd.Parameters.Add("VMName", vm.Name);
+ // DVD drive
+ var dvdInfo = DvdDriveHelper.Get(PowerShell, vm.Name);
+ vm.DvdDriveInstalled = dvdInfo != null;
- result = ExecuteShellCommand(runSpace, cmd, false);
- vm.DvdDriveInstalled = (result != null && result.Count > 0);
-
- vm.Disks = GetVirtualHardDisks(runSpace, vm.Name);
+ // HDD
+ vm.Disks = VirtualMachineHelper.GetVirtualHardDisks(PowerShell, vm.Name);
- if ((vm.Disks != null) & (vm.Disks.GetLength(0) > 0))
+ if (vm.Disks != null && vm.Disks.GetLength(0) > 0)
{
vm.VirtualHardDrivePath = vm.Disks[0].Path;
vm.HddSize = Convert.ToInt32(vm.Disks[0].FileSize);
}
-
-
+ // network adapters
+ vm.Adapters = NetworkAdapterHelper.Get(PowerShell, vm.Name);
}
-
}
}
catch (Exception ex)
@@ -213,192 +213,52 @@ namespace WebsitePanel.Providers.Virtualization
HostedSolutionLog.LogError("GetVirtualMachine", ex);
throw;
}
- finally
- {
- CloseRunspace(runSpace);
- }
HostedSolutionLog.LogEnd("GetVirtualMachine");
return vm;
}
-
- internal OperationalStatus GetVMHeartBeatStatus(Runspace runSpace, string name)
- {
-
- OperationalStatus status = OperationalStatus.None;
-
- Command cmd = new Command("Get-VMIntegrationService");
-
- cmd.Parameters.Add("VMName", name);
- cmd.Parameters.Add("Name", "HeartBeat");
-
- Collection result = ExecuteShellCommand(runSpace, cmd, false);
- if (result != null && result.Count > 0)
- {
- status = (OperationalStatus)Enum.Parse(typeof(OperationalStatus), GetPSObjectProperty(result[0], "PrimaryOperationalStatus").ToString());
- }
- return status;
- }
-
- public VirtualMachine GetVirtualMachineEx(string vmId)
- {
- return GetVirtualMachineInternal( vmId, true);
- }
-
-
- internal int GetVMProcessors(Runspace runSpace, string name)
- {
-
- int procs = 0;
-
- Command cmd = new Command("Get-VMProcessor");
-
- cmd.Parameters.Add("VMName", name);
-
- Collection result = ExecuteShellCommand(runSpace, cmd, false);
- if (result != null && result.Count > 0)
- {
- procs = Convert.ToInt32(GetPSObjectProperty(result[0], "Count"));
-
- }
- return procs;
- }
-
- internal MemoryInfo GetVMMemory(Runspace runSpace, string name)
- {
-
- MemoryInfo info = new MemoryInfo();
-
- Command cmd = new Command("Get-VMMemory");
-
- cmd.Parameters.Add("VMName", name);
-
- Collection result = ExecuteShellCommand(runSpace, cmd, false);
- if (result != null && result.Count > 0)
- {
- info.DynamicMemoryEnabled = Convert.ToBoolean(GetPSObjectProperty(result[0], "DynamicMemoryEnabled"));
- info.Startup = Convert.ToInt32(GetPSObjectProperty(result[0], "Startup"));
- info.Minimum = Convert.ToInt32(GetPSObjectProperty(result[0], "Minimum"));
- info.Maximum = Convert.ToInt32(GetPSObjectProperty(result[0], "Maximum"));
- info.Buffer = Convert.ToInt16(GetPSObjectProperty(result[0], "Buffer"));
- info.Priority = Convert.ToInt16(GetPSObjectProperty(result[0], "Prioriy"));
- }
- return info;
- }
-
- internal BiosInfo GetVMBios(Runspace runSpace, string name)
- {
-
- BiosInfo info = new BiosInfo();
-
- Command cmd = new Command("Get-VMBios");
-
- cmd.Parameters.Add("VMName", name);
-
- Collection result = ExecuteShellCommand(runSpace, cmd, false);
- if (result != null && result.Count > 0)
- {
- info.NumLockEnabled = Convert.ToBoolean(GetPSObjectProperty(result[0], "NumLockEnabled"));
- info.StartupOrder = (string[])GetPSObjectProperty(result[0], "StartupOrder");
- }
- return info;
- }
-
- internal VirtualHardDiskInfo[] GetVirtualHardDisks(Runspace runSpace, string name)
- {
-
- List disks = new List();
-
- Command cmd = new Command("Get-VMHardDiskDrive");
- cmd.Parameters.Add("VMName", name);
-
- Collection result = ExecuteShellCommand(runSpace, cmd, false);
- if (result != null && result.Count > 0)
- {
- foreach(PSObject d in result)
- {
- VirtualHardDiskInfo disk = new VirtualHardDiskInfo();
-
- disk.SupportPersistentReservations = Convert.ToBoolean(GetPSObjectProperty(d, "SupportPersistentReservations"));
- disk.MaximumIOPS= Convert.ToInt32(GetPSObjectProperty(d, "MaximumIOPS"));
- disk.MinimumIOPS= Convert.ToInt32(GetPSObjectProperty(d, "MinimumIOPS"));
- disk.VHDControllerType = (ControllerType)Enum.Parse(typeof(ControllerType), GetPSObjectProperty(d, "ControllerType").ToString());
- disk.ControllerNumber = Convert.ToInt16(GetPSObjectProperty(d, "ControllerNumber"));
- disk.ControllerLocation = Convert.ToInt16(GetPSObjectProperty(d, "ControllerLocation"));
- disk.Path = GetPSObjectProperty(d, "Path").ToString();
- disk.Name = GetPSObjectProperty(d, "Name").ToString();
-
- GetVirtualHardDiskDetail(runSpace, disk.Path, ref disk);
-
- disks.Add(disk);
- }
- }
- return disks.ToArray();
- }
-
- internal void GetVirtualHardDiskDetail(Runspace runSpace, string path, ref VirtualHardDiskInfo disk)
- {
- if (!string.IsNullOrEmpty(path))
- {
- Command cmd = new Command("Get-VHD");
- cmd.Parameters.Add("Path", path);
- Collection result = ExecuteShellCommand(runSpace, cmd, false);
- if (result != null && result.Count > 0)
- {
- disk.DiskFormat = (VirtualHardDiskFormat)Enum.Parse(typeof(VirtualHardDiskFormat), GetPSObjectProperty(result[0], "VhdFormat").ToString());
- disk.DiskType = (VirtualHardDiskType)Enum.Parse(typeof(VirtualHardDiskType), GetPSObjectProperty(result[0], "Type").ToString());
- disk.ParentPath = GetPSObjectProperty(result[0], "ParentPath").ToString();
- disk.MaxInternalSize = Convert.ToInt32(GetPSObjectProperty(result[0], "Size")) / Size1G;
- disk.FileSize = Convert.ToInt32(GetPSObjectProperty(result[0], "FileSize")) / Size1G;
- disk.Attached = Convert.ToBoolean(GetPSObjectProperty(result[0], "Attached"));
- }
- }
- }
-
-
- /*
- public VirtualMachine GetVirtualMachineExInternal(runSpace, string vmId)
- {
-
-
-
-
- // network adapters
- List nics = new List();
- ManagementObject objVM = GetVirtualMachineObject(vmId);
-
- // synthetic adapters
- foreach (ManagementObject objNic in wmi.GetWmiObjects("Msvm_SyntheticEthernetPortSettingData", "InstanceID like 'Microsoft:{0}%'", vmId))
- nics.Add(new VirtualMachineNetworkAdapter() { Name = (string)objNic["ElementName"], MacAddress = (string)objNic["Address"] });
-
- // legacy adapters
- foreach (ManagementObject objNic in wmi.GetWmiObjects("Msvm_EmulatedEthernetPortSettingData", "InstanceID like 'Microsoft:{0}%'", vmId))
- nics.Add(new VirtualMachineNetworkAdapter() { Name = (string)objNic["ElementName"], MacAddress = (string)objNic["Address"] });
-
- vm.Adapters = nics.ToArray();
-
- return vm;
-
- }
- */
-
public List GetVirtualMachines()
{
- List vms = new List();
- /*
- ManagementObjectCollection objVms = wmi.ExecuteWmiQuery("select * from msvm_ComputerSystem where Name <> ElementName");
- foreach (ManagementObject objVm in objVms)
- vms.Add(CreateVirtualMachineFromWmiObject(objVm));
- */
- return vms;
+ HostedSolutionLog.LogStart("GetVirtualMachines");
+
+ List vmachines = new List();
+
+ try
+ {
+ Command cmd = new Command("Get-VM");
+
+ Collection result = PowerShell.Execute(cmd, false);
+ foreach (PSObject current in result)
+ {
+ VirtualMachine vm = new VirtualMachine
+ {
+ VirtualMachineId = current.GetProperty("Id").ToString(),
+ Name = current.GetProperty("Name").ToString(),
+ State = (VirtualMachineState)Enum.Parse(typeof(VirtualMachineState), current.GetProperty("State").ToString()),
+ Uptime = Convert.ToInt64(current.GetProperty("UpTime").TotalMilliseconds)
+ };
+ vmachines.Add(vm);
+ }
+ }
+ catch (Exception ex)
+ {
+ HostedSolutionLog.LogError("GetVirtualMachines", ex);
+ throw;
+ }
+
+ HostedSolutionLog.LogEnd("GetVirtualMachines");
+ return vmachines;
+
}
public byte[] GetVirtualMachineThumbnailImage(string vmId, ThumbnailSize size)
{
- ManagementBaseObject objSummary = GetVirtualMachineSummaryInformation(vmId, (SummaryInformationRequest)size);
- wmi.Dump(objSummary);
- return GetTumbnailFromSummaryInformation(objSummary, size);
+ //ManagementBaseObject objSummary = GetVirtualMachineSummaryInformation(vmId, (SummaryInformationRequest)size);
+ //wmi.Dump(objSummary);
+ //return GetTumbnailFromSummaryInformation(objSummary, size);
+ // TODO:
+ return (byte[]) (new ImageConverter()).ConvertTo(new Bitmap(80, 60), typeof (byte[]));
}
private byte[] GetTumbnailFromSummaryInformation(ManagementBaseObject objSummary, ThumbnailSize size)
@@ -508,11 +368,11 @@ namespace WebsitePanel.Providers.Virtualization
vmID = (string)objVM["Name"];
// update general settings
- UpdateVirtualMachineGeneralSettings(vmID, objVM,
- vm.CpuCores,
- vm.RamSize,
- vm.BootFromCD,
- vm.NumLockEnabled);
+ //UpdateVirtualMachineGeneralSettings(vmID, objVM,
+ // vm.CpuCores,
+ // vm.RamSize,
+ // vm.BootFromCD,
+ // vm.NumLockEnabled);
// hard disks
// load IDE 0 controller
@@ -567,113 +427,32 @@ namespace WebsitePanel.Providers.Virtualization
public VirtualMachine UpdateVirtualMachine(VirtualMachine vm)
{
- string vmId = vm.VirtualMachineId;
+ HostedSolutionLog.LogStart("UpdateVirtualMachine");
+ HostedSolutionLog.DebugInfo("Virtual Machine: {0}", vm.VirtualMachineId);
- // get VM object
- ManagementObject objVM = GetVirtualMachineObject(vmId);
+ Runspace runSpace = null;
- // update general settings
- UpdateVirtualMachineGeneralSettings(vmId, objVM,
- vm.CpuCores,
- vm.RamSize,
- vm.BootFromCD,
- vm.NumLockEnabled);
-
- // check DVD drive
- ManagementObject objDvdDrive = wmi.GetWmiObject(
- "Msvm_ResourceAllocationSettingData", "ResourceSubType = 'Microsoft Synthetic DVD Drive'"
- + " and InstanceID like 'Microsoft:{0}%' and Address = 0", vmId);
-
- if (vm.DvdDriveInstalled && objDvdDrive == null)
- AddVirtualMachineDvdDrive(vmId, objVM);
- else if (!vm.DvdDriveInstalled && objDvdDrive != null)
- RemoveVirtualMachineResources(objVM, objDvdDrive);
-
- // External NIC
- if (!vm.ExternalNetworkEnabled
- && !String.IsNullOrEmpty(vm.ExternalNicMacAddress))
+ try
{
- // delete adapter
- DeleteNetworkAdapter(objVM, vm.ExternalNicMacAddress);
+ var realVm = GetVirtualMachine(vm.VirtualMachineId);
+
+ VirtualMachineHelper.UpdateBios(PowerShell, realVm, vm.BootFromCD, vm.NumLockEnabled);
+ VirtualMachineHelper.UpdateProcessors(PowerShell, realVm, vm.CpuCores, CpuLimitSettings, CpuReserveSettings, CpuWeightSettings);
+ VirtualMachineHelper.UpdateMemory(PowerShell, realVm, vm.RamSize);
+ DvdDriveHelper.Update(PowerShell, realVm, vm.DvdDriveInstalled);
- // reset MAC
- vm.ExternalNicMacAddress = null;
}
- else if (vm.ExternalNetworkEnabled
- && !String.IsNullOrEmpty(vm.ExternalNicMacAddress))
+ catch (Exception ex)
{
- // add external adapter
- AddNetworkAdapter(objVM, vm.ExternalSwitchId, vm.Name, vm.ExternalNicMacAddress, EXTERNAL_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
- }
-
-
- // Private NIC
- if (!vm.PrivateNetworkEnabled
- && !String.IsNullOrEmpty(vm.PrivateNicMacAddress))
- {
- // delete adapter
- DeleteNetworkAdapter(objVM, vm.PrivateNicMacAddress);
-
- // reset MAC
- vm.PrivateNicMacAddress = null;
- }
- else if (vm.PrivateNetworkEnabled
- && !String.IsNullOrEmpty(vm.PrivateNicMacAddress))
- {
- // add private adapter
- AddNetworkAdapter(objVM, vm.PrivateSwitchId, vm.Name, vm.PrivateNicMacAddress, PRIVATE_NETWORK_ADAPTER_NAME, vm.LegacyNetworkAdapter);
+ HostedSolutionLog.LogError("UpdateVirtualMachine", ex);
+ throw;
}
+ HostedSolutionLog.LogEnd("UpdateVirtualMachine");
+
return vm;
}
- private void UpdateVirtualMachineGeneralSettings(string vmId, ManagementObject objVM, int cpuCores, int ramMB, bool bootFromCD, bool numLockEnabled)
- {
- // request management service
- ManagementObject objVmsvc = GetVirtualSystemManagementService();
-
- // VM resources
- List vmConfig = new List();
-
- // get system settings
- ManagementObject objSettings = GetVirtualMachineSettingsObject(vmId);
-
- // BIOS (num lock)
- objSettings["BIOSNumLock"] = numLockEnabled;
-
- // BIOS (boot order)
- // BootOrder = 0 - Boot from floppy, 1 - Boot from CD, 2 - Boot from disk, 3 - PXE Boot
- objSettings["BootOrder"] = bootFromCD ? new int[] { 1, 2, 3, 0 } : new int[] { 2, 1, 3, 0 };
-
- // modify machine settings
- ManagementBaseObject inParams = objVmsvc.GetMethodParameters("ModifyVirtualSystem");
- inParams["ComputerSystem"] = objVM;
- inParams["SystemSettingData"] = objSettings.GetText(TextFormat.CimDtd20);
- ManagementBaseObject outParams = objVmsvc.InvokeMethod("ModifyVirtualSystem", inParams, null);
- JobResult job = CreateJobResultFromWmiMethodResults(outParams);
-
- // setup CPU
- ManagementObject objCpu = wmi.GetWmiObject("Msvm_ProcessorSettingData", "InstanceID Like 'Microsoft:{0}%'", vmId);
- objCpu["VirtualQuantity"] = cpuCores;
- objCpu["Limit"] = Convert.ToInt64(CpuLimitSettings * 1000);
- objCpu["Reservation"] = Convert.ToInt64(CpuReserveSettings * 1000);
- objCpu["Weight"] = CpuWeightSettings;
- vmConfig.Add(objCpu.GetText(TextFormat.CimDtd20));
-
- // setup RAM
- ManagementObject objRam = wmi.GetWmiObject("Msvm_MemorySettingData", "InstanceID Like 'Microsoft:{0}%'", vmId);
- objRam["VirtualQuantity"] = ramMB.ToString();
- objRam["Reservation"] = ramMB.ToString();
- objRam["Limit"] = ramMB.ToString();
- vmConfig.Add(objRam.GetText(TextFormat.CimDtd20));
-
- // modify machine resources
- inParams = objVmsvc.GetMethodParameters("ModifyVirtualSystemResources");
- inParams["ComputerSystem"] = objVM;
- inParams["ResourceSettingData"] = vmConfig.ToArray();
- outParams = objVmsvc.InvokeMethod("ModifyVirtualSystemResources", inParams, null);
- job = CreateJobResultFromWmiMethodResults(outParams);
- }
private void AddVirtualMachineDvdDrive(string vmId, ManagementObject objVM)
{
@@ -838,32 +617,90 @@ namespace WebsitePanel.Providers.Virtualization
public JobResult ChangeVirtualMachineState(string vmId, VirtualMachineRequestedState newState)
{
- // target computer
- ManagementObject objVm = GetVirtualMachineObject(vmId);
+ HostedSolutionLog.LogStart("ChangeVirtualMachineState");
+ var jobResult = new JobResult();
- // get method
- ManagementBaseObject inParams = objVm.GetMethodParameters("RequestStateChange");
- inParams["RequestedState"] = (Int32)newState;
+ var vm = GetVirtualMachine(vmId);
- // invoke method
- ManagementBaseObject outParams = objVm.InvokeMethod("RequestStateChange", inParams, null);
- return CreateJobResultFromWmiMethodResults(outParams);
+ try
+ {
+ string cmdTxt;
+ List paramList = new List();
+
+ switch (newState)
+ {
+ case VirtualMachineRequestedState.Start:
+ cmdTxt = "Start-VM";
+ break;
+ case VirtualMachineRequestedState.Pause:
+ cmdTxt = "Suspend-VM";
+ break;
+ case VirtualMachineRequestedState.Reset:
+ cmdTxt = "Restart-VM";
+ break;
+ case VirtualMachineRequestedState.Resume:
+ cmdTxt = "Resume-VM";
+ break;
+ case VirtualMachineRequestedState.ShutDown:
+ cmdTxt = "Stop-VM";
+ break;
+ case VirtualMachineRequestedState.TurnOff:
+ cmdTxt = "Stop-VM";
+ paramList.Add("TurnOff");
+ break;
+ case VirtualMachineRequestedState.Save:
+ cmdTxt = "Save-VM";
+ break;
+ default:
+ throw new ArgumentOutOfRangeException("newState");
+ }
+
+ Command cmd = new Command(cmdTxt);
+
+ cmd.Parameters.Add("Name", vm.Name);
+ //cmd.Parameters.Add("AsJob");
+ paramList.ForEach(p => cmd.Parameters.Add(p));
+
+ PowerShell.Execute(cmd, false);
+ jobResult = CreateSuccessJobResult();
+ }
+ catch (Exception ex)
+ {
+ HostedSolutionLog.LogError("ChangeVirtualMachineState", ex);
+ throw;
+ }
+
+ HostedSolutionLog.LogEnd("ChangeVirtualMachineState");
+
+ return jobResult;
}
public ReturnCode ShutDownVirtualMachine(string vmId, bool force, string reason)
{
- // load virtual machine object
- ManagementObject objVm = GetVirtualMachineObject(vmId);
- ManagementObject objShutdown = wmi.GetRelatedWmiObject(objVm, "msvm_ShutdownComponent");
+ HostedSolutionLog.LogStart("ShutDownVirtualMachine");
+ ReturnCode returnCode = ReturnCode.OK;
- // execute InitiateShutdown method
- ManagementBaseObject inParams = objShutdown.GetMethodParameters("InitiateShutdown");
- inParams["Force"] = force;
- inParams["Reason"] = reason;
+ var vm = GetVirtualMachine(vmId);
- // invoke method
- ManagementBaseObject outParams = objShutdown.InvokeMethod("InitiateShutdown", inParams, null);
- return (ReturnCode)Convert.ToInt32(outParams["ReturnValue"]);
+ try
+ {
+ Command cmd = new Command("Stop-VM");
+
+ cmd.Parameters.Add("Name", vm.Name);
+ if (force) cmd.Parameters.Add("Force");
+ //if (!string.IsNullOrEmpty(reason)) cmd.Parameters.Add("Reason", reason);
+
+ PowerShell.Execute(cmd, false);
+ }
+ catch (Exception ex)
+ {
+ HostedSolutionLog.LogError("ShutDownVirtualMachine", ex);
+ throw;
+ }
+
+ HostedSolutionLog.LogEnd("ShutDownVirtualMachine");
+
+ return returnCode;
}
public List GetVirtualMachineJobs(string vmId)
@@ -1221,14 +1058,7 @@ namespace WebsitePanel.Providers.Virtualization
#region Virtual Switches
public List GetSwitches()
{
- List switches = new List();
-
- // load wmi objects
- ManagementObjectCollection objSwitches = wmi.GetWmiObjects("msvm_VirtualSwitch");
- foreach (ManagementObject objSwitch in objSwitches)
- switches.Add(CreateSwitchFromWmiObject(objSwitch));
-
- return switches;
+ return GetSwitches(null, null);
}
public List GetExternalSwitches(string computerName)
@@ -1246,19 +1076,19 @@ namespace WebsitePanel.Providers.Virtualization
try
{
- runSpace = OpenRunspace();
+
Command cmd = new Command("Get-VMSwitch");
if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName);
if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type);
- Collection result = ExecuteShellCommand(runSpace, cmd,false);
+ Collection result = PowerShell.Execute(cmd,false);
foreach (PSObject current in result)
{
VirtualSwitch sw = new VirtualSwitch();
- sw.SwitchId = GetPSObjectProperty(current, "Id").ToString();
- sw.Name = GetPSObjectProperty(current, "Name").ToString();
- sw.SwitchType = GetPSObjectProperty(current, "SwitchType").ToString();
+ sw.SwitchId = current.GetProperty("Name").ToString();
+ sw.Name = current.GetProperty("Name").ToString();
+ sw.SwitchType = current.GetProperty("SwitchType").ToString();
switches.Add(sw);
}
}
@@ -1267,10 +1097,6 @@ namespace WebsitePanel.Providers.Virtualization
HostedSolutionLog.LogError("GetSwitches", ex);
throw;
}
- finally
- {
- CloseRunspace(runSpace);
- }
HostedSolutionLog.LogEnd("GetSwitches");
return switches;
@@ -1987,8 +1813,30 @@ exit", Convert.ToInt32(objDisk["Index"])));
#region Jobs
public ConcreteJob GetJob(string jobId)
{
- ManagementObject objJob = wmi.GetWmiObject("CIM_ConcreteJob", "InstanceID = '{0}'", jobId);
- return CreateJobFromWmiObject(objJob);
+ HostedSolutionLog.LogStart("GetJob");
+ HostedSolutionLog.DebugInfo("jobId: {0}", jobId);
+
+ Runspace runSpace = null;
+ ConcreteJob job;
+
+ try
+ {
+
+ Command cmd = new Command("Get-Job");
+
+ if (!string.IsNullOrEmpty(jobId)) cmd.Parameters.Add("Id", jobId);
+
+ Collection result = PowerShell.Execute( cmd, false);
+ job = CreateJobFromPSObject(result);
+ }
+ catch (Exception ex)
+ {
+ HostedSolutionLog.LogError("GetJob", ex);
+ throw;
+ }
+
+ HostedSolutionLog.LogEnd("GetJob");
+ return job;
}
public List GetAllJobs()
@@ -2254,6 +2102,35 @@ exit", Convert.ToInt32(objDisk["Index"])));
#endregion
#region Private Methods
+ protected JobResult CreateSuccessJobResult()
+ {
+ JobResult result = new JobResult();
+
+ result.Job = new ConcreteJob(){JobState = ConcreteJobState.Completed};
+ result.ReturnValue = ReturnCode.OK;
+
+ return result;
+ }
+ protected JobResult CreateJobResultFromPSResults(Collection objJob)
+ {
+ if (objJob == null || objJob.Count == 0)
+ return null;
+
+ JobResult result = new JobResult();
+
+ result.Job = CreateJobFromPSObject(objJob);
+
+ result.ReturnValue = ReturnCode.JobStarted;
+ switch (result.Job.JobState)
+ {
+ case ConcreteJobState.Failed:
+ result.ReturnValue = ReturnCode.Failed;
+ break;
+ }
+
+ return result;
+ }
+
protected JobResult CreateJobResultFromWmiMethodResults(ManagementBaseObject outParams)
{
JobResult result = new JobResult();
@@ -2337,6 +2214,36 @@ exit", Convert.ToInt32(objDisk["Index"])));
return sw;
}
+ private ConcreteJob CreateJobFromPSObject(Collection objJob)
+ {
+ if (objJob == null || objJob.Count == 0)
+ return null;
+
+ ConcreteJob job = new ConcreteJob();
+ job.Id = objJob[0].GetProperty("Id").ToString();
+ job.JobState = objJob[0].GetEnum("JobStateInfo");
+ job.Caption = objJob[0].GetProperty("Name");
+ job.Description = objJob[0].GetProperty("Command");
+ job.StartTime = objJob[0].GetProperty("PSBeginTime");
+ job.ElapsedTime = objJob[0].GetProperty("PSEndTime") ?? DateTime.Now;
+
+ // PercentComplete
+ job.PercentComplete = 0;
+ var progress = (PSDataCollection)objJob[0].GetProperty("Progress");
+ if (progress != null && progress.Count > 0)
+ job.PercentComplete = progress[0].PercentComplete;
+
+ // Errors
+ var errors = (PSDataCollection)objJob[0].GetProperty("Error");
+ if (errors != null && errors.Count > 0)
+ {
+ job.ErrorDescription = errors[0].ErrorDetails.Message + ". " + errors[0].ErrorDetails.RecommendedAction;
+ job.ErrorCode = errors[0].Exception != null ? -1 : 0;
+ }
+
+ return job;
+ }
+
private ConcreteJob CreateJobFromWmiObject(ManagementBaseObject objJob)
{
if (objJob == null || objJob.Properties.Count == 0)
@@ -2623,155 +2530,24 @@ exit", Convert.ToInt32(objDisk["Index"])));
#endregion Hyper-V Cloud
#region PowerShell integration
- private static InitialSessionState session = null;
- internal virtual Runspace OpenRunspace()
+ private PowerShellManager _powerShell;
+ protected PowerShellManager PowerShell
{
- HostedSolutionLog.LogStart("OpenRunspace");
-
- if (session == null)
- {
- session = InitialSessionState.CreateDefault();
- session.ImportPSModule(new string[] { "Hyper-V" });
- }
- Runspace runSpace = RunspaceFactory.CreateRunspace(session);
- //
- runSpace.Open();
- //
- runSpace.SessionStateProxy.SetVariable("ConfirmPreference", "none");
- HostedSolutionLog.LogEnd("OpenRunspace");
- return runSpace;
+ get { return _powerShell ?? (_powerShell = new PowerShellManager()); }
}
- internal void CloseRunspace(Runspace runspace)
- {
- try
- {
- if (runspace != null && runspace.RunspaceStateInfo.State == RunspaceState.Opened)
- {
- runspace.Close();
- }
- }
- catch (Exception ex)
- {
- HostedSolutionLog.LogError("Runspace error", ex);
- }
- }
-
- internal Collection ExecuteShellCommand(Runspace runSpace, Command cmd)
- {
- return ExecuteShellCommand(runSpace, cmd, true);
- }
-
- internal Collection ExecuteShellCommand(Runspace runSpace, Command cmd, bool useDomainController)
- {
- object[] errors;
- return ExecuteShellCommand(runSpace, cmd, useDomainController, out errors);
- }
-
- internal Collection ExecuteShellCommand(Runspace runSpace, Command cmd, out object[] errors)
- {
- return ExecuteShellCommand(runSpace, cmd, true, out errors);
- }
-
- internal Collection ExecuteShellCommand(Runspace runSpace, Command cmd, bool useDomainController, out object[] errors)
- {
- HostedSolutionLog.LogStart("ExecuteShellCommand");
- List