Update the delete website function to delete the website directory tree and the remote management access accounts.

This commit is contained in:
Haya Nmeir 2012-09-18 09:14:06 +03:00
parent f7d7bcfafc
commit e45eff5297
7 changed files with 181 additions and 24 deletions

View file

@ -983,5 +983,42 @@ namespace WebsitePanel.EnterpriseServer
}
public static int DeleteDirectoryRecursive(int packageId, string rootPath)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// check package
int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);
if (packageCheck < 0) return packageCheck;
// place log record
TaskManager.StartTask("FILES", "DELETE_DIRECTORY_RECURSIVE", rootPath);
TaskManager.ItemId = packageId;
try
{
OS.OperatingSystem os = GetOS(packageId);
os.DeleteDirectoryRecursive(rootPath);
return 0;
}
catch (Exception ex)
{
//Log and return a generic error rather than throwing an exception
TaskManager.WriteError(ex);
return BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED;
}
finally
{
TaskManager.CompleteTask();
}
}
}
}

View file

@ -599,6 +599,14 @@ namespace WebsitePanel.EnterpriseServer
//
web.DeleteSite(siteItem.SiteId);
// Delete WebManagementAccess Account
WebServerController.RevokeWebManagementAccess(siteItemId);
// Delete website directory from file server
// This will remove the hard quota as well
FilesController.DeleteDirectoryRecursive(siteItem.PackageId, new DirectoryInfo(siteItem.DataPath).Parent.FullName);
// delete service item
PackageController.DeletePackageItem(siteItemId);

View file

@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.IO;
namespace WebsitePanel.Providers.OS
{
@ -82,5 +83,7 @@ namespace WebsitePanel.Providers.OS
FolderGraph GetFolderGraph(string path);
void ExecuteSyncActions(FileSyncAction[] actions);
void SetQuotaLimitOnFolder(string cmdFilePath, string virtualFileClusterName, string folderPath, string quotaLimit, int mode, string wmiUserName, string wmiPassword);
void DeleteDirectoryRecursive(string rootPath);
}
}

View file

@ -215,9 +215,9 @@ namespace WebsitePanel.Providers.OS
FileUtils.SetQuotaLimitOnFolder(cmdFilePath, virtualFileClusterName, folderPath, quotaLimit, mode, wmiUserName, wmiPassword);
}
public static void DeleteDirRecursive(DirectoryInfo treeRoot)
public virtual void DeleteDirectoryRecursive(string rootPath)
{
FileUtils.DeleteDirectoryRecursive(treeRoot);
FileUtils.DeleteDirectoryRecursive(rootPath);
}
#endregion

View file

@ -64,6 +64,8 @@ namespace WebsitePanel.Providers.OS {
private System.Threading.SendOrPostCallback SetQuotaLimitOnFolderOperationCompleted;
private System.Threading.SendOrPostCallback DeleteDirectoryRecursiveOperationCompleted;
private System.Threading.SendOrPostCallback DirectoryExistsOperationCompleted;
private System.Threading.SendOrPostCallback GetFileOperationCompleted;
@ -146,8 +148,12 @@ namespace WebsitePanel.Providers.OS {
/// <remarks/>
public event FileExistsCompletedEventHandler FileExistsCompleted;
/// <remarks/>
public event SetQuotaLimitOnFolderCompletedEventHandler SetQuotaLimitOnFolderCompleted;
/// <remarks/>
public event DeleteDirectoryRecursiveCompletedEventHandler DeleteDirectoryRecursiveCompleted;
/// <remarks/>
public event DirectoryExistsCompletedEventHandler DirectoryExistsCompleted;
@ -370,9 +376,9 @@ namespace WebsitePanel.Providers.OS {
/// <remarks/>
public void SetQuotaLimitOnFolderAsync(string cmdFilePath, string virtualFileClusterName, string folderPath, string quotaLimit, int mode, string wmiUserName, string wmiPassword, object userState)
{
if ((this.FileExistsOperationCompleted == null))
if ((this.SetQuotaLimitOnFolderOperationCompleted == null))
{
this.FileExistsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFileExistsOperationCompleted);
this.SetQuotaLimitOnFolderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSetQuotaLimitOnFolderOperationCompleted);
}
this.InvokeAsync("SetQuotaLimitOnFolder", new object[] {
cmdFilePath, virtualFileClusterName, folderPath, quotaLimit, mode, wmiUserName, wmiPassword}, this.SetQuotaLimitOnFolderOperationCompleted, userState);
@ -387,6 +393,57 @@ namespace WebsitePanel.Providers.OS {
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/DeleteDirectoryRecursive", RequestNamespace = "http://smbsaas/websitepanel/server/", ResponseNamespace = "http://smbsaas/websitepanel/server/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool DeleteDirectoryRecursive(string rootPath)
{
object[] results = this.Invoke("DeleteDirectoryRecursive", new object[] {
rootPath });
return ((bool)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginDeleteDirectoryRecursive(string rootPath, System.AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("DeleteDirectoryRecursive", new object[] {
rootPath}, callback, asyncState);
}
/// <remarks/>
public bool EndDeleteDirectoryRecursive(System.IAsyncResult asyncResult)
{
object[] results = this.EndInvoke(asyncResult);
return ((bool)(results[0]));
}
/// <remarks/>
public void DeleteDirectoryRecursiveAsync(string rootPath)
{
this.DeleteDirectoryRecursiveAsync(rootPath, null);
}
/// <remarks/>
public void DeleteDirectoryRecursiveAsync(string rootPath, object userState)
{
if ((this.DeleteDirectoryRecursiveOperationCompleted == null))
{
this.DeleteDirectoryRecursiveOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDeleteDirectoryRecursiveOperationCompleted);
}
this.InvokeAsync("DeleteDirectoryRecursive", new object[] {
rootPath}, this.DeleteDirectoryRecursiveOperationCompleted, userState);
}
private void OnDeleteDirectoryRecursiveOperationCompleted(object arg)
{
if ((this.DeleteDirectoryRecursiveCompleted != null))
{
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.DeleteDirectoryRecursiveCompleted(this, new DeleteDirectoryRecursiveCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/DirectoryExists", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
@ -1985,6 +2042,37 @@ namespace WebsitePanel.Providers.OS {
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void DeleteDirectoryRecursiveCompletedEventHandler(object sender, DeleteDirectoryRecursiveCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class DeleteDirectoryRecursiveCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
{
private object[] results;
internal DeleteDirectoryRecursiveCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState)
{
this.results = results;
}
/// <remarks/>
public bool Result
{
get
{
this.RaiseExceptionIfNecessary();
return ((bool)(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void DirectoryExistsCompletedEventHandler(object sender, DirectoryExistsCompletedEventArgs e);

View file

@ -846,8 +846,12 @@ namespace WebsitePanel.Providers.Utils
cat = null;
}
public static void DeleteDirectoryRecursive(DirectoryInfo treeRoot)
public static void DeleteDirectoryRecursive(string rootPath)
{
// This code is done this way to force folder deletion
// even if the folder was opened
DirectoryInfo treeRoot = new DirectoryInfo(rootPath);
if (treeRoot.Exists)
{
@ -855,7 +859,7 @@ namespace WebsitePanel.Providers.Utils
while (dirs.Length > 0)
{
foreach (DirectoryInfo dir in dirs)
DeleteDirectoryRecursive(dir);
DeleteDirectoryRecursive(dir.FullName);
dirs = treeRoot.GetDirectories();
}
@ -871,6 +875,7 @@ namespace WebsitePanel.Providers.Utils
Directory.Delete(treeRoot.FullName, true);
}
}
public static void SetQuotaLimitOnFolder(string cmdFilePath, string virtualFileClusterName, string folderPath, string quotaLimit, int mode, string wmiUserName, string wmiPassword)

View file

@ -550,6 +550,22 @@ namespace WebsitePanel.Server
throw;
}
}
[WebMethod, SoapHeader("settings")]
public void DeleteDirectoryRecursive(string rootPath)
{
try
{
Log.WriteStart("'{0}' DeleteDirectoryRecursive", ProviderSettings.ProviderName);
OsProvider.DeleteDirectoryRecursive(rootPath);
Log.WriteEnd("'{0}' DeleteDirectoryRecursive", ProviderSettings.ProviderName);
}
catch (Exception ex)
{
Log.WriteError(String.Format("'{0}' DeleteDirectoryRecursive", ProviderSettings.ProviderName), ex);
throw;
}
}
#endregion
#region Synchronizing