From a27bbc6f4e6f0be35a1b430f5e48c6b3499fba6e Mon Sep 17 00:00:00 2001 From: robvde Date: Sun, 23 Jun 2013 20:10:03 +0400 Subject: [PATCH] Partial Check on DAAS, folder hard quota support added for 2012 --- WebsitePanel/Database/update_db.sql | 13 +- .../Exchange2013.cs | 6 +- ...bsitePanel.Providers.OS.Windows2012.csproj | 5 + .../Windows2012.cs | 232 ++++++++++++++++++ 4 files changed, 249 insertions(+), 7 deletions(-) diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index 98713d0d..dc294ad9 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -450,9 +450,14 @@ INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName] VALUES (1401, 41, N'Lync2013', N'Microsoft Lync Server 2013 Multitenant Hosting Pack', N'WebsitePanel.Providers.HostedSolution.Lync2013, WebsitePanel.Providers.HostedSolution.Lync2013', N'Lync', NULL) END GO + +IF NOT EXISTS (SELECT * FROM [dbo].[Quotas] WHERE [QuotaName] = 'Web.AppPoolsRestart') +BEGIN -- add Application Pools Restart Quota INSERT [dbo].[Quotas] ([QuotaID], [GroupID], [QuotaOrder], [QuotaName], [QuotaDescription], [QuotaTypeID], [ServiceQuota], [ItemTypeID], [HideQuota]) VALUES (411, 2, 13, N'Web.AppPoolsRestart', N'Application Pools Restart', 1, 0, NULL, NULL) +END GO + -------------------------------- Scheduler Service------------------------------------------------------ IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS @@ -1444,23 +1449,23 @@ GO -------------------------------- Remote Desktop Services ------------------------------------------------------ -IF NOT EXISTS (SELECT * FROM [dbo].[ResourceGroups] WHERE [GroupName] = 'Remote Desktop Services') +IF NOT EXISTS (SELECT * FROM [dbo].[ResourceGroups] WHERE [GroupName] = 'RemoteDesktopServices') BEGIN INSERT [dbo].[ResourceGroups] ([GroupID], [GroupName], [GroupOrder], [GroupController], [ShowGroup]) VALUES (43, N'RemoteDesktopServices', 24, N'WebsitePanel.EnterpriseServer.RemoteDesktopServicesController', 1) END GO -IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [DisplayName] = 'Remote Desktop Windows 2012') +IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [DisplayName] = 'Remote Desktop Services Windows 2012') BEGIN INSERT [dbo].[Providers] ([ProviderId], [GroupId], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES(500, 43, N'RemoteDesktop2012', N'Remote Desktop Services Windows 2012', N'WebsitePanel.Providers.RemoteDesktopServices.Windows2012, WebsitePanel.Providers.RemoteDesktopServices.Windows2012', N'RemoteDesktopServices', 1) END ELSE BEGIN -UPDATE [dbo].[Providers] SET [DisableAutoDiscovery] = NULL WHERE [DisplayName] = 'Remote Desktop Windows 2012' +UPDATE [dbo].[Providers] SET [DisableAutoDiscovery] = NULL WHERE [DisplayName] = 'Remote Desktop Services Windows 2012' END GO -IF NOT EXISTS (SELECT * FROM [dbo].[ResourceGroups] WHERE [GroupName] = 'Enterprise Storage') +IF NOT EXISTS (SELECT * FROM [dbo].[ResourceGroups] WHERE [GroupName] = 'EnterpriseStorage') BEGIN INSERT [dbo].[ResourceGroups] ([GroupID], [GroupName], [GroupOrder], [GroupController], [ShowGroup]) VALUES (44, N'EnterpriseStorage', 25, N'WebsitePanel.EnterpriseServer.EnterpriseStorageController', 1) END diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs index 0669805a..d43b8072 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Exchange2013/Exchange2013.cs @@ -636,7 +636,7 @@ namespace WebsitePanel.Providers.HostedSolution #region IHostingServiceProvider Members - public virtual void ChangeServiceItemsState(ServiceProviderItem[] items, bool enabled) + public override void ChangeServiceItemsState(ServiceProviderItem[] items, bool enabled) { foreach (ServiceProviderItem item in items) { @@ -656,7 +656,7 @@ namespace WebsitePanel.Providers.HostedSolution } } - public virtual void DeleteServiceItems(ServiceProviderItem[] items) + public override void DeleteServiceItems(ServiceProviderItem[] items) { foreach (ServiceProviderItem item in items) { @@ -680,7 +680,7 @@ namespace WebsitePanel.Providers.HostedSolution } } - public virtual ServiceProviderItemDiskSpace[] GetServiceItemsDiskSpace(ServiceProviderItem[] items) + public override ServiceProviderItemDiskSpace[] GetServiceItemsDiskSpace(ServiceProviderItem[] items) { List itemsDiskspace = new List(); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/WebsitePanel.Providers.OS.Windows2012.csproj b/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/WebsitePanel.Providers.OS.Windows2012.csproj index bef6e5d3..c3f2a811 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/WebsitePanel.Providers.OS.Windows2012.csproj +++ b/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/WebsitePanel.Providers.OS.Windows2012.csproj @@ -57,6 +57,11 @@ + + + False + ..\..\Lib\System.Management.Automation.dll + diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/Windows2012.cs index cbdd6422..fae5194e 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/Windows2012.cs @@ -26,15 +26,247 @@ // (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.IO; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +using System.Reflection; +using System.Globalization; + +using Microsoft.Win32; + +using WebsitePanel.Providers; +using WebsitePanel.Providers.HostedSolution; +using WebsitePanel.Providers.Utils; +using WebsitePanel.Server.Utils; + +using System.Management; +using System.Management.Automation; +using System.Management.Automation.Runspaces; + +using WebsitePanel.Providers.Common; +using WebsitePanel.Providers; +using WebsitePanel.Providers.HostedSolution; + + namespace WebsitePanel.Providers.OS { + public class Windows2012 : Windows2003 { + #region Properties + internal string PrimaryDomainController + { + get { return ProviderSettings["PrimaryDomainController"]; } + } + + #endregion Properties + public override bool IsInstalled() { Server.Utils.OS.WindowsVersion version = WebsitePanel.Server.Utils.OS.GetVersion(); return version == WebsitePanel.Server.Utils.OS.WindowsVersion.WindowsServer2012 || version == WebsitePanel.Server.Utils.OS.WindowsVersion.Windows8; } + + public override void SetQuotaLimitOnFolder(string folderPath, string shareNameDrive, string quotaLimit, int mode, string wmiUserName, string wmiPassword) + { + Log.WriteStart("SetQuotaLimitOnFolder"); + Log.WriteInfo("FolderPath : {0}", folderPath); + Log.WriteInfo("ShareNameDrive : {0}", shareNameDrive); + Log.WriteInfo("QuotaLimit : {0}", quotaLimit); + + Runspace runSpace = null; + try + { + runSpace = OpenRunspace(); + string[] splits = folderPath.Split('\\'); + if (splits.Length > 0) + { + string sharePath = String.Empty; + + if (splits.Length > 4) + { + // Form the share physicalPath + sharePath = shareNameDrive + @":\" + splits[3]; + + if (splits.Length == 5 && !quotaLimit.Equals(String.Empty)) + { + Command cmd = new Command("Set-FsrmQuota"); + cmd.Parameters.Add("Path", sharePath + @"\" + splits[4]); + cmd.Parameters.Add("Size", quotaLimit); + cmd.Parameters.Add("Confirm", true); + ExecuteShellCommand(runSpace, cmd, false); + } + } + } + } + catch (Exception ex) + { + Log.WriteError("SetQuotaLimitOnFolder", ex); + throw; + } + finally + { + + CloseRunspace(runSpace); + } + + Log.WriteEnd("SetQuotaLimitOnFolder"); + } + + #region PowerShell integration + private static InitialSessionState session = null; + + internal virtual Runspace OpenRunspace() + { + Log.WriteStart("OpenRunspace"); + + if (session == null) + { + session = InitialSessionState.CreateDefault(); + session.ImportPSModule(new string[] { "FileServerResourceManager" }); + } + Runspace runSpace = RunspaceFactory.CreateRunspace(session); + // + runSpace.Open(); + // + runSpace.SessionStateProxy.SetVariable("ConfirmPreference", "none"); + Log.WriteEnd("OpenRunspace"); + return runSpace; + } + + internal void CloseRunspace(Runspace runspace) + { + try + { + if (runspace != null && runspace.RunspaceStateInfo.State == RunspaceState.Opened) + { + runspace.Close(); + } + } + catch (Exception ex) + { + Log.WriteError("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) + { + Log.WriteStart("ExecuteShellCommand"); + List errorList = new List(); + + if (useDomainController) + { + CommandParameter dc = new CommandParameter("DomainController", PrimaryDomainController); + if (!cmd.Parameters.Contains(dc)) + { + cmd.Parameters.Add(dc); + } + } + + Collection results = null; + // Create a pipeline + Pipeline pipeLine = runSpace.CreatePipeline(); + using (pipeLine) + { + // Add the command + pipeLine.Commands.Add(cmd); + // Execute the pipeline and save the objects returned. + results = pipeLine.Invoke(); + + // Log out any errors in the pipeline execution + // NOTE: These errors are NOT thrown as exceptions! + // Be sure to check this to ensure that no errors + // happened while executing the command. + if (pipeLine.Error != null && pipeLine.Error.Count > 0) + { + foreach (object item in pipeLine.Error.ReadToEnd()) + { + errorList.Add(item); + string errorMessage = string.Format("Invoke error: {0}", item); + Log.WriteWarning(errorMessage); + } + } + } + pipeLine = null; + errors = errorList.ToArray(); + Log.WriteEnd("ExecuteShellCommand"); + return results; + } + + internal object GetPSObjectProperty(PSObject obj, string name) + { + return obj.Members[name].Value; + } + + /// + /// Returns the identity of the object from the shell execution result + /// + /// + /// + internal string GetResultObjectIdentity(Collection result) + { + Log.WriteStart("GetResultObjectIdentity"); + if (result == null) + throw new ArgumentNullException("result", "Execution result is not specified"); + + if (result.Count < 1) + throw new ArgumentException("Execution result is empty", "result"); + + if (result.Count > 1) + throw new ArgumentException("Execution result contains more than one object", "result"); + + PSMemberInfo info = result[0].Members["Identity"]; + if (info == null) + throw new ArgumentException("Execution result does not contain Identity property", "result"); + + string ret = info.Value.ToString(); + Log.WriteEnd("GetResultObjectIdentity"); + return ret; + } + + internal string GetResultObjectDN(Collection result) + { + Log.WriteStart("GetResultObjectDN"); + if (result == null) + throw new ArgumentNullException("result", "Execution result is not specified"); + + if (result.Count < 1) + throw new ArgumentException("Execution result does not contain any object"); + + if (result.Count > 1) + throw new ArgumentException("Execution result contains more than one object"); + + PSMemberInfo info = result[0].Members["DistinguishedName"]; + if (info == null) + throw new ArgumentException("Execution result does not contain DistinguishedName property", "result"); + + string ret = info.Value.ToString(); + Log.WriteEnd("GetResultObjectDN"); + return ret; + } + + + #endregion + } }