From 22745dde02cbd0c879d745d7ba322babe2a05dbf Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Wed, 5 Mar 2014 12:14:41 -0800 Subject: [PATCH] WebDav Performance issues fixed --- .../Windows2012.cs | 31 ++++++------ .../Windows2003.cs | 5 ++ .../Windows2012.cs | 47 +++++++++++++++++++ 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs index 22bbd04e..4575b22c 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs @@ -81,6 +81,8 @@ namespace WebsitePanel.Providers.EnterpriseStorage // get directories DirectoryInfo[] dirs = root.GetDirectories(); + var quotas = windows.GetQuotasForOrganization(rootPath, string.Empty, string.Empty); + foreach (DirectoryInfo dir in dirs) { string fullName = System.IO.Path.Combine(rootPath, dir.Name); @@ -91,22 +93,23 @@ namespace WebsitePanel.Providers.EnterpriseStorage folder.FullName = dir.FullName; folder.IsDirectory = true; - Quota quota = windows.GetQuotaOnFolder(fullName, string.Empty, string.Empty); - - folder.Size = quota.Usage; - - if (folder.Size == -1) + if (quotas.ContainsKey(fullName)) { - folder.Size = FileUtils.BytesToMb(FileUtils.CalculateFolderSize(dir.FullName)); + folder.Size = quotas[fullName].Usage; + + if (folder.Size == -1) + { + folder.Size = FileUtils.BytesToMb(FileUtils.CalculateFolderSize(dir.FullName)); + } + + folder.Url = string.Format("https://{0}/{1}/{2}", setting.Domain, organizationId, dir.Name); + folder.Rules = webdav.GetFolderWebDavRules(organizationId, dir.Name); + folder.FRSMQuotaMB = quotas[fullName].Size; + folder.FRSMQuotaGB = windows.ConvertMegaBytesToGB(folder.FRSMQuotaMB); + folder.FsrmQuotaType = quotas[fullName].QuotaType; + + items.Add(folder); } - - folder.Url = string.Format("https://{0}/{1}/{2}", setting.Domain, organizationId, dir.Name); - folder.Rules = webdav.GetFolderWebDavRules(organizationId, dir.Name); - folder.FRSMQuotaMB = quota.Size; - folder.FRSMQuotaGB = windows.ConvertMegaBytesToGB(folder.FRSMQuotaMB); - folder.FsrmQuotaType = quota.QuotaType; - - items.Add(folder); } } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2003/Windows2003.cs b/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2003/Windows2003.cs index 80d66840..c88effdd 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2003/Windows2003.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2003/Windows2003.cs @@ -220,6 +220,11 @@ namespace WebsitePanel.Providers.OS throw new NotImplementedException(); } + public virtual Dictionary GetQuotasForOrganization(string folderPath, string wmiUserName, string wmiPassword) + { + throw new NotImplementedException(); + } + public virtual void DeleteDirectoryRecursive(string rootPath) { FileUtils.DeleteDirectoryRecursive(rootPath); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/Windows2012.cs index 4d05643c..35d18c9b 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.OS.Windows2012/Windows2012.cs @@ -175,6 +175,53 @@ namespace WebsitePanel.Providers.OS return quota; } + public override Dictionary GetQuotasForOrganization(string folderPath, string wmiUserName, string wmiPassword) + { + Log.WriteStart("GetQuotasLimitsForOrganization"); + + + Runspace runSpace = null; + Quota quota = null; + var quotas = new Dictionary(); + + try + { + runSpace = OpenRunspace(); + + Command cmd = new Command("Get-FsrmQuota"); + cmd.Parameters.Add("Path", folderPath + "\\*"); + var result = ExecuteShellCommand(runSpace, cmd, false); + + if (result.Count > 0) + { + foreach (var element in result) + { + quota = new Quota(); + + quota.Size = ConvertBytesToMB(Convert.ToInt64(GetPSObjectProperty(element, "Size"))); + quota.QuotaType = Convert.ToBoolean(GetPSObjectProperty(element, "SoftLimit")) ? QuotaType.Soft : QuotaType.Hard; + quota.Usage = ConvertBytesToMB(Convert.ToInt64(GetPSObjectProperty(element, "usage"))); + + quotas.Add(Convert.ToString(GetPSObjectProperty(element, "Path")), quota); + } + } + + } + catch (Exception ex) + { + Log.WriteError("GetQuotasLimitsForOrganization", ex); + throw; + } + finally + { + CloseRunspace(runSpace); + } + + Log.WriteEnd("GetQuotasLimitsForOrganization"); + + return quotas; + } + public UInt64 CalculateQuota(string quota) { UInt64 OneKb = 1024;